V25 with 64-bit support
[pforth] / csrc / pf_main.c
CommitLineData
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
48int 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
58int 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
bb6b2dcd 77/* Parse command line. */\r
78 for( i=1; i<argc; i++ )\r
79 {\r
80 s = argv[i];\r
81\r
82 if( *s == '-' )\r
83 {\r
84 char c;\r
85 s++; /* past '-' */\r
86 c = *s++;\r
87 switch(c)\r
88 {\r
89 case 'i':\r
90 IfInit = TRUE;\r
91 DicName = NULL;\r
92 break;\r
b3651f38 93 \r
bb6b2dcd 94 case 'q':\r
95 pfSetQuiet( TRUE );\r
96 break;\r
b3651f38 97 \r
bb6b2dcd 98 case 'd':\r
99 if( *s != '\0' ) DicName = s;\r
b3651f38 100 // Allow space after -d (Thanks Aleksej Saushev)\r
101 // Make sure there is another argument.\r
102 else if( (i+1) < argc )\r
103 {\r
104 DicName = argv[++i];\r
105 }\r
106 if (DicName == NULL || *DicName == '\0')\r
107 {\r
108 DicName = PF_DEFAULT_DICTIONARY;\r
109 }\r
bb6b2dcd 110 break;\r
b3651f38 111 \r
bb6b2dcd 112 default:\r
113 ERR(("Unrecognized option!\n"));\r
114 ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));\r
115 Result = 1;\r
116 goto on_error;\r
117 break;\r
118 }\r
119 }\r
120 else\r
121 {\r
122 SourceName = s;\r
123 }\r
124 }\r
125/* Force Init */\r
126#ifdef PF_INIT_MODE\r
127 IfInit = TRUE;\r
128 DicName = NULL;\r
129#endif\r
130\r
131 Result = pfDoForth( DicName, SourceName, IfInit);\r
132\r
133on_error:\r
134 return Result;\r
135}\r
136\r
137#endif /* PF_EMBEDDED */\r
138\r
139\r