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 | ** | |
1f99f95d S |
12 | ** Permission to use, copy, modify, and/or distribute this |
13 | ** software for any purpose with or without fee is hereby granted. | |
14 | ** | |
15 | ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | |
16 | ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | |
17 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL | |
18 | ** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR | |
19 | ** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING | |
20 | ** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF | |
21 | ** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 | ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
8e9db35f PB |
23 | ** |
24 | ***************************************************************/ | |
25 | ||
26 | #if (defined(PF_NO_STDIO) || defined(PF_EMBEDDED)) | |
27 | #define NULL ((void *) 0) | |
28 | #define ERR(msg) /* { printf msg; } */ | |
29 | #else | |
30 | #include <stdio.h> | |
31 | #define ERR(msg) { printf msg; } | |
32 | #endif | |
33 | ||
34 | #include "pforth.h" | |
35 | ||
36 | #ifndef PF_DEFAULT_DICTIONARY | |
37 | #define PF_DEFAULT_DICTIONARY "pforth.dic" | |
38 | #endif | |
39 | ||
40 | #ifdef __MWERKS__ | |
41 | #include <console.h> | |
42 | #include <sioux.h> | |
43 | #endif | |
44 | ||
45 | #ifndef TRUE | |
46 | #define TRUE (1) | |
47 | #define FALSE (0) | |
48 | #endif | |
49 | ||
50 | #ifdef PF_EMBEDDED | |
51 | int main( void ) | |
52 | { | |
53 | char IfInit = 0; | |
54 | const char *DicName = NULL; | |
55 | const char *SourceName = NULL; | |
56 | pfMessage("\npForth Embedded\n"); | |
57 | return pfDoForth( DicName, SourceName, IfInit); | |
58 | } | |
59 | #else | |
60 | ||
61 | int main( int argc, char **argv ) | |
62 | { | |
63 | #ifdef PF_STATIC_DIC | |
64 | const char *DicName = NULL; | |
65 | #else /* PF_STATIC_DIC */ | |
66 | const char *DicName = PF_DEFAULT_DICTIONARY; | |
67 | #endif /* !PF_STATIC_DIC */ | |
68 | ||
69 | const char *SourceName = NULL; | |
70 | char IfInit = FALSE; | |
71 | char *s; | |
72 | cell_t i; | |
529bb4e2 | 73 | ThrowCode Result; |
8e9db35f PB |
74 | |
75 | /* For Metroworks on Mac */ | |
76 | #ifdef __MWERKS__ | |
77 | argc = ccommand(&argv); | |
78 | #endif | |
79 | ||
80 | pfSetQuiet( FALSE ); | |
81 | /* Parse command line. */ | |
82 | for( i=1; i<argc; i++ ) | |
83 | { | |
84 | s = argv[i]; | |
85 | ||
86 | if( *s == '-' ) | |
87 | { | |
88 | char c; | |
89 | s++; /* past '-' */ | |
90 | c = *s++; | |
91 | switch(c) | |
92 | { | |
93 | case 'i': | |
94 | IfInit = TRUE; | |
95 | DicName = NULL; | |
96 | break; | |
97 | ||
98 | case 'q': | |
99 | pfSetQuiet( TRUE ); | |
100 | break; | |
101 | ||
102 | case 'd': | |
103 | if( *s != '\0' ) DicName = s; | |
104 | /* Allow space after -d (Thanks Aleksej Saushev) */ | |
105 | /* Make sure there is another argument. */ | |
106 | else if( (i+1) < argc ) | |
107 | { | |
108 | DicName = argv[++i]; | |
109 | } | |
110 | if (DicName == NULL || *DicName == '\0') | |
111 | { | |
112 | DicName = PF_DEFAULT_DICTIONARY; | |
113 | } | |
114 | break; | |
115 | ||
116 | default: | |
117 | ERR(("Unrecognized option!\n")); | |
118 | ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n")); | |
119 | Result = 1; | |
120 | goto on_error; | |
121 | break; | |
122 | } | |
123 | } | |
124 | else | |
125 | { | |
126 | SourceName = s; | |
127 | } | |
128 | } | |
129 | /* Force Init */ | |
130 | #ifdef PF_INIT_MODE | |
131 | IfInit = TRUE; | |
132 | DicName = NULL; | |
133 | #endif | |
134 | ||
135 | #ifdef PF_UNIT_TEST | |
136 | if( (Result = pfUnitTest()) != 0 ) | |
137 | { | |
138 | ERR(("pForth stopping on unit test failure.\n")); | |
139 | goto on_error; | |
140 | } | |
141 | #endif | |
142 | ||
143 | Result = pfDoForth( DicName, SourceName, IfInit); | |
144 | ||
145 | on_error: | |
529bb4e2 | 146 | return (int)Result; |
8e9db35f PB |
147 | } |
148 | ||
149 | #endif /* PF_EMBEDDED */ | |
150 | ||
151 |