forked from zsaleeba/picoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picoc.c
105 lines (86 loc) · 2.68 KB
/
picoc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* picoc main program - this varies depending on your operating system and
* how you're using picoc */
/* include only picoc.h here - should be able to use it with only the external interfaces, no internals from interpreter.h */
#include "picoc.h"
/* platform-dependent code for running programs is in this file */
#if defined(UNIX_HOST) || defined(WIN32)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define PICOC_STACK_SIZE (128*1024) /* space for the the stack */
int main(int argc, char **argv)
{
int ParamCount = 1;
int DontRunMain = FALSE;
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
Picoc pc;
if (argc < 2)
{
printf("Format: picoc <csource1.c>... [- <arg1>...] : run a program (calls main() to start it)\n"
" picoc -s <csource1.c>... [- <arg1>...] : script mode - runs the program without calling main()\n"
" picoc -i : interactive mode\n");
exit(1);
}
PicocInitialise(&pc, StackSize);
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0)
{
DontRunMain = TRUE;
PicocIncludeAllSystemHeaders(&pc);
ParamCount++;
}
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0)
{
PicocIncludeAllSystemHeaders(&pc);
PicocParseInteractive(&pc);
}
else
{
if (PicocPlatformSetExitPoint(&pc))
{
PicocCleanup(&pc);
return pc.PicocExitValue;
}
for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++)
PicocPlatformScanFile(&pc, argv[ParamCount]);
if (!DontRunMain)
PicocCallMain(&pc, argc - ParamCount, &argv[ParamCount]);
}
PicocCleanup(&pc);
return pc.PicocExitValue;
}
#else
# ifdef SURVEYOR_HOST
# define HEAP_SIZE C_HEAPSIZE
# include <setjmp.h>
# include "../srv.h"
# include "../print.h"
# include "../string.h"
int picoc(char *SourceStr)
{
char *pos;
PicocInitialise(HEAP_SIZE);
if (SourceStr)
{
for (pos = SourceStr; *pos != 0; pos++)
{
if (*pos == 0x1a)
{
*pos = 0x20;
}
}
}
PicocExitBuf[40] = 0;
PicocPlatformSetExitPoint();
if (PicocExitBuf[40]) {
printf("Leaving PicoC\n\r");
PicocCleanup();
return PicocExitValue;
}
if (SourceStr)
PicocParse("nofile", SourceStr, strlen(SourceStr), TRUE, TRUE, FALSE);
PicocParseInteractive();
PicocCleanup();
return PicocExitValue;
}
# endif
#endif