|
@@ -113,28 +113,21 @@ static const char* fGetDefineName(Define* d) {
|
|
|
}
|
|
|
|
|
|
static int fStartDefine(OpenFile* of, bool* newLine) {
|
|
|
- if(files.defineIndex >= MAX_INDEX) {
|
|
|
- files.error("too many defines");
|
|
|
- }
|
|
|
- Define* d = files.defines + files.defineIndex++;
|
|
|
-
|
|
|
fAddChar(of, '#');
|
|
|
int end = fReserverInt(of);
|
|
|
+ int nameFileIndex = fReserverInt(of);
|
|
|
+ int nameIndex = fReserverInt(of);
|
|
|
+ int codeFileIndex = fReserverInt(of);
|
|
|
+ int codeIndex = fReserverInt(of);
|
|
|
|
|
|
char command[64];
|
|
|
*newLine = fReadCommandString(of, command, 64);
|
|
|
- d->name.fileIndex = of->arrayIndex;
|
|
|
- d->name.index = of->index;
|
|
|
+ fSetInt(of, nameFileIndex, of->arrayIndex);
|
|
|
+ fSetInt(of, nameIndex, of->index);
|
|
|
fAdd(of, command, strlen(command) + 1);
|
|
|
|
|
|
- for(int i = 0; i < files.defineIndex - 1; i++) {
|
|
|
- if(strcmp(command, fGetDefineName(files.defines + i)) == 0) {
|
|
|
- files.error("'%s' is already defined", command);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- d->code.fileIndex = of->arrayIndex;
|
|
|
- d->code.index = of->index;
|
|
|
+ fSetInt(of, codeFileIndex, of->arrayIndex);
|
|
|
+ fSetInt(of, codeIndex, of->index);
|
|
|
return end;
|
|
|
}
|
|
|
|
|
@@ -308,6 +301,35 @@ static bool fCheckForReplacement() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+static void fReadDefine() {
|
|
|
+ int base = files.readIndex.index + 1;
|
|
|
+ int end = fReadInt(currentFile(), base);
|
|
|
+ int nameFileIndex = fReadInt(currentFile(), base + sizeof(int));
|
|
|
+ int nameIndex = fReadInt(currentFile(), base + sizeof(int) * 2);
|
|
|
+ int codeFileIndex = fReadInt(currentFile(), base + sizeof(int) * 3);
|
|
|
+ int codeIndex = fReadInt(currentFile(), base + sizeof(int) * 4);
|
|
|
+
|
|
|
+ const char* name = files.files[nameFileIndex].content + nameIndex;
|
|
|
+
|
|
|
+ if(files.defineIndex >= MAX_INDEX) {
|
|
|
+ files.error("too many defines");
|
|
|
+ }
|
|
|
+ Define* d = files.defines + files.defineIndex++;
|
|
|
+ for(int i = 0; i < files.defineIndex - 1; i++) {
|
|
|
+ if(strcmp(name, fGetDefineName(files.defines + i)) == 0) {
|
|
|
+ d = files.defines + i;
|
|
|
+ files.defineIndex--;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ d->name.fileIndex = nameFileIndex;
|
|
|
+ d->name.index = nameIndex;
|
|
|
+ d->code.fileIndex = codeFileIndex;
|
|
|
+ d->code.index = codeIndex;
|
|
|
+
|
|
|
+ files.readIndex.index = end;
|
|
|
+}
|
|
|
+
|
|
|
static void fPrepareChar() {
|
|
|
while(true) {
|
|
|
int c = fReadChar();
|
|
@@ -319,8 +341,7 @@ static void fPrepareChar() {
|
|
|
} else if(c == EOF && stackIndex > 0) {
|
|
|
files.readIndex = stack[--stackIndex];
|
|
|
} else if(c == '#') {
|
|
|
- files.readIndex.index =
|
|
|
- fReadInt(currentFile(), files.readIndex.index + 1);
|
|
|
+ fReadDefine();
|
|
|
} else if(isLetter(c) && !isLetter(lastChar)) {
|
|
|
if(fCheckForReplacement()) {
|
|
|
continue;
|