//---------------------------------------------------------------------------- // lengthy helper for use in write..., parses a init command int pcan_parse_input_init(char *buffer, TPCANInit *Init) { char *ptr = buffer; int i = 0; u32 dwDummy; int err = -EINVAL; // DPRINTK(KERN_DEBUG "%s: pcan_parse_input_init()\n", DEVICE_NAME); // remove leading blanks skip_blanks(&ptr); // is it really a init string if (scan_char(&ptr) != 'i') goto reject; // parse init string, a CR is not allowed here if (skip_blanks_and_test_for_CR(&ptr)) goto reject; // get BTR0BTR1 if ((err = scan_unsigned_number(&ptr, &dwDummy))) goto reject; if (dwDummy > 0xFFFF) goto reject; Init->wBTR0BTR1 = (u16)dwDummy; Init->ucCANMsgType = 0; Init->ucListenOnly = 0; // optional rest, only 2 switches are possible for (i = 0; i < 2; i++) { if (skip_blanks_and_test_for_CR(&ptr)) break; switch(scan_char(&ptr)) { case 's': break; case 'e': Init->ucCANMsgType |= MSGTYPE_EXTENDED; break; case 'l': Init->ucListenOnly |= 1; break; default: break; } } // DPRINTK(KERN_DEBUG "%s: pcan_parse_input_init() is OK\n", DEVICE_NAME); return 0; reject: // DPRINTK(KERN_DEBUG "%s: reject in pcan_parse_input_init()\n", DEVICE_NAME); return err; }
static int scan_int(void) { if(*src == '\'') { ++src; ++yylloc.last_column; scan_char(); } else if(*src == '0') { ++src; ++yylloc.last_column; if(*src == 'x') { ++src; ++yylloc.last_column; scan_uint(16); } else if(*src == 'b') { ++src; ++yylloc.last_column; scan_uint(2); } else { --src; /* we go one char back to recognize a single '0' */ --yylloc.last_column; scan_uint(8); } } else if(isdigit(*src)) scan_uint(10); else return 0; #ifdef DEBUG printf("yylex returns %d\n", yylval.integer); #endif return INTEGER; }
void Parser::scan() { if (!scan_char()) return; for(; !src->eof();) { if (current_char == L_SECTION) { scan_section(); //we'll skip everything after R_SECTION // put your comments there or w/e //Also // let's skip all empty lines do skip_until_after(NEWLINE); while (current_char == NEWLINE); } else { scan_line(); do skip_until_after(NEWLINE); while (current_char == NEWLINE); } } };
void Parser::scan_section() { if (current_char != L_SECTION) return; std::string line = ""; while (scan_char() && current_char != R_SECTION && current_char != NEWLINE) { line += current_char; } //Remember: // Section takes care of freeing the resources of its siblings // so new is actually safe here Section *section = new Section(line); //current_section might be a section, but if not, our ctor guarantees it to be NULL. section->previous = current_section; //Use current_section rather than the getter since we don't want it to instantiate. if (current_section) { section->previous = getSection(); getSection()->next = section; } setSection(section); };
/*(*** http_parse_header_line */ int http_parse_header_line(http_header_line *hl, char *p, int m) { scanbuf sb; int i; int name_i, name_j; int value_i, value_j; char *name; lines *value; scan_init(&sb, p, m); #define check(x) if((x) < 0) return 0; name_i = 0; name_j = scan_alphabet_plus (&sb, name_i, is_valid_header_name_char); check(name_j); i = scan_char (&sb, name_j, ':'); check(i); value_i = scan_alphabet_plus (&sb, i, is_valid_space); check(value_i); value_j = sb.sb_length; #undef check name = scan_extract(&sb, name_i, name_j - 1); value = lines_create(0, 0); lines_add_bytes(value, sb.sb_data + value_i, value_j - value_i); hl->hhl_allocated = 1; hl->hhl_name = name; hl->hhl_value = value; return 1; }
int main() { skip_vars(); fixed_len(); alloc_string(); pos_var(); match_chatset(); scan_char(); return 0; }
void Parser::scan_line() { if (current_char == NEWLINE) return; std::string line = ""; line += current_char; while (scan_char() && current_char != NEWLINE) line += current_char; getSection()->lines.push_back( parse_assignment(line)); };
void scan_list(ROOM_INDEX_DATA *scan_room, CHAR_DATA *ch, sh_int depth, sh_int door) { CHAR_DATA *rch; if (scan_room == NULL) return; for (rch=scan_room->people; rch != NULL; rch=rch->next_in_room) { if (rch == ch) continue; if (!IS_NPC(rch) && rch->invis_level > get_trust(ch)) continue; if ( get_trust(ch) < rch->ghost_level) continue; if (can_see(ch, rch)) scan_char(rch, ch, depth, door); } return; }
/*(*** http_parse_request_line */ int http_parse_request_line(http_request_line *rl, char *p, int m) { scanbuf sb; int i; int method_i, method_j; int uri_i, uri_j; int major_i, major_j; int minor_i, minor_j; char *method; char *uri; char *major, *minor; scan_init(&sb, p, m); #define check(x) if((x) < 0) return 0; method_i = 0; method_j = scan_alphabet_plus (&sb, method_i, is_valid_alpha); check(method_j); uri_i = scan_alphabet_plus (&sb, method_j, is_valid_space); check(uri_i); uri_j = scan_alphabet_plus (&sb, uri_i, is_valid_uri_char); check(uri_j); i = scan_alphabet_plus (&sb, uri_j, is_valid_space); check(i); major_i = scan_convert_nulstr (&sb, i, toupper, "HTTP/"); check(i); major_j = scan_alphabet_plus (&sb, major_i, is_valid_digit); check(major_j); minor_i = scan_char (&sb, major_j, '.'); check(minor_i); minor_j = scan_alphabet_plus (&sb, minor_i, is_valid_digit); check(minor_j); i = scan_end (&sb, minor_j); check(i); method = scan_extract(&sb, method_i, method_j - 1); uri = scan_extract(&sb, uri_i, uri_j - 1); major = scan_extract(&sb, major_i, major_j - 1); minor = scan_extract(&sb, minor_i, minor_j - 1); #undef check scan_upperify(method); rl->hrl_allocated = 1; rl->hrl_method = method; rl->hrl_uri = uri; rl->hrl_major = major; rl->hrl_minor = minor; return 1; }
//---------------------------------------------------------------------------- // lengthy helper for use in write..., reject empty and comment lines int pcan_parse_input_idle(char *buffer) { char *ptr = buffer; // DPRINTK(KERN_DEBUG "%s: pcan_parse_input_idle()\n", DEVICE_NAME); // remove leading blanks skip_blanks(&ptr); // search for 'm' or 'r' to distinguish between message or init strings switch (scan_char(&ptr)) { case '#': // comment case '\n': return 0; default: return -EINVAL; } }
void scan_sty() { char spec[STRING_MAX]; int tmp; MESSAGE("Scanning style file %s", sty_fn); while (scan_spec(spec)) { sty_tc++; put_dot = TRUE; /* output pre- and post-ambles */ if (STREQ(spec, PREAMBLE)) { (void)scan_string(preamble); prelen = count_lfd(preamble); } else if (STREQ(spec, POSTAMBLE)) { (void)scan_string(postamble); postlen = count_lfd(postamble); } else if (STREQ(spec, GROUP_SKIP)) { (void)scan_string(group_skip); skiplen = count_lfd(group_skip); } else if (STREQ(spec, LETHEAD_PRE)) { (void)scan_string(lethead_pre); headprelen = count_lfd(lethead_pre); } else if (STREQ(spec, LETHEAD_SUF)) { (void)scan_string(lethead_suf); headsuflen = count_lfd(lethead_suf); } else if (STREQ(spec, LETHEAD_FLAG)) { SCAN_NO(&lethead_flag); } else if (STREQ(spec, SETPAGEOPEN)) { (void)scan_string(setpage_open); setpagelen = count_lfd(setpage_open); } else if (STREQ(spec, SETPAGECLOSE)) { (void)scan_string(setpage_close); setpagelen = count_lfd(setpage_close); /* output index item commands */ } else if (STREQ(spec, ITEM_0)) { (void)scan_string(item_r[0]); ilen_r[0] = count_lfd(item_r[0]); } else if (STREQ(spec, ITEM_1)) { (void)scan_string(item_r[1]); ilen_r[1] = count_lfd(item_r[1]); } else if (STREQ(spec, ITEM_2)) { (void)scan_string(item_r[2]); ilen_r[2] = count_lfd(item_r[2]); } else if (STREQ(spec, ITEM_01)) { (void)scan_string(item_u[1]); ilen_u[1] = count_lfd(item_u[1]); } else if (STREQ(spec, ITEM_12)) { (void)scan_string(item_u[2]); ilen_u[2] = count_lfd(item_u[2]); } else if (STREQ(spec, ITEM_x1)) { (void)scan_string(item_x[1]); ilen_x[1] = count_lfd(item_x[1]); } else if (STREQ(spec, ITEM_x2)) { (void)scan_string(item_x[2]); ilen_x[2] = count_lfd(item_x[2]); /* output encapsulators */ } else if (STREQ(spec, ENCAP_0)) (void)scan_string(encap_p); else if (STREQ(spec, ENCAP_1)) (void)scan_string(encap_i); else if (STREQ(spec, ENCAP_2)) (void)scan_string(encap_s); /* output delimiters */ else if (STREQ(spec, DELIM_0)) (void)scan_string(delim_p[0]); else if (STREQ(spec, DELIM_1)) (void)scan_string(delim_p[1]); else if (STREQ(spec, DELIM_2)) (void)scan_string(delim_p[2]); else if (STREQ(spec, DELIM_N)) (void)scan_string(delim_n); else if (STREQ(spec, DELIM_R)) (void)scan_string(delim_r); /* output line width */ else if (STREQ(spec, LINEMAX)) { SCAN_NO(&tmp); if (tmp > 0) linemax = tmp; else STY_ERROR2("%s must be positive (got %d)", LINE_MAX, tmp); /* output line indentation length*/ } else if (STREQ(spec, INDENT_LENGTH)) { SCAN_NO(&tmp); if (tmp >= 0) indent_length = tmp; else STY_ERROR2("%s must be nonnegative (got %d)", INDENT_LENGTH, tmp); /* output line indentation*/ } else if (STREQ(spec, INDENT_SPACE)) { (void)scan_string(indent_space); /* composite page delimiter */ } else if (STREQ(spec, COMPOSITOR)) { (void)scan_string(page_comp); /* page precedence */ } else if (STREQ(spec, PRECEDENCE)) { (void)scan_string(page_prec); (void)process_precedence(); /* index input format */ } else if (STREQ(spec, KEYWORD)) (void)scan_string(idx_keyword); else if (STREQ(spec, AOPEN)) (void)scan_char(&idx_aopen); else if (STREQ(spec, ACLOSE)) (void)scan_char(&idx_aclose); else if (STREQ(spec, LEVEL)) (void)scan_char(&idx_level); else if (STREQ(spec, ROPEN)) (void)scan_char(&idx_ropen); else if (STREQ(spec, RCLOSE)) (void)scan_char(&idx_rclose); else if (STREQ(spec, QUOTE)) (void)scan_char(&idx_quote); else if (STREQ(spec, ACTUAL)) (void)scan_char(&idx_actual); else if (STREQ(spec, ENCAP)) (void)scan_char(&idx_encap); else if (STREQ(spec, ESCAPE)) (void)scan_char(&idx_escape); else { (void)next_nonblank(); STY_SKIPLINE; STY_ERROR("Unknown specifier %s.\n", spec); put_dot = FALSE; } if (put_dot) { STY_DOT; } } /* check if quote and escape are distinct */ if (idx_quote == idx_escape) { STY_ERROR("Quote and escape symbols must be distinct (both `%c' now).\n", idx_quote); idx_quote = IDX_QUOTE; idx_escape = IDX_ESCAPE; } DONE(sty_tc - sty_ec, "attributes redefined", sty_ec, "ignored"); CLOSE(sty_fp); }
//---------------------------------------------------------------------------- // lengthy helper for use in write..., parses a message command int pcan_parse_input_message(char *buffer, TPCANMsg *Message) { char *ptr = buffer; u32 dwLen; u32 dwDat; int i; int err = -EINVAL; // DPRINTK(KERN_DEBUG "%s: pcan_parse_input_message()\n", DEVICE_NAME); // remove leading blanks skip_blanks(&ptr); // search for 'm' or 'r' to distinguish between message or init strings Message->MSGTYPE = 0; switch (scan_char(&ptr)) { case 'm': break; // normal message case 'r': Message->MSGTYPE |= MSGTYPE_RTR; break; // rtr message default: goto reject; } if (skip_blanks_and_test_for_CR(&ptr)) // no CR allowed here goto reject; // read message type switch (scan_char(&ptr)) { case 's': break; case 'e': Message->MSGTYPE |= MSGTYPE_EXTENDED; break; default: goto reject; } if (skip_blanks_and_test_for_CR(&ptr)) goto reject; // read CAN-ID if ((err = scan_unsigned_number(&ptr, &Message->ID))) goto reject; if (Message->MSGTYPE & MSGTYPE_EXTENDED) { if (Message->ID > 0x3fffffff) goto reject; } else { if (Message->ID > 2047) goto reject; } if (skip_blanks_and_test_for_CR(&ptr)) goto reject; //read datalength if ((err = scan_unsigned_number(&ptr, &dwLen))) goto reject; if (dwLen > 8) goto reject; Message->LEN = (u8)dwLen; // read data elements up to message len i = 0; while (i < dwLen) { if (skip_blanks_and_test_for_CR(&ptr)) goto reject; if ((err = scan_unsigned_number(&ptr, &dwDat))) goto reject; if (dwDat > 255) goto reject; Message->DATA[i] = (u8)dwDat; i++; } // DPRINTK(KERN_DEBUG "%s: pcan_parse_input_message() is OK\n", DEVICE_NAME); return 0; reject: // DPRINTK(KERN_DEBUG "%s: reject in pcan_parse_input_message()\n", DEVICE_NAME); return err; }
/// <summary> /// Skip_until_after the specified end. /// </summary> /// <param name="end">The end.</param> void Parser::skip_until_after(const char end) { for (; current_char != end && scan_char(); ); scan_char(); };
bool tokz_get_token(Tokenizer *tokz, Token *tok) { int c, c2, e; if (!(tokz->flags&TOKZ_READ_FROM_BUFFER)) assert(tokz->file!=NULL); tok_free(tok); if(!TOK_IS_INVALID(&(tokz->ungettok))){ *tok=tokz->ungettok; tokz->ungettok.type=TOK_INVALID; return TRUE; } while(1){ e=0; do{ c=GETCH(); }while(c!='\n' && c!=EOF && isspace(c)); tok->line=tokz->line; switch(c){ case EOF: TOK_SET_OP(tok, OP_EOF); return TRUE; case '\n': INC_LINE(); if(tokz->flags&TOKZ_IGNORE_NEXTLINE) continue; TOK_SET_OP(tok, OP_NEXTLINE); return TRUE; case '\\': do{ c=GETCH(); if(c==EOF){ TOK_SET_OP(tok, OP_EOF); return FALSE; } if(!isspace(c) && e==0){ e=E_TOKZ_EOL_EXPECTED; tokz_warn_error(tokz, tokz->line, e); if(!(tokz->flags&TOKZ_ERROR_TOLERANT)) return FALSE; } }while(c!='\n'); INC_LINE(); continue; case '#': if(tokz->flags&TOKZ_READ_COMMENTS){ e=scan_line_comment(tok, tokz); break; }else if((e=skip_line_comment(tokz))){ break; } continue; case '/': c2=GETCH(); if(c2=='='){ TOK_SET_OP(tok, OP_AS_DIV); return TRUE; } if(c2!='*'){ UNGETCH(c2); TOK_SET_OP(tok, OP_DIV); return TRUE; } if(tokz->flags&TOKZ_READ_COMMENTS){ e=scan_c_comment(tok, tokz); break; }else if((e=skip_c_comment(tokz))){ break; } continue; case '\"': e=scan_string(tok, tokz, TRUE); break; case '\'': e=scan_char(tok, tokz); break; default: if(('0'<=c && c<='9') || c=='-' || c=='+'){ e=scan_number(tok, tokz, c); break; } if(START_IDENT(c)) e=scan_identifier(tok, tokz, c); else e=scan_op(tok, tokz, c); } if(!e) return TRUE; tokz_warn_error(tokz, tokz->line, e); return FALSE; } }