From cb4c34b506b37ae223c69c80236a248e84c907fa Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Wed, 5 Oct 2011 10:57:24 +0000 Subject: [PATCH] Created Visual Studio 2011 project. Modified to compile under Visual Studio 2011. git-svn-id: http://picoc.googlecode.com/svn/trunk@572 21eae674-98b7-11dd-bd71-f92a316d2d60 --- cstdlib/stdio.c | 22 +++++- cstdlib/string.c | 12 +++- cstdlib/time.c | 20 +++--- expression.c | 8 +-- include.c | 8 ++- lex.c | 2 +- msvc/picoc/picoc.sln | 20 ++++++ msvc/picoc/picoc.vcxproj | 111 +++++++++++++++++++++++++++++++ msvc/picoc/picoc.vcxproj.filters | 99 +++++++++++++++++++++++++++ picoc.c | 2 +- picoc.h | 2 +- platform.c | 4 +- platform.h | 103 ++++++++++++++++------------ platform/library_msvc.c | 5 ++ platform/platform_msvc.c | 80 ++++++++++++++++++++++ 15 files changed, 432 insertions(+), 66 deletions(-) create mode 100644 msvc/picoc/picoc.sln create mode 100644 msvc/picoc/picoc.vcxproj create mode 100644 msvc/picoc/picoc.vcxproj.filters create mode 100644 platform/library_msvc.c create mode 100644 platform/platform_msvc.c diff --git a/cstdlib/stdio.c b/cstdlib/stdio.c index 4a79a8d..60b69e9 100644 --- a/cstdlib/stdio.c +++ b/cstdlib/stdio.c @@ -114,8 +114,12 @@ void StdioFprintfWord(StdOutStream *Stream, const char *Format, unsigned int Val else if (Stream->StrOutLen >= 0) { - int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); - Stream->StrOutPtr += CCount; +#ifndef WIN32 + int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); +#else + int CCount = _snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); +#endif + Stream->StrOutPtr += CCount; Stream->StrOutLen -= CCount; Stream->CharCount += CCount; } @@ -135,8 +139,12 @@ void StdioFprintfFP(StdOutStream *Stream, const char *Format, double Value) else if (Stream->StrOutLen >= 0) { +#ifndef WIN32 int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); - Stream->StrOutPtr += CCount; +#else + int CCount = _snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); +#endif + Stream->StrOutPtr += CCount; Stream->StrOutLen -= CCount; Stream->CharCount += CCount; } @@ -156,7 +164,11 @@ void StdioFprintfPointer(StdOutStream *Stream, const char *Format, void *Value) else if (Stream->StrOutLen >= 0) { +#ifndef WIN32 int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); +#else + int CCount = _snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value); +#endif Stream->StrOutPtr += CCount; Stream->StrOutLen -= CCount; Stream->CharCount += CCount; @@ -414,7 +426,11 @@ void StdioFerror(struct ParseState *Parser, struct Value *ReturnValue, struct Va void StdioFileno(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { +#ifndef WIN32 ReturnValue->Val->Integer = fileno(Param[0]->Val->Pointer); +#else + ReturnValue->Val->Integer = _fileno(Param[0]->Val->Pointer); +#endif } void StdioFflush(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) diff --git a/cstdlib/string.c b/cstdlib/string.c index 88f349f..8b0c7a1 100644 --- a/cstdlib/string.c +++ b/cstdlib/string.c @@ -35,6 +35,7 @@ void StringStrncat(struct ParseState *Parser, struct Value *ReturnValue, struct ReturnValue->Val->Pointer = strncat(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Integer); } +#ifndef WIN32 void StringIndex(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Pointer = index(Param[0]->Val->Pointer, Param[1]->Val->Integer); @@ -44,6 +45,7 @@ void StringRindex(struct ParseState *Parser, struct Value *ReturnValue, struct V { ReturnValue->Val->Pointer = rindex(Param[0]->Val->Pointer, Param[1]->Val->Integer); } +#endif void StringStrlen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { @@ -125,6 +127,7 @@ void StringStrxfrm(struct ParseState *Parser, struct Value *ReturnValue, struct ReturnValue->Val->Integer = strxfrm(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Integer); } +#ifndef WIN32 void StringStrdup(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Pointer = strdup(Param[0]->Val->Pointer); @@ -134,12 +137,15 @@ void StringStrtok_r(struct ParseState *Parser, struct Value *ReturnValue, struct { ReturnValue->Val->Pointer = strtok_r(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Pointer); } +#endif /* all string.h functions */ struct LibraryFunction StringFunctions[] = { - { StringIndex, "char *index(char *,int);" }, +#ifndef WIN32 + { StringIndex, "char *index(char *,int);" }, { StringRindex, "char *rindex(char *,int);" }, +#endif { StringMemcpy, "void *memcpy(void *,void *,int);" }, { StringMemmove, "void *memmove(void *,void *,int);" }, { StringMemchr, "void *memchr(char *,int,int);" }, @@ -162,8 +168,10 @@ struct LibraryFunction StringFunctions[] = { StringStrstr, "char *strstr(char *,char *);" }, { StringStrtok, "char *strtok(char *,char *);" }, { StringStrxfrm, "int strxfrm(char *,char *,int);" }, - { StringStrdup, "char *strdup(char *);" }, +#ifndef WIN32 + { StringStrdup, "char *strdup(char *);" }, { StringStrtok_r, "char *strtok_r(char *,char *,char **);" }, +#endif { NULL, NULL } }; diff --git a/cstdlib/time.c b/cstdlib/time.c index 0406679..1db0f31 100644 --- a/cstdlib/time.c +++ b/cstdlib/time.c @@ -41,11 +41,6 @@ void StdGmtime(struct ParseState *Parser, struct Value *ReturnValue, struct Valu ReturnValue->Val->Pointer = gmtime(Param[0]->Val->Pointer); } -void StdGmtime_r(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) -{ - ReturnValue->Val->Pointer = gmtime_r(Param[0]->Val->Pointer, Param[1]->Val->Pointer); -} - void StdLocaltime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Pointer = localtime(Param[0]->Val->Pointer); @@ -53,12 +48,12 @@ void StdLocaltime(struct ParseState *Parser, struct Value *ReturnValue, struct V void StdMktime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->Integer = mktime(Param[0]->Val->Pointer); + ReturnValue->Val->Integer = (int)mktime(Param[0]->Val->Pointer); } void StdTime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->Integer = time(Param[0]->Val->Pointer); + ReturnValue->Val->Integer = (int)time(Param[0]->Val->Pointer); } void StdStrftime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) @@ -66,6 +61,7 @@ void StdStrftime(struct ParseState *Parser, struct Value *ReturnValue, struct Va ReturnValue->Val->Integer = strftime(Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Pointer, Param[3]->Val->Pointer); } +#ifndef WIN32 void StdStrptime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { extern char *strptime(const char *s, const char *format, struct tm *tm); @@ -73,10 +69,16 @@ void StdStrptime(struct ParseState *Parser, struct Value *ReturnValue, struct Va ReturnValue->Val->Pointer = strptime(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Pointer); } +void StdGmtime_r(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) +{ + ReturnValue->Val->Pointer = gmtime_r(Param[0]->Val->Pointer, Param[1]->Val->Pointer); +} + void StdTimegm(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Integer = timegm(Param[0]->Val->Pointer); } +#endif /* handy structure definitions */ const char StdTimeDefs[] = "\ @@ -94,13 +96,15 @@ struct LibraryFunction StdTimeFunctions[] = { StdDifftime, "double difftime(int, int);" }, #endif { StdGmtime, "struct tm *gmtime(int *);" }, - { StdGmtime_r, "struct tm *gmtime_r(int *, struct tm *);" }, { StdLocaltime, "struct tm *localtime(int *);" }, { StdMktime, "int mktime(struct tm *ptm);" }, { StdTime, "int time(int *);" }, { StdStrftime, "int strftime(char *, int, char *, struct tm *);" }, +#ifndef WIN32 { StdStrptime, "char *strptime(char *, char *, struct tm *);" }, + { StdGmtime_r, "struct tm *gmtime_r(int *, struct tm *);" }, { StdTimegm, "int timegm(struct tm *);" }, +#endif { NULL, NULL } }; diff --git a/expression.c b/expression.c index c02228b..9ecf77e 100644 --- a/expression.c +++ b/expression.c @@ -370,11 +370,11 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct switch (DestValue->Typ->Base) { case TypeInt: DestValue->Val->Integer = ExpressionCoerceInteger(SourceValue); break; - case TypeShort: DestValue->Val->ShortInteger = ExpressionCoerceInteger(SourceValue); break; - case TypeChar: DestValue->Val->Character = ExpressionCoerceUnsignedInteger(SourceValue); break; + case TypeShort: DestValue->Val->ShortInteger = (short)ExpressionCoerceInteger(SourceValue); break; + case TypeChar: DestValue->Val->Character = (unsigned char)ExpressionCoerceUnsignedInteger(SourceValue); break; case TypeLong: DestValue->Val->LongInteger = ExpressionCoerceInteger(SourceValue); break; case TypeUnsignedInt: DestValue->Val->UnsignedInteger = ExpressionCoerceUnsignedInteger(SourceValue); break; - case TypeUnsignedShort: DestValue->Val->UnsignedShortInteger = ExpressionCoerceUnsignedInteger(SourceValue); break; + case TypeUnsignedShort: DestValue->Val->UnsignedShortInteger = (unsigned short)ExpressionCoerceUnsignedInteger(SourceValue); break; case TypeUnsignedLong: DestValue->Val->UnsignedLongInteger = ExpressionCoerceUnsignedInteger(SourceValue); break; #ifndef NO_FP @@ -1171,7 +1171,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) ExpressionStackPushValueNode(Parser, &StackTop, MacroResult); } - else if (VariableValue->Typ == TypeVoid) + else if (VariableValue->Typ == &VoidType) ProgramFail(Parser, "a void value isn't much use here"); else ExpressionStackPushLValue(Parser, &StackTop, VariableValue, 0); /* it's a value variable */ diff --git a/include.c b/include.c index 3425a10..a0f9be3 100644 --- a/include.c +++ b/include.c @@ -25,15 +25,17 @@ void IncludeInit() #ifndef BUILTIN_MINI_STDLIB IncludeRegister("ctype.h", NULL, &StdCtypeFunctions[0], NULL); IncludeRegister("errno.h", &StdErrnoSetupFunc, NULL, NULL); -#ifndef NO_FP +# ifndef NO_FP IncludeRegister("math.h", &MathSetupFunc, &MathFunctions[0], NULL); -#endif +# endif IncludeRegister("stdbool.h", &StdboolSetupFunc, NULL, StdboolDefs); IncludeRegister("stdio.h", &StdioSetupFunc, &StdioFunctions[0], StdioDefs); IncludeRegister("stdlib.h", &StdlibSetupFunc, &StdlibFunctions[0], NULL); IncludeRegister("string.h", &StringSetupFunc, &StringFunctions[0], NULL); IncludeRegister("time.h", &StdTimeSetupFunc, &StdTimeFunctions[0], StdTimeDefs); - IncludeRegister("unistd.h", &UnistdSetupFunc, &UnistdFunctions[0], UnistdDefs); +# ifndef WIN32 + IncludeRegister("unistd.h", &UnistdSetupFunc, &UnistdFunctions[0], UnistdDefs); +# endif #endif } diff --git a/lex.c b/lex.c index 7402574..93683ba 100644 --- a/lex.c +++ b/lex.c @@ -28,7 +28,7 @@ #define MAX_CHAR_VALUE 255 /* maximum value which can be represented by a "char" data type */ static union AnyValue LexAnyValue; -static struct Value LexValue = { TypeVoid, &LexAnyValue, NULL, FALSE, FALSE, FALSE }; +static struct Value LexValue = { &VoidType, &LexAnyValue, NULL, FALSE, FALSE, FALSE }; struct ReservedWord { diff --git a/msvc/picoc/picoc.sln b/msvc/picoc/picoc.sln new file mode 100644 index 0000000..e2be657 --- /dev/null +++ b/msvc/picoc/picoc.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 11 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "picoc", "picoc.vcxproj", "{C0156FB3-55AB-4F82-8A97-A776DFC57951}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0156FB3-55AB-4F82-8A97-A776DFC57951}.Debug|Win32.ActiveCfg = Debug|Win32 + {C0156FB3-55AB-4F82-8A97-A776DFC57951}.Debug|Win32.Build.0 = Debug|Win32 + {C0156FB3-55AB-4F82-8A97-A776DFC57951}.Release|Win32.ActiveCfg = Release|Win32 + {C0156FB3-55AB-4F82-8A97-A776DFC57951}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/msvc/picoc/picoc.vcxproj b/msvc/picoc/picoc.vcxproj new file mode 100644 index 0000000..63f24a0 --- /dev/null +++ b/msvc/picoc/picoc.vcxproj @@ -0,0 +1,111 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + $(VCTargetsPath11) + + + {C0156FB3-55AB-4F82-8A97-A776DFC57951} + Win32Proj + picoc + + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/picoc/picoc.vcxproj.filters b/msvc/picoc/picoc.vcxproj.filters new file mode 100644 index 0000000..77be70a --- /dev/null +++ b/msvc/picoc/picoc.vcxproj.filters @@ -0,0 +1,99 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {9cc822ce-c7ed-4deb-93d2-ab0077cfe681} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files\cstdlib + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/picoc.c b/picoc.c index 400be11..1f98eec 100644 --- a/picoc.c +++ b/picoc.c @@ -6,7 +6,7 @@ /* platform-dependent code for running programs is in this file */ -#ifdef UNIX_HOST +#if defined(UNIX_HOST) || defined(WIN32) #include #include #include diff --git a/picoc.h b/picoc.h index fd77d8e..ab95985 100644 --- a/picoc.h +++ b/picoc.h @@ -17,7 +17,7 @@ #endif -#ifdef UNIX_HOST +#if defined(UNIX_HOST) || defined(WIN32) #include /* mark where to end the program for platforms which require this */ diff --git a/platform.c b/platform.c index e718479..1a83168 100644 --- a/platform.c +++ b/platform.c @@ -46,7 +46,7 @@ void PicocCleanup() } /* platform-dependent code for running programs */ -#ifdef UNIX_HOST +#if defined(UNIX_HOST) || defined(WIN32) #define CALL_MAIN_NO_ARGS_RETURN_VOID "main();" #define CALL_MAIN_WITH_ARGS_RETURN_VOID "main(__argc,__argv);" @@ -124,7 +124,7 @@ void PrintSourceTextErrorLine(const char *FileName, const char *SourceText, int else { /* assume we're in interactive mode - try to make the arrow match up with the input text */ - for (CCount = 0; CCount < CharacterPos + strlen(INTERACTIVE_PROMPT_STATEMENT); CCount++) + for (CCount = 0; CCount < CharacterPos + (int)strlen(INTERACTIVE_PROMPT_STATEMENT); CCount++) PrintCh(' ', CStdOut); } PlatformPrintf("^\n%s:%d: ", FileName, Line, CharacterPos); diff --git a/platform.h b/platform.h index 1ff9ba0..1134859 100644 --- a/platform.h +++ b/platform.h @@ -9,6 +9,7 @@ * #define SURVEYOR_HOST * #define SRV1_UNIX_HOST * #define UMON_HOST + * #define WIN32 (predefined on MSVC) */ #define LARGE_INT_POWER_OF_TEN 1000000000 /* the largest power of ten which fits in an int on this architecture */ @@ -57,63 +58,83 @@ extern jmp_buf ExitBuf; #else -# ifdef FLYINGFOX_HOST -# define HEAP_SIZE (16*1024) /* space for the heap and the stack */ -# define NO_HASH_INCLUDE +# ifdef WIN32 +# define USE_MALLOC_STACK /* stack is allocated using malloc() */ +# define USE_MALLOC_HEAP /* heap is allocated using malloc() */ +# include # include # include # include +# include # include +# include # include # include # include -# define assert(x) -# define BUILTIN_MINI_STDLIB +# define PICOC_MATH_LIBRARY # undef BIG_ENDIAN +extern jmp_buf ExitBuf; + # else -# ifdef SURVEYOR_HOST -# define HEAP_SIZE C_HEAPSIZE -# define NO_FP -# define NO_CTYPE +# ifdef FLYINGFOX_HOST +# define HEAP_SIZE (16*1024) /* space for the heap and the stack */ # define NO_HASH_INCLUDE -# define NO_MODULUS -# include -# include "../string.h" -# include "../print.h" -# include "../srv.h" -# include "../setjmp.h" -# include "../stdarg.h" -# include "../colors.h" -# include "../neural.h" -# include "../gps.h" -# include "../i2c.h" -# include "../jpeg.h" -# include "../malloc.h" -# include "../xmodem.h" +# include +# include +# include +# include +# include +# include +# include # define assert(x) -# undef BIG_ENDIAN -# define NO_CALLOC -# define NO_REALLOC -# define BROKEN_FLOAT_CASTS # define BUILTIN_MINI_STDLIB +# undef BIG_ENDIAN + # else -# ifdef UMON_HOST -# define HEAP_SIZE (128*1024) /* space for the heap and the stack */ +# ifdef SURVEYOR_HOST +# define HEAP_SIZE C_HEAPSIZE # define NO_FP -# define BUILTIN_MINI_STDLIB -# include -# include -# include -# include -# include -# include -# include "monlib.h" +# define NO_CTYPE +# define NO_HASH_INCLUDE +# define NO_MODULUS +# include +# include "../string.h" +# include "../print.h" +# include "../srv.h" +# include "../setjmp.h" +# include "../stdarg.h" +# include "../colors.h" +# include "../neural.h" +# include "../gps.h" +# include "../i2c.h" +# include "../jpeg.h" +# include "../malloc.h" +# include "../xmodem.h" # define assert(x) -# define malloc mon_malloc -# define calloc(a,b) mon_malloc(a*b) -# define realloc mon_realloc -# define free mon_free +# undef BIG_ENDIAN +# define NO_CALLOC +# define NO_REALLOC +# define BROKEN_FLOAT_CASTS +# define BUILTIN_MINI_STDLIB +# else +# ifdef UMON_HOST +# define HEAP_SIZE (128*1024) /* space for the heap and the stack */ +# define NO_FP +# define BUILTIN_MINI_STDLIB +# include +# include +# include +# include +# include +# include +# include "monlib.h" +# define assert(x) +# define malloc mon_malloc +# define calloc(a,b) mon_malloc(a*b) +# define realloc mon_realloc +# define free mon_free +# endif # endif # endif diff --git a/platform/library_msvc.c b/platform/library_msvc.c new file mode 100644 index 0000000..c2c54b4 --- /dev/null +++ b/platform/library_msvc.c @@ -0,0 +1,5 @@ +#include "../interpreter.h" + +void PlatformLibraryInit() +{ +} diff --git a/platform/platform_msvc.c b/platform/platform_msvc.c new file mode 100644 index 0000000..14718aa --- /dev/null +++ b/platform/platform_msvc.c @@ -0,0 +1,80 @@ +#include "../picoc.h" +#include "../interpreter.h" + +/* mark where to end the program for platforms which require this */ +jmp_buf PicocExitBuf; + +void PlatformInit() +{ +} + +void PlatformCleanup() +{ +} + +/* get a line of interactive input */ +char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt) +{ + if (Prompt != NULL) + printf("%s", Prompt); + + fflush(stdout); + return fgets(Buf, MaxLen, stdin); +} + +/* get a character of interactive input */ +int PlatformGetCharacter() +{ + fflush(stdout); + return getchar(); +} + +/* write a character to the console */ +void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *Stream) +{ + putchar(OutCh); +} + +/* read a file into memory */ +char *PlatformReadFile(const char *FileName) +{ + struct stat FileInfo; + char *ReadText; + FILE *InFile; + int BytesRead; + + if (stat(FileName, &FileInfo)) + ProgramFail(NULL, "can't read file %s\n", FileName); + + ReadText = malloc(FileInfo.st_size + 1); + if (ReadText == NULL) + ProgramFail(NULL, "out of memory\n"); + + InFile = fopen(FileName, "r"); + if (InFile == NULL) + ProgramFail(NULL, "can't read file %s\n", FileName); + + BytesRead = fread(ReadText, 1, FileInfo.st_size, InFile); + if (BytesRead == 0) + ProgramFail(NULL, "can't read file %s\n", FileName); + + ReadText[BytesRead] = '\0'; + fclose(InFile); + + return ReadText; +} + +/* read and scan a file for definitions */ +void PicocPlatformScanFile(const char *FileName) +{ + char *SourceStr = PlatformReadFile(FileName); + + PicocParse(FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE, TRUE); +} + +/* exit the program */ +void PlatformExit(int RetVal) +{ + PicocExitValue = RetVal; + longjmp(PicocExitBuf, 1); +}