// // Get the include file name without surrouding angle brackets or double quoation marks // static CC_STRING GetIncludeFileName(const CC_STRING& line, bool& quoted) { const char *p1, *p2; CC_STRING filename; char style = '\0'; p1 = line.c_str(); skip_blanks(p1); if( *p1 == '"') style = '"'; else if( *p1 == '<' ) style = '>'; else goto error; p1++; skip_blanks(p1); p2 = p1 + strlen(p1) - 1; while( *p2 == '\t' || *p2 == ' ' || *p2 == '\r' || *p2 == '\n') { if(--p2 < p1) goto error; } if( *p2 != style ) goto error; p2--; while( *p2 == '\t' || *p2 == ' ' ) { if(--p2 < p1) goto error; } filename = CC_STRING(p1, p2+1); quoted = (style == '"'); error: return filename; }
CC_STRING Parser::do_elif(int mode) { CC_STRING output; CC_STRING trailing; const char *p; if( pline.comment_start > 0 ) trailing = pline.from.c_str() + pline.comment_start ; else { p = pline.from.c_str(); while( *p != '\r' && *p != '\n' && *p != '\0') p++; trailing = p; } if(mode == 2) output = "#else"; else if(mode == 1){ p = pline.from.c_str(); skip_blanks(p); p ++; /* # */ skip_blanks(p); p += 4; /* elif */ trailing = p; output = "#if"; } output += trailing; return output; }
static void ExecTable(char *param) { char *t; VERBOSE(1, ("ExecTable(%s)\n", param)); if (FltOptions('c')) { t = skip_ident(param); if (*skip_blanks(t) == '\0') { int save = *t; *t = 0; if (*param) { flt_make_symtab(param); flt_read_keywords(MY_NAME); } else { set_symbol_table(default_table); } *t = (char) save; } } t = skip_ident(param); flt_puts(param, (int) (t - param), Literal_attr); if (*skip_blanks(t) == '\0') { flt_puts(t, (int) strlen(t), ""); } else { flt_error("unexpected tokens"); flt_puts(t, (int) strlen(t), Error_attr); } }
struct entry *add_entries (char *buf, char *username, struct entry *link) { struct entry *list = link; char *p = buf, *q; while (*p) { struct entry *entry = malloc(sizeof(struct entry)); q = read_time_entry(p, &entry->te); if (!q) { free(entry); } else { entry->next = list; list = entry; p = skip_blanks(q); /* username */ if (username) entry->username = strdup(username); else { q = p; while (isalnum(*q)) q++; entry->username = strndup(p, q-p); p = skip_blanks(q); } /* command */ q = p; while (!eoln(q)) q++; entry->command = strndup(p, q-p); p = q; } p = next_line(p); } return list; }
static int parse_conf(const char *conf,char *name,char *value) { int res; char buf[1024]; char *ptr; conf=skip_blanks(conf); if(*conf=='#'||*conf=='\0'||*conf=='=') { res=-1; } else { strcpy(buf,conf); if((ptr=strchr(buf,'='))==NULL) return -1; *ptr='\0'; strcpy(name,trim_blanks(buf)); ptr++; ptr=skip_blanks(ptr); if(*ptr=='\0'|| *ptr=='#') return -1; char *tmp=NULL; if((tmp=strchr(ptr,'#'))!=NULL) *tmp='\0'; strcpy(value,trim_blanks(ptr)); res=0; } return res; }
static int scan_keyword_assignment(struct misc_file_buffer* file, struct scan_token* token, int line) { int rc; rc = scan_keyword(file, &token->content.keyword.keyword, line); if (rc) return rc; skip_blanks(file); if (misc_get_char(file, 0) != '=') { error_reason("Line %d: unexpected characters after keyword", line); return -1; } file->pos++; skip_blanks(file); rc = scan_value_string(file, &token->content.keyword.value, line); if (rc) return rc; if (skip_trailing_blanks(file)) { error_reason("Line %d: unexpected characters at end of line", line); return -1; } token->id = scan_id_keyword_assignment; token->line = line; return 0; }
void process_Lisp_file(void) { register char *p; char *gettext, *interactive; enum boolean dgettext = FALSE; while (p = GET_LINE) { gettext = strstr(p, "gettext"); interactive = strstr(p, "(interactive"); if (gettext || interactive) { if (!interactive) p = gettext; else if (!gettext) p = interactive; else if (gettext < interactive) { p = gettext; interactive = NULL; } else { p = interactive; gettext = NULL; } if (gettext) { if (p > line && *(p - 1) == 'd') dgettext = TRUE; p += 7; /* Skip over "gettext" */ } else p += 12; /* Skip over "(interactive" */ p = skip_blanks(p); if (*p != '\"') /* Make sure there is a quoted string */ continue; if (dgettext) { /* Skip first quoted string (domain name) */ while (*++p != '"') ; /* null statement */ ++p; p = skip_blanks(p); if (*p != '\"') /* Check for second quoted string (message) */ continue; } if (interactive && no_interactive_prompt(p)) continue; fprintf(outfile, "gettext("); p = copy_up_to_paren(p); fprintf(outfile, ")\n"); } } }
void parser_base::shrink_stream() { // Skip any leading blanks. skip_blanks(); if (!remaining_size()) return; // Skip any trailing blanks. skip_blanks_reverse(); // Skip leading <!-- if present. const char* com_open = "<!--"; size_t com_open_len = std::strlen(com_open); if (remaining_size() < com_open_len) // Not enough stream left. Bail out. return; const char* p = mp_char; for (size_t i = 0; i < com_open_len; ++i, ++p) { if (*p != com_open[i]) return; next(); } mp_char = p; // Skip leading blanks once again. skip_blanks(); // Skip trailing --> if present. const char* com_close = "-->"; size_t com_close_len = std::strlen(com_close); size_t n = remaining_size(); if (n < com_close_len) // Not enough stream left. Bail out. return; p = mp_char + n; // move to the last char. for (size_t i = com_close_len; i > 0; --i, --p) { if (*p != com_close[i-1]) return; } mp_end -= com_close_len; skip_blanks_reverse(); }
/* * Skip {BLANK}{EQLS}{BLANK}. */ static int skip_eqls_ch(char **param) { char *s = *param; int rc = 0; s = skip_blanks(s); if (*s == eqls_ch) { rc = 1; ++s; s = skip_blanks(s); } *param = s; return rc; }
uint32_t get_hex(char **p, int DefaultValue) { uint32_t Value = 0; unsigned char UseDefault; UseDefault = 1; skip_blanks(p); while ((**p == '0') && ( (*(*p+1) == 'x') ||(*(*p+1) == 'X') )) (*p) = (*p)+2; while ( ((**p)<= '9' && (**p)>= '0') || ((**p)<= 'f' && (**p)>= 'a') || ((**p)<= 'F' && (**p)>= 'A') ) { if (**p >= 'a') Value = Value * 16 + (**p) - 'a' + 10; else if (**p >= 'A') Value = Value * 16 + (**p) - 'A' + 10; else Value = Value * 16 + (**p) - '0'; UseDefault = 0; (*p)++; } if (UseDefault) return DefaultValue; else return Value; }
int get_signed_int(char **p, int DefaultValue) { int Value = 0; unsigned char UseDefault; unsigned char NegativeNum = 0; UseDefault = 1; skip_blanks(p); if ( (**p) == '-') { NegativeNum = 1; (*p)++; } while ( ((**p)<= '9' && (**p)>= '0') ) { Value = Value * 10 + (**p) - '0'; UseDefault = 0; (*p)++; } if (UseDefault) return DefaultValue; else return ((NegativeNum == 0)? Value : -Value); }
struct Token* get_token() { struct Token newToken; struct Token* retToken; char c = '\0'; retToken = (struct Token*)malloc(sizeof(struct Token)); c = skip_blanks(); if(peek_char() == '{') { c = skip_comment(); } if(char_table[c] == LETTER) { newToken = get_word(c); } else if(char_table[c] == DIGIT) { newToken = get_number(c); } else if(char_table[c] == QUOTE) { newToken = get_string(c); } else if(c == EOF) { newToken.literalValue.valString[0] = '.'; newToken.literalType = INTEGER_LIT; newToken.tokenCode = END_OF_FILE; } else if(char_table[c] == SPECIAL) { newToken = get_special(c); } memcpy(retToken, &newToken, sizeof(struct Token)); return retToken; }
bool Parser::do_define(const char *line) { const char *p; CC_STRING word; sym_t mid; p = line; skip_blanks(p); if(*p == '\r' || *p == '\n' || *p == '\0') { errmsg = "no macro name given in #define directive"; return false; } if( isalpha(*p) || *p == '_' ) { word = *p++; while( isalpha(*p) || *p == '_' || isdigit(*p) ) word += *p++; mid = intab->syLut.Put(word); SynMacro *ma = (SynMacro*) malloc(sizeof(*ma)); ma->id = SSID_INVALID; ma->line = strdup(line); ma->parsed = NULL; ma->va_args = false; intab->maLut.Put(mid, ma); assert(intab->maLut.Lookup(mid) != NULL); } return true; }
/* Return a pointer to a string containing the array size */ char *parse_array_size (char string[]) { char output_buffer[BUFFER_LEN]; int length; char *size_string, *ptr = string; memset (output_buffer, '\0', BUFFER_LEN); ptr = find_char (ptr, '('); while (ptr < find_char(string,')')) { if (strlen(output_buffer) != 0) strcat (output_buffer, "*"); length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1; strcat (output_buffer, "("); if (find_char(ptr,':')-ptr < length) { strcat (output_buffer, "1-"); strncat (output_buffer, ptr, find_char(ptr,':')-ptr-1); strcat (output_buffer, "+"); ptr = find_char (ptr, ':'); length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1; } strncat (output_buffer, ptr, length); strcat (output_buffer, ")"); ptr = skip_blanks (find_char (ptr, ',')); } size_string = malloc (strlen(output_buffer)+1); if (size_string == NULL) memory_error (); strcpy (size_string, output_buffer); return (size_string); }
/* Return pointer to copy of filename in the command buffer */ static const char * get_filename( const char ** const ibufpp ) { static char * buf = 0; static int bufsz = 0; const int pmax = path_max( 0 ); int n; *ibufpp = skip_blanks( *ibufpp ); if( **ibufpp != '\n' ) { int size = 0; if( !get_extended_line( ibufpp, &size, true ) ) return 0; if( **ibufpp == '!' ) { ++*ibufpp; return get_shell_command( ibufpp ); } else if( size > pmax ) { set_error_msg( "Filename too long" ); return 0; } } else if( !traditional() && !def_filename[0] ) { set_error_msg( "No current filename" ); return 0; } if( !resize_buffer( &buf, &bufsz, pmax + 1 ) ) return 0; for( n = 0; **ibufpp != '\n'; ++n, ++*ibufpp ) buf[n] = **ibufpp; buf[n] = 0; while( **ibufpp == '\n' ) ++*ibufpp; /* skip newline */ return ( may_access_filename( buf ) ? buf : 0 ); }
static int leading_uc(char *dst, char *src) { char *base = dst; int c; while ((c = *src) != EOS && c != SLASHC) { if (isAlpha(c)) { if (isLower(c)) return (0); } else if (!strchr("0123456789$_", c)) return (0); *dst++ = c; *dst = EOS; src++; } *dst = EOS; if ((*base) && (dst = getenv(base)) != 0) { c = strlen(base); dst = skip_blanks(dst); (void) strcpy(base, dst); return (c); } return (0); }
void process_C_file(void) { register char *p; char *gettext, *defun; while (p = GET_LINE) { gettext = strstr(p, "GETTEXT"); defun = strstr(p, "DEFUN"); if (gettext || defun) { if (gettext) { p = gettext; p += 7; /* Skip over "GETTEXT" */ } else if (defun) { p = defun; p += 5; /* Skip over "DEFUN" */ } p = skip_blanks(p); if (*p++ != '(') continue; if (defun) { register int i; for (i = 0; i < 5; i++) /* Skip over commas to doc string */ while (*p++ != ',') CHECK_EOL(p); if (*p == '\n') p = GET_LINE; } p = skip_blanks(p); if (*p != '\"') /* Make sure there is a quoted string */ continue; if (defun && no_interactive_prompt(p)) continue; fprintf(outfile, "gettext("); if (gettext) p = copy_up_to_paren(p); else p = copy_quoted_string(p); fprintf(outfile, ")\n"); } } }
CFGItem *parse_line(char *str) { int argc = 0; char *cp, *arg; char *argv[MAXARGS]; CFGItem *item; int i; char *argstr = NULL; printf("PARSE: '%s'\n", str); if (*str == EOS) { return NULL; } str = strdup(str); argstr = arg = cp = skip_blanks(str); while (*argstr && !IS_WHITE(*argstr)) { argstr++; } argstr = skip_blanks(argstr); argstr = strdup(argstr); while (*arg != EOS) { while (*cp && !(IS_WHITE(*cp))) { cp++; } *cp++ = EOS; argv[argc] = arg; argc++; arg = cp = skip_blanks(cp); } item = malloc(sizeof(CFGItem)); item->next = NULL; item->name = argv[0]; item->argstr = argstr; item->argv = malloc(sizeof(char *) * (argc-1)); for (i=1; i<argc; i++) { item->argv[i-1] = argv[i]; } item->argc = argc-1; return item; }
CC_STRING CMaExpander::TryExpand() { CToken token; CC_STRING outs; static int debug_level; CC_STRING saved_inStr = inStr; debug_level++; while(1) { const char *const last_pos = pos; IgnoreSpaces(); if( ! get_token(tc, &pos, &token, for_include) ) break; if( token.attr == CToken::TA_IDENT ) { CMacro *ma; CC_STRING tmp; ma = GetMacro(token.id); if( IS_MACRO(ma) && ! in_defined_context() ) { if( IS_FLM(ma) ) { skip_blanks(pos); if( *pos == '(' ) { tmp = Expand_FLM(ma); } else goto do_cat; } else { tmp = Expand_OLM(ma); } const ssize_t offset = last_pos - inStr.c_str(); CC_STRING newStr; newStr.strcat(inStr.c_str(), last_pos); newStr += tmp; newStr += pos; inStr = newStr; pos = inStr.c_str() + offset; } else goto do_cat; } else { do_cat: outs.strcat(last_pos, pos); } last_ids[0] = last_ids[1]; last_ids[1] = token.id; } // printf("Leave [%u] %s\n", debug_level, outs.c_str()); --debug_level; // fprintf(stderr, "*** %u: %s => %s\n", debug_level, saved_inStr.c_str(), outs.c_str()); return outs; }
//---------------------------------------------------------------------------- // skip blanks, return 0 if the 1st non-blank char is not '\n' static int skip_blanks_and_test_for_CR(char **ptr) { // remove blanks or tabs skip_blanks(ptr); if (**ptr == '\n') return -1; else return 0; }
static int parse_directive(char *line) { /* *INDENT-OFF* */ static struct { const char *name; void (*func) (char *); } table[] = { { "abbrev", ExecAbbrev }, { "brief", ExecBrief }, { "class", ExecClass }, { "default", ExecDefault }, { "equals", ExecEquals }, { "include", ExecInclude }, { "merge", ExecSource }, { "meta", ExecMeta }, { "source", ExecSource }, { "table", ExecTable }, }; /* *INDENT-ON* */ unsigned n, len; char *s; VERBOSE(1, ("parse_directive(%s)\n", line)); if (*(s = skip_blanks(line)) == meta_ch) { s = skip_blanks(s + 1); if ((len = (unsigned) (skip_ident(s) - s)) != 0) { for (n = 0; n < sizeof(table) / sizeof(table[0]); n++) { if (!strncmp(s, table[n].name, len)) { flt_puts(line, (int) (s + len - line), Ident_attr); s = flt_put_blanks(s + len); (*table[n].func) (s); return 1; } } } flt_error("unknown directive"); flt_puts(line, (int) strlen(line), Error_attr); } return 0; }
static int track_rest(GtBEDParser *bed_parser, GtIO *bed_file, GtError *err) { char cc; int had_err = 0; gt_error_check(err); bed_parser->offset = 0; /* reset offset for new track line */ if (bed_separator(bed_file)) /* skip to first attribute=value pair */ had_err = skip_blanks(bed_file, err); while (!had_err && (cc = gt_io_peek(bed_file)) != GT_END_OF_LINE && cc != GT_CARRIAGE_RETURN) { /* parse attribute */ word(bed_parser->word, bed_file); had_err = gt_io_expect(bed_file, PAIR_SEPARATOR, err); /* parse value */ if (!had_err) { if (gt_io_peek(bed_file) == QUOTE_CHAR) had_err = quoted_word(bed_parser->another_word, bed_file, err); else word(bed_parser->another_word, bed_file); } /* process offset if necessary */ if (!had_err && !strcmp(gt_str_get(bed_parser->word), OFFSET_KEYWORD)) { if (gt_parse_word(&bed_parser->offset, gt_str_get(bed_parser->another_word))) { gt_error_set(err, "file \"%s\": line "GT_WU": could not parse offset value " "'%s'", gt_io_get_filename(bed_file), gt_io_get_line_number(bed_file), gt_str_get(bed_parser->another_word)); had_err = -1; } } /* skip blanks up to next attribute or end-of-line */ if (!had_err && bed_separator(bed_file)) had_err = skip_blanks(bed_file, err); } /* the end of the line should now be reached */ if (!had_err) had_err = gt_io_expect(bed_file, GT_END_OF_LINE, err); return had_err; }
void json_parser<_Handler>::number_with_exp(double base) { assert(cur_char() == 'e' || cur_char() == 'E'); next(); if (!has_char()) throw json::parse_error("number_with_exp: illegal exponent value.", offset()); long exp = parse_long_or_throw(); base *= std::pow(10.0, exp); m_handler.number(base); skip_blanks(); }
char get_token() { // char token_string[MAX_TOKEN_STRING_LENGTH]; //Store your token here as you build it. get_source_line(token_string); while(token_string[0] != '\0') { //printf("I went through the while loop: %d times\n", debugCount); //debug line transfer(skipArray,token_string); skip_blanks(skipArray); //1. Skip past all of the blanks transfer(token_string,skipArray); //printf("This is token_string after skip_blanks :2%s2\n", token_string); //debug //printf("ldksaf"); if(token_string[0] == '\n') { return 'a'; } if(token_string[0] == '.') { printf("\t>> .\t.\n"); return '.'; } if(isalpha(token_string[0])) { get_word(); } else if(isdigit(token_string[0])) { //token_string = get_number(token_string); get_number(); } else if(token_string[0] == '\'') { //token_string = get_string(token_string); get_string(); } else if(token_string[0] == '{'){ skip_comment(token_string); } else { if(token_string[0] == '.') { return '.'; } get_special(); } } return 'a'; //What should be returned here? }
static char get_char(char token_string[]) { /* If at the end of the current line (how do you check for that?), we should call get source line. If at the EOF (end of file) we should set the character ch to EOF and leave the function. Write some code to set the character ch to the next character in the buffer checks the current state of the source_buffer and gets a new line of code if it is at the end of a line. If it sees a Pascal Comment it skips the comment (a pascal comment is anything between ‘{‘ and ‘}’). */ static char source_buffer[MAX_SOURCE_LINE_LENGTH]; static size_t i = 0; size_t nextIndex = 0; char ch; if ((source_buffer[i] == '\0') || (source_buffer[i] == '\n')) { i = 0; BOOLEAN ret = get_source_line(source_buffer); if (ret == FALSE) { ch = EOF; return ch; } else { i = skip_blanks(source_buffer, i); i = skip_comment(source_buffer, i); ch = source_buffer[i]; } } else { ch = source_buffer[i]; } nextIndex = buildToken(source_buffer, token_string, i); i = nextIndex; return ch; }
//---------------------------------------------------------------------------- // 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; }
void json_parser<_Handler>::array() { assert(cur_char() == '['); m_handler.begin_array(); for (next(); has_char(); next()) { if (cur_char() == ']') { m_handler.end_array(); next(); skip_blanks(); return; } skip_blanks(); value(); skip_blanks(); if (has_char()) { switch (cur_char()) { case ']': m_handler.end_array(); next(); skip_blanks(); return; case ',': continue; default: json::parse_error::throw_with( "array: either ']' or ',' expected, but '", cur_char(), "' found.", offset()); } } } throw json::parse_error("array: failed to parse array.", offset()); }
void json_parser<_Handler>::parse() { m_handler.begin_parse(); skip_blanks(); if (has_char()) root_value(); if (has_char()) throw json::parse_error("parse: unexpected trailing string segment.", offset()); m_handler.end_parse(); }
void get_str(char **p, char *Buffer) { skip_blanks(p); while (**p != 0 && **p != ' ') { *Buffer = **p; (*p)++; Buffer++; } *Buffer = 0; }
static char* get_char(char source_buffer[MAX_TOKEN_STRING_LENGTH], char *token_ptr) { if(source_buffer[0] == NULL) { if(!get_source_line(source_buffer)) { return '.'; } token_ptr = &source_buffer[0]; } if((*(token_ptr)) == 10) { if(!get_source_line(source_buffer)) { return '.'; } token_ptr = source_buffer; if(*(token_ptr) == '\n') { token_ptr = get_char(source_buffer,token_ptr); } } if((*(token_ptr)) == 46) { *token_ptr = '.'; return token_ptr; } if((*(token_ptr)) == 123) { token_ptr = skip_comment(token_ptr); } if(*token_ptr == 9) // Horizontal Tabs are a pain in my rump!!! { token_ptr++; if(*(token_ptr) == 9) //Recursively make them go away. { token_ptr = get_char(source_buffer,token_ptr); } } if((*(token_ptr)) == 32) { token_ptr = skip_blanks(token_ptr); //1. Skip past all of the blanks } /* If at the end of the current line (how do you check for that?), we should call get source line. If at the EOF (end of file) we should set the character ch to EOF and leave the function. */ return token_ptr; }