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
// /*TOKEN ** p = */argp--;
// argp = (TOKEN **)*argp;
- DEBUG printf("ExitMacro: argp: %d -> ", argp);
+ DEBUG { printf("ExitMacro: argp: %d -> ", argp); }
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();
}
//
int defmac1(char * ln, int notEndFlag)
{
-// PTR p;
-// LONG len;
-
if (list_flag)
{
listeol(); // Flush previous source line
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)
{
// 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)
{
// by itself to terminate the definition.
// curmln = NULL;
curmac->lineList = NULL;
- lncatch(defmac1, "endm ");
+ LNCatch(defmac1, "endm ");
return 0;
}
//
int defr1(char * ln, int kwno)
{
- LONG len;
- LONG * p;
-
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)
{
- case 0: // .endr
+ case 0: // .endr
if (--rptlevel == 0)
- return(0);
- goto addln;
- case 1: // .rept
+ return 0;
+
+ break;
+ case 1: // .rept
rptlevel++;
- default:
+ }
+
//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
//
-int defrept(void)
+int DefineRept(void)
{
- INOBJ * inobj;
- IREPT * irept;
VALUE eval;
// Evaluate repeat expression
firstrpt = NULL;
nextrpt = NULL;
rptlevel = 1;
- lncatch(defr1, "endr rept ");
+ LNCatch(defr1, "endr rept ");
// 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;
//
-// 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.
//
-// 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.
//
-int lncatch(int (* lnfunc)(), char * dirlist)
+static int LNCatch(int (* lnfunc)(), char * dirlist)
{
char * p;
int k;
if (lnfunc != NULL)
- lnsave++; // Tell tokenizer to keep lines
+ lnsave++; // Tell tokenizer to keep lines
for(;;)
{
{
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[1]]; // Symbol
+ p = string[tok[1]]; // Symbol
}
}
if (p != NULL)
{
- if (*p == '.') // ignore leading '.'s
+ if (*p == '.') // ignore leading '.'s
p++;
- k = kwmatch(p, dirlist);
+ k = KWMatch(p, dirlist);
}
// Hand-off line to function
}
if (lnfunc != NULL)
- lnsave--; // Tell tokenizer to stop keeping lines
+ lnsave--; // Tell tokenizer to stop keeping lines
return 0;
}
// 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;
}
// Skip to beginning of next keyword in `kwlist'
- while (*kwlist && *kwlist != ' ')
+ while (*kwlist && (*kwlist != ' '))
++kwlist;
if (*kwlist== ' ')
//
// 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)
{
break;
}
- DEBUG printf("%d\n", argp);
+ DEBUG { printf("%d\n", argp); }
// 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_nextln = (TOKEN *)mac->svalue;
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
{
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]);
}
}