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
This commit is contained in:
zik.saleeba 2010-07-27 15:35:25 +00:00
parent 8e02f32095
commit df9129b355
4 changed files with 9 additions and 5 deletions

View file

@ -3,7 +3,6 @@
#define CALL_MAIN_NO_ARGS "main();" #define CALL_MAIN_NO_ARGS "main();"
#define CALL_MAIN_WITH_ARGS "main(__argc,__argv);" #define CALL_MAIN_WITH_ARGS "main(__argc,__argv);"
/* initialise everything */ /* initialise everything */
void Initialise(int StackSize) void Initialise(int StackSize)
{ {
@ -93,7 +92,7 @@ int main(int argc, char **argv)
if (PlatformSetExitPoint()) if (PlatformSetExitPoint())
{ {
Cleanup(); Cleanup();
return 1; return ExitValue;
} }
for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++) for (; ParamCount < argc && strcmp(argv[ParamCount], "-") != 0; ParamCount++)
@ -125,7 +124,7 @@ int picoc(char *SourceStr)
if (ExitBuf[40]) { if (ExitBuf[40]) {
printf("leaving picoC\n\r"); printf("leaving picoC\n\r");
Cleanup(); Cleanup();
return 1; return ExitValue;
} }
if (SourceStr) if (SourceStr)

View file

@ -428,10 +428,11 @@ void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *);
void PlatformErrorPrefix(struct ParseState *Parser); void PlatformErrorPrefix(struct ParseState *Parser);
void PlatformPrintf(const char *Format, ...); void PlatformPrintf(const char *Format, ...);
void PlatformVPrintf(const char *Format, va_list Args); void PlatformVPrintf(const char *Format, va_list Args);
void PlatformExit(); void PlatformExit(int ExitVal);
void PlatformLibraryInit(); void PlatformLibraryInit();
void Initialise(); void Initialise();
void Cleanup(); void Cleanup();
extern int ExitValue;
/* include.c */ /* include.c */
void IncludeInit(); void IncludeInit();

View file

@ -1,5 +1,8 @@
#include "picoc.h" #include "picoc.h"
/* the value passed to exit() */
int ExitValue = 0;
void PrintSourceTextErrorLine(const char *FileName, const char *SourceText, int Line, int CharacterPos) void PrintSourceTextErrorLine(const char *FileName, const char *SourceText, int Line, int CharacterPos)
{ {
int LineCount; int LineCount;

View file

@ -106,8 +106,9 @@ void PlatformScanFile(const char *FileName)
jmp_buf ExitBuf; jmp_buf ExitBuf;
/* exit the program */ /* exit the program */
void PlatformExit() void PlatformExit(int RetVal)
{ {
ExitValue = RetVal;
longjmp(ExitBuf, 1); longjmp(ExitBuf, 1);
} }