Imported Upstream version 21
[debian/pforth] / csrc / pf_main.c
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, Devid 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 #ifdef PF_NO_STDIO
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 #ifdef __MWERKS__
34         #include <console.h>
35         #include <sioux.h>
36 #endif
37
38 #ifndef TRUE
39 #define TRUE (1)
40 #define FALSE (0)
41 #endif
42
43 int main( int argc, char **argv )
44 {
45         const char *DicName = "pforth.dic";
46         const char *SourceName = NULL;
47         char IfInit = FALSE;
48         char *s;
49         int32 i;
50         int Result;
51
52 /* For Metroworks on Mac */
53         #ifdef __MWERKS__
54         argc = ccommand(&argv);
55         #endif
56
57 /* Parse command line. */
58         for( i=1; i<argc; i++ )
59         {
60                 s = argv[i];
61
62                 if( *s == '-' )
63                 {
64                         char c;
65                         s++; /* past '-' */
66                         c = *s++;
67                         switch(c)
68                         {
69                         case 'i':
70                                 IfInit = TRUE;
71                                 DicName = NULL;
72                                 break;
73                         case 'q':
74                                 pfSetQuiet( TRUE );
75                                 break;
76                         case 'd':
77                                 DicName = s;
78                                 break;
79                         default:
80                                 ERR(("Unrecognized option!\n"));
81                                 ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));
82                                 Result = 1;
83                                 goto on_error;
84                                 break;
85                         }
86                 }
87                 else
88                 {
89                         SourceName = s;
90                 }
91         }
92 /* Force Init */
93 #ifdef PF_INIT_MODE
94         IfInit = TRUE;
95         DicName = NULL;
96 #endif
97
98         Result = pfDoForth( DicName, SourceName, IfInit);
99
100 on_error:
101         return Result;
102 }