From 57766aa28f20112fef2f80a736c142034696f2f9 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Fri, 18 Feb 2011 22:59:12 +0000 Subject: [PATCH] Changes from Brian Schmalz to bring the surveyor platform back to a working state after I broke everything :) git-svn-id: http://picoc.googlecode.com/svn/trunk@556 21eae674-98b7-11dd-bd71-f92a316d2d60 --- picoc.c | 15 ++++++++------- picoc.h | 6 ++++++ platform/library_surveyor.c | 5 +++-- platform/platform_surveyor.c | 23 ++++++++++++----------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/picoc.c b/picoc.c index d836270..ac21130 100644 --- a/picoc.c +++ b/picoc.c @@ -60,8 +60,9 @@ int main(int argc, char **argv) # ifdef SURVEYOR_HOST # define HEAP_SIZE C_HEAPSIZE # include - -extern int ExitBuf[]; +# include "../srv.h" +# include "../print.h" +# include "../string.h" int picoc(char *SourceStr) { @@ -80,12 +81,12 @@ int picoc(char *SourceStr) } } - ExitBuf[40] = 0; - setjmp(ExitBuf); - if (ExitBuf[40]) { + PicocExitBuf[40] = 0; + setjmp(PicocExitBuf); + if (PicocExitBuf[40]) { printf("Leaving PicoC\n\r"); PicocCleanup(); - return ExitValue; + return PicocExitValue; } if (SourceStr) @@ -94,7 +95,7 @@ int picoc(char *SourceStr) PicocParseInteractive(); PicocCleanup(); - return ExitValue; + return PicocExitValue; } # endif #endif diff --git a/picoc.h b/picoc.h index f8ab998..56497fd 100644 --- a/picoc.h +++ b/picoc.h @@ -25,6 +25,12 @@ extern jmp_buf PicocExitBuf; #define PicocPlatformSetExitPoint() setjmp(PicocExitBuf) #endif +#ifdef SURVEYOR_HOST +/* mark where to end the program for platforms which require this */ +extern int PicocExitBuf[]; + +#define PicocPlatformSetExitPoint() setjmp(PicocExitBuf) +#endif /* parse.c */ void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource); diff --git a/platform/library_surveyor.c b/platform/library_surveyor.c index 180ae9b..c620406 100644 --- a/platform/library_surveyor.c +++ b/platform/library_surveyor.c @@ -1,4 +1,5 @@ #include "../interpreter.h" +#include "../picoc.h" static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2, Iy1, Iy2, Iu1, Iu2, Iv1, Iv2; static int Cxmin, Cxmax, Cymin, Cymax; @@ -850,8 +851,8 @@ void Cautorun (struct ParseState *Parser, struct Value *ReturnValue, struct Valu if (getchar(&ch)) { if (ch == 0x1B) { // if ESC found, exit picoC printf("found ESC\r\n"); - ExitBuf[40] = 1; - longjmp(ExitBuf, 1); + PicocExitBuf[40] = 1; + longjmp(PicocExitBuf, 1); } } } diff --git a/platform/platform_surveyor.c b/platform/platform_surveyor.c index 3bb7193..1557747 100644 --- a/platform/platform_surveyor.c +++ b/platform/platform_surveyor.c @@ -1,5 +1,8 @@ #include "../interpreter.h" +#include "../picoc.h" +/* mark where to end the program for platforms which require this */ +int PicocExitBuf[41]; /* deallocate any storage */ void PlatformCleanup() @@ -11,12 +14,12 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt) { int ix; char ch, *cp; - + printf(Prompt); - + ix = 0; cp = 0; - + // If the first character is \n or \r, eat it ch = getch(); if (ch == '\n' || ch == '\r') @@ -24,10 +27,11 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt) // And get the next character ch = getch(); } - + while (ix++ < MaxLen) { + if (ch == 0x1B || ch == 0x03) { // ESC character or ctrl-c (to avoid problem with TeraTerm) - exit - printf("Leaving PicoC\n"); + printf("Leaving PicoC\n"); return NULL; } if (ch == '\n') { @@ -57,14 +61,11 @@ int PlatformGetCharacter() return getch(); } -/* mark where to end the program for platforms which require this */ -int ExitBuf[41]; - /* exit the program */ void PlatformExit(int RetVal) { - ExitValue = RetVal; - ExitBuf[40] = 1; - longjmp(ExitBuf, 1); + PicocExitValue = RetVal; + PicocExitBuf[40] = 1; + longjmp(PicocExitBuf, 1); }