static void test_case(const char *data) { AoS_Copy *tokens = aosc_create(20); printf("Test: [%s]\n", data); const char *word = data; while (*word != '\0') { const char *eow; eow = word = skip_space(word); if (is_alnum(*word) || (word[0] == '\'' && is_alnum(word[1]))) eow = scan_alnum(word); else if (is_punct(*word)) eow = scan_punct(word); if (eow == word) break; aosc_addbytes(tokens, word, eow); word = eow; } int num = 0; aosc_apply_ctxt(tokens, 0, aosc_length(tokens), printer, &num); putchar('\n'); aosc_destroy(tokens); }
static const char *scan_alnum(const char *src) { assert(is_alnum(*src) || *src == '\''); while (is_alnum(*src) || (src[0] == '\'' && (is_alnum(src[1]) || is_space(src[1])))) src++; return src; }
int count_words(char *str) { int i; int words; i = 0; words = 1; while (str[i] && str[i + 1]) { if (is_alnum(str[i]) == 0 && is_alnum(str[i + 1]) == 1) words++; i++; } return (words); }
int word_count(char *str) { int i; int word; word = 0; i = 0; while (str[i]) { if (is_alnum(str[i]) == 1 && is_alnum(str[i + 1]) == 0) word = word + 1; i = i + 1; } return (word); }
// identifier = letter { letter | digit } static enum v7_err parse_identifier(struct v7 *v7) { CHECK(is_alpha(*v7->cursor) || *v7->cursor == '_', V7_SYNTAX_ERROR); v7->tok = v7->cursor; v7->cursor++; while (is_alnum(*v7->cursor) || *v7->cursor == '_') v7->cursor++; v7->tok_len = (unsigned long) (v7->cursor - v7->tok); skip_whitespaces_and_comments(v7); return V7_OK; }
//------------------------------------------------------------------ bool code_colorer::is_identifier(const char_type* p, unsigned* len) const { if(*p && (is_alpha(*p) || m_identifier_charset.find(*p) != m_identifier_charset.end())) { const char_type* start = p; while(*p && (is_alnum(*p) || m_identifier_charset.find(*p) != m_identifier_charset.end())) ++p; *len = unsigned(p - start); return true; } return false; }
//------------------------------------------------------------------ bool code_colorer::is_number(const char_type* p, unsigned* len) const { if(is_digit(*p)) { const char_type* start = p; while(*p && is_alnum(*p)) ++p; *len = unsigned(p - start); return true; } return false; }
/** * @short Gets the sessionid cookie, if any, and sets it to req->session_id. * @memberof onion_request_t * @ingroup request */ void onion_request_guess_session_id(onion_request *req){ if (req->session_id) // already known. return; const char *ov=onion_dict_get(req->headers, "Cookie"); const char *v=ov; ONION_DEBUG("Session ID, maybe from %s",v); char *r=NULL; onion_dict *session=NULL; do{ // Check all possible sessions if (r) { onion_low_free(r); r=NULL; } if (!v) return; v=strstr(v,"sessionid="); if (!v) // exit point, no session found. return; if (v>ov && is_alnum(v[-1])){ ONION_DEBUG("At -1: %c %d (%p %p)",v[-1],is_alnum(v[-1]),v,ov); v=strstr(v,";"); } else{ v+=10; r=onion_low_strdup(v); // Maybe allocated more memory, not much anyway. char *p=r; while (*p!='\0' && *p!=';') p++; *p='\0'; ONION_DEBUG0("Checking if %s exists in sessions", r); session=onion_sessions_get(req->connection.listen_point->server->sessions, r); } }while(!session); req->session_id=r; req->session=session; ONION_DEBUG("Session ID, from cookie, is %s",req->session_id); }
int word_size(char *str, int j) { int i; i = 0; while (str[j]) { if (is_alnum(str[j]) == 0) return (i); j++; i++; } return (i); }
/** * returns true if the text is keyword */ int is_keyword(const char *name) { char *p = (char *) name; if (p == NULL) { return 0; } if (is_alpha(name[0])) { while (is_alnum(*p) || (*p == '_')) { p++; } return (*p == '\0'); } return 0; }
//------------------------------------------------------------------ void code_colorer::add_to_identifier_charset(const keyword& suffix) { const strset_type* k = m_cfg.find_keywords(m_language, suffix); if(k) { strset_type::const_iterator i = k->begin(); for(; i != k->end(); ++i) { const string_type& str = *i; for(unsigned j = 0; j < str.length(); j++) { char_type c = str[j]; if(!is_alnum(c)) { m_identifier_charset.insert(replace_keysym(c)); } } } } }
char *get_keyword(char *text, char *dest) { char *p = (char *) text; char *d = dest; if (p == NULL) { *dest = '\0'; return 0; } while (is_space(*p)) { p++; } while (is_alnum(*p) || (*p == '_')) { *d = to_upper(*p); d++; p++; } // Code to kill the $ // if ( *p == '$' ) // p ++; if (*p == '$') { *d++ = *p++; } *d = '\0'; while (is_space(*p)) { p++; } // special case, something wrong, jump to next char if (p == text) { *dest = *p; *(dest + 1) = '\0'; p++; } return p; }
//input: *c=='[' **pc==':' static u16 bracket_class(u8 *c,u8 **pc,u8 **sc,u8 not,u8 sc_folded) { u8 char_class[CHAR_CLASS_MAX+1];//don't forget the 0 terminating char u16 r=bracket_char_class_get(c,pc,not,sc_folded,&char_class[0]); if(r!=OK) return r; if((STREQ(char_class,"alnum")&&is_alnum(**sc)) ||(STREQ(char_class,"alpha")&&is_alpha(**sc)) ||(STREQ(char_class,"blank")&&is_blank(**sc)) ||(STREQ(char_class,"cntrl")&&is_cntrl(**sc)) ||(STREQ(char_class,"digit")&&is_digit(**sc)) ||(STREQ(char_class,"graph")&&is_graph(**sc)) ||(STREQ(char_class,"lower")&&is_lower(**sc)) ||(STREQ(char_class,"print")&&is_print(**sc)) ||(STREQ(char_class,"punct")&&is_punct(**sc)) ||(STREQ(char_class,"space")&&is_space(**sc)) ||(STREQ(char_class,"upper")&&is_upper(**sc)) ||(STREQ(char_class,"xdigit")&&is_xdigit(**sc))) return bracket_matched(c,pc,not); *c=*(*pc)++; return OK; }
static bool is_word(u_char c) { return c == '_' || is_alnum(c); }
static enum rules_token lex(struct scanner *s, union lvalue *val) { skip_more_whitespace_and_comments: /* Skip spaces. */ while (is_space(peek(s))) if (next(s) == '\n') return TOK_END_OF_LINE; /* Skip comments. */ if (chr(s, '#')) { skip_to_eol(s); goto skip_more_whitespace_and_comments; } /* See if we're done. */ if (eof(s)) return TOK_END_OF_FILE; /* New token. */ s->token_line = s->line; s->token_column = s->column; s->buf_pos = 0; /* LHS Keysym. */ if (chr(s, '<')) { while (peek(s) != '>' && !eol(s)) buf_append(s, next(s)); if (!chr(s, '>')) { scanner_err(s, "unterminated keysym literal"); return TOK_ERROR; } if (!buf_append(s, '\0')) { scanner_err(s, "keysym literal is too long"); return TOK_ERROR; } val->string.str = s->buf; val->string.len = s->buf_pos; return TOK_LHS_KEYSYM; } /* Colon. */ if (chr(s, ':')) return TOK_COLON; if (chr(s, '!')) return TOK_BANG; if (chr(s, '~')) return TOK_TILDE; /* String literal. */ if (chr(s, '\"')) { while (!eof(s) && !eol(s) && peek(s) != '\"') { if (chr(s, '\\')) { uint8_t o; if (chr(s, '\\')) { buf_append(s, '\\'); } else if (chr(s, '"')) { buf_append(s, '"'); } else if (chr(s, 'x') || chr(s, 'X')) { if (hex(s, &o)) buf_append(s, (char) o); else scanner_warn(s, "illegal hexadecimal escape sequence in string literal"); } else if (oct(s, &o)) { buf_append(s, (char) o); } else { scanner_warn(s, "unknown escape sequence (%c) in string literal", peek(s)); /* Ignore. */ } } else { buf_append(s, next(s)); } } if (!chr(s, '\"')) { scanner_err(s, "unterminated string literal"); return TOK_ERROR; } if (!buf_append(s, '\0')) { scanner_err(s, "string literal is too long"); return TOK_ERROR; } if (!is_valid_utf8(s->buf, s->buf_pos - 1)) { scanner_err(s, "string literal is not a valid UTF-8 string"); return TOK_ERROR; } val->string.str = s->buf; val->string.len = s->buf_pos; return TOK_STRING; } /* Identifier or include. */ if (is_alpha(peek(s)) || peek(s) == '_') { s->buf_pos = 0; while (is_alnum(peek(s)) || peek(s) == '_') buf_append(s, next(s)); if (!buf_append(s, '\0')) { scanner_err(s, "identifier is too long"); return TOK_ERROR; } if (streq(s->buf, "include")) return TOK_INCLUDE; val->string.str = s->buf; val->string.len = s->buf_pos; return TOK_IDENT; } /* Discard rest of line. */ skip_to_eol(s); scanner_err(s, "unrecognized token"); return TOK_ERROR; }
int main(int argc, char **argv) { wchar_t t; int i, opt_end = 0; int sigs[] = {SIGHUP, SIGINT, SIGPIPE, 0}; #if defined(__lint) yydebug = 0; #endif for (i = 0; sigs[i]; ++i) { if (signal(sigs[i], SIG_IGN) != SIG_IGN) (void) signal(sigs[i], catchsig); } tempfile = mktemp(tmp_name); (void) close(creat(tempfile, 0)); (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if ((mb_cur_max = MB_CUR_MAX) > 1) wide = 1; procnam = argv[0]; getflags(&argc, &argv, &opt_end); initalloc(); setfname("-"); if (argc > 1) { --argc; ++argv; if (strcmp(argv[0], "-")) { ifile[ifx] = m4open(&argv, "r", &argc); setfname(argv[0]); } } for (;;) { token[0] = t = getchr(); token[1] = EOS; if (t == WEOF) { if (ifx > 0) { (void) fclose(ifile[ifx]); ipflr = ipstk[--ifx]; continue; } getflags(&argc, &argv, &opt_end); if (argc <= 1) /* * If dowrap() has been called, the m4wrap * macro has been processed, and a linked * list of m4wrap strings has been created. * The list starts at wrapstart. */ if (wrapstart) { /* * Now that EOF has been processed, * display the m4wrap strings. */ showwrap(); continue; } else break; --argc; ++argv; if (ifile[ifx] != stdin) (void) fclose(ifile[ifx]); if (strcmp(argv[0], "-")) ifile[ifx] = m4open(&argv, "r", &argc); else ifile[ifx] = stdin; setfname(argv[0]); continue; } if (is_alpha(t) || t == '_') { wchar_t *tp = token+1; int tlim = toksize; struct nlist *macadd; /* temp variable */ while ((*tp = getchr()) != WEOF && (is_alnum(*tp) || *tp == '_')) { tp++; if (--tlim <= 0) error2(gettext( "more than %d chars in word"), toksize); } putbak(*tp); *tp = EOS; macadd = lookup(token); *Ap = (wchar_t *)macadd; if (macadd->def) { if ((wchar_t *)(++Ap) >= astklm) { --Ap; error2(gettext( "more than %d items on " "argument stack"), stksize); } if (Cp++ == NULL) Cp = callst; Cp->argp = Ap; *Ap++ = op; puttok(token); stkchr(EOS); t = getchr(); putbak(t); if (t != '(') pbstr(L"()"); else /* try to fix arg count */ *Ap++ = op; Cp->plev = 0; } else { puttok(token); } } else if (match(t, lquote)) { int qlev = 1; for (;;) { token[0] = t = getchr(); token[1] = EOS; if (match(t, rquote)) { if (--qlev > 0) puttok(token); else break; } else if (match(t, lquote)) { ++qlev; puttok(token); } else { if (t == WEOF) error(gettext( "EOF in quote")); putchr(t); } } } else if (match(t, lcom) && ((lcom[0] != L'#' || lcom[1] != L'\0') || prev_char != '$')) { /* * Don't expand commented macro (between lcom and * rcom). * What we know so far is that we have found the * left comment char (lcom). * Make sure we haven't found '#' (lcom) immediately * preceded by '$' because we want to expand "$#". */ puttok(token); for (;;) { token[0] = t = getchr(); token[1] = EOS; if (match(t, rcom)) { puttok(token); break; } else { if (t == WEOF) error(gettext( "EOF in comment")); putchr(t); } } } else if (Cp == NULL) { putchr(t); } else if (t == '(') { if (Cp->plev) stkchr(t); else { /* skip white before arg */ while ((t = getchr()) != WEOF && is_space(t)) ; putbak(t); } ++Cp->plev; } else if (t == ')') { --Cp->plev; if (Cp->plev == 0) { stkchr(EOS); expand(Cp->argp, Ap-Cp->argp-1); op = *Cp->argp; Ap = Cp->argp-1; if (--Cp < callst) Cp = NULL; } else stkchr(t); } else if (t == ',' && Cp->plev <= 1) { stkchr(EOS); *Ap = op; if ((wchar_t *)(++Ap) >= astklm) { --Ap; error2(gettext( "more than %d items on argument stack"), stksize); } while ((t = getchr()) != WEOF && is_space(t)) ; putbak(t); } else { stkchr(t); } } if (Cp != NULL) error(gettext( "EOF in argument list")); delexit(exitstat, 1); return (0); }
int _xkbcommon_lex(YYSTYPE *yylval, struct scanner *s) { int tok; skip_more_whitespace_and_comments: /* Skip spaces. */ while (is_space(peek(s))) next(s); /* Skip comments. */ if (lit(s, "//") || chr(s, '#')) { while (!eof(s) && !eol(s)) next(s); goto skip_more_whitespace_and_comments; } /* See if we're done. */ if (eof(s)) return END_OF_FILE; /* New token. */ s->token_line = s->line; s->token_column = s->column; s->buf_pos = 0; /* String literal. */ if (chr(s, '\"')) { while (!eof(s) && !eol(s) && peek(s) != '\"') { if (chr(s, '\\')) { uint8_t o; if (chr(s, '\\')) buf_append(s, '\\'); else if (chr(s, 'n')) buf_append(s, '\n'); else if (chr(s, 't')) buf_append(s, '\t'); else if (chr(s, 'r')) buf_append(s, '\r'); else if (chr(s, 'b')) buf_append(s, '\b'); else if (chr(s, 'f')) buf_append(s, '\f'); else if (chr(s, 'v')) buf_append(s, '\v'); else if (chr(s, 'e')) buf_append(s, '\033'); else if (oct(s, &o)) buf_append(s, (char) o); else { scanner_warn(s, "unknown escape sequence in string literal"); /* Ignore. */ } } else { buf_append(s, next(s)); } } if (!buf_append(s, '\0') || !chr(s, '\"')) return scanner_error(s, "unterminated string literal"); yylval->str = strdup(s->buf); if (!yylval->str) return scanner_error(s, "scanner out of memory"); return STRING; } /* Key name literal. */ if (chr(s, '<')) { while (is_graph(peek(s)) && peek(s) != '>') buf_append(s, next(s)); if (!buf_append(s, '\0') || !chr(s, '>')) return scanner_error(s, "unterminated key name literal"); /* Empty key name literals are allowed. */ yylval->sval = xkb_atom_intern(s->ctx, s->buf, s->buf_pos - 1); return KEYNAME; } /* Operators and punctuation. */ if (chr(s, ';')) return SEMI; if (chr(s, '{')) return OBRACE; if (chr(s, '}')) return CBRACE; if (chr(s, '=')) return EQUALS; if (chr(s, '[')) return OBRACKET; if (chr(s, ']')) return CBRACKET; if (chr(s, '(')) return OPAREN; if (chr(s, ')')) return CPAREN; if (chr(s, '.')) return DOT; if (chr(s, ',')) return COMMA; if (chr(s, '+')) return PLUS; if (chr(s, '-')) return MINUS; if (chr(s, '*')) return TIMES; if (chr(s, '/')) return DIVIDE; if (chr(s, '!')) return EXCLAM; if (chr(s, '~')) return INVERT; /* Identifier. */ if (is_alpha(peek(s)) || peek(s) == '_') { s->buf_pos = 0; while (is_alnum(peek(s)) || peek(s) == '_') buf_append(s, next(s)); if (!buf_append(s, '\0')) return scanner_error(s, "identifier too long"); /* Keyword. */ tok = keyword_to_token(s->buf); if (tok != -1) return tok; yylval->str = strdup(s->buf); if (!yylval->str) return scanner_error(s, "scanner out of memory"); return IDENT; } /* Number literal (hexadecimal / decimal / float). */ if (number(s, &yylval->num, &tok)) { if (tok == ERROR_TOK) return scanner_error(s, "malformed number literal"); return tok; } return scanner_error(s, "unrecognized token"); }
inline bool is_alnum<unicode::char_t> (unicode::char_t c) { return c.value <= 127 && is_alnum(static_cast<char>(c.value)); }
const token &tokenizer::next_token() { #if DEBUG_TOKENIZER previous_token_ = token_; #endif token_.value.clear(); // Dump spaces and inlined comments for(;;) { while (is_space(current_)) { next_char_fast(); } if (current_ != 254) break; skip_comment(); // skip the line end next_char_fast(); } if (current_ == '#') skip_comment(); startlineno_ = lineno_; switch(current_) { case EOF: token_.type = token::END; break; case '<': if (peek_char() != '<') { token_.type = token::MISC; token_.value += current_; break; } token_.type = token::QSTRING; next_char_fast(); for (;;) { next_char(); if (current_ == EOF) { token_.type = token::UNTERMINATED_QSTRING; break; } if (current_ == '>' && peek_char() == '>') { next_char_fast(); break; } token_.value += current_; } break; case '"': token_.type = token::QSTRING; for (;;) { next_char(); if (current_ == EOF) { token_.type = token::UNTERMINATED_QSTRING; break; } if (current_ == '"') { if (peek_char() != '"') break; next_char_fast(); } if (current_ == 254) { skip_comment(); --lineno_; continue; } token_.value += current_; } break; case '[': case ']': case '/': case '\n': case '=': case ',': case '+': token_.type = token::token_type(current_); token_.value = current_; break; case '_': if (!is_alnum(peek_char())) { token_.type = token::token_type(current_); token_.value = current_; break; } // no break default: if (is_alnum(current_)) { token_.type = token::STRING; do { token_.value += current_; next_char_fast(); while (current_ == 254) { skip_comment(); next_char_fast(); } } while (is_alnum(current_)); } else { token_.type = token::MISC; token_.value += current_; next_char(); } return token_; } if (current_ != EOF) next_char(); return token_; }
// Match word character (look ahead) bool is_character(const char& chr) { // valid alpha, numeric or unicode char (plus hyphen) return is_alnum(chr) || is_unicode(chr) || chr == '-'; }
RIFAction RIFAction::parse(DPtr<uint8_t> *utf8str) throw(BadAllocException, SizeUnknownException, InvalidCodepointException, InvalidEncodingException, MalformedIRIRefException, TraceableException) { if (utf8str == NULL) { THROW(TraceableException, "utf8str must not be NULL."); } if (!utf8str->sizeKnown()) { THROWX(SizeUnknownException); } const uint8_t *begin = utf8str->dptr(); const uint8_t *end = begin + utf8str->size(); const uint8_t *beginkw = begin; for (; beginkw != end && is_space(*beginkw); ++beginkw) { // find beginning of keyword } if (beginkw == end) { THROW(TraceableException, "No keyword found when parsing RIFAction."); } const uint8_t *endkw = beginkw; for (; endkw != end && is_alnum(*endkw); ++endkw) { // find end of keyword } enum RIFActType type; if (endkw - beginkw == 6) { if (ascii_strncmp(beginkw, "Assert", 6) == 0) { type = ASSERT_FACT; } else if (ascii_strncmp(beginkw, "Modify", 6) == 0) { type = MODIFY; } else { THROW(TraceableException, "Unrecognized RIFAction type."); } } else if (endkw - beginkw == 7) { if (ascii_strncmp(beginkw, "Retract", 7) == 0) { type = RETRACT_FACT; // validate later } else if (ascii_strncmp(beginkw, "Execute", 7) == 0) { type = EXECUTE; } else { THROW(TraceableException, "Unrecognized RIFAction type."); } } else { THROW(TraceableException, "Unrecognized RIFAction type."); } const uint8_t *left_bound = endkw; for (; left_bound != end && *left_bound != to_ascii('('); ++left_bound) { // find left paren enclosing target } if (left_bound == end) { THROW(TraceableException, "Could not find left paren when parsing RIFAction."); } const uint8_t *right_bound = end; for (--right_bound; right_bound != left_bound && *right_bound != to_ascii(')'); --right_bound) { // find right paren enclosing target } if (right_bound == left_bound) { THROW(TraceableException, "Could not find right paren when parsing RIFAction."); } for (++left_bound; left_bound != right_bound && is_space(*left_bound); ++left_bound) { // find left bound of target } if (left_bound == right_bound) { if (type == EXECUTE) { return RIFAction(); } THROW(TraceableException, "No target specified for RIFAction."); } for (--right_bound; right_bound != left_bound && is_space(*right_bound); --right_bound) { // find right bound of target } ++right_bound; DPtr<uint8_t> *targetstr = utf8str->sub(left_bound - begin, right_bound - left_bound); try { RIFAtomic atom = RIFAtomic::parse(targetstr); RIFAction act (type, atom); targetstr->drop(); return act; } catch (BadAllocException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (InvalidCodepointException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (InvalidEncodingException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (MalformedIRIRefException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (BaseException<enum RIFActType> &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (TraceableException &e) { if (type != RETRACT_FACT) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } } try { RIFTerm term = RIFTerm::parse(targetstr); RIFAction act (term); targetstr->drop(); return act; } catch (BadAllocException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (InvalidCodepointException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (InvalidEncodingException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (MalformedIRIRefException &e) { targetstr->drop(); RETHROW(e, "Unable to parse target."); } catch (TraceableException &e) { // ignore and check if RETRACT_SLOTS } RIFTerm obj, attr; begin = targetstr->dptr(); end = begin + targetstr->size(); while (begin != end) { for (; begin != end && is_space(*begin); ++begin) { // creep forward to first non-space } for (++begin; begin != end && !is_space(*begin); ++begin) { // search for space between terms } if (begin == end) { targetstr->drop(); THROW(TraceableException, "Invalid RETRACT target."); } DPtr<uint8_t> *str = targetstr->sub(0, begin - targetstr->dptr()); try { obj = RIFTerm::parse(str); str->drop(); } catch (TraceableException &e) { str->drop(); continue; } for (++begin; begin != end && is_space(*begin); ++begin) { // search for second term } str = targetstr->sub(begin - targetstr->dptr(), end - begin); try { attr = RIFTerm::parse(str); str->drop(); } catch (TraceableException &e) { str->drop(); continue; } try { targetstr->drop(); return RIFAction(obj, attr); } RETHROW_BAD_ALLOC } targetstr->drop(); THROW(TraceableException, "Invalid RETRACT target."); }
/* Search the version string in the ROM Arguments: - ptr: a ROM or update image - size: the size of the buffer - version: the returned string version */ static int get_rom_version(char *ptr, int size, char *version) { int i; strcpy(version, "?.??"); for (i = SPP; i < size-16; i += 2) { if (is_num(ptr[i])&&(ptr[i+1]=='.') && is_num(ptr[i+2]) && (ptr[i+3]==0)&&is_alnum(ptr[i+4]) && is_alnum(ptr[i+5]) && (ptr[i+6]=='/')&&is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) && (ptr[i+9]=='/')&&is_alnum(ptr[i+10]) && is_alnum(ptr[i+11])) break; if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && is_num(ptr[i+3]) && (ptr[i+4]==0) && is_alnum(ptr[i+5]) && is_alnum(ptr[i+6]) && (ptr[i+7]=='/') && is_alnum(ptr[i+8]) && is_alnum(ptr[i+9]) && (ptr[i+10]=='/') && is_alnum(ptr[i+11]) && is_alnum(ptr[i+12])) break; if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && (ptr[i+3]==0) && is_alnum(ptr[i+4]) && is_alnum(ptr[i+5]) && is_alnum(ptr[i+6]) && is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) && is_alnum(ptr[i+9]) && is_alnum(ptr[i+10]) && is_alnum(ptr[i+11])) break; if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && is_alnum(ptr[i+3]) && (ptr[i+4]==0) && is_alnum(ptr[i+5]) && is_alnum(ptr[i+6]) && is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) && is_alnum(ptr[i+9]) && is_alnum(ptr[i+10]) && is_alnum(ptr[i+11])) break; } if (i < size-16) { int n; for(n = i; n < i+16; n++) { if (ptr[n]==0) { strcpy(version, ptr+i); (version)[n-i]=0; return 0; } } } return 0; }
const char* alnum(const char* src) { return is_alnum(*src) ? src + 1 : 0; }
//------------------------------------------------------------------ void code_colorer::color_code(const element& e) { m_language.assign(e.name(), e.name_len()); m_block_comments = m_cfg.strlist(string_type(e.name(), e.name_len()), keyword_block_comments_suffix); m_line_comments = m_cfg.strlist(string_type(e.name(), e.name_len()), keyword_line_comments_suffix); m_string_quotation = m_cfg.strlist(string_type(e.name(), e.name_len()), keyword_strings_suffix); m_string_mask = m_cfg.strlist(string_type(e.name(), e.name_len()), keyword_string_mask_suffix); m_operators = m_cfg.strlist(string_type(e.name(), e.name_len()), keyword_operators_suffix); replace_strlist_keysym(m_block_comments); replace_strlist_keysym(m_line_comments); replace_strlist_keysym(m_string_quotation); replace_strlist_keysym(m_string_mask); replace_strlist_keysym(m_operators); m_identifier_charset.clear(); add_to_identifier_charset(keyword_kw1_suffix); add_to_identifier_charset(keyword_kw2_suffix); add_to_identifier_charset(keyword_kw3_suffix); add_to_identifier_charset(keyword_kw4_suffix); m_operator_charset.clear(); unsigned i; for(i = 0; i < m_operators.size(); ++i) { const string_type& str = m_operators[i]; for(unsigned j = 0; j < str.length(); j++) { char_type c = str[j]; if(!is_alnum(c)) { m_operator_charset.insert(replace_keysym(c)); } } } content_storage code; element_serializer ser(code, e, false, false); code.replace_text_keysym(); m_result.add(backslash); if(str_cmp(m_language, keyword_m) == 0) { m_result.add(keyword_m.name, keyword_m.len); m_result.add(open_brace); m_result.add(code.text()); m_result.add(close_brace); } else if(str_cmp(m_language, keyword_code) == 0) { m_result.add(keyword_code.name, keyword_code.len); if(e.attr_len()) { m_result.add(open_bracket); m_result.add(e.attr(), e.attr_len()); m_result.add(close_bracket); } m_result.add(open_brace); m_result.add(code.text()); m_result.add(close_brace); } else { m_result.add(keyword_code.name, keyword_code.len); if(e.attr_len()) { m_result.add(open_bracket); m_result.add(e.attr(), e.attr_len()); m_result.add(close_bracket); } m_result.add(open_brace); color_code(code.text()); m_result.add(close_brace); } }
long int strtol(const char *str, char **endptr, int base) { const char *buf = str; long int value = 0; int sign = 1, k = 0; if (base < 2 || base > 36) { return 0; } /* swallow white spaces */ while (*buf == ' ' || *buf == '\t') { ++buf; } /* parse sign if any */ if (*buf == '-') { sign = -1; ++buf; } else if (*buf == '+') { sign = 1; ++buf; } /* parse base */ if (base == 0) { if (*buf == '0') { if (to_lower(*(++buf)) == 'x' && is_xdigit(buf[1])) { ++buf; base = 16; } else { base = 8; } } else { base = 10; } } else if (base == 16 && buf[0] == '0' && to_lower(buf[1]) == 'x') { str += 2; } /* parse alpha-numerical string */ while (is_alnum(*buf)) { if (is_alpha(*buf)) { k = to_lower(*buf) - 'a' + 10; if (k > base) { break; } } else { k = *buf - '0'; } value = value * base + k; ++buf; } if (endptr != NULL) { *endptr = (char *)buf; } return sign * value; }