From df9129b3553e861b55d0041df01aba078d276e7f Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 27 Jul 2010 15:35:25 +0000 Subject: [PATCH] Calls to exit(n) now return the exit value n to the command line. This fixes issue 100. git-svn-id: http://picoc.googlecode.com/svn/trunk@478 21eae674-98b7-11dd-bd71-f92a316d2d60 --- picoc.c | 5 ++--- picoc.h | 3 ++- platform.c | 3 +++ platform/platform_unix.c | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/picoc.c b/picoc.c index 42b7dd7..d32674f 100644 --- a/picoc.c +++ b/picoc.c @@ -3,7 +3,6 @@ #define CALL_MAIN_NO_ARGS "main();" #define CALL_MAIN_WITH_ARGS "main(__argc,__argv);" - /* initialise everything */ void Initialise(int StackSize) { @@ -93,7 +92,7 @@ int main(int argc, char **argv) if (PlatformSetExitPoint()) { Cleanup(); - return 1; + return ExitValue; } for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++) @@ -125,7 +124,7 @@ int picoc(char *SourceStr) if (ExitBuf[40]) { printf("leaving picoC\n\r"); Cleanup(); - return 1; + return ExitValue; } if (SourceStr) diff --git a/picoc.h b/picoc.h index fc27f7c..efa5244 100644 --- a/picoc.h +++ b/picoc.h @@ -428,10 +428,11 @@ void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *); void PlatformErrorPrefix(struct ParseState *Parser); void PlatformPrintf(const char *Format, ...); void PlatformVPrintf(const char *Format, va_list Args); -void PlatformExit(); +void PlatformExit(int ExitVal); void PlatformLibraryInit(); void Initialise(); void Cleanup(); +extern int ExitValue; /* include.c */ void IncludeInit(); diff --git a/platform.c b/platform.c index b4b26f9..1359f08 100644 --- a/platform.c +++ b/platform.c @@ -1,5 +1,8 @@ #include "picoc.h" +/* the value passed to exit() */ +int ExitValue = 0; + void PrintSourceTextErrorLine(const char *FileName, const char *SourceText, int Line, int CharacterPos) { int LineCount; diff --git a/platform/platform_unix.c b/platform/platform_unix.c index 50f6b57..9654f34 100644 --- a/platform/platform_unix.c +++ b/platform/platform_unix.c @@ -106,8 +106,9 @@ void PlatformScanFile(const char *FileName) jmp_buf ExitBuf; /* exit the program */ -void PlatformExit() +void PlatformExit(int RetVal) { + ExitValue = RetVal; longjmp(ExitBuf, 1); }