]> Shamusworld >> Repos - rmac/blobdiff - token.c
Fix for bug #51. Now at v2.0.22.
[rmac] / token.c
diff --git a/token.c b/token.c
index 22bc64ac557dd73bc8c3957a330e1b78bc653663..fa5af09b1dd6d60d18bae85d8f59417f643c0d7d 100644 (file)
--- a/token.c
+++ b/token.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Reboot's Macro Assembler for all Atari computers
 // TOKEN.C - Token Handling
-// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -22,7 +22,7 @@
 
 
 int lnsave;                                    // 1; strcpy() text of current line
-uint16_t curlineno;                    // Current line number (64K max currently)
+uint32_t curlineno;                    // Current line number (64K max currently)
 int totlines;                          // Total # of lines
 int mjump_align = 0;           // mjump alignment flag
 char lntag;                                    // Line tag
@@ -560,7 +560,8 @@ DEBUG { printf("ExM: SYMBOL=\"%s\"", d); }
 //         to choke on legitimate code... Need to investigate this further
 //         before changing anything else here!
                                                        case CONST:
-                                                               sprintf(numbuf, "$%lx", (uint64_t)*tk++);
+//                                                             sprintf(numbuf, "$%lx", (uint64_t)*tk++);
+                                                               sprintf(numbuf, "$%" PRIX64, (uint64_t)*tk++);
                                                                tk++;
                                                                d = numbuf;
                                                                break;
@@ -603,6 +604,9 @@ DEBUG { printf("ExM: SYMBOL=\"%s\"", d); }
                                                        case CR_ABSCOUNT:
                                                                d = "^^abscount";
                                                                break;
+                                                       case CR_FILESIZE:
+                                                               d = "^^filesize";
+                                                               break;
                                                        case CR_DATE:
                                                                d = "^^date";
                                                                break;
@@ -669,7 +673,6 @@ overflow:
 char * GetNextMacroLine(void)
 {
        IMACRO * imacro = cur_inobj->inobj.imacro;
-//     LONG * strp = imacro->im_nextln;
        LLIST * strp = imacro->im_nextln;
 
        if (strp == NULL)                                               // End-of-macro
@@ -788,7 +791,7 @@ int fpop(void)
        if (numUnmatched > 0)
                warn("missing %d .endif(s)", numUnmatched);
 
-       tok = inobj->in_otok;   // Restore tok and otok
+       tok = inobj->in_otok;   // Restore tok and etok
        etok = inobj->in_etok;
 
        switch (inobj->in_type)
@@ -949,7 +952,6 @@ int TokenizeLine(void)
        uint8_t c;                                      // Random char
        uint64_t v;                                     // Random value
        uint32_t cursize = 0;           // Current line's size (.b, .w, .l, .s, .q, .d)
-       double f;                                       // Random float
        uint8_t * nullspot = NULL;      // Spot to clobber for SYMBOL termination
        int stuffnull;                          // 1:terminate SYMBOL '\0' at *nullspot
        uint8_t c1;
@@ -1041,7 +1043,13 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); }
        // macro-type blocks, since it is expensive to unconditionally copy every
        // line.
        if (lnsave)
+       {
+               // Sanity check
+               if (strlen(ln) > LNSIZ)
+                       return error("line too long (%d, max %d)", strlen(ln), LNSIZ);
+
                strcpy(lnbuf, ln);
+       }
 
        // General housekeeping
        tok = tokeol;                   // Set "tok" to EOL in case of error
@@ -1072,6 +1080,12 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); }
        //  o  handle multiple-character tokens (constants, strings, etc.).
        for(; *ln!=EOS;)
        {
+               // Check to see if there's enough space in the token buffer
+               if (tk.cp >= ((uint8_t *)(&tokbuf[TOKBUFSIZE])) - 20)
+               {
+                       return error("token buffer overrun");
+               }
+
                // Skip whitespace, handle EOL
                while (chrtab[*ln] & WHITE)
                        ln++;
@@ -1170,7 +1184,7 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); }
                        }
 
                        // Make j = -1 if user tries to use a RISC register while in 68K mode
-                       if (!(rgpu || rdsp) && ((TOKEN)j >= KW_R0 && (TOKEN)j <= KW_R31))
+                       if (!(rgpu || rdsp || dsp56001) && ((TOKEN)j >= KW_R0 && (TOKEN)j <= KW_R31))
                        {
                                j = -1;
                        }
@@ -1286,6 +1300,10 @@ dostring:
                                                case '\\':
                                                        c = '\\';
                                                        break;
+                                               case '{':
+                                                       // If we're evaluating a macro
+                                                       // this is valid because it's
+                                                       // a parameter expansion
                                                case '!':
                                                        // If we're evaluating a macro
                                                        // this is valid and expands to
@@ -1727,6 +1745,8 @@ void DumpToken(TOKEN t)
                printf("[ENDEXPR]");
        else if (t == CR_ABSCOUNT)
                printf("[CR_ABSCOUNT]");
+       else if (t == CR_FILESIZE)
+               printf("[CR_FILESIZE]");
        else if (t == CR_DEFINED)
                printf("[CR_DEFINED]");
        else if (t == CR_REFERENCED)
@@ -1831,6 +1851,8 @@ void DumpTokenBuffer(void)
                        printf("[ENDEXPR]");
                else if (*t == CR_ABSCOUNT)
                        printf("[CR_ABSCOUNT]");
+               else if (*t == CR_FILESIZE)
+                       printf("[CR_FILESIZE]");
                else if (*t == CR_DEFINED)
                        printf("[CR_DEFINED]");
                else if (*t == CR_REFERENCED)