bb6b2dcd |
1 | /* @(#) pf_main.c 98/01/26 1.2 */\r |
2 | /***************************************************************\r |
3 | ** Forth based on 'C'\r |
4 | **\r |
5 | ** main() routine that demonstrates how to call PForth as\r |
6 | ** a module from 'C' based application.\r |
7 | ** Customize this as needed for your application.\r |
8 | **\r |
9 | ** Author: Phil Burk\r |
10 | ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom\r |
11 | **\r |
12 | ** The pForth software code is dedicated to the public domain,\r |
13 | ** and any third party may reproduce, distribute and modify\r |
14 | ** the pForth software code or any derivative works thereof\r |
15 | ** without any compensation or license. The pForth software\r |
16 | ** code is provided on an "as is" basis without any warranty\r |
17 | ** of any kind, including, without limitation, the implied\r |
18 | ** warranties of merchantability and fitness for a particular\r |
19 | ** purpose and their equivalents under the laws of any jurisdiction.\r |
20 | **\r |
21 | ***************************************************************/\r |
22 | \r |
23 | #if (defined(PF_NO_STDIO) || defined(PF_EMBEDDED))\r |
24 | #define NULL ((void *) 0)\r |
25 | #define ERR(msg) /* { printf msg; } */\r |
26 | #else\r |
27 | #include <stdio.h>\r |
28 | #define ERR(msg) { printf msg; }\r |
29 | #endif\r |
30 | \r |
31 | #include "pforth.h"\r |
32 | \r |
33 | #ifndef PF_DEFAULT_DICTIONARY\r |
34 | #define PF_DEFAULT_DICTIONARY "pforth.dic"\r |
35 | #endif\r |
36 | \r |
37 | #ifdef __MWERKS__\r |
38 | #include <console.h>\r |
39 | #include <sioux.h>\r |
40 | #endif\r |
41 | \r |
42 | #ifndef TRUE\r |
43 | #define TRUE (1)\r |
44 | #define FALSE (0)\r |
45 | #endif\r |
46 | \r |
47 | #ifdef PF_EMBEDDED\r |
48 | int main( void )\r |
49 | {\r |
50 | char IfInit = 0; \r |
51 | const char *DicName = NULL;\r |
1cb310e6 |
52 | const char *SourceName = NULL;\r |
bb6b2dcd |
53 | pfMessage("\npForth Embedded\n");\r |
54 | return pfDoForth( DicName, SourceName, IfInit);\r |
55 | }\r |
56 | #else\r |
57 | \r |
58 | int main( int argc, char **argv )\r |
59 | {\r |
60 | #ifdef PF_STATIC_DIC\r |
61 | const char *DicName = NULL;\r |
62 | #else /* PF_STATIC_DIC */\r |
63 | const char *DicName = PF_DEFAULT_DICTIONARY;\r |
64 | #endif /* !PF_STATIC_DIC */\r |
65 | \r |
66 | const char *SourceName = NULL;\r |
67 | char IfInit = FALSE;\r |
68 | char *s;\r |
1cb310e6 |
69 | cell_t i;\r |
bb6b2dcd |
70 | int Result;\r |
1cb310e6 |
71 | \r |
bb6b2dcd |
72 | /* For Metroworks on Mac */\r |
73 | #ifdef __MWERKS__\r |
74 | argc = ccommand(&argv);\r |
75 | #endif\r |
1cb310e6 |
76 | \r |
a80283a7 |
77 | pfSetQuiet( FALSE );\r |
bb6b2dcd |
78 | /* Parse command line. */\r |
79 | for( i=1; i<argc; i++ )\r |
80 | {\r |
81 | s = argv[i];\r |
82 | \r |
83 | if( *s == '-' )\r |
84 | {\r |
85 | char c;\r |
86 | s++; /* past '-' */\r |
87 | c = *s++;\r |
88 | switch(c)\r |
89 | {\r |
90 | case 'i':\r |
91 | IfInit = TRUE;\r |
92 | DicName = NULL;\r |
93 | break;\r |
b3651f38 |
94 | \r |
bb6b2dcd |
95 | case 'q':\r |
96 | pfSetQuiet( TRUE );\r |
97 | break;\r |
b3651f38 |
98 | \r |
bb6b2dcd |
99 | case 'd':\r |
100 | if( *s != '\0' ) DicName = s;\r |
a80283a7 |
101 | /* Allow space after -d (Thanks Aleksej Saushev) */\r |
102 | /* Make sure there is another argument. */\r |
b3651f38 |
103 | else if( (i+1) < argc )\r |
104 | {\r |
105 | DicName = argv[++i];\r |
106 | }\r |
107 | if (DicName == NULL || *DicName == '\0')\r |
108 | {\r |
109 | DicName = PF_DEFAULT_DICTIONARY;\r |
110 | }\r |
bb6b2dcd |
111 | break;\r |
b3651f38 |
112 | \r |
bb6b2dcd |
113 | default:\r |
114 | ERR(("Unrecognized option!\n"));\r |
115 | ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));\r |
116 | Result = 1;\r |
117 | goto on_error;\r |
118 | break;\r |
119 | }\r |
120 | }\r |
121 | else\r |
122 | {\r |
123 | SourceName = s;\r |
124 | }\r |
125 | }\r |
126 | /* Force Init */\r |
127 | #ifdef PF_INIT_MODE\r |
128 | IfInit = TRUE;\r |
129 | DicName = NULL;\r |
130 | #endif\r |
131 | \r |
e2531e83 |
132 | #ifdef PF_UNIT_TEST\r |
133 | if( (Result = pfUnitTest()) != 0 )\r |
134 | {\r |
135 | ERR(("pForth stopping on unit test failure.\n"));\r |
136 | goto on_error;\r |
137 | }\r |
138 | #endif\r |
139 | \r |
bb6b2dcd |
140 | Result = pfDoForth( DicName, SourceName, IfInit);\r |
141 | \r |
142 | on_error:\r |
143 | return Result;\r |
144 | }\r |
145 | \r |
146 | #endif /* PF_EMBEDDED */\r |
147 | \r |
148 | \r |