X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=token.c;h=4067711be2ff7ddd1dcd5e4f51fb04cc3cad6795;hp=1cd9ebadc5df82706d94a683cdc5e02570fc5d24;hb=0fd4b86c9899d254d9aea0660e5046c4234cfd42;hpb=c74d8ef6f193cb2be876c920c5cb7f599dd5418a diff --git a/token.c b/token.c index 1cd9eba..4067711 100644 --- a/token.c +++ b/token.c @@ -24,7 +24,7 @@ int mjump_align = 0; // mjump alignment flag char lntag; // Line tag char * curfname; // Current filename char tolowertab[128]; // Uppercase ==> lowercase -char hextab[128]; // Table of hex values +int8_t hextab[128]; // Table of hex values char dotxtab[128]; // Table for ".b", ".s", etc. char irbuf[LNSIZ]; // Text for .rept block line char lnbuf[LNSIZ]; // Text of current line @@ -554,6 +554,9 @@ DEBUG printf("ExM: SYMBOL=\"%s\"", d); case DOTL: d = ".l"; break; + case CR_ABSCOUNT: + d = "^^abscount"; + break; case CR_DATE: d = "^^date"; break; @@ -676,8 +679,8 @@ int include(int handle, char * fname) INOBJ * inobj; FILEREC * fr; - // Verbose mode - if (verb_flag) + // Debug mode + if (debug) printf("[include: %s, cfileno=%u]\n", fname, cfileno); // Alloc and initialize include-descriptors @@ -727,30 +730,41 @@ int fpop(void) { // Pop IFENT levels until we reach the conditional assembly context we // were at when the input object was entered. + int numUnmatched = 0; + while (ifent != inobj->in_ifent) - d_endif(); + { + if (d_endif() != 0) // Something bad happened during endif parsing? + return -1; // If yes, bail instead of getting stuck in a loop + + numUnmatched++; + } - tok = inobj->in_otok; // Restore tok and otok + // Give a warning to the user that we had to wipe their bum for them + if (numUnmatched > 0) + warni("missing %d .endif(s)", numUnmatched); + + tok = inobj->in_otok; // Restore tok and otok etok = inobj->in_etok; switch (inobj->in_type) { - case SRC_IFILE: // Pop and release an IFILE - if (verb_flag) + case SRC_IFILE: // Pop and release an IFILE + if (debug) printf("[Leaving: %s]\n", curfname); ifile = inobj->inobj.ifile; ifile->if_link = f_ifile; f_ifile = ifile; close(ifile->ifhandle); // Close source file -if (verb_flag) printf("[fpop (pre): curfname=%s]\n", curfname); +if (debug) printf("[fpop (pre): curfname=%s]\n", curfname); curfname = ifile->ifoldfname; // Set current filename -if (verb_flag) printf("[fpop (post): curfname=%s]\n", curfname); -if (verb_flag) printf("[fpop: (pre) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); +if (debug) printf("[fpop (post): curfname=%s]\n", curfname); +if (debug) printf("[fpop: (pre) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); curlineno = ifile->ifoldlineno; // Set current line# DEBUG printf("cfileno=%d ifile->ifno=%d\n", (int)cfileno, (int)ifile->ifno); cfileno = ifile->ifno; // Restore current file number -if (verb_flag) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); +if (debug) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); break; case SRC_IMACRO: // Pop and release an IMACRO imacro = inobj->inobj.imacro; @@ -905,9 +919,14 @@ retry: case SRC_IFILE: if ((ln = GetNextLine()) == NULL) { -if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); - fpop(); // Pop input level - goto retry; // Try for more lines +if (debug) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); + if (fpop() == 0) // Pop input level + goto retry; // Try for more lines + else + { + ifent->if_prev = (IFENT *) - 1; //Signal Assemble() that we have reached EOF with unbalanced if/endifs + return TKEOF; + } } curlineno++; // Bump line number @@ -940,8 +959,10 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); case SRC_IMACRO: if ((ln = GetNextMacroLine()) == NULL) { - ExitMacro(); // Exit macro (pop args, do fpop(), etc) - goto retry; // Try for more lines... + if (ExitMacro() == 0) // Exit macro (pop args, do fpop(), etc) + goto retry; // Try for more lines... + else + return TKEOF; // Oops, we got a non zero return code, signal EOF } lntag = '@'; @@ -952,7 +973,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); case SRC_IREPT: if ((ln = GetNextRepeatLine()) == NULL) { -if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); +if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); fpop(); goto retry; } @@ -1006,6 +1027,27 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); v = 0; // Assume no DOT attrib follows symbol stuffnull = 1; + + // In some cases, we need to check for a DOTx at the *beginning* + // of a symbol, as the "start" of the line we're currently looking + // at could be somewhere in the middle of that line! + if (*ln == '.') + { + // Make sure that it's *only* a .[bwsl] following, and not the + // start of a local symbol: + if ((chrtab[*(ln + 1)] & DOT) + && (dotxtab[*(ln + 1)] != 0) + && !(chrtab[*(ln + 2)] & CTSYM)) + { + // We found a legitimate DOTx construct, so add it to the + // token stream: + ln++; + stuffnull = 0; + *tk++ = (TOKEN)dotxtab[*ln++]; + continue; + } + } + p = nullspot = ln++; // Nullspot -> start of this symbol // Find end of symbol (and compute its length) @@ -1023,13 +1065,13 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); // the chararacter after THAT one must not have a start-symbol // attribute (to prevent symbols that look like, for example, // "zingo.barf", which might be a good idea anyway....) - if ((((int)chrtab[*ln] & DOT) == 0) || ((int)dotxtab[*ln] <= 0)) - return error("[bwsl] must follow `.' in symbol"); + if (((chrtab[*ln] & DOT) == 0) || (dotxtab[*ln] == 0)) + return error("[bwsl] must follow '.' in symbol"); v = (VALUE)dotxtab[*ln++]; - if ((int)chrtab[*ln] & CTSYM) - return error("misuse of `.', not allowed in symbols"); + if (chrtab[*ln] & CTSYM) + return error("misuse of '.', not allowed in symbols"); } // If the symbol is small, check to see if it's really the name of @@ -1081,7 +1123,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); } // If not tokenized keyword OR token was not found - if (j < 0 || state < 0) + if ((j < 0) || (state < 0)) { *tk++ = SYMBOL; //#warning @@ -1200,12 +1242,12 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *p++ = EOS; continue; case '$': // $, hex constant - if ((int)chrtab[*ln] & HDIGIT) + if (chrtab[*ln] & HDIGIT) { v = 0; // Parse the hex value - while ((int)hextab[*ln] >= 0) + while (hextab[*ln] >= 0) v = (v << 4) + (int)hextab[*ln++]; // ggn: Okay, some comments here are in order I think.... @@ -1236,14 +1278,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); // auto-optimise? I think it's ok for now... if (*ln == '.') { - if (obj_format == ALCYON) - { - if ((*(ln + 1) == 'b') || (*(ln + 1) == 'B') || (*(ln + 1) == 'w') || (*(ln + 1) == 'W') || (*(ln + 1) == 'l') || (*(ln + 1) == 'L')) - { - ln += 2; - } - } - else + if (obj_format == BSD) { if ((*(ln + 1) & 0xDF) == 'B') { @@ -1264,6 +1299,20 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = CONST; *tk++ = v; + + if (obj_format == ALCYON) + { + if ((*(ln + 1) == 'w') || (*(ln + 1) == 'W')) + { + *tk++ = DOTW; + ln += 2; + } + else if ((*(ln + 1) == 'l') || (*(ln + 1) == 'L')) + { + *tk++ = DOTL; + ln += 2; + } + } } else *tk++ = '$'; @@ -1547,11 +1596,7 @@ int d_goto(WORD unused) // Compare names (sleazo string compare) // This string compare is not right. Doesn't check for lengths. // (actually it does, but in a crappy, unclear way.) -#ifndef _MSC_VER - #warning "!!! Bad string comparison !!!" -#else - #pragma WARNING(!!!! Bad string comparison !!!) -#endif +WARNING(!!!! Bad string comparison !!!) s1 = sym; // s2 = (char *)(defln + 1) + 1; s2 = defln->line; @@ -1640,6 +1685,8 @@ void DumpTokenBuffer(void) printf("[DOTI]"); else if (*t == ENDEXPR) printf("[ENDEXPR]"); + else if (*t == CR_ABSCOUNT) + printf("[CR_ABSCOUNT]"); else if (*t == CR_DEFINED) printf("[CR_DEFINED]"); else if (*t == CR_REFERENCED)