diff --git a/Makefile b/Makefile index 043dc45..1e2f098 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,18 @@ all: depend $(TARGET) $(TARGET): $(OBJS) $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LIBS) +# rebuild the version number every time so we always have the +# correct subversion version +version.h: + echo "#define PICOC_SUBVERSION_VERSION \"`svnversion`\"" > version.h + +.PHONY: version.h + test: all (cd tests; make test) clean: - rm -f $(TARGET) $(OBJS) *~ + rm -f $(TARGET) $(OBJS) version.h *~ count: @echo "Core:" @@ -30,6 +37,7 @@ count: @cat $(SRCS) *.h */*.h | wc depend: + touch version.h $(CC) -MM $(SRCS) >.depend -include .depend diff --git a/clibrary.c b/clibrary.c index c890ae4..53a9696 100644 --- a/clibrary.c +++ b/clibrary.c @@ -1,7 +1,21 @@ #include "picoc.h" +#include "version.h" -/* initialise a library */ -void LibraryInit(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList) +/* the picoc version string */ +#define PICOC_VERSION "v2.1 beta r" PICOC_SUBVERSION_VERSION +static const char *VersionString = NULL; + + +/* global initialisation for libraries */ +void LibraryInit() +{ + /* define the version number macro */ + VersionString = TableStrRegister(PICOC_VERSION); + VariableDefinePlatformVar(NULL, "PICOC_VERSION", CharPtrType, (union AnyValue *)&VersionString, FALSE); +} + +/* add a library */ +void LibraryAdd(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList) { struct ParseState Parser; int Count; @@ -11,6 +25,7 @@ void LibraryInit(struct Table *GlobalTable, const char *LibraryName, struct Libr void *Tokens; const char *IntrinsicName = TableStrRegister("c library"); + /* read all the library definitions */ for (Count = 0; FuncList[Count].Prototype != NULL; Count++) { Tokens = LexAnalyse(IntrinsicName, FuncList[Count].Prototype, strlen((char *)FuncList[Count].Prototype), NULL); diff --git a/include.c b/include.c index 49c9dc4..f9c1293 100644 --- a/include.c +++ b/include.c @@ -95,7 +95,7 @@ void IncludeFile(char *FileName) /* set up the library functions */ if (LInclude->FuncList != NULL) - LibraryInit(&GlobalTable, FileName, LInclude->FuncList); + LibraryAdd(&GlobalTable, FileName, LInclude->FuncList); } return; diff --git a/picoc.c b/picoc.c index e13b952..a7c2308 100644 --- a/picoc.c +++ b/picoc.c @@ -17,8 +17,9 @@ void Initialise(int StackSize) #ifndef NO_HASH_INCLUDE IncludeInit(); #endif + LibraryInit(); #ifdef BUILTIN_MINI_STDLIB - LibraryInit(&GlobalTable, "c library", &CLibrary[0]); + LibraryAdd(&GlobalTable, "c library", &CLibrary[0]); CLibraryInit(); #endif PlatformLibraryInit(); diff --git a/picoc.h b/picoc.h index 75017e4..0978e84 100644 --- a/picoc.h +++ b/picoc.h @@ -408,7 +408,8 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe /* clibrary.c */ void BasicIOInit(); -void LibraryInit(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList); +void LibraryInit(); +void LibraryAdd(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList); void CLibraryInit(); void PrintCh(char OutCh, IOFILE *Stream); void PrintSimpleInt(long Num, IOFILE *Stream);