int parse(char *buf, int linenum, int reload) { char *s, *t, *dir; int n; int retval = 1; int ac = 0; char *av[MAXPARAMS]; dir = strtok(buf, " \t\r\n"); s = strtok(NULL, ""); if (s) { while (isspace(*s)) s++; while (*s) { if (ac >= MAXPARAMS) { error(linenum, "Warning: too many parameters (%d max)", MAXPARAMS); break; } t = s; if (*s == '"') { t++; s++; while (*s && *s != '"') { if (*s == '\\' && s[1] != 0) s++; s++; } if (!*s) error(linenum, "Warning: unterminated double-quoted string"); else *s++ = 0; } else { s += strcspn(s, " \t\r\n"); if (*s) *s++ = 0; } av[ac++] = t; while (isspace(*s)) s++; } } if (!dir) return 1; for (n = 0; n < lenof(directives); n++) { Directive *d = &directives[n]; retval = parse_directive(d, dir, ac, av, linenum, reload, s); if (!retval) { break; } } return retval; }
static bool parse_planet_basis(az_load_planet_t *loader) { if (setjmp(loader->jump) != 0) { az_destroy_planet(loader->planet); return false; } parse_planet_header(loader); while (parse_directive(loader)); validate_planet_basis(loader); return true; }
void parser::parse_text( std::istream &in ) { while ( !in.eof() && in ) { int c = in.get(); if ( std::char_traits<char>::not_eof( c ) ) { if ( c == '[' ) { switch ( in.peek() ) { case '[': _func.push_text(); parse_expr( in ); break; case '%': _func.push_text( true ); parse_code( in ); break; case '#': _func.push_text( true ); parse_directive( in ); break; case '/': _func.push_text( true ); parse_comment( in ); break; default: _func.add( static_cast<char>( c ) ); break; } } else _func.add( static_cast<char>( c ) ); } } _func.push_text(); }
static char *filter_macros(char *line) { /* check for non-standard space-then-# */ char *hash = line; if(*hash == '#' || *(hash = str_spc_skip(hash)) == '#'){ if(*line != '#') CPP_WARN(WTRADITIONAL, "'#' for directive isn't in the first column"); parse_directive(hash + 1); free(line); return NULL; }else{ if(parse_should_noop()) *line = '\0'; else line = eval_expand_macros(line); return line; } }
struct ci_fmt_entry *check_tables(const char *var, struct ci_fmt_entry *u_table, int *directive_len, unsigned int *width, int *left_align, char *parameter) { int i; unsigned int params_len; params_len = parse_directive(var, width, left_align, parameter); for (i=0; GlobalTable[i].directive; i++) { if(check_directive(var+params_len,GlobalTable[i].directive, directive_len)) { *directive_len += params_len; return &GlobalTable[i]; } } if (u_table) { for (i=0; u_table[i].directive; i++) { if (check_directive(var+params_len, u_table[i].directive, directive_len)) { *directive_len += params_len; return &u_table[i]; } } } return NULL; }
/* Read the next database info from the file and put it in db_info_out. The * buf may contain first line of the database info. When this function * finishes, the buf may contain unprocessed information (which should be * passed to the next call to read_db_info). */ static int read_db_info (FILE *fp, char *buf, DBConfDBInfo_t **db_info_out, const char *directive, const int directive_len, int *eof) { char *ptr; int found_directive = 0; DBConfDBInfo_t *db_info; int rv; *db_info_out = 0; rv = skip_blank_lines_and_spaces(fp, buf, &ptr, eof); if (rv != LDAPU_SUCCESS || *eof) return rv; /* We possibly have a directive of the form "directory <name> <url>" */ rv = parse_directive(ptr, directive, directive_len, &db_info); if (rv != LDAPU_SUCCESS) return rv; /* We have parsed the directive successfully -- lets look for additional * property-value pairs for the database. */ if (!fgets(buf, BIG_LINE, fp)) { *eof = 1; rv = LDAPU_SUCCESS; } else { rv = dbconf_read_propval(fp, buf, db_info, eof); } if (rv != LDAPU_SUCCESS) { dbconf_free_dbinfo(db_info); *db_info_out = 0; } else { *db_info_out = db_info; } return rv; }
static int parse_text(ssi_buffer* ssib) { // find all includes & start subrequests int size; char* t=nxb_get_unfinished(ssib->nxb, &size); char* p; char* p1=t; char* p2; char* p3; int size1=size; for (;size1>0;) { p=memchr(p1, '<', size1); if (!p || (p-p1)+5>size1) break; if (p[1]=='!' && p[2]=='-' && p[3]=='-' && p[4]=='#') { p3=p+5; R: p2=memchr(p3, '>', size-(p3-t)); if (!p2) break; if (*(p2-1)!='-' || *(p2-2)!='-') { p3=p2+1; if ((p3-t)>size) break; goto R; } // ssi directive found! nxb_finish_partial(ssib->nxb, (p2-t)+1); // text + directive if (p-t) { nxweb_composite_stream_append_bytes(ssib->cs, t, p-t); } *(p2-2)='\0'; if (parse_directive(ssib, p+5, (p2-p)-5-2)==-1) { // ssi syntax error nxweb_composite_stream_append_bytes(ssib->cs, "<!--[ssi syntax error]-->", sizeof("<!--[ssi syntax error]-->")-1); } return 1; } else { p1=p+1; size1=size-(p1-t); } } return 0; }
extern void parse_program(char *source) { lexical_source = source; while (parse_directive(FALSE)) ; }
static int vfs_mountroot_parse(struct sbuf *sb, struct mount *mpdevfs) { struct mount *mp; char *conf; int error; root_mount_mddev = -1; retry: conf = sbuf_data(sb); mp = TAILQ_NEXT(mpdevfs, mnt_list); error = (mp == NULL) ? 0 : EDOOFUS; root_mount_onfail = A_CONTINUE; while (mp == NULL) { error = parse_skipto(&conf, CC_NONWHITESPACE); if (error == PE_EOL) { parse_advance(&conf); continue; } if (error < 0) break; switch (parse_peek(&conf)) { case '#': error = parse_skipto(&conf, '\n'); break; case '.': error = parse_directive(&conf); break; default: error = parse_mount(&conf); break; } if (error < 0) break; /* Ignore any trailing garbage on the line. */ if (parse_peek(&conf) != '\n') { printf("mountroot: advancing to next directive...\n"); (void)parse_skipto(&conf, '\n'); } mp = TAILQ_NEXT(mpdevfs, mnt_list); } if (mp != NULL) return (0); /* * We failed to mount (a new) root. */ switch (root_mount_onfail) { case A_CONTINUE: break; case A_PANIC: panic("mountroot: unable to (re-)mount root."); /* NOTREACHED */ case A_RETRY: goto retry; case A_REBOOT: kern_reboot(RB_NOSYNC); /* NOTREACHED */ } return (error); }
int parse_line(struct prog_info *pi, char *line) { char *ptr=NULL; int k; int flag=0, i; int global_label = False; char temp[LINEBUFFER_LENGTH]; struct label *label = NULL; struct macro_call *macro_call; while(IS_HOR_SPACE(*line)) line++; /* At first remove leading spaces / tabs */ if(IS_END_OR_COMMENT(*line)) /* Skip comment line or empty line */ return(True); /* Filter out .stab debugging information */ /* .stabs sometimes contains colon : symbol - might be interpreted as label */ if(*line == '.') { /* minimal slowdown of existing code */ if(strncmp(temp,".stabs ",7) == 0 ) { /* compiler output is always lower case */ strcpy(temp,line); /* TODO : Do we need this temp variable ? Please check */ return parse_stabs( pi, temp ); } if(strncmp(temp,".stabn ",7) == 0 ) { strcpy(temp,line); return parse_stabn( pi, temp ); } } /* Meta information translation */ ptr=line; k=0; while((ptr=strchr(ptr, '%')) != NULL) { if(!strncmp(ptr, "%MINUTE%", 8) ) { /* Replacement always shorter than tag -> no length check */ k=strftime(ptr,3,"%M", localtime(&pi->time)); strcpy(ptr+k,ptr+8); ptr+=k; continue; } if(!strncmp(ptr, "%HOUR%", 6) ) { k=strftime(ptr,3,"%H", localtime(&pi->time)); strcpy(ptr+k,ptr+6); ptr+=k; continue; } if(!strncmp(ptr, "%DAY%", 5) ) { k=strftime(ptr,3,"%d", localtime(&pi->time)); strcpy(ptr+k,ptr+5); ptr+=k; continue; } if(!strncmp(ptr, "%MONTH%", 7) ) { k=strftime(ptr,3,"%m", localtime(&pi->time)); strcpy(ptr+k,ptr+7); ptr+=k; continue; } if(!strncmp(ptr, "%YEAR%", 6) ) { k=strftime(ptr,5,"%Y", localtime(&pi->time)); strcpy(ptr+k,ptr+6); ptr+=k; continue; } ptr++; } // if(pi->pass == PASS_2) // TODO : Test // strcpy(pi->list_line, line); strcpy(pi->fi->scratch,line); for(i = 0; IS_LABEL(pi->fi->scratch[i]) || (pi->fi->scratch[i] == ':'); i++) if(pi->fi->scratch[i] == ':') { /* it is a label */ pi->fi->scratch[i] = '\0'; if(pi->pass == PASS_1) { for(macro_call = pi->macro_call; macro_call; macro_call = macro_call->prev_on_stack) { for(label = pi->macro_call->first_label; label; label = label->next) { if(!nocase_strcmp(label->name, &pi->fi->scratch[0])) { print_msg(pi, MSGTYPE_ERROR, "Can't redefine local label %s", &pi->fi->scratch[0]); break; } } } if(test_label(pi,&pi->fi->scratch[0],"Can't redefine label %s")!=NULL) break; if(test_variable(pi,&pi->fi->scratch[0],"%s have already been defined as a .SET variable")!=NULL) break; if(test_constant(pi,&pi->fi->scratch[0],"%s has already been defined as a .EQU constant")!=NULL) break; label = malloc(sizeof(struct label)); if(!label) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } label->next = NULL; label->name = malloc(strlen(&pi->fi->scratch[0]) + 1); if(!label->name) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(label->name, &pi->fi->scratch[0]); switch(pi->segment) { case SEGMENT_CODE: label->value = pi->cseg_addr; break; case SEGMENT_DATA: label->value = pi->dseg_addr; break; case SEGMENT_EEPROM: label->value = pi->eseg_addr; break; } if(pi->macro_call && !global_label) { if(pi->macro_call->last_label) pi->macro_call->last_label->next = label; else pi->macro_call->first_label = label; pi->macro_call->last_label = label; } else { if(pi->last_label) pi->last_label->next = label; else pi->first_label = label; pi->last_label = label; } } i++; while(IS_HOR_SPACE(pi->fi->scratch[i]) && !IS_END_OR_COMMENT(pi->fi->scratch[i])) i++; if(IS_END_OR_COMMENT(pi->fi->scratch[i])) { if((pi->pass == PASS_2) && pi->list_on) { // Diff tilpassing fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } return(True); } strcpy(pi->fi->scratch, &pi->fi->scratch[i]); break; } #if 0 if(pi->fi->scratch[0] == '.') { #else if((pi->fi->scratch[0] == '.') || (pi->fi->scratch[0] == '#')) { #endif pi->fi->label = label; flag = parse_directive(pi); if((pi->pass == PASS_2) && pi->list_on && pi->list_line) { // Diff tilpassing fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } return(flag); } else { return parse_mnemonic(pi); } } /* * Get the next token, and terminate the last one. * Termination identifier is specified. */ char *get_next_token(char *data, int term) { int i = 0, j, anti_comma = False; switch(term) { case TERM_END: // while(!IS_END_OR_COMMENT(data[i])) i++; Problems with 2. operand == ';' while( ((data[i] != ',') || anti_comma) && !(((data[i] == ';') && !anti_comma) || IS_ENDLINE(data[i])) ) { if((data[i] == '\'') || (data[i] == '"')) anti_comma = anti_comma ? False : True; i++; } break; case TERM_SPACE: while(!IS_HOR_SPACE(data[i]) && !IS_END_OR_COMMENT(data[i])) i++; break; case TERM_DASH: while((data[i] != '-') && !IS_END_OR_COMMENT(data[i])) i++; break; case TERM_COLON: while((data[i] != ':') && !IS_ENDLINE(data[i])) i++; break; case TERM_DOUBLEQUOTE: while((data[i] != '"') && !IS_ENDLINE(data[i])) i++; break; case TERM_COMMA: while(((data[i] != ',') || anti_comma) && !(((data[i] == ';') && !anti_comma) || IS_ENDLINE(data[i])) ) { if((data[i] == '\'') || (data[i] == '"')) anti_comma = anti_comma ? False : True; i++; } break; case TERM_EQUAL: while((data[i] != '=') && !IS_END_OR_COMMENT(data[i])) i++; break; } if(IS_END_OR_COMMENT(data[i])) { data[i--] = '\0'; while(IS_HOR_SPACE(data[i])) data[i--] = '\0'; return(0); } j = i - 1; while(IS_HOR_SPACE(data[j])) data[j--] = '\0'; data[i++] = '\0'; while(IS_HOR_SPACE(data[i]) && !IS_END_OR_COMMENT(data[i])) i++; if(IS_END_OR_COMMENT(data[i])) return(0); return(&data[i]); }