2011-05-01 02:50:00 -04:00
|
|
|
/* picoc main program - this varies depending on your operating system and
|
|
|
|
* how you're using picoc */
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2011-02-17 21:16:51 -05:00
|
|
|
/* include only picoc.h here - should be able to use it with only the external interfaces, no internals from interpreter.h */
|
2011-02-11 22:31:28 -05:00
|
|
|
#include "picoc.h"
|
|
|
|
|
|
|
|
/* platform-dependent code for running programs is in this file */
|
|
|
|
|
2011-10-05 06:57:24 -04:00
|
|
|
#if defined(UNIX_HOST) || defined(WIN32)
|
2011-02-17 02:11:20 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-02-11 22:31:28 -05:00
|
|
|
|
2015-06-09 03:45:00 -04:00
|
|
|
/* Override via STACKSIZE environment variable */
|
|
|
|
#define PICOC_STACK_SIZE (1024*1024) /* space for the the stack */
|
2011-02-11 22:31:28 -05:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ParamCount = 1;
|
|
|
|
int DontRunMain = FALSE;
|
2011-02-17 02:11:20 -05:00
|
|
|
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
2012-09-22 01:11:44 -04:00
|
|
|
Picoc pc;
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2015-06-07 00:40:08 -04:00
|
|
|
if (argc < 2) {
|
2015-06-06 23:37:28 -04:00
|
|
|
printf(PICOC_VERSION " \n"
|
2015-06-06 23:48:35 -04:00
|
|
|
"Format: picoc <file1.c>... [- <arg1>...] : run a program (calls main() to start it)\n"
|
|
|
|
" picoc -s <file1.c>... [- <arg1>...] : script mode - runs the program without calling main()\n"
|
2015-06-07 02:28:10 -04:00
|
|
|
" picoc -i : interactive mode\n");
|
2011-02-11 22:31:28 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocInitialise(&pc, StackSize);
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2015-06-07 00:40:08 -04:00
|
|
|
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0) {
|
2011-02-11 22:31:28 -05:00
|
|
|
DontRunMain = TRUE;
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocIncludeAllSystemHeaders(&pc);
|
2011-02-11 22:31:28 -05:00
|
|
|
ParamCount++;
|
|
|
|
}
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2015-06-07 00:40:08 -04:00
|
|
|
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0) {
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocIncludeAllSystemHeaders(&pc);
|
|
|
|
PicocParseInteractive(&pc);
|
2015-06-07 00:40:08 -04:00
|
|
|
} else {
|
|
|
|
if (PicocPlatformSetExitPoint(&pc)) {
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocCleanup(&pc);
|
|
|
|
return pc.PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2011-02-11 22:31:28 -05:00
|
|
|
for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++)
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocPlatformScanFile(&pc, argv[ParamCount]);
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2011-02-11 22:31:28 -05:00
|
|
|
if (!DontRunMain)
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocCallMain(&pc, argc - ParamCount, &argv[ParamCount]);
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
2015-06-06 23:37:28 -04:00
|
|
|
|
2012-09-22 01:11:44 -04:00
|
|
|
PicocCleanup(&pc);
|
|
|
|
return pc.PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
#endif
|