char *copy_token(char *p, char *tok) { char *ptok = tok; int i = 0; while (iscsym(*p) && i < MAX_IDEN_SIZE) *ptok++ = *p++; *ptok = '\0'; return p; }
/** * Return a pointer to the specified string, stripped of leading and trailing * non-C symbol characters. * * Note that pszStr may be changed after return, the first trailing non-C symbol * will be replaced with a null. * * @param pszStr The string to strip. * * @return A pointer to the start of the stripped string. */ static __inline PSZ stripNonCSyms( PSZ pszStr ) { CHAR *pFront = pszStr; CHAR *pBack = pszStr + strlen(pszStr); while ( pBack > pFront && ! iscsym(*pBack) ) pBack--; if ( ! iscsym(*pBack) ) { // No C symbols in string. *pBack = 0x0; } else { *(++pBack) = 0x0; while ( pFront < pBack && ! iscsym(*pFront) ) pFront++; } return pFront; }
void GetName() { unsigned int v = 0; char *NamePtr = Name; while (iscsym(*FilePtr)) { *NamePtr++ = *FilePtr++; if (v++ >= NAME_MAX) Error(Error_Fatal, "Symbol too int"); } *NamePtr++ = 0; return; }
bool CSrScriptFile::TokenAlpha (const char*& pParse) { const char* pStartToken = pParse; srscripttoken_t* pToken; while (*pParse) { if (!iscsym(*pParse)) break; ++pParse; } pToken = m_Tokens.AddNew(); pToken->Token.Copy(pStartToken, pParse - pStartToken); pToken->Type = SR_TOKEN_IDENTIFIER; return true; }
char * GetSym() { unsigned int v = 0; char *NamePtr = xName; char c; while (iscsym(*FilePtr)) { c = *FilePtr++; if (c == '.') c = '_'; *NamePtr++ = c; if (v++ >= MOSYNC_NAME_MAX) Error(Error_Fatal, "Symbol too int"); } *NamePtr++ = 0; return xName; }
// --- bool get_token( const char*& s, CStr& t ) { if ( !s ) return false; while( isspace(*s) ) s++; while( skip_comment(s) ) ; switch( *s ) { case TERM: return false; case STAR : case BRACKET_O : case BRACKET_C : case BRACE_O : case COMMA : case SEMICOLON : case COLON : ((char*)memcpy( t=new char[2], s++, 1 ))[1] = 0; return true; } const char* b = s; while( iscsym(*s) ) s++; if ( s > b ) { ((char*)memcpy( t=new char[s-b+1], b, s-b ))[s-b] = 0; return true; } else { t = 0; return false; } }
UBYTE *tokenize_word(register UBYTE *line,/* (in) -> current line position */ register UBYTE *word,/* (in) -> output token buffer */ UBYTE *qstring, /* (in) -> quoted string o/p buffer*/ SHORT *plen, /* (out) # of bytes put in word buf */ SHORT *ttype, /* (out) token type */ Boolean quote /* (in) preserve quotes on string? */ ) { UBYTE *wrkptr; UBYTE *sword = word; int toklen; SHORT toktype; register unsigned int c; UBYTE c1; UBYTE c2; /*---------------------------------------------------------------------------- * Skip leading whitespace, get the first character, return NULL if no char. *--------------------------------------------------------------------------*/ while (isspace(*line) ) ++line; if ('\0' == (c = *line)) { line = NULL; goto OUT; } /*---------------------------------------------------------------------------- * Handle keywords, types, symbols *--------------------------------------------------------------------------*/ if (iscsymf(c)) { line = po_chop_csym(line, word, MAX_SYM_LEN-1, &wrkptr); word = wrkptr; toktype = TOK_UNDEF; } #ifdef DEADWOOD else if (iscsymf(c)) { toktype = TOK_UNDEF; *word++ = c; ++line; toklen = MAX_SYM_LEN; for (;;) { c = *line; if (iscsym(c)) { ++line; if (toklen) { *word++ = c; --toklen; } } else break; } } #endif /* DEADWOOD */ /*---------------------------------------------------------------------------- * Handle numeric constants *--------------------------------------------------------------------------*/ else if (isdigit(c)) { toklen = get_digits(line,word,&toktype); line += toklen; word += toklen; } /*---------------------------------------------------------------------------- * Handle C operators and string/char constants... * This processes non-alphanumeric characters. Most will be passed through * as single character tokens. Some, like ==, !=, >= and <= are easier to * handle here than in parser (which only has a one-token look-ahead). * Also, quoted strings and chars are now handled in this switch statement. *--------------------------------------------------------------------------*/ else { c1 = line[1]; /* lookahead characters */ c2 = line[2]; switch (c) { case '"': /* note: a shortcut in this loop */ /* assumes that a quoted string */ if (qstring != NULL) /* could never be longer than */ sword = word = qstring; /* SZTOKE-3 chars. */ toktype = TOK_QUO; if (quote) *word++ = '"'; ++line; toklen = SZTOKE-3; /* room for nullterm and two quotes */ while(--toklen) { c = *line++; if (c == 0) break; else if (c == '\\') { if (quote) { *word++ = c; *word++ = *line++; } else { wrkptr = line; *word++ = translate_escape(&wrkptr); line = wrkptr; } } else if (c == '\"') { break; } else { *word++ = c; } } if (quote) *word++ = '"'; break; case '\'': if (quote) *word++ = '\''; toktype = TOK_SQUO; ++line; for (;;) { c = *line++; if (c == 0) break; else if (c == '\\') { if (quote) { *word++ = c; *word++ = *line++; } else { wrkptr = line; *word++ = translate_escape(&wrkptr); line = wrkptr; } } else if (c == '\'') { break; } else { *word++ = c; } } if (quote) *word++ = '\''; break; case '.': if (c1 == '.' && c2 == '.') { toktype = TOK_UNDEF; goto THREECHAR; } else goto SIMPLE; case '%': if (c1 == '=') /* mod-equals */ { toktype = TOK_MOD_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '/': if (c1 == '=') /* div-equals */ { toktype = TOK_DIV_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '*': if (c1 == '=') { toktype = TOK_MUL_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '+': if (c1 == '+') { toktype = TOK_PLUS_PLUS; goto TWOCHAR; } else if (c1 == '=') { toktype = TOK_PLUS_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '-': if (c1 == '-') { toktype = TOK_MINUS_MINUS; goto TWOCHAR; } else if (c1 == '=') { toktype = TOK_MINUS_EQUALS; goto TWOCHAR; } else if (c1 == '>') { toktype = TOK_ARROW; goto TWOCHAR; } else goto SIMPLE; case '=': if (c1 == '=') /* double equals */ { toktype = TOK_EQ; goto TWOCHAR; } else goto SIMPLE; case '!': if (c1 == '=') /* != */ { toktype = TOK_NE; goto TWOCHAR; } else goto SIMPLE; case '<': if (c1 == '=') /* <= */ { toktype = TOK_LE; goto TWOCHAR; } else if (c1 == '<') /* << */ { if (c2 == '=') { toktype = TOK_LSHIFT_EQUALS; goto THREECHAR; } else { toktype = TOK_LSHIFT; goto TWOCHAR; } } else goto SIMPLE; case '>': if (c1 == '=') /* >= */ { toktype = TOK_GE; goto TWOCHAR; } else if (c1 == '>') /* >> */ { if (c2 == '=') { toktype = TOK_RSHIFT_EQUALS; goto THREECHAR; } else { toktype = TOK_RSHIFT; goto TWOCHAR; } } else goto SIMPLE; case '&': if (c1 == '&') /* logical and - && */ { toktype = TOK_LAND; goto TWOCHAR; } else if (c1 == '=') { toktype = TOK_AND_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '|': if (c1 == '|') /* logical or - || */ { toktype = TOK_LOR; goto TWOCHAR; } else if (c1 == '=') { toktype = TOK_OR_EQUALS; goto TWOCHAR; } else goto SIMPLE; case '^': if (c1 == '=') { toktype = TOK_XOR_EQUALS; goto TWOCHAR; } else goto SIMPLE; default: SIMPLE: toktype = *word++ = c; ++line; break; } } OUT: *ttype = toktype; *word = 0; if (plen != NULL) *plen = word - sword; return line; TWOCHAR: *word++ = c; *word++ = c1; line += 2; goto OUT; THREECHAR: *word++ = c; *word++ = c1; *word++ = c2; line += 3; goto OUT; }