int quoted(char **pp) /* pick up next thing after a \\ */ /* and increment *pp */ { char *p = *pp; int c; if ((c = *p++) == 't') c = '\t'; else if (c == 'n') c = '\n'; else if (c == 'f') c = '\f'; else if (c == 'r') c = '\r'; else if (c == 'b') c = '\b'; else if (c == '\\') c = '\\'; else if (c == 'x') { /* hexadecimal goo follows */ c = hexstr(&p); /* this adds a null if number is invalid */ } else if (isoctdigit(c)) { /* \d \dd \ddd */ int n = c - '0'; if (isoctdigit(*p)) { n = 8 * n + *p++ - '0'; if (isoctdigit(*p)) n = 8 * n + *p++ - '0'; } c = n; } /* else */ /* c = c; */ *pp = p; return c; }
void quoted(char **s, char **to, char *end) /* handle escaped sequence */ { char *p = *s; char *t = *to; wchar_t c; switch(c = *p++) { case 't': c = '\t'; break; case 'n': c = '\n'; break; case 'f': c = '\f'; break; case 'r': c = '\r'; break; case 'b': c = '\b'; break; default: if (t < end-1) /* all else must be escaped */ *t++ = '\\'; if (c == 'x') { /* hexadecimal goo follows */ c = hexstr(&p); if (t < end-MB_CUR_MAX) t += wctomb(t, c); else overflow(); *to = t; *s = p; return; } else if (isoctdigit(c)) { /* \d \dd \ddd */ c -= '0'; if (isoctdigit(*p)) { c = 8 * c + *p++ - '0'; if (isoctdigit(*p)) c = 8 * c + *p++ - '0'; } } break; } if (t < end-1) *t++ = c; *s = p; *to = t; }
static char ReadEscapeNumeric(LPCSTR& szSrc, int iBase) { char s[4]; LPSTR sz; int i = 0; for(; i < 3; i++) { int c = szSrc[i]; if (iBase == 16) { if (!isxdigit(c)) break; } else { if (!isoctdigit(c)) break; } s[i] = szSrc[i]; } s[i] = 0; szSrc += i; return char(strtol(s, &sz, iBase)); }
void CQuickBuildString::UnescapeString(LPCSTR szSrc) { CQuickBuildString& cs = *this; while(*szSrc) { unsigned char c = *szSrc++; if (c == '\\') { char c = *szSrc++; switch(c) { case 'a' : cs += '\a'; continue; case 'b' : cs += '\b'; continue; case 'f' : cs += '\f'; continue; case 'n' : cs += '\n'; continue; case 'r' : cs += '\r'; continue; case 't' : cs += '\t'; continue; case 'v' : cs += '\v'; continue; case '\'': cs += '\''; continue; case '"' : cs += '\"'; continue; case '\\': cs += '\\'; continue; case 'x': cs += ReadEscapeNumeric(szSrc, 16); break; default: if (isoctdigit(c)) cs += ReadEscapeNumeric(szSrc, 8); break; } } else { cs += c; } } CheckValid(); }
int parse_wide_string_literal (unsigned char **str_ptr, caddr_t box, wcharset_t *charset) { unsigned int i = 0; volatile unsigned int q; wchar_t z; UCHAR *str = (**str_ptr == 'N' || **str_ptr == 'n') ? *str_ptr + 1 : *str_ptr; UCHAR beg_quote = *str++; /* And skip past N and it. */ wchar_t c; wchar_t *result = (wchar_t *)box; if (!charset) { client_connection_t *cli = GET_IMMEDIATE_CLIENT_OR_NULL; if (cli) charset = cli->cli_charset; } if (!charset) charset = default_charset; for (/* no init */; '\0' != str[0]; str++) { switch (str[0]) { case '\\': /* An escaped character follows? */ { if (!parse_not_char_c_escape) { /* New escapes added 23.AUG.1991 \a for bell, and \v for vertical tab as specified in ANSI C standard. Also now recognizes hexadecimal character constants beginning with \x Note that \e for escape does not belong to standard. (Commented out) */ switch (*++str) /* Check the next character. */ { /* If a string anomalously ends with a trailing (single) backslash, then leave it dangling there: */ case '\0': { c = CHAR_TO_WCHAR(*(str - 1), charset); break; } case 'a': { c = (wchar_t)7; break; } /* BEL audible alert */ case 'b': { c = (wchar_t)'\b'; break; } /* BS backspace */ /* case 'e': { c = '\033'; break; } *//* ESC escape */ case 'f': { c = (wchar_t)'\f'; break; } /* FF form feed */ case 'n': { c = (wchar_t)'\n'; break; } /* NL (LF) newline */ case 'r': { c = (wchar_t)'\r'; break; } /* CR carriage return */ case 't': { c = (wchar_t)'\t'; break; } /* HT horizontal tab */ case 'v': { c = (wchar_t)'\013'; break; } /* VT vertical tab */ case 'x': /* There's a hexadecimal char constant \xhh */ case 'X': { /* We should check that only max 2 digits are parsed */ q = 4; z = 0; str++; while (*str && isxdigit (*str) && (q--)) { z = ((z << 4) + (isdigit (*str) ? (*str - '0') : (toupper (*str) - 'A' + 10))); str++; } c = z; if (!z) return -1; str--; /* str is incremented soon. */ break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { /* So it's an octal sequence like \033 : */ q = 6; z = 0; while (isoctdigit (*str) && (q--)) { z = ((z << 3) + (*str++ - '0')); } c = z; str--; /* str is incremented soon. */ if (!z) return -1; break; } /* octal digits */ /* \\\n should not appear in the output at all */ case '\n': case '\r': continue; default: /* Every other character after backslash produces */ { /* that same character, i.e. \\ = \, \' = ', etc. */ c = CHAR_TO_WCHAR(*str, charset); break; } /* default */ } /* inner switch for character after a backslash */ if (result) result[i] = c; i++; break; } /* if for processing backslashes */ } /* case for backslash. */ default: { if (*str == beg_quote) { /* If the next char is a quote also, then this is not yet the terminating quote */ if (*(str + 1) == beg_quote) { str++; /* Skip that quote next time. */ goto copy_char; } else { /* String is terminated. */ goto out; } } else /* Any other character. */ { copy_char: if (result) result[i] = CHAR_TO_WCHAR(*str, charset); i++; break; } } } /* outer switch */ } /* for loop */ out:; if (result) { result[i] = L'\0'; } /* Put a terminating zero. */ if (*str) /* The terminating quote is here. */ { *str_ptr = str + 1; /* Skip past it. */ } else { /* The terminating quote is missing, we should produce an error here! */ *str_ptr = str; /* But in this version we are tolerant of that. */ } return ((i + 1) * sizeof(wchar_t)); /* Return the length. */ }
int vanilla::scanner::read_number_lit(token& t) { if(*_cur == '0') { next(); // Base 16. if(*_cur == 'x' || *_cur == 'X') { next(); char const* begin = _cur; while(std::isxdigit(*_cur)) next(); char const* end = _cur; if(begin == end) return SCANNER_ERROR; t.type = ttype::int_lit; t.lexeme = cstr_range(begin, end); t.flags = token_flags::INT_FLAG_BASE16; return SCANNER_SUCCESS; } // Base8. else if(isoctdigit(*_cur)) { char const* begin = _cur; do { next(); } while(isoctdigit(*_cur)); char const* end = _cur; t.type = ttype::int_lit; t.lexeme = cstr_range(begin, end); t.flags = token_flags::INT_FLAG_BASE8; return SCANNER_SUCCESS; } // Base2. else if(*_cur == 'b' || *_cur == 'B') { next(); char const* begin = _cur; while(isbindigit(*_cur)) next(); char const* end = _cur; if(begin == end) return SCANNER_ERROR; t.type = ttype::int_lit; t.lexeme = cstr_range(begin, end); t.flags = token_flags::INT_FLAG_BASE2; return SCANNER_SUCCESS; } // A real of the format 0.***** // Or 0 followed by the element selection operator! else if(*_cur == '.' && std::isdigit(_cur[1])) { char const* begin = _cur - 1; next(); while(std::isdigit(*_cur)) next(); char const* end = _cur; t.type = ttype::real_lit; t.lexeme = cstr_range(begin, end); t.flags = 0; return SCANNER_SUCCESS; } // The 0 literal. else { t.type = ttype::int_lit; t.lexeme = cstr_range(_cur - 1, _cur); t.flags = token_flags::INT_FLAG_BASE10; return SCANNER_SUCCESS; } } // Base 10. else { char const* begin = _cur; while(std::isdigit(*_cur)) next(); char const* end = _cur; if(begin == end) return SCANNER_NOMATCH; // A real OR an int followed by the element selection operator! if(*_cur == '.' && std::isdigit(_cur[1])) { next(); while(std::isdigit(*_cur)) next(); end = _cur; t.type = ttype::real_lit; t.lexeme = cstr_range(begin, end); t.flags = 0; return SCANNER_SUCCESS; } t.type = ttype::int_lit; t.lexeme = cstr_range(begin, end); t.flags = token_flags::INT_FLAG_BASE10; return SCANNER_SUCCESS; } }
/* * primop = ( conexpr ) * | integer * | label */ int parse_primop(char **p) { char lbl[MAX_SYMLEN]; char *pp; long val; int idx; skip_ws(p); pp = *p; /* handle parenthesized expressions */ if (*pp == '(') { pp++; /* skip open paren */ val = parse_logop(&pp); skip_ws(&pp); if (*pp != ')') { error("missing closing paren"); } *p = pp+1; /* skip closing paren. */ return val; } /* handle integers and labels */ if (*pp == '0') { pp++; if (*pp == 'x') { /* hex number: 0x[0-9a-f]+ */ pp++; if (!ishexdigit(*pp)) { /* must have at least one digit after the "0x" */ error("badly formed hex number"); *p = pp; return 0; } val = hexval(*pp); pp++; while (ishexdigit(*pp)) { val = 16*val + hexval(*pp); pp++; } } else { /* octal number: 0[0-7]* */ val = 0; while (isoctdigit(*pp)) { val = 8*val + (*pp) - '0'; pp++; } } } else if (isdigit((unsigned)*pp)) { /* presumably decimal value */ val = 0; while (isdigit((unsigned)*pp)) { val = 10*val + (*pp) - '0'; pp++; } } else { /* assume it is a label */ parse_label(p, lbl); if (strlen(lbl) == 0) { /* oops, what is it? */ error("error: expected constant expression"); return 0; } idx = find_sym_idx(lbl); if (idx) { val = symtab[idx].value; } else { val = 0x00; /* dummy value */ if (g_pass == 2) error("couldn't find symbol in second pass"); } pp = *p; /* nullifies later assignment */ } *p = pp; return val; }