/*=directive define * * arg: name [ <text> ] * * text: * Will add the name to the define list as if it were a DEFINE program * argument. Its value will be the first non-whitespace token following * the name. Quotes are @strong{not} processed. * * After the definitions file has been processed, any remaining entries * in the define list will be added to the environment. =*/ static char* doDir_define(char* pzArg, char* pzScan) { char* pzName = pzArg; /* * Skip any #defines that do not look reasonable */ if (! IS_VAR_FIRST_CHAR(*pzArg)) return pzScan; while (IS_VARIABLE_NAME_CHAR(*pzArg)) pzArg++; /* * IF this is a macro definition (rather than a value def), * THEN we will ignore it. */ if (*pzArg == '(') return pzScan; /* * We have found the end of the name. * IF there is no more data on the line, * THEN we do not have space for the '=' required by PUTENV. * Therefore, move the name back over the "#define" * directive itself, giving us the space needed. */ if (! IS_WHITESPACE_CHAR(*pzArg)) { char* pzS = pzName; char* pzD = (pzName -= 6); *pzArg = NUL; while ((*(pzD++) = *(pzS++)) != NUL) ; pzD[-1] = '='; pzD[ 0] = NUL; } else { /* * Otherwise, insert the '=' and move any data up against it. * We only accept one name-type, space separated token. * We are not ANSI-C. ;-) */ char* pz = pzArg+1; *pzArg++ = '='; while (IS_WHITESPACE_CHAR(*pz)) pz++; for (;;) { if ((*pzArg++ = *pz++) == NUL) break; if (! IS_UNQUOTABLE_CHAR(*pz)) { *pzArg = NUL; break; } } } SET_OPT_DEFINE(pzName); return pzScan; }
/** * Will add the name to the define list as if it were a DEFINE program * argument. Its value will be the first non-whitespace token following * the name. Quotes are @strong{not} processed. * * After the definitions file has been processed, any remaining entries * in the define list will be added to the environment. */ char * doDir_define(directive_enum_t id, char const * dir, char * scan_next) { char * def_name = SPN_WHITESPACE_CHARS(dir); (void)id; /* * Skip any #defines that do not look reasonable */ if (! IS_VAR_FIRST_CHAR(*def_name)) return scan_next; dir = SPN_VARIABLE_NAME_CHARS(def_name); /* * IF this is a macro definition (rather than a value def), * THEN we will ignore it. */ if (*dir == '(') return scan_next; /* * We have found the end of the name. * IF there is no more data on the line, * THEN we do not have space for the '=' required by PUTENV. * Therefore, move the name back over the "#define" * directive itself, giving us the space needed. */ if (! IS_WHITESPACE_CHAR(*dir)) { char * pzS = (char *)dir; char * pzD = (def_name - 6); *pzS = NUL; // whatever it used to be, it is a NUL now. pzS = def_name; while ((*(pzD++) = *(pzS++)) != NUL) ; pzD[-1] = '='; pzD[ 0] = NUL; def_name -= 6; } else { /* * Otherwise, insert the '=' and move any data up against it. * We only accept one name-type, space separated token. * We are not ANSI-C. ;-) */ char * pz = (char *)(dir++); *pz++ = '='; dir = SPN_WHITESPACE_CHARS(dir); /* * Copy chars for so long as it is not NUL and does not require quoting */ for (;;) { if ((*pz++ = *dir++) == NUL) break; if (! IS_UNQUOTABLE_CHAR(*dir)) { *pz = NUL; break; } } } SET_OPT_DEFINE(def_name); return scan_next; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * It may be a number, a name, a keyword or garbage. * Figure out which. */ static char* assembleName(char * pzScan, te_dp_event * pRetVal) { /* * Check for a number. * Scan it in and advance "pzScan". */ if ( IS_DEC_DIGIT_CHAR(*pzScan) || ( (*pzScan == '-') && IS_DEC_DIGIT_CHAR(pzScan[1]) ) ) { pz_token = pzScan; (void)strtol(pzScan, &pzScan, 0); *pRetVal = DP_EV_NUMBER; return pzScan; } if (! IS_UNQUOTABLE_CHAR(*pzScan)) AG_ABEND(aprf("%s Error: Invalid input char '%c' in %s on line %d\n", pzProg, *pzScan, pCurCtx->pzCtxFname, pCurCtx->lineNo)); { unsigned char* pz = (unsigned char*)pzScan; while (IS_VALUE_NAME_CHAR(*pz)) pz++; if (IS_UNQUOTABLE_CHAR(*pz)) { *pRetVal = DP_EV_OTHER_NAME; while (IS_UNQUOTABLE_CHAR(*++pz)) ; } else *pRetVal = DP_EV_VAR_NAME; /* * Return a NAME token, maybe. * If the name is actually a keyword, * we will return that token code instead. */ pz_token = pzScan; pzScan = (char*)pz; } /* * Now scan the keyword table. */ if (*pRetVal == DP_EV_VAR_NAME) { char sv_ch = *pzScan; /* preserve the following character */ int kw_ix = 0; *pzScan = NUL; /* NUL terminate the name */ do { if (streqvcmp(apzKeywords[ kw_ix ], (char*)pz_token) == 0) { /* * Return the keyword token code instead of DP_EV_NAME */ *pRetVal = aKeywordTkn[ kw_ix ]; break; } } while (++kw_ix < KEYWORD_CT); *pzScan = sv_ch; /* restore the following character */ } return pzScan; }