Fixed POSIX IO, (ACCEPT) now emits SPACE at end of line.
[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
52 const char *SourceName = NULL;\r
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
69 int32 i;\r
70 int Result;\r
71\r
72/* For Metroworks on Mac */\r
73#ifdef __MWERKS__\r
74 argc = ccommand(&argv);\r
75#endif\r
76\r
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
93 case 'q':\r
94 pfSetQuiet( TRUE );\r
95 break;\r
96 case 'd':\r
97 if( *s != '\0' ) DicName = s;\r
98 else DicName = PF_DEFAULT_DICTIONARY;\r
99 break;\r
100 default:\r
101 ERR(("Unrecognized option!\n"));\r
102 ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));\r
103 Result = 1;\r
104 goto on_error;\r
105 break;\r
106 }\r
107 }\r
108 else\r
109 {\r
110 SourceName = s;\r
111 }\r
112 }\r
113/* Force Init */\r
114#ifdef PF_INIT_MODE\r
115 IfInit = TRUE;\r
116 DicName = NULL;\r
117#endif\r
118\r
119 Result = pfDoForth( DicName, SourceName, IfInit);\r
120\r
121on_error:\r
122 return Result;\r
123}\r
124\r
125#endif /* PF_EMBEDDED */\r
126\r
127\r