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