]> Shamusworld >> Repos - rmac/commitdiff
Minor code cleanups.
authorShamus Hammons <jlhamm@acm.org>
Sat, 24 Jun 2017 00:58:41 +0000 (19:58 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sat, 24 Jun 2017 00:58:41 +0000 (19:58 -0500)
macro.c
macro.h
procln.c
version.h

diff --git a/macro.c b/macro.c
index 2ebaf52e0455773fd5305009ca029f50e0332399..23d879719d7d47ad45d6ecd99c010033effa0a4f 100644 (file)
--- a/macro.c
+++ b/macro.c
@@ -30,6 +30,10 @@ static LONG * firstrpt;              // First .rept line
 static LONG * nextrpt;         // Last .rept line
 static int rptlevel;           // .rept nesting level
 
 static LONG * nextrpt;         // Last .rept line
 static int rptlevel;           // .rept nesting level
 
+// Function prototypes
+static int KWMatch(char *, char *);
+static int LNCatch(int (*)(), char *);
+
 
 //
 // Initialize macro processor
 
 //
 // Initialize macro processor
@@ -74,9 +78,9 @@ of another (nested macros). Need to fix that somehow.
 
 //     /*TOKEN ** p = */argp--;
 //     argp = (TOKEN **)*argp;
 
 //     /*TOKEN ** p = */argp--;
 //     argp = (TOKEN **)*argp;
-       DEBUG printf("ExitMacro: argp: %d -> ", argp);
+       DEBUG { printf("ExitMacro: argp: %d -> ", argp); }
        argp -= imacro->im_nargs;
        argp -= imacro->im_nargs;
-       DEBUG printf("%d (nargs = %d)\n", argp, imacro->im_nargs);
+       DEBUG { printf("%d (nargs = %d)\n", argp, imacro->im_nargs); }
 
        return fpop();
 }
 
        return fpop();
 }
@@ -107,9 +111,6 @@ int defmac2(char * argname)
 //
 int defmac1(char * ln, int notEndFlag)
 {
 //
 int defmac1(char * ln, int notEndFlag)
 {
-//     PTR p;
-//     LONG len;
-
        if (list_flag)
        {
                listeol();                                                      // Flush previous source line
        if (list_flag)
        {
                listeol();                                                      // Flush previous source line
@@ -127,11 +128,12 @@ Allocate a space big enough for the string + NULL + pointer.
 Set the pointer to NULL.
 Copy the string to the space after the pointer.
 If this is the 1st time through, set the SYM * "svalue" to the pointer.
 Set the pointer to NULL.
 Copy the string to the space after the pointer.
 If this is the 1st time through, set the SYM * "svalue" to the pointer.
-If this is the 2nd time through, derefence the ** to point to the memory you just allocated.
-Then, set the ** to the location of the memory you allocated for the next pass through.
+If this is the 2nd time through, derefence the ** to point to the memory you
+just allocated. Then, set the ** to the location of the memory you allocated
+for the next pass through.
 
 
-This is a really low level way to do a linked list, and by bypassing all the safety
-features of the language. Seems like we can do better here.
+This is a really low level way to do a linked list, and by bypassing all the
+safety features of the language. Seems like we can do better here.
 */
        if (notEndFlag)
        {
 */
        if (notEndFlag)
        {
@@ -184,7 +186,8 @@ features of the language. Seems like we can do better here.
 //  Helper functions:
 //  -----------------
 //  `defmac1' adds lines of text to the macro definition
 //  Helper functions:
 //  -----------------
 //  `defmac1' adds lines of text to the macro definition
-//  `defmac2' processes the formal arguments (and sticks them into the symbol table)
+//  `defmac2' processes the formal arguments (and sticks them into the symbol
+//   table)
 //
 int DefineMacro(void)
 {
 //
 int DefineMacro(void)
 {
@@ -215,7 +218,7 @@ int DefineMacro(void)
        // by itself to terminate the definition.
 //     curmln = NULL;
        curmac->lineList = NULL;
        // by itself to terminate the definition.
 //     curmln = NULL;
        curmac->lineList = NULL;
-       lncatch(defmac1, "endm ");
+       LNCatch(defmac1, "endm ");
 
        return 0;
 }
 
        return 0;
 }
@@ -226,58 +229,52 @@ int DefineMacro(void)
 //
 int defr1(char * ln, int kwno)
 {
 //
 int defr1(char * ln, int kwno)
 {
-       LONG len;
-       LONG * p;
-
        if (list_flag)
        {
        if (list_flag)
        {
-               listeol();                                                              // Flush previous source line
-               lstout('#');                                                    // Mark this a 'rept' block
+               listeol();                              // Flush previous source line
+               lstout('#');                    // Mark this a 'rept' block
        }
 
        switch (kwno)
        {
        }
 
        switch (kwno)
        {
-       case 0:                                                                         // .endr
+       case 0:                                         // .endr
                if (--rptlevel == 0)
                if (--rptlevel == 0)
-               return(0);
-               goto addln;
-       case 1:                                                                         // .rept
+                       return 0;
+
+               break;
+       case 1:                                         // .rept
                rptlevel++;
                rptlevel++;
-       default:
+       }
+
 //MORE stupidity here...
 //MORE stupidity here...
-WARNING(!!! Casting (char *) as LONG !!!)
-       addln:
-               // Allocate length of line + 1('\0') + LONG
-               len = strlen(ln) + 1 + sizeof(LONG);
-//             p = (LONG *)amem(len);
-               p = (LONG *)malloc(len);
-               *p = 0;
+WARNING("!!! Casting (char *) as LONG !!!")
+       // Allocate length of line + 1('\0') + LONG
+       LONG len = strlen(ln) + 1 + sizeof(LONG);
+       LONG * p = (LONG *)malloc(len);
+       *p = 0;
 
 
-               strcpy((char *)(p + 1), ln);
+       strcpy((char *)(p + 1), ln);
 
 
-               if (nextrpt == NULL)
-               {
-                       firstrpt = p;           // First line of rept statement
-               }
-               else
-               {
-                       *nextrpt = (LONG)p;
-               }
+       if (nextrpt == NULL)
+       {
+               firstrpt = p;           // First line of rept statement
+       }
+       else
+       {
+               *nextrpt = (LONG)p;
+       }
 
 
-               nextrpt = p;
+       nextrpt = p;
 
 
-               return rptlevel;
-       }
+       return rptlevel;
 }
 
 
 //
 // Define a .rept block, this gets hairy because they can be nested
 //
 }
 
 
 //
 // Define a .rept block, this gets hairy because they can be nested
 //
-int defrept(void)
+int DefineRept(void)
 {
 {
-       INOBJ * inobj;
-       IREPT * irept;
        VALUE eval;
 
        // Evaluate repeat expression
        VALUE eval;
 
        // Evaluate repeat expression
@@ -288,13 +285,13 @@ int defrept(void)
        firstrpt = NULL;
        nextrpt = NULL;
        rptlevel = 1;
        firstrpt = NULL;
        nextrpt = NULL;
        rptlevel = 1;
-       lncatch(defr1, "endr rept ");
+       LNCatch(defr1, "endr rept ");
 
        // Alloc and init input object
        if (firstrpt)
        {
 
        // Alloc and init input object
        if (firstrpt)
        {
-               inobj = a_inobj(SRC_IREPT);                             // Create a new REPT input object
-               irept = inobj->inobj.irept;
+               INOBJ * inobj = a_inobj(SRC_IREPT);     // Create a new REPT input object
+               IREPT * irept = inobj->inobj.irept;
                irept->ir_firstln = firstrpt;
                irept->ir_nextln = NULL;
                irept->ir_count = eval;
                irept->ir_firstln = firstrpt;
                irept->ir_nextln = NULL;
                irept->ir_count = eval;
@@ -305,28 +302,28 @@ int defrept(void)
 
 
 //
 
 
 //
-// Hand off lines of text to the function `lnfunc' until a line containing one
-// of the directives in `dirlist' is encountered. Return the number of the
-// keyword encountered (0..n)
+// Hand off lines of text to the function 'lnfunc' until a line containing one
+// of the directives in 'dirlist' is encountered. Return the number of the
+// keywords encountered (0..n)
 //
 //
-// `dirlist' contains null-seperated terminated keywords.  A final null
+// 'dirlist' contains null-seperated terminated keywords.  A final null
 // terminates the list. Directives are compared to the keywords without regard
 // to case.
 //
 // terminates the list. Directives are compared to the keywords without regard
 // to case.
 //
-// If `lnfunc' is NULL, then lines are simply skipped.
-// If `lnfunc' returns an error, processing is stopped.
+// If 'lnfunc' is NULL, then lines are simply skipped.
+// If 'lnfunc' returns an error, processing is stopped.
 //
 //
-// `lnfunc' is called with an argument of -1 for every line but the last one,
+// 'lnfunc' is called with an argument of -1 for every line but the last one,
 // when it is called with an argument of the keyword number that caused the
 // match.
 //
 // when it is called with an argument of the keyword number that caused the
 // match.
 //
-int lncatch(int (* lnfunc)(), char * dirlist)
+static int LNCatch(int (* lnfunc)(), char * dirlist)
 {
        char * p;
        int k;
 
        if (lnfunc != NULL)
 {
        char * p;
        int k;
 
        if (lnfunc != NULL)
-               lnsave++;                                                               // Tell tokenizer to keep lines
+               lnsave++;                       // Tell tokenizer to keep lines
 
        for(;;)
        {
 
        for(;;)
        {
@@ -346,21 +343,21 @@ int lncatch(int (* lnfunc)(), char * dirlist)
                {
                        if ((tok[2] == ':' || tok[2] == DCOLON))
                        {
                {
                        if ((tok[2] == ':' || tok[2] == DCOLON))
                        {
-                               if (tok[3] == SYMBOL)                   // label: symbol
+                               if (tok[3] == SYMBOL)   // label: symbol
                                        p = string[tok[4]];
                        }
                        else
                        {
                                        p = string[tok[4]];
                        }
                        else
                        {
-                               p = string[tok[1]];                             // Symbol
+                               p = string[tok[1]];             // Symbol
                        }
                }
 
                if (p != NULL)
                {
                        }
                }
 
                if (p != NULL)
                {
-                       if (*p == '.')                                          // ignore leading '.'s
+                       if (*p == '.')          // ignore leading '.'s
                                p++;
 
                                p++;
 
-                       k = kwmatch(p, dirlist);
+                       k = KWMatch(p, dirlist);
                }
 
                // Hand-off line to function
                }
 
                // Hand-off line to function
@@ -374,7 +371,7 @@ int lncatch(int (* lnfunc)(), char * dirlist)
        }
 
        if (lnfunc != NULL)
        }
 
        if (lnfunc != NULL)
-               lnsave--;                                                               // Tell tokenizer to stop keeping lines
+               lnsave--;                               // Tell tokenizer to stop keeping lines
 
        return 0;
 }
 
        return 0;
 }
@@ -385,19 +382,14 @@ int lncatch(int (* lnfunc)(), char * dirlist)
 // return the number of the keyword matched.  Return -1 if there was no match.
 // Strings are compared without regard for case.
 //
 // return the number of the keyword matched.  Return -1 if there was no match.
 // Strings are compared without regard for case.
 //
-int kwmatch(char * kw, char * kwlist)
+static int KWMatch(char * kw, char * kwlist)
 {
 {
-       char * p;
-       char c1;
-       char c2;
-       int k;
-
-       for(k=0; *kwlist; ++k)
+       for(int k=0; *kwlist; k++)
        {
        {
-               for(p=kw;;)
+               for(char * p=kw;;)
                {
                {
-                       c1 = *kwlist++;
-                       c2 = *p++;
+                       char c1 = *kwlist++;
+                       char c2 = *p++;
 
                        if (c2 >= 'A' && c2 <= 'Z')
                                c2 += 32;
 
                        if (c2 >= 'A' && c2 <= 'Z')
                                c2 += 32;
@@ -410,7 +402,7 @@ int kwmatch(char * kw, char * kwlist)
                }
 
                // Skip to beginning of next keyword in `kwlist'
                }
 
                // Skip to beginning of next keyword in `kwlist'
-               while (*kwlist && *kwlist != ' ')
+               while (*kwlist && (*kwlist != ' '))
                        ++kwlist;
 
                if (*kwlist== ' ')
                        ++kwlist;
 
                if (*kwlist== ' ')
@@ -423,8 +415,8 @@ int kwmatch(char * kw, char * kwlist)
 
 //
 // Invoke a macro
 
 //
 // Invoke a macro
-// o  parse, count and copy arguments
-// o  push macro's string-stream
+//  o  parse, count and copy arguments
+//  o  push macro's string-stream
 //
 int InvokeMacro(SYM * mac, WORD siz)
 {
 //
 int InvokeMacro(SYM * mac, WORD siz)
 {
@@ -570,21 +562,20 @@ streams, we can alleviate this problem.]
                        break;
        }
 
                        break;
        }
 
-       DEBUG printf("%d\n", argp);
+       DEBUG { printf("%d\n", argp); }
 
        // Setup imacro:
 
        // Setup imacro:
-       // o  # arguments;
-       // o  -> macro symbol;
-       // o  -> macro definition string list;
-       // o  save 'curuniq', to be restored when the macro pops;
-       // o  bump `macuniq' counter and set 'curuniq' to it;
+       //  o  # arguments;
+       //  o  -> macro symbol;
+       //  o  -> macro definition string list;
+       //  o  save 'curuniq', to be restored when the macro pops;
+       //  o  bump `macuniq' counter and set 'curuniq' to it;
        imacro->im_nargs = nargs;
        imacro->im_macro = mac;
        imacro->im_nargs = nargs;
        imacro->im_macro = mac;
-//     imacro->im_nextln = (TOKEN *)mac->svalue;
        imacro->im_nextln = mac->lineList;
        imacro->im_olduniq = curuniq;
        curuniq = macuniq++;
        imacro->im_nextln = mac->lineList;
        imacro->im_olduniq = curuniq;
        curuniq = macuniq++;
-       imacro->argBase = argp - nargs;                 // Shamus: keep track of argument base
+       imacro->argBase = argp - nargs; // Shamus: keep track of argument base
 
        DEBUG
        {
 
        DEBUG
        {
@@ -593,8 +584,6 @@ streams, we can alleviate this problem.]
                for(nargs=0; nargs<imacro->im_nargs; nargs++)
                {
                        printf("arg%d=", nargs);
                for(nargs=0; nargs<imacro->im_nargs; nargs++)
                {
                        printf("arg%d=", nargs);
-//                     dumptok(argp[imacro->im_nargs - nargs - 1]);
-//                     dumptok(argPtrs[imacro->im_nargs - nargs - 1]);
                        dumptok(argPtrs[(argp - imacro->im_nargs) + nargs]);
                }
        }
                        dumptok(argPtrs[(argp - imacro->im_nargs) + nargs]);
                }
        }
diff --git a/macro.h b/macro.h
index 06ec89bff1a63a98daedb781de0489e9f5116ee3..1a067130a64faef7fec8c2c9dfd0fdc6639dedf6 100644 (file)
--- a/macro.h
+++ b/macro.h
@@ -19,9 +19,7 @@ extern TOKEN * argPtrs[];
 void InitMacro(void);
 int ExitMacro(void);
 int DefineMacro(void);
 void InitMacro(void);
 int ExitMacro(void);
 int DefineMacro(void);
-int defrept(void);
-int lncatch(int (*)(), char *);
-int kwmatch(char *, char *);
+int DefineRept(void);
 int InvokeMacro(SYM *, WORD);
 
 #endif // __MACRO_H__
 int InvokeMacro(SYM *, WORD);
 
 #endif // __MACRO_H__
index 989bc68f6538ddb4f248978e6fd4cdfb57add038..600aaa0e9685438bdf0504032ac73fe7f8ef7a53 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -353,7 +353,7 @@ as68label:
                                                goto loop;
                                }
 
                                                goto loop;
                                }
 
-                               defrept();
+                               DefineRept();
                        }
 
                        goto loop;
                        }
 
                        goto loop;
index dda6183f66c93b2b5162ac069c1a837d4cebdc79..4db56ceb5440889dbacda0948dfa6e94bffd0799 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,7 +15,7 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   7              // Minor version number
 
 #define MAJOR   1              // Major version number
 #define MINOR   7              // Minor version number
-#define PATCH   1              // Patch release number
+#define PATCH   2              // Patch release number
 
 #endif // __VERSION_H__
 
 
 #endif // __VERSION_H__