Add -m32 and -x c to Makefile for 64-bit Snow Leopard.
[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
970d32b5 46
47static const char *gErrorMsg32Bit = "ERROR - A long is not 4 bytes. Are we running on a 64-bit machine?!\n";
bb6b2dcd 48\r
49#ifdef PF_EMBEDDED\r
50int main( void )\r
51{\r
52 char IfInit = 0; \r
53 const char *DicName = NULL;\r
970d32b5 54 const char *SourceName = NULL;
55 // Check to make sure we are running in 32-bit mode.
56 if( sizeof(long) != 4 )
57 {
58 pfMessage(gErrorMsg32Bit);
59 return 1;
60 }\r
bb6b2dcd 61 pfMessage("\npForth Embedded\n");\r
62 return pfDoForth( DicName, SourceName, IfInit);\r
63}\r
64#else\r
65\r
66int main( int argc, char **argv )\r
67{\r
68#ifdef PF_STATIC_DIC\r
69 const char *DicName = NULL;\r
70#else /* PF_STATIC_DIC */\r
71 const char *DicName = PF_DEFAULT_DICTIONARY;\r
72#endif /* !PF_STATIC_DIC */\r
73\r
74 const char *SourceName = NULL;\r
75 char IfInit = FALSE;\r
76 char *s;\r
77 int32 i;\r
78 int Result;\r
970d32b5 79
80 // Check to make sure we are running in 32-bit mode.
81 if( sizeof(long) != 4 )
82 {
83 ERR((gErrorMsg32Bit));
84 return 1;
85 }
86 \r
bb6b2dcd 87/* For Metroworks on Mac */\r
88#ifdef __MWERKS__\r
89 argc = ccommand(&argv);\r
90#endif\r
91\r
92/* Parse command line. */\r
93 for( i=1; i<argc; i++ )\r
94 {\r
95 s = argv[i];\r
96\r
97 if( *s == '-' )\r
98 {\r
99 char c;\r
100 s++; /* past '-' */\r
101 c = *s++;\r
102 switch(c)\r
103 {\r
104 case 'i':\r
105 IfInit = TRUE;\r
106 DicName = NULL;\r
107 break;\r
b3651f38 108 \r
bb6b2dcd 109 case 'q':\r
110 pfSetQuiet( TRUE );\r
111 break;\r
b3651f38 112 \r
bb6b2dcd 113 case 'd':\r
114 if( *s != '\0' ) DicName = s;\r
b3651f38 115 // Allow space after -d (Thanks Aleksej Saushev)\r
116 // Make sure there is another argument.\r
117 else if( (i+1) < argc )\r
118 {\r
119 DicName = argv[++i];\r
120 }\r
121 if (DicName == NULL || *DicName == '\0')\r
122 {\r
123 DicName = PF_DEFAULT_DICTIONARY;\r
124 }\r
bb6b2dcd 125 break;\r
b3651f38 126 \r
bb6b2dcd 127 default:\r
128 ERR(("Unrecognized option!\n"));\r
129 ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));\r
130 Result = 1;\r
131 goto on_error;\r
132 break;\r
133 }\r
134 }\r
135 else\r
136 {\r
137 SourceName = s;\r
138 }\r
139 }\r
140/* Force Init */\r
141#ifdef PF_INIT_MODE\r
142 IfInit = TRUE;\r
143 DicName = NULL;\r
144#endif\r
145\r
146 Result = pfDoForth( DicName, SourceName, IfInit);\r
147\r
148on_error:\r
149 return Result;\r
150}\r
151\r
152#endif /* PF_EMBEDDED */\r
153\r
154\r