2011-05-01 02:50:00 -04:00
|
|
|
/* picoc main program - this varies depending on your operating system and
|
|
|
|
* how you're using picoc */
|
|
|
|
|
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
|
|
|
|
2011-02-17 02:11:20 -05:00
|
|
|
#define PICOC_STACK_SIZE (128*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;
|
2011-02-11 22:31:28 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocInitialise(StackSize);
|
2011-02-11 22:31:28 -05:00
|
|
|
|
|
|
|
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0)
|
|
|
|
{
|
|
|
|
DontRunMain = TRUE;
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocIncludeAllSystemHeaders();
|
2011-02-11 22:31:28 -05:00
|
|
|
ParamCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0)
|
|
|
|
{
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocIncludeAllSystemHeaders();
|
2011-05-01 02:50:00 -04:00
|
|
|
PicocParseInteractive(TRUE);
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 02:11:20 -05:00
|
|
|
if (PicocPlatformSetExitPoint())
|
2011-02-11 22:31:28 -05:00
|
|
|
{
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocCleanup();
|
|
|
|
return PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++)
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocPlatformScanFile(argv[ParamCount]);
|
2011-02-11 22:31:28 -05:00
|
|
|
|
|
|
|
if (!DontRunMain)
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocCallMain(argc - ParamCount, &argv[ParamCount]);
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocCleanup();
|
|
|
|
return PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
# ifdef SURVEYOR_HOST
|
2011-02-17 02:11:20 -05:00
|
|
|
# define HEAP_SIZE C_HEAPSIZE
|
2011-02-17 21:16:51 -05:00
|
|
|
# include <setjmp.h>
|
2011-02-18 17:59:12 -05:00
|
|
|
# include "../srv.h"
|
|
|
|
# include "../print.h"
|
|
|
|
# include "../string.h"
|
2011-02-15 16:06:47 -05:00
|
|
|
|
2011-02-17 21:16:51 -05:00
|
|
|
int picoc(char *SourceStr)
|
2011-02-15 16:06:47 -05:00
|
|
|
{
|
|
|
|
char *pos;
|
|
|
|
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocInitialise(HEAP_SIZE);
|
2011-02-11 23:23:37 -05:00
|
|
|
|
2011-02-15 16:06:47 -05:00
|
|
|
if (SourceStr)
|
2011-02-14 01:05:53 -05:00
|
|
|
{
|
2011-02-15 16:06:47 -05:00
|
|
|
for (pos = SourceStr; *pos != 0; pos++)
|
2011-02-14 01:05:53 -05:00
|
|
|
{
|
2011-02-15 16:06:47 -05:00
|
|
|
if (*pos == 0x1a)
|
2011-02-14 01:05:53 -05:00
|
|
|
{
|
2011-02-15 16:06:47 -05:00
|
|
|
*pos = 0x20;
|
2011-02-14 01:05:53 -05:00
|
|
|
}
|
|
|
|
}
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
2011-02-15 16:06:47 -05:00
|
|
|
|
2011-02-18 17:59:12 -05:00
|
|
|
PicocExitBuf[40] = 0;
|
2011-02-22 14:28:08 -05:00
|
|
|
PicocPlatformSetExitPoint();
|
2011-02-18 17:59:12 -05:00
|
|
|
if (PicocExitBuf[40]) {
|
2011-02-17 16:52:15 -05:00
|
|
|
printf("Leaving PicoC\n\r");
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocCleanup();
|
2011-02-18 17:59:12 -05:00
|
|
|
return PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
2011-02-15 16:06:47 -05:00
|
|
|
|
|
|
|
if (SourceStr)
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocParse("nofile", SourceStr, strlen(SourceStr), TRUE, TRUE, FALSE);
|
2011-02-15 16:06:47 -05:00
|
|
|
|
2011-02-17 02:11:20 -05:00
|
|
|
PicocParseInteractive();
|
|
|
|
PicocCleanup();
|
|
|
|
|
2011-02-18 17:59:12 -05:00
|
|
|
return PicocExitValue;
|
2011-02-11 22:31:28 -05:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|