1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <stdio.h>
#include <unistd.h>
//#include "typedef.h"
#include "splitter.hpp"
#include "sludge_functions.h"
#include "moreio.h"
#include "helpers.h"
#include "tokens.h"
#include "objtype.h"
#include "interface.h"
#include "messbox.h"
#include "allknown.h"
#include "compilerinfo.h"
int subNum = 0;
//extern HWND compWin;
const char * emptyString = "";
const char * inThisClass = emptyString;
//extern stringArray * & localVars;
stringArray * globalVarFileOrigins;
bool globalVar (char * theString, stringArray * & globalVars, compilationSpace & globalSpace, const char * filename, unsigned int fileLine) {
int numVar;
stringArray * multi = splitString (theString, ',');
while (multi) {
stringArray * getVarName = splitString (multi -> string, '=', ONCE);
if (! checkValidName (getVarName->string, "Not a valid global variable name", filename)) return false;
// if (! checkNotKnown (getVarName -> string)) return false;
char * variableName = joinStrings (inThisClass, getVarName -> string);
if (! checkNotKnown (variableName, filename)) return false;
addToStringArray (globalVars, variableName);
addToStringArray (globalVarFileOrigins, filename);
numVar = findElement (globalVars, variableName);
stringArray * thisVar = returnArray(globalVars, numVar);
thisVar->line = fileLine;
delete variableName;
if (getVarName -> next) {
if (! compileSourceLine (getVarName -> next -> string, globalVars, globalSpace, nullArray, filename, 0)) return addComment (ERRORTYPE_PROJECTERROR, "Can't compile code to set initial value for global variable", multi -> string, filename,0);
outputDoneCode (globalSpace, SLU_SET_GLOBAL, numVar);
}
destroyAll (getVarName);
destroyFirst (multi);
}
return true;
}
bool realWork (int fileNumber, stringArray * & globalVars, compilationSpace & globalSpace) {
char * theSource;
char inputName[13];
stringArray * origName;
stringArray * theBits;
stringArray * removeTokenString;
sprintf (inputName, "_T%05i.TMP", fileNumber);
theSource = grabWholeFile (inputName);
unlink (inputName);
origName = splitString (theSource, '*', ONCE);
delete theSource;
if (! origName) return false;
setCompilerText (COMPILER_TXT_FILENAME, origName -> string);
theBits = splitString (origName -> next -> string, ';', REPEAT);
subNum = 0;
while (theBits) {
if (theBits -> string[0]) {
removeTokenString = splitString (theBits -> string, ' ', ONCE);
switch (getToken (removeTokenString -> string)) {
case TOK_SUB:
if (! destroyFirst (removeTokenString)) {
return addComment (ERRORTYPE_PROJECTERROR, "Bad sub declaration", theBits -> string, origName->string, theBits->line);
}
if (! outdoorSub (removeTokenString -> string, origName -> string, theBits->line)) {
return false;
}
break;
case TOK_VAR:
if (! destroyFirst (removeTokenString)) return addComment (ERRORTYPE_PROJECTERROR, "Bad global variable definition", theBits -> string, origName->string, theBits->line);
if (! globalVar (removeTokenString -> string, globalVars, globalSpace, origName->string, theBits->line)) return false;
break;
case TOK_FLAG:
case TOK_FLAGS:
if (! destroyFirst (removeTokenString)) return addComment (ERRORTYPE_PROJECTERROR, "Bad flags definition", theBits -> string, origName->string, theBits->line);
if (! handleFlags (removeTokenString -> string)) return false;
break;
case TOK_OBJECTTYPE:
if (! destroyFirst (removeTokenString)) {
return addComment (ERRORTYPE_PROJECTERROR, "Bad objectType declaration", theBits -> string, origName->string, theBits->line);
}
if (! createObjectType (removeTokenString -> string, origName -> string, globalVars, globalSpace, origName -> string)) return false;
break;
case TOK_UNKNOWN:
default:
addComment (ERRORTYPE_PROJECTERROR, "Unknown or illegal token (only 'sub', 'var', 'flag', 'flags' and 'objectType' allowed here)", removeTokenString -> string, origName->string, theBits->line);
return false;
}
destroyAll (removeTokenString);
}
subNum ++;
destroyFirst (theBits);
}
destroyAll (origName);
// finishTask ();
return true;
}
|