/** Check if codec is in auxiliary list */ static int soa_sdp_is_auxiliary_codec(sdp_rtpmap_t const *rm, char const *auxiliary) { char const *codec; size_t clen, alen; char const *match; if (!rm || !rm->rm_encoding || !auxiliary) return 0; codec = rm->rm_encoding; clen = strlen(codec), alen = strlen(auxiliary); if (clen > alen) return 0; for (match = auxiliary; (match = su_strcasestr(match, codec)); match = match + 1) { if (IS_ALPHANUM(match[clen]) || match[clen] == '-') continue; if (match != auxiliary && (IS_ALPHANUM(match[-1]) || match[-1] == '-')) continue; return 1; } return 0; }
/***************************************************************************** * CkNumberType: * checks /number=single_token - numbers and letters * /number=4 or /number=6b * -Tatiana 2/1/00 ******************************************************************************/ NLM_EXTERN CharPtr CkNumberType(CharPtr str) { for (; *str != '\0' && !IS_ALPHANUM(*str); str++) continue; if (*str != '\0') { return NULL; } return str; }
const char* LCD_MODULE::get_next_txt_row(const char *txt) { unsigned int width,len, pos; unsigned int c; if(txt && txt[0]) { while(*txt == ' ' || *txt =='\r' || *txt == '\n') txt++; pos = pos_x + font->hdistance; len = 0; width = 0; while( pos < size_x ) { c=txt[len++]; if( !IS_ALPHANUM(c)) { width = pos; if(c == 0 || c =='\r' || c == '\n') break; } pos += font->hspacing; } if(!width && len) { width = pos_x + font->hdistance + (len-1)*font->hspacing; } if(width) { len = width -pos_x -font->hdistance; if(allign != ALL_LEFT) { pos = size_x - len; if(allign == ALL_CENTER) pos >>= 1; } else pos = pos_x + font->hdistance; width = pos + len; while( (pos < width) && *txt) { txt++; pos += font->hspacing; } }
/* read a glyph name and return the equivalent glyph index */ static FT_UInt afm_atoindex( FT_Byte** start, FT_Byte* limit, T1_Font* type1 ) { FT_Byte* p = *start; FT_Int len; FT_UInt result = 0; char temp[64]; /* skip whitespace */ while ( ( *p == ' ' || *p == '\t' || *p == ':' || *p == ';' ) && p < limit ) p++; *start = p; /* now, read glyph name */ while ( IS_ALPHANUM( *p ) && p < limit ) p++; len = p - *start; if ( len > 0 && len < 64 ) { FT_Int n; /* copy glyph name to intermediate array */ MEM_Copy( temp, *start, len ); temp[len] = 0; /* lookup glyph name in face array */ for ( n = 0; n < type1->num_glyphs; n++ ) { char* gname = (char*)type1->glyph_names[n]; if ( gname && gname[0] == temp[0] && strcmp( gname, temp ) == 0 ) { result = n; break; } } } *start = p; return result; }
int sd_field_start(syslog_parser *parser, char nb) { if (IS_ALPHANUM(nb)) { cstr_buff_put(parser->buffer, nb); set_state(parser, s_sd_field); } else { switch (nb) { case ']': set_state(parser, s_sd_start); break; default: parser->error = SLERR_BAD_SD_FIELD; } } return pa_advance; }
/** * Reads a name from the cache * * Description: * Name ::= NameStartChar (NameChar)* * NameStartChar ::= ":" | [A-Z] | "_" | [a-z] //add "?" * NameChar ::= NameStartChar | "-" | "." | [0-9] * @param var * @return RES_OK if the char was skipped, RES_EOF if no more tags, errors.. */ RES_CODE CCache::get_name(CSTRING& var) { char ch; RES_CODE res; res = get_pc(ch); if (res == RES_OK) { if (ch == ':' || ch == '_' || ch == '?' || IS_ALPHA(ch)) { var += ch; while (!var.empty()) { res = getc(ch); switch (res) { case RES_OK: if (ch == ':' || ch == '_' || ch == '-' || ch == '.' || IS_ALPHANUM(ch)) { var += ch; } else { ungetc(); return RES_OK; } break; case RES_EOF: return RES_OK; default: return (res); } } return RES_OUT_OF_MEMORY; } ungetc(); res = RES_INVALID_DATA; } return (res); }
/** * Match name * @param str * @return */ RES_CODE CCache::match_name(const char* str) { RES_CODE res; res = match(str); if (res == RES_OK) { char c; res = getc(c); if (res == RES_OK) { ungetc(); if (IS_ALPHANUM(c) || c == ':' || c == '_' || c == '-' || c == '.') { //this is not a name unsigned int len = strlen(str); while (len) { if (!ungetc()) { CSTRING s(str, len); buffer(s); break; } len--; } res = RES_INVALID_DATA; } } else if (res == RES_EOF) res = RES_OK; } return (res); }
/***************************************************************************** * * Int2 AsnLexTWord(aip) * reads words, punctuation, and asn keywords with 2 parts * returns tokens defined at top * *****************************************************************************/ NLM_EXTERN Int2 AsnLexTWord (AsnIoPtr aip) { register CharPtr pos; register int len; Int1 state; Int2 token, asntype, linepos; int done; Boolean first = FALSE, hitnewline = FALSE; CharPtr commentptr; if (! aip->bytes) /* no data loaded */ { hitnewline = TRUE; first = TRUE; AsnIoGets(aip); } linepos = aip->linepos; pos = aip->linebuf + linepos; state = aip->state; len = 0; token = -1; while (*pos == '\n' || *pos == '\r') /* skip empty lines */ { hitnewline = TRUE; pos = AsnIoGets(aip); if (pos == NULL) return EOF_TOKEN; } if (state == IN_STRING_STATE) { aip->word = pos; if (* pos == '\"') /* end of string */ { token = END_STRING; pos++; state = 0; /* reset state */ } else { token = IN_STRING; while ((* pos != '\"') && (* pos != '\n') && (* pos != '\r')) { pos++; len++; } if ((*pos != '\n') && (*pos != '\r') && (* (pos + 1) == '\"')) /* internal quote */ { len++; /* include in previous string */ pos += 2; /* point to rest of string */ } } } else if (state == IN_BITHEX_STATE) { aip->word = pos; if (*pos == '\'') /* end of binhex */ { state = 0; /* set to normal */ pos++; /* move past quote */ while (IS_WHITESP(*pos)) pos++; if (* pos == 'H') token = OCTETS; else if (* pos == 'B') token = ASNBITS; else { AsnIoErrorMsg(aip, 58, aip->linenumber); token = ERROR_TOKEN; } } else { token = IN_BITHEX; while ((* pos != '\'') && (* pos != '\n') && (* pos != '\r')) { pos++; len++; } } } else /* normal scanning */ { done = 0; while (! done) { while (* pos <= ' ') /* skip leading white space */ { if (*pos == '\n' || *pos == '\r') { hitnewline = TRUE; pos = AsnIoGets(aip); if (pos == NULL) return EOF_TOKEN; } else pos++; } done = 1; while (done && (*pos == '-') && (*(pos+1) == '-')) /* skip comments */ { pos += 2; if (first) /* could be revision */ { first = FALSE; if (StrMatch(asnwords[57], pos, 10)) /* $Revision: */ { token = REVISION_TOKEN; pos += 10; while (IS_WHITESP(*pos)) pos++; aip->word = pos; while (IS_DIGIT(*pos)) /* eg. 1.2 */ { len++; pos++; } if (*pos == '.') /* take after . if present */ { pos++; len++; while (IS_DIGIT(*pos)) { len++; pos++; } } } } commentptr = pos; done = 0; while (! done) /* skip to end of comment */ { if ((*pos == '-') && (*(pos +1) == '-')) { if (token != REVISION_TOKEN) { AsnLexTAddComment(commentptr, pos, aip); if ((! hitnewline) && (aip->token != COMMENT_TOKEN)) token = COMMENT_TOKEN; } pos += 2; done = 1; } else if (*pos == '\n' || *pos == '\r') { if (token != REVISION_TOKEN) { AsnLexTAddComment(commentptr, pos, aip); if ((! hitnewline) && (aip->token != COMMENT_TOKEN)) token = COMMENT_TOKEN; } done = 1; } else pos++; } if ((token == REVISION_TOKEN) || (token == COMMENT_TOKEN)) { aip->linepos = pos - aip->linebuf; aip->state = state; aip->wordlen = len; aip->token = token; return token; } if (*pos <= ' ') done = 0; else done = 1; } } aip->word = pos; if (* pos == '\"') { token = START_STRING; state = IN_STRING_STATE; } else if (* pos == '\'') { token = START_BITHEX; state = IN_BITHEX_STATE; } else if (* pos == ',') token = COMMA; else if (* pos == '{') token = START_STRUCT; else if (* pos == '}') token = END_STRUCT; else if (* pos == '[') token = START_TAG; else if (* pos == ']') token = END_TAG; else if (* pos == '(') token = OPEN_PAREN; else if (* pos == ')') token = CLOSE_PAREN; else if (* pos == ';') token = SEMI_COLON; else if (* pos == ':') { if ((*(pos + 1) == ':') && (*(pos + 2) == '=')) { token = ISDEF; pos += 2; len = 3; } else { AsnIoErrorMsg(aip, 59, *pos, aip->linenumber); token = ERROR_TOKEN; } } else if (IS_UPPER(*pos)) /* a reference or keyword */ { token = REF; while ((IS_ALPHANUM(*pos)) || (*pos == '-')) { pos++; len++; } aip->wordlen = len; asntype = AsnLexTMatchToken(aip); /* check types */ if (asntype) /* did it match ? */ { if ((asntype > 27) && (asntype < 57)) /* not a primitive type */ { token = asntype + 400; /* make a keyword type */ if (asntype == COMPS_TOKEN) /* COMPONENTS OF */ { if ((*(pos + 1) == 'O') && (*(pos + 2) == 'F') && (IS_WHITESP(*(pos+3)))) { pos += 3; /* move past OF */ len += 3; } else AsnIoErrorMsg(aip, 89, aip->linenumber); } } else if (asntype == 57) /* StringStore */ token = STRSTORE_TYPE; else if (asntype == 59) /* BitInt */ token = BIGINT_TYPE; else { switch (asntype) { case 3: /* BIT */ case 4: /* OCTET */ if (! StrMatch(asnwords[11], (pos+1), 6)) AsnIoErrorMsg(aip, 90, aip->linenumber); pos += 7; /* move past STRING */ len += 7; break; case 11: /* SEQUENCE */ case 13: /* SET */ if ((*(pos + 1) == 'O') && (*(pos + 2) == 'F')) { asntype++; /* SET or SEQ OF */ pos += 3; len += 3; if (! IS_WHITESP(*pos)) AsnIoErrorMsg(aip, 91, aip->linenumber); } break; case 6: /* OBJECT */ if ((! StrMatch(asnwords[55], (pos+1), 10))) /* IDENTIFIER */ AsnIoErrorMsg(aip, 92, aip->linenumber); pos += 11; len += 11; break; default: break; } token = asntype + 300; /* change to point at type */ } } pos--; /* move back for increment at end */ len--; } else if (IS_LOWER(*pos)) /* an identifier or valuereference */ { token = IDENT; while ((IS_ALPHANUM(*pos)) || (*pos == '-')) { pos++; len++; } pos--; /* move back for increment at end */ len--; } else if ((IS_DIGIT(*pos)) || ((*pos == '-') && (IS_DIGIT(*(pos+1))))) { token = NUMBER; if (*pos == '-') { pos++; len++; } while (IS_DIGIT(*pos)) { pos++; len++; } pos--; /* move back for increment at end */ len--; } else { AsnIoErrorMsg(aip, 59, *pos, aip->linenumber); token = ERROR_TOKEN; } len++; pos++; /* move over last symbol */ } aip->linepos = pos - aip->linebuf; aip->state = state; aip->wordlen = len; aip->token = token; return token; }
/** * Identifies the next token in the input stream. When the function starts, the * cursor points to the beginning of the token to identify. When the function * returns, the cursor points to the beginning of the next token, one character * past the end of the current token. The return value is an enum indicating * the identified token's type. Since this function also identifies non-syntax * elements such as whitespace and comments, additional filtering may be useful. */ Token lex(char const **p, char const *end) { if (end <= *p) { return LEX_END; /* Whitespace: */ } else if (IS_SPACE(**p)) { do { ++*p; } while (*p < end && IS_SPACE(**p)); return LEX_WHITESPACE; /* Newline: */ } else if (**p == '\n' || **p == '\f') { ++*p; return LEX_NEWLINE; } else if (**p == '\r') { ++*p; if (*p < end && **p == '\n') ++*p; return LEX_NEWLINE; /* Comments: */ } else if (**p == '/') { ++*p; if (end <= *p) return LEX_SLASH; /* C++ style comments: */ if (**p == '/') { do { ++*p; } while (*p < end && !IS_NEWLINE(**p)); return LEX_COMMENT; /* C style comments: */ } else if (**p == '*') { do { do { ++*p; if (end <= *p) return LEX_ERROR_END; } while (**p != '*'); do { ++*p; if (end <= *p) return LEX_ERROR_END; } while (**p == '*'); } while (**p != '/'); ++*p; return LEX_COMMENT; /* Lone slash: */ } else { return LEX_SLASH; } /* Double-quoted string literal: */ } else if (**p == '\"') { do { ++*p; if (end <= *p) return LEX_ERROR_END; if (**p == '\\') { ++*p; if (end <= *p) return LEX_ERROR_END; ++*p; if (end <= *p) return LEX_ERROR_END; } } while (**p != '\"'); ++*p; return LEX_STRING; /* Single-quoted character literal: */ } else if (**p == '\'') { do { ++*p; if (end <= *p) return LEX_ERROR_END; if (**p == '\\') { ++*p; if (end <= *p) return LEX_ERROR_END; ++*p; if (end <= *p) return LEX_ERROR_END; } } while (**p != '\''); ++*p; return LEX_CHAR; /* Numeric literals (including malformed ones, which are ignored): */ } else if ('0' <= **p && **p <= '9') { do { ++*p; } while (*p < end && IS_ALPHANUM(**p)); return LEX_NUMBER; /* Identifiers: */ } else if (IS_ALPHA(**p)) { do { ++*p; } while (*p < end && IS_ALPHANUM(**p)); return LEX_IDENTIFIER; /* Token-pasting: */ } else if (**p == '\\') { ++*p; if (end <= *p) return LEX_BACKSLASH; if (**p == '\\') { ++*p; return LEX_PASTE; } else if (**p == 'o') { ++*p; if (*p < end && **p == 'l') { ++*p; return LEX_ESCAPE; } else { --*p; return LEX_BACKSLASH; } } return LEX_BACKSLASH; /* Symbols: */ } else if (**p == '!') { ++*p; return LEX_BANG; } else if (**p == '&') { ++*p; return LEX_AMP; } else if (**p == '(') { ++*p; return LEX_PAREN_L; } else if (**p == ')') { ++*p; return LEX_PAREN_R; } else if (**p == '*') { ++*p; return LEX_STAR; } else if (**p == ',') { ++*p; return LEX_COMMA; } else if (**p == '.') { ++*p; return LEX_DOT; /* LEX_SLASH was recognized earlier. */ } else if (**p == ';') { ++*p; return LEX_SEMICOLON; } else if (**p == '<') { ++*p; return LEX_LT; } else if (**p == '=') { ++*p; return LEX_EQUALS; } else if (**p == '>') { ++*p; return LEX_GT; /* LEX_BACKSLASH was recognized earlier. */ } else if (**p == '{') { ++*p; return LEX_BRACE_L; } else if (**p == '|') { ++*p; return LEX_PIPE; } else if (**p == '}') { ++*p; return LEX_BRACE_R; /* Any other character: */ } else { ++*p; return LEX_ERROR; } }
/***************************************************************************** * * Int2 AsnLexScan(aip, name) * scans until name ::= to start reading asn.1 past garbage * *****************************************************************************/ static Int2 AsnLexScan (AsnIoPtr aip, CharPtr name) { register CharPtr pos; Int2 token = 0; register int linepos, len; int done; Boolean started = FALSE, matched_ref = FALSE; if (aip->type_indent) /* only for start */ return ERROR_TOKEN; if (! aip->bytes) /* no data loaded */ AsnIoGets(aip); linepos = aip->linepos; pos = aip->linebuf + linepos; len = 0; while (*pos == '\n' || *pos == '\r') /* skip empty lines */ { pos = AsnIoGets(aip); /* get a line */ if (pos == NULL) return EOF_TOKEN; } while (! started) { while ((* pos <= ' ') || ((*pos == '-') && (*(pos+1) == '-'))) /* skip leading white space */ { if (*pos == '\n' || *pos == '\r') { pos = AsnIoGets(aip); if (pos == NULL) return EOF_TOKEN; } else if ((*pos == '-') && (*(pos+1) == '-')) /* skip comments */ { pos += 2; done = 0; while (! done) { if ((*pos == '-') && (*(pos +1) == '-')) { pos += 2; done = 1; } else if (*pos == '\n' || *pos == '\r') done = 1; else pos++; } } else pos++; } aip->word = pos; len = 0; if (* pos == ':') { if ((*(pos + 1) == ':') && (*(pos + 2) == '=')) { token = ISDEF; pos += 2; len = 3; if (matched_ref) started = TRUE; else { AsnIoErrorMsg(aip, 59, *pos, aip->linenumber); return ERROR_TOKEN; } } else matched_ref = FALSE; } else if (IS_UPPER(*pos)) /* a reference or keyword */ { token = REF; while ((IS_ALPHANUM(*pos)) || (*pos == '-')) { pos++; len++; } pos--; /* move back for increment at end */ aip->wordlen = len; if (StrMatch(name, aip->word, (Int2)len)) matched_ref = TRUE; else matched_ref = FALSE; } else matched_ref = FALSE; pos++; /* move over last symbol */ } /* found it , do normal return after ::= */ aip->linepos = pos - aip->linebuf; aip->wordlen = len; aip->token = token; return token; }
static Int2 AsnLexWordEx (AsnIoPtr aip, Uint1 fix_non_print) { register CharPtr pos; Int1 state; Int2 token; register int linepos, len; int done; if (aip->tagsaved) /* had to read ahead */ { aip->tagsaved = FALSE; return aip->token; } if (! aip->bytes) /* no data loaded */ AsnIoGets(aip); linepos = aip->linepos; pos = aip->linebuf + linepos; state = aip->state; len = 0; while (*pos == '\n' || *pos == '\r') /* skip empty lines */ { pos = AsnIoGets(aip); /* get a line */ if (pos == NULL) return EOF_TOKEN; } if (state == IN_STRING_STATE) { aip->word = pos; if ((* pos == '\"') && (*(pos + 1) != '\"')) /* end of string */ { token = END_STRING; pos++; state = 0; /* reset state */ } else { token = IN_STRING; while ((* pos != '\"') && (* pos != '\n') && (* pos != '\r')) { if ((fix_non_print != 2) && ((*pos < ' ') || (*pos > '~'))) { done = (int)(*pos); *pos = '\0'; if ((fix_non_print == 0) || (fix_non_print == 3)) { AsnIoErrorMsg(aip, 106, done, aip->word); } done = 0; *pos = '#'; /* replace with # */ } pos++; len++; } if ((*pos != '\n') && (*pos != '\r') && (* (pos + 1) == '\"')) /* internal quote */ { len++; /* include in previous string */ pos += 2; /* point to rest of string */ } } } else if (state == IN_BITHEX_STATE) { aip->word = pos; if (*pos == '\'') /* end of binhex */ { state = 0; /* set to normal */ pos++; /* move past quote */ while (IS_WHITESP(*pos)) { if (*pos == '\n' || *pos == '\r') /* skip empty lines */ { pos = AsnIoGets(aip); /* get a line */ if (pos == NULL) return EOF_TOKEN; } else pos++; } if (* pos == 'H') token = OCTETS; else if (* pos == 'B') token = ASNBITS; else { AsnIoErrorMsg(aip, 58, aip->linenumber); token = ERROR_TOKEN; } pos++; /* move past H or B */ } else { token = IN_BITHEX; while ((* pos != '\'') && (* pos != '\n') && (* pos != '\r')) { pos++; len++; } } } else /* normal scanning */ { while ((* pos <= ' ') || ((*pos == '-') && (*(pos+1) == '-'))) /* skip leading white space */ { if (*pos == '\n' || *pos == '\r') { pos = AsnIoGets(aip); if (pos == NULL) return EOF_TOKEN; } else if ((*pos == '-') && (*(pos+1) == '-')) /* skip comments */ { pos += 2; done = 0; while (! done) { if ((*pos == '-') && (*(pos +1) == '-')) { pos += 2; done = 1; } else if (*pos == '\n' || *pos == '\r') done = 1; else pos++; } } else pos++; } aip->word = pos; if (* pos == '\"') { token = START_STRING; state = IN_STRING_STATE; } else if (* pos == '\'') { token = START_BITHEX; state = IN_BITHEX_STATE; } else if (* pos == ',') token = COMMA; else if (* pos == '{') token = START_STRUCT; else if (* pos == '}') token = END_STRUCT; else if (* pos == '[') token = START_TAG; else if (* pos == ']') token = END_TAG; else if (* pos == '(') token = OPEN_PAREN; else if (* pos == ')') token = CLOSE_PAREN; else if (* pos == ';') token = SEMI_COLON; else if (* pos == ':') { if ((*(pos + 1) == ':') && (*(pos + 2) == '=')) { token = ISDEF; pos += 2; len = 3; } else { AsnIoErrorMsg(aip, 59, *pos, aip->linenumber); token = ERROR_TOKEN; } } else if (IS_UPPER(*pos)) /* a reference or keyword */ { token = REF; while ((IS_ALPHANUM(*pos)) || (*pos == '-')) { pos++; len++; } pos--; /* move back for increment at end */ len--; } else if (IS_LOWER(*pos)) /* an identifier or valuereference */ { token = IDENT; while ((IS_ALPHANUM(*pos)) || (*pos == '-')) { pos++; len++; } pos--; /* move back for increment at end */ len--; } else if ((IS_DIGIT(*pos)) || ((*pos == '-') && (IS_DIGIT(*(pos+1))))) { token = NUMBER; if (*pos == '-') { pos++; len++; } while (IS_DIGIT(*pos)) { pos++; len++; } pos--; /* move back for increment at end */ len--; } else { AsnIoErrorMsg(aip, 59, *pos, aip->linenumber); token = ERROR_TOKEN; } len++; pos++; /* move over last symbol */ } aip->linepos = pos - aip->linebuf; /******************** check on MSWIN linepos = 0; while (pos != linebuf) { linepos++; pos++; } aip->linepos = linepos; **********************/ aip->state = state; aip->wordlen = len; aip->token = token; return token; }
static enum http_host_state http_parse_host_char(enum http_host_state s, const char ch) { switch(s) { case s_http_userinfo: case s_http_userinfo_start: if (ch == '@') { return s_http_host_start; } if (IS_USERINFO_CHAR(ch)) { return s_http_userinfo; } break; case s_http_host_start: if (ch == '[') { return s_http_host_v6_start; } if (IS_HOST_CHAR(ch)) { return s_http_host; } break; case s_http_host: if (IS_HOST_CHAR(ch)) { return s_http_host; } /* FALLTHROUGH */ case s_http_host_v6_end: if (ch == ':') { return s_http_host_port_start; } break; case s_http_host_v6: if (ch == ']') { return s_http_host_v6_end; } /* FALLTHROUGH */ case s_http_host_v6_start: if (IS_HEX(ch) || ch == ':' || ch == '.') { return s_http_host_v6; } if (s == s_http_host_v6 && ch == '%') { return s_http_host_v6_zone_start; } break; case s_http_host_v6_zone: if (ch == ']') { return s_http_host_v6_end; } /* FALLTHROUGH */ case s_http_host_v6_zone_start: /* RFC 6874 Zone ID consists of 1*( unreserved / pct-encoded) */ if (IS_ALPHANUM(ch) || ch == '%' || ch == '.' || ch == '-' || ch == '_' || ch == '~') { return s_http_host_v6_zone; } break; case s_http_host_port: case s_http_host_port_start: if (IS_NUM(ch)) { return s_http_host_port; } break; default: break; } return s_http_host_dead; }