X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=macro.c;h=23d879719d7d47ad45d6ecd99c010033effa0a4f;hp=2ebaf52e0455773fd5305009ca029f50e0332399;hb=c3bb316d42b8471dbe87fa4b8c9787265e7b01da;hpb=96a5cd69571096f11a3a2a40f6133374f0adc9bb diff --git a/macro.c b/macro.c index 2ebaf52..23d8797 100644 --- 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 +// Function prototypes +static int KWMatch(char *, char *); +static int LNCatch(int (*)(), char *); + // // Initialize macro processor @@ -74,9 +78,9 @@ of another (nested macros). Need to fix that somehow. // /*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(); } @@ -107,9 +111,6 @@ int defmac2(char * argname) // int defmac1(char * ln, int notEndFlag) { -// PTR p; -// LONG len; - 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. -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) { @@ -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 -// `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) { @@ -215,7 +218,7 @@ int DefineMacro(void) // by itself to terminate the definition. // curmln = NULL; curmac->lineList = NULL; - lncatch(defmac1, "endm "); + LNCatch(defmac1, "endm "); return 0; } @@ -226,58 +229,52 @@ int DefineMacro(void) // 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 @@ -288,13 +285,13 @@ int defrept(void) 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; @@ -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. // -// 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(;;) { @@ -346,21 +343,21 @@ int lncatch(int (* lnfunc)(), char * dirlist) { 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 @@ -374,7 +371,7 @@ int lncatch(int (* lnfunc)(), char * dirlist) } if (lnfunc != NULL) - lnsave--; // Tell tokenizer to stop keeping lines + lnsave--; // Tell tokenizer to stop keeping lines 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. // -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; @@ -410,7 +402,7 @@ int kwmatch(char * kw, char * kwlist) } // Skip to beginning of next keyword in `kwlist' - while (*kwlist && *kwlist != ' ') + while (*kwlist && (*kwlist != ' ')) ++kwlist; if (*kwlist== ' ') @@ -423,8 +415,8 @@ int kwmatch(char * kw, char * 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) { @@ -570,21 +562,20 @@ streams, we can alleviate this problem.] 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 { @@ -593,8 +584,6 @@ streams, we can alleviate this problem.] for(nargs=0; nargsim_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]); } }