int skipWhiteSpace( UCHAR stream ) { int c; do { c = GET(stream); if (WHITESPACE(c) || c == ESCH) { if (c == ESCH) { c = GET(stream); if (!WHITESPACE(c)) { // push char back out, return esch UngetTxtChr(c, file); c = ESCH; break; } } colZero = FALSE; // we've moved past col 0 } if (c == '\\') c = skipBackSlash(c, stream); } while(WHITESPACE(c)); if (COMMENT(c,colZero,init)) { skipComments(stream); // current char is always c = '\n'; // \n after comments colZero = TRUE; // always in col 0 after a comment } return(c); // true if we're in col 0 }
/******************************************************************************* This function parses a text line into a number of arguments, and puts a pointer to each argument (up to the maximum number maxnargs) in the pointer array. THIS IS A DESTRUCTIVE FUNCTION. It puts null termination characters at the end of each of the arguments in the input line. *******************************************************************************/ int parseline(char *bolchptr, char *argptrtbl[], int maxnargs) { Flag escapeflag; char *toptr, *fromptr; char *chptr = bolchptr; /* bol = beginning of line */ int idx, argctr = 0; /* if line has ESCAPECHAR anywhere in it */ escapeflag = (strchr(bolchptr, ESCAPECHAR) != NULL ? TRUE : FALSE); for (idx=0; idx<maxnargs; idx++) /* set all pointers to NULL */ argptrtbl[idx] = NULL; while(WHITESPACE(*chptr)) /* skip any initial whitespaces */ chptr++; while (*chptr) { /* main loop */ /* if a comment or we've already got enough args, get out */ if (*chptr == COMCHAR || argctr >= maxnargs) break; if (NONESCAPEDQUOTE(bolchptr, chptr)) { /* deal with quotes */ argptrtbl[argctr++] = ++chptr; while (*chptr && !NONESCAPEDQUOTE(bolchptr, chptr)) chptr++; } else { /* normal case, no quotes */ argptrtbl[argctr++] = chptr++; while (*chptr && !WHITESPACE(*chptr)) chptr++; } *chptr++ = '\0'; while (*chptr && WHITESPACE(*chptr)) /* skip whitespace after arg */ chptr++; } if (escapeflag) { /* if _any_ of the args had an <\">, rm all the <\> */ for (idx=0; idx<argctr; idx++) { fromptr = toptr = bolchptr = argptrtbl[idx]; while (*fromptr) { if (ESCAPEDQUOTE(bolchptr, fromptr)) toptr--; *toptr++ = *fromptr++; } *toptr = '\0'; } } return argctr; }
static void usage(char *name) { printf("usage: %s %s\n", name , "--system=SYSTEM_TO_USE"); printf(" %s %s\n", WHITESPACE(strlen(name)), "--ubench=MICROBENCHMARK_TO_RUN"); printf(" %s %s\n", WHITESPACE(strlen(name)), "--runtime=RUNTIME_OF_EXPERIMENT_IN_SECONDS"); printf(" %s %s\n", WHITESPACE(strlen(name)), "--nthreads=NUMBER_OF_THREADS"); printf(" %s %s\n", WHITESPACE(strlen(name)), "--nwrites=NUMBER_OF_WRITES_PER_TRANSACTION"); printf("\nValid arguments:\n"); printf(" --ubench [base|tornbit]\n"); printf(" --system [rawlog]\n"); printf(" --nthreads [1-%d]\n", MAX_NUM_THREADS); exit(1); }
UCHAR getToken( unsigned n, // size of s[] UCHAR expected // STRING means get line ) // w/o checking for #;:= { char *s; char *end; int c; s = buf; end = buf + n; if (firstToken) { // global var ++line; firstToken = FALSE; // parser needs to see some kind of c = lgetc(); // newline to initialize it if ((colZero = (BOOL) !WHITESPACE(c))) { if (c == EOF) return(determineTokenFor(c,s,end)); else UngetTxtChr(c,file); return(NEWLINE); } return(NEWLINESPACE); } if (expected == STRING || expected == VALUE) { // get everything up to \n getString(expected,s,end); return(expected); } // were/are we c = skipWhiteSpace(FROMLOCAL); // past col 0? *s++ = (char) c; // save the letter *s = '\0'; // terminate s return(determineTokenFor(c,s,end)); }
UCHAR include( int c ) { size_t n; char *s; if (c == '\n' || c == EOF) makeError(line,SYNTAX_NO_NAME); *buf = (char) c; if (!fgets(buf+1,MAXBUF - 1,file)) { if (feof(file)) makeError(line,SYNTAX_UNEXPECTED_TOKEN,"EOF"); makeError(line,CANT_READ_FILE); } n = _tcslen(buf) - 1; if (buf[n] == '\n') { buf[n] = '\0'; } s = buf; while (WHITESPACE(*s)) ++s; return(processIncludeFile(s)); }
bool wxHtmlSearchEngine::Scan(const wxFSFile& file) { wxASSERT_MSG(!m_Keyword.empty(), wxT("wxHtmlSearchEngine::LookFor must be called before scanning!")); wxHtmlFilterHTML filter; wxString bufStr = filter.ReadFile(file); if (!m_CaseSensitive) bufStr.LowerCase(); { // remove html tags wxString bufStrCopy; bufStrCopy.reserve( bufStr.size() ); bool insideTag = false; for (const wxChar * pBufStr = bufStr.c_str(); *pBufStr; ++pBufStr) { wxChar c = *pBufStr; if (insideTag) { if (c == wxT('>')) { insideTag = false; // replace the tag by an empty space c = wxT(' '); } else continue; } else if (c == wxT('<')) { wxChar nextCh = *(pBufStr + 1); if (nextCh == wxT('/') || !WHITESPACE(nextCh)) { insideTag = true; continue; } } bufStrCopy += c; } bufStr.swap( bufStrCopy ); } wxString keyword = m_Keyword; if (m_WholeWords) { // insert ' ' at the beginning and at the end keyword.insert( 0, wxT(" ") ); keyword.append( wxT(" ") ); bufStr.insert( 0, wxT(" ") ); bufStr.append( wxT(" ") ); } // remove continuous spaces keyword = CompressSpaces( keyword ); bufStr = CompressSpaces( bufStr ); // finally do the search return bufStr.find( keyword ) != wxString::npos; }
// replace continuous spaces by one single space static inline wxString CompressSpaces(const wxString & str) { wxString buf; buf.reserve( str.size() ); bool space_counted = false; for( const wxChar * pstr = str.c_str(); *pstr; ++pstr ) { wxChar ch = *pstr; if( WHITESPACE( ch ) ) { if( space_counted ) { continue; } ch = wxT(' '); space_counted = true; } else { space_counted = false; } buf += ch; } return buf; }
static void m_stats_statset_print(FILE *fout, m_stats_statset_t *statset, int shiftlen, int print_header) { int i; char header[512]; double mean; m_stats_statcounter_t max; m_stats_statcounter_t min; m_stats_statcounter_t total; m_stats_statcounter_t count; if (print_header) { sprintf(header, "Transaction: %s", statset->name); fprintf(fout, "%s%s\n\n", WHITESPACE(shiftlen), header); } fprintf(fout, "%s%s%s:%13s%13s%13s%13s\n", WHITESPACE(shiftlen+2), "", WHITESPACE(25), "Min", "Mean", "Max", "Total"); count = statset->count; fprintf(fout, "%s%s%s:%13s%13s%13s%13u\n", WHITESPACE(shiftlen+2), "Transactions", WHITESPACE(25 - strlen("Transactions")), "", "", "", count); for (i=0; i<m_stats_numofstats; i++) { total = statset->stats[i].total; min = statset->stats[i].min; max = statset->stats[i].max; mean = (double) total / (double) count; fprintf(fout, "%s%s%s:%13u%13.2f%13u%13u\n", WHITESPACE(shiftlen+2), stats_strings[i], WHITESPACE(25 - strlen(stats_strings[i])), min, mean, max, total); } }
char * nextComponent( char **szExpStr ) { char *t, *next; t = *szExpStr; while (WHITESPACE(*t)) t++; next = t; if (!*t) return(NULL); if (*t == '"') { for (; *++t && *t != '"';) ; } else { for (; *t && *t != ' ' && *t != '\t'; t++) ; } if (WHITESPACE(*t)) { *t = '\0'; } else if (*t == '"') { t++; if(*t=='\0') t--; // If this is the end of the string, backup a byte, so we don't go past next time else *t = '\0'; // else stop here for this time. } else if (!*t) { // If at end of string then backup a byte so that next time we don't go past t--; } *szExpStr = t+1; return(next); }
void tokenizeLine( // gets args delimited char *s, // by whitespace and unsigned *count, // constructs an arg char **vector[] // vector ) { char *t; if ((t = _tcschr(s,'\\'))) { if (WHITESPACE(*(t-1)) && (*(t+1) == '\n')) { *t = '\0'; } } for (t = _tcstok(s," \t\n"); t; t = _tcstok(NULL," \t\n")) { if (*t == '@') { makeError(0,SYNTAX_CMDFILE,t+1); break; // should we keep on parsing here? } addArgument(t,*count,vector); ++*count; } }
/* expects s-expressions of the user friendly form (spocp (resource (printer hp))) and converts it to the canonical form */ static char *sexp_to_canonical( char *canon, char *sexp ) { char *sp, *cp, *lp, *ep, c ; int n, len ; sp = sexp, cp = canon ; len = 0 ; ep = 0 ; while( *sp ) { if( LISTDELIM(*sp) ) { c = *sp ; *sp++ = 0 ; if( ep ) { cp = print_len_spec( cp, strlen(ep) ) ; strcpy( cp, ep ) ; cp += strlen( ep ) ; ep = 0 ; } *cp++ = c ; } else if( WHITESPACE(*sp )) { *sp++ = 0 ; if( ep ) { cp = print_len_spec( cp, strlen(ep) ) ; strcpy( cp, ep ) ; cp += strlen( ep ) ; ep = 0 ; } while( WHITESPACE(*sp) ) sp++ ; } else if( *sp == '"' ) { lp = ep = ++sp ; while( *lp && *lp != '"' ) lp++ ; if( *lp ) { *lp++ = 0 ; n = ep - lp ; cp = print_len_spec( cp, n ) ; /* Flawfinder: ignore */ strcpy( cp, ep ) ; cp += strlen( ep ) ; ep = 0 ; sp = ep ; } else { free( canon ) ; return 0 ; } } else{ if( ep == 0 ) ep = sp ; sp++ ; } } *cp = 0 ; return canon ; }
/* Read one token from the port <port>. */ static SshAsn1Status asn1parsetoken(SshAsn1Format port, SshAsn1FormatToken token) { int ch; unsigned int i = 0; token->data = NULL; loop: ch = GETCH(port); /* EOF? */ if (ch == '\0') { token->type = tEOF; return SSH_ASN1_STATUS_OK; } /* Whitespace? */ if (WHITESPACE(ch)) goto loop; /* Symbol? */ if (INITIAL(ch)) { if ((token->data = ssh_fastalloc_alloc(port->valuebag)) == NULL) return SSH_ASN1_STATUS_ERROR; /* Yes it is a symbol. */ token->data[i++] = ch; while (1) { if (i + 1 >= ASN1_MAX_TOKEN_LEN) { ssh_fastalloc_free(port->valuebag, token->data); return SSH_ASN1_STATUS_UNKNOWN_COMMAND; } ch = GETCH(port); if (ch == tEOF) break; if (!SUBSEQUENT(ch)) { UNGETCH(port, ch); break; } token->data[i++] = ch; } token->data[i] = '\0'; token->type = tSYMBOL; return SSH_ASN1_STATUS_OK; } /* Number? */ if (DIGIT(ch)) { UNGETCH(port, ch); return asn1parsenumber(port, token); } /* Parenthesis. */ if (ch == '(') { token->type = tLPAREN; return SSH_ASN1_STATUS_OK; } if (ch == ')') { token->type = tRPAREN; return SSH_ASN1_STATUS_OK; } return SSH_ASN1_STATUS_UNKNOWN_COMMAND; }
void processLine( char *s, unsigned *count, char **vector[] ) { char *t; char *u; size_t m; size_t n; BOOL allocFlag = FALSE; if (!(t = _tcschr(s,'"'))) { // no quoted strings, tokenizeLine(s,count,vector); // just standard fare } else { // There are two kinds of situations in which quotes can occur: // 1. "FOO = bar baz" // 2. FOO="bar baz" if ((t == s) || (*(t-1) != '=')) { // Case 1 above *t++ = '\0'; // quoted macrodef tokenizeLine(s,count,vector); // get tokens before " } else { // Case 2 above *t-- = ' '; for (u = t; u > s; --u) // find the beginning of the macro name if (*u == ' ' || *u == '\t' || *u == '\n') break; if (u != s) { *u++ = '\0'; tokenizeLine(s, count, vector); } t = u; } n = _tcslen(t); for (u = t; *u; ++u) { // look for closing " if (*u == '"') { // need " and not "" if (*(u+1) == '"') { _tcscpy(u,u+1); continue; } *u++ = '\0'; // terminate macrodef addArgument(t,*count,vector); // treat as one arg ++*count; processLine(u+1,count,vector); // recurse on rest of line break; } // TAIL RECURSION if ((*u == '\\') && WHITESPACE(*(u-1)) && (*(u+1) == '\n')) { // \n always last char *u = '\0'; // 2 chars go to 1 m = (n = n-2); // adjust length count if (!allocFlag) { allocFlag = TRUE; t = makeString(t); } getRestOfLine(&t,&n); // get some more text u = t + m ; // reset u & continue looping } } if (u == t + n) { // if at end of line makeError(0,SYNTAX_NO_QUOTE); // and no ", error } if (allocFlag) { FREE(t); } } }
UCHAR processIncludeFile( char *s ) { MACRODEF *m; struct _finddata_t finddata; NMHANDLE searchHandle; char *t, *p, *u; int c = 0; int i; if (!*s || *s == '#') { makeError(line, SYNTAX_NO_NAME); } if ((t = _tcspbrk(s,"\t#"))) { if (*t == '#') { c = *t; } *t = '\0'; if (!c) { for (u = t; *++u;) { // check for extra if (*u == '#') { break; // text on line } if (!WHITESPACE(*u)) { makeError(line, SYNTAX_UNEXPECTED_TOKEN, u); } } } } else { t = s + _tcslen(s); } // remove trailing white space while (t > s) { char *prev; prev = _tcsdec(s, t); if (!WHITESPACE(*prev)) break; t = prev; } *t = '\0'; if (*s == '<' && *(t-1) == '>') { char *pt; *--t = '\0'; p = removeMacros(++s); p = p == s ? makeString(s) : p; t = (m = findMacro("INCLUDE")) ? m->values->text : (char*) NULL; if (t != NULL) { // expand INCLUDE macro before passing it on char * pt1; pt1= makeString(t); pt = removeMacros(pt1); if (pt != pt1) { FREE(pt1); // we've got a new string, free old one } } else { pt = NULL; } if (!(u = searchPath(pt, p, &finddata, &searchHandle))) { makeError(line, CANT_OPEN_FILE, p); } if (pt) { FREE(pt); } FREE(p); s = u; } else { if (*s == '"' && *(t-1) == '"') { *--t = '\0'; ++s; } p = removeMacros(s); p = p == s ? makeString(s) : p; if (!findFirst(p, &finddata, &searchHandle)) { if (!_tcspbrk(p, "\\/:")) { //use C sematics for include for (i = incTop;i >= 0;i--) { t = (i == incTop) ? fName : incStack[i].name; if (!(t = getPath(t))) continue; u = (char *)allocate(_tcslen(t) + 1 + _tcslen(p) + 1); _tcscat(_tcscat(_tcscpy(u, t), PATH_SEPARATOR), p); if (findFirst(u, &finddata, &searchHandle)) { s = u; FREE(t); break; } FREE(t); FREE(u); } FREE(p); if (i < 0) { makeError(line, CANT_OPEN_FILE, s); } } else { makeError(line, CANT_OPEN_FILE, p); } } } for (i = 0; i < incTop; ++i) { // test for cycles if (!_tcsicmp(s,incStack[i].name)) { makeError(line, CYCLE_IN_INCLUDES, s); } } incStack[incTop].file = file; // push info on stack incStack[incTop].line = line; incStack[incTop++].name = fName; currentLine = 0; if (!(file = OpenValidateMakefile(s,"rt"))) { // read, text mode makeError(line,CANT_OPEN_FILE,s); } fName = makeString(s); line = 1; colZero = TRUE; // parser needs to see some kind of c = lgetc(); // newline to initialize it for this if ((colZero = (BOOL) !WHITESPACE(c))) { // file UngetTxtChr(c,file); line=0; // We did not start reading the file return(NEWLINE); } return(NEWLINESPACE); }
/* * Parser itself */ ssize_t __LIBFAST__pxml_parse(int *stateContext, const void *xmlbuf, size_t size, pxml_callback_f *cb, void *key) { pstate_e state = (pstate_e)*stateContext; const char *chunk_start = (const char *)xmlbuf; const char *p = chunk_start; const char *end = p + size; for(; p < end; p++) { int C = *(const unsigned char *)p; switch(state) { case ST_TEXT: /* * Initial state: we're in the middle of some text, * or just have started. */ if (C == LANGLE) /* We're now in the tag, probably */ TOKEN_CB(PXML_TEXT, ST_TAG_START, 0); break; case ST_TAG_START: if (ALPHA(C) || (C == CSLASH)) state = ST_TAG_BODY; else if (C == EXCLAM) state = ST_COMMENT_WAIT_DASH1; else /* * Not characters and not whitespace. * Must be something like "3 < 4". */ TOKEN_CB(PXML_TEXT, ST_TEXT, 1);/* Flush as data */ break; case ST_TAG_BODY: switch(C) { case RANGLE: /* End of the tag */ TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); break; case LANGLE: /* * The previous tag wasn't completed, but still * recognized as valid. (Mozilla-compatible) */ TOKEN_CB_FINAL(PXML_TAG, ST_TAG_START, 0); break; case CEQUAL: state = ST_TAG_QUOTE_WAIT; break; } break; case ST_TAG_QUOTE_WAIT: /* * State after the equal sign ("=") in the tag. */ switch(C) { case CQUOTE: state = ST_TAG_QUOTED_STRING; break; case RANGLE: /* End of the tag */ TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); break; default: if(!WHITESPACE(C)) /* Unquoted string value */ state = ST_TAG_UNQUOTED_STRING; } break; case ST_TAG_QUOTED_STRING: /* * Tag attribute's string value in quotes. */ if(C == CQUOTE) { /* Return back to the tag state */ state = ST_TAG_BODY; } break; case ST_TAG_UNQUOTED_STRING: if(C == RANGLE) { /* End of the tag */ TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); } else if(WHITESPACE(C)) { /* Return back to the tag state */ state = ST_TAG_BODY; } break; case ST_COMMENT_WAIT_DASH1: if(C == CDASH) { state = ST_COMMENT_WAIT_DASH2; } else { /* Some ordinary tag. */ state = ST_TAG_BODY; } break; case ST_COMMENT_WAIT_DASH2: if(C == CDASH) { /* Seen "<--" */ state = ST_COMMENT; } else { /* Some ordinary tag */ state = ST_TAG_BODY; } break; case ST_COMMENT: if(C == CDASH) { state = ST_COMMENT_CLO_DASH2; } break; case ST_COMMENT_CLO_DASH2: if(C == CDASH) { state = ST_COMMENT_CLO_RT; } else { /* This is not an end of a comment */ state = ST_COMMENT; } break; case ST_COMMENT_CLO_RT: if(C == RANGLE) { TOKEN_CB_FINAL(PXML_COMMENT, ST_TEXT, 1); } else if(C == CDASH) { /* Maintain current state, still waiting for '>' */ } else { state = ST_COMMENT; } break; } /* switch(*ptr) */ } /* for() */ /* * Flush the partially processed chunk, state permitting. */ if(p - chunk_start) { switch (state) { case ST_COMMENT: TOKEN_CB(PXML_COMMENT, state, 0); break; case ST_TEXT: TOKEN_CB(PXML_TEXT, state, 0); break; default: break; /* a no-op */ } } finish: *stateContext = (int)state; return chunk_start - (const char *)xmlbuf; }
void getName( char *s, char *end // pts to end of s ) { int c; UCHAR state; UCHAR input=DEFAULT_; BOOL seenBackSlash = FALSE; BOOL fQuoted = FALSE; char *beg = s - 1; BOOL parsechar; // flag to examine char. type switch (*(s-1)) { case '$': state = (UCHAR) 2; break; case '{': state = (UCHAR) 8; break; case '"': fQuoted = TRUE; state = (UCHAR)16; break; default: state = (UCHAR) 0; break; } for (;;) { c = lgetc(); parsechar = 1; // Default is examine char. if (c == ESCH) { c = lgetc(); switch (c) { case '{': // Special characters; must case '}': // not elide esch from string case '(': case ')': case '$': case ESCH: *s++ = ESCH; case '#': // elide esch right now! case '\n': case '\\': input = DEFAULT_; parsechar = 0; // DON'T examine character break; default: break; // DO examine character. } } if (parsechar) { switch (c) { case '#' : input = COMMENT_; break; case '=' : input = EQUALS_; break; case ';' : input = SEMICOLON_; break; case ':' : input = COLON_; break; case '$' : input = DOLLAR_; break; case '(' : input = OPENPAREN_; break; case ')' : input = CLOSEPAREN_; break; case '{' : input = OPENCURLY_; break; case '}' : input = CLOSECURLY_; break; case ' ' : case '\t': input = (UCHAR)((fQuoted) ? DEFAULT_ : WHITESPACE_); break; case '\n': case EOF : input = NEWLINE_; break; case '\\': input = BKSLSH_; break; case '"' : input = QUOTE_; if (state == 18) { // found a quote after a path list {...} // handle as quoted name fQuoted = 1; } break; // Add support for $* and $@ on the dependency line default : if (ON(actionFlags, A_DEPENDENT)) input = (UCHAR)((MACRO_CHAR(c) || c == '*' || c == '@') ?MACROCHAR_:DEFAULT_); else input = (UCHAR)(MACRO_CHAR(c)?MACROCHAR_:DEFAULT_); break; } } state = nameStates[state][input]; // Cheat lex table to think that you are handling quoted string case if (fQuoted && state == 1) state = 16; // seenBackSlash is used to provide lookahead when \ is seen on a // dependency line if (seenBackSlash) // if \ followed by \n then use it as a continuation if (input == NEWLINE_) { ++line; colZero = TRUE; c = lgetc(); colZero = FALSE; if (WHITESPACE(c)) { state = OK; do { c = lgetc(); } while (WHITESPACE(c)); } else state = (UCHAR)((s == buf + 1) ? BEG : DEF); } else *s++ = '\\'; seenBackSlash = FALSE; if (s >= end) makeError(line,NAME_TOO_LONG); if (state == OK) { UngetTxtChr(c,file); *s = '\0'; removeTrailChars(beg); return; } else if (ON(state,ERROR_MASK)) makeError(line,(state&~ERROR_MASK)+FATAL_ERR,c); if (state == BKS) { seenBackSlash = TRUE; //set lookahead flag } else *s++ = (char) c; } }
void getString( UCHAR type, // build string or macro value? char *s, char *end ) { int c; // buffer UCHAR state; UCHAR input = DEFAULT_; int tempC; unsigned size=0; // whenever state char *begin; // is 0, we're in // column zero BOOL parsechar; // flag to examine char. type BOOL inQuotes = (BOOL) FALSE; // flag when inside quote marks begin = s; c = lgetc(); if (type == STRING) state = (UCHAR) 2; else if (WHITESPACE(c)) { state = (UCHAR) 2; c = skipWhiteSpace(FROMLOCAL); } else if (c == ESCH) { c = lgetc(); if (WHITESPACE(c)) { state = (UCHAR) 2; c = skipWhiteSpace(FROMLOCAL); } else { UngetTxtChr(c, file); state = (UCHAR) 1; // default state c = ESCH; } } else state = (UCHAR) 1; // default state for (;;c = lgetc()) { if (c == '\"') inQuotes = (BOOL) !inQuotes; parsechar = 1; // Default is examine character. if (c == ESCH && !inQuotes && type == VALUE) { c = lgetc(); switch (c) { case '$': case ESCH: // Special characters; must case '{': case '}': // not elide esch from string case '(': case ')': case '!': case '-': case '@': *s++ = ESCH; if (s == end) { if (string == NULL) { // Increase size of s string = (char *) allocate(MAXBUF<<1); _tcsncpy(string,begin,MAXBUF); s = string + MAXBUF; size = MAXBUF << 1; end = string + size; } else { if ((size + MAXBUF < size) // overflow error || !(string = (char *) REALLOC(string,size+MAXBUF))) makeError(line, MACRO_TOO_LONG); s = string + size; size += MAXBUF; end = string + size; } begin = string; } case '#': case '\n': // elide esch right now! case '\\': case '\"': input = DEFAULT_; parsechar = 0; // DON'T examine character break; default: break; // DO examine character. } } else if (c == ESCH) { c = lgetc(); UngetTxtChr(c, file); c = ESCH; } if (parsechar) { switch (c) { case '#': input = COMMENT_; break; case '=': input = EQUALS_; break; case ':': input = COLON_; break; case '$': input = DOLLAR_; break; case '(': input = OPENPAREN_; break; case ')': input = CLOSEPAREN_; break; case '\\': input = BACKSLASH_; break; case '\n': case EOF: input = NEWLINE_; break; case ' ': case '\t': input = WHITESPACE_; break; case '*': input = STAR_; break; case '@': case '<': case '?': input = SPECIAL1_; break; case 'F': case 'D': case 'B': case 'R': input = SPECIAL2_; break; case ';': input = (UCHAR) (!state && init ? COMMENT_ : DEFAULT_); break; /* Handle comments in tools.ini */ default: input = (UCHAR) (MACRO_CHAR(c) ? MACROCHAR_:DEFAULT_); break; } } if (input == SPECIAL1_ && type == STRING && c == '<') { if ((tempC = lgetc()) == '<') { // << means start s = makeInlineFiles(s, &begin, &end); // an inline file input = NEWLINE_; c = '\n'; line--; // adding a '\n', we need to remove a line to compensate } else { UngetTxtChr(tempC,file); } state = stringStates[state][input]; } else if (input == COMMENT_) { // Handle comments if (!state) { inQuotes = (BOOL) FALSE; skipComments(FROMLOCAL); ++line; continue; } else if (type == VALUE) state = OK; // don't elide from command else state = stringStates[state][input]; } else state = stringStates[state][input]; if (state == OK) { // Accept end of string inQuotes = (BOOL) FALSE; UngetTxtChr(c,file); // Strip trailing whitespace from string. Easier to do it here, // else we have to treat a multi-string value (OBJS=a b c) as // separate tokens. while (s > begin && _istspace(s[-1])) --s; *s = '\0'; if (string) { if ((s = (char *) REALLOC(string, (size_t) (s - string + 1)))) string = s; } else string = makeString(begin); return; } else if (ON(state,ERROR_MASK)) // Error code from table makeError(line,(state&~ERROR_MASK)+FATAL_ERR,c); if (!state) { // Col 0; we just hit \nl *--s = ' '; // so treat it like white- ++s; ++line; // space; overwrite the colZero = TRUE; // backslash with a space. c = lgetc(); colZero = FALSE; if (WHITESPACE(c)) { state = 2; do { c = lgetc(); } while (WHITESPACE(c)); } UngetTxtChr(c,file); } else { // Keep storing string *s++ = (char) c; if (s == end) { if (!string) { // Increase size of s string = (char *) allocate(MAXBUF<<1); _tcsncpy(string,begin,MAXBUF); s = string + MAXBUF; size = MAXBUF << 1; end = string + size; } else { if ((size + MAXBUF < size) // overflow error || !(string = (char *) REALLOC(string,size+MAXBUF))) makeError(line, MACRO_TOO_LONG); s = string + size; size += MAXBUF; end = string + size; } } } } }
UCHAR determineTokenFor( int c, char *s, char *end ) { switch (c) { case EOF: if (!feof(file)) makeError(line,LEXER+FATAL_ERR); if (incTop) popFileStack(); else if (ifTop >= 0) // all directives not processed makeError(line,SYNTAX_EOF_NO_DIRECTIVE); else return(ACCEPT); case '\n': ++line; colZero = TRUE; c = lgetc(); if (COMMENT(c,TRUE,init)) { skipComments(FROMLOCAL); ++line; colZero = TRUE; c = lgetc(); } if ((colZero = (BOOL) !WHITESPACE(c))) { if (c == EOF) return(determineTokenFor(c,s,end)); else UngetTxtChr(c,file); //save for next token return(NEWLINE); } return(NEWLINESPACE); case ':': colZero = FALSE; if ((c = lgetc()) == ':') { *s++ = (char) c; *s = '\0'; return(DOUBLECOLON); } UngetTxtChr(c,file); return(COLON); case ';': colZero = FALSE; return(SEMICOLON); case '=': colZero = FALSE; return(EQUALS); case '[': if (init && colZero) return(ACCEPT); case ESCH: UngetTxtChr(c, file); // getName has to get esch s--; // so we don't double the caret default: getName(s,end); if (colZero && !_tcsicmp(buf, "include")) { colZero = FALSE; if ((c = skipWhiteSpace(FROMLOCAL)) != ':' && c != '=') { if (init) makeError(line, SYNTAX_UNEXPECTED_TOKEN, s); return(include(c)); } UngetTxtChr(c,file); } else colZero = FALSE; return(NAME); } }