int readstuffs(char *fname) { FILE *tmpfile; char line[255]; unsigned long lines=0; phase=0; coordcount=0; lopeta=0; tmpfile=fopen(fname,"rt"); if (!tmpfile) fileerror("Error opening source file..."); while(!feof(tmpfile) && !lopeta) { fgets(line,255,tmpfile); if(strlen(line)<1) break; ++lines; p=line; get_token(); if (*token) { if (tok_type==STRING) parse_strings(); else if (tok_type==NUMBER && strchr(token,'+')) parse_expo(); else if(tok_type==NUMBER) parse_datahdr(); // skip everything else } } fclose(tmpfile); return 0; }
/* Parses the whole DO REPEAT command specification. Returns success. */ static bool parse_specification (struct lexer *lexer, struct dictionary *dict, struct hmap *dummies) { struct dummy_var *first_dv = NULL; hmap_init (dummies); do { struct dummy_var *dv; const char *name; bool ok; /* Get a stand-in variable name and make sure it's unique. */ if (!lex_force_id (lexer)) goto error; name = lex_tokcstr (lexer); if (dict_lookup_var (dict, name)) msg (SW, _("Dummy variable name `%s' hides dictionary variable `%s'."), name, name); if (find_dummy_var (dummies, name, strlen (name))) { msg (SE, _("Dummy variable name `%s' is given twice."), name); goto error; } /* Make a new macro. */ dv = xmalloc (sizeof *dv); dv->name = xstrdup (name); dv->values = NULL; dv->n_values = 0; hmap_insert (dummies, &dv->hmap_node, hash_dummy (name, strlen (name))); /* Skip equals sign. */ lex_get (lexer); if (!lex_force_match (lexer, T_EQUALS)) goto error; /* Get the details of the variable's possible values. */ if (lex_token (lexer) == T_ID || lex_token (lexer) == T_ALL) ok = parse_ids (lexer, dict, dv); else if (lex_is_number (lexer)) ok = parse_numbers (lexer, dv); else if (lex_is_string (lexer)) ok = parse_strings (lexer, dv); else { lex_error (lexer, NULL); goto error; } if (!ok) goto error; assert (dv->n_values > 0); if (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD) { lex_error (lexer, NULL); goto error; } /* If this is the first variable then it defines how many replacements there must be; otherwise enforce this number of replacements. */ if (first_dv == NULL) first_dv = dv; else if (first_dv->n_values != dv->n_values) { msg (SE, _("Dummy variable `%s' had %zu substitutions, so `%s' must " "also, but %zu were specified."), first_dv->name, first_dv->n_values, dv->name, dv->n_values); goto error; } lex_match (lexer, T_SLASH); } while (!lex_match (lexer, T_ENDCMD)); while (lex_match (lexer, T_ENDCMD)) continue; return true; error: destroy_dummies (dummies); return false; }
static int parse_header(void *addr, int len) { struct cb_header *header; unsigned char *ptr = (unsigned char *)addr; int i; for (i = 0; i < len; i += 16, ptr += 16) { header = (struct cb_header *)ptr; if (!strncmp((const char *)header->signature, "LBIO", 4)) break; } /* We walked the entire space and didn't find anything. */ if (i >= len) return -1; if (!header->table_bytes) return 0; /* FIXME: Check the checksum. */ if (ipchksum((uint16_t *) header, sizeof(*header))) return -1; if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes) != header->table_checksum) return -1; /* Now, walk the tables. */ ptr += header->header_bytes; for (i = 0; i < header->table_entries; i++) { struct cb_record *rec = (struct cb_record *)ptr; switch (rec->tag) { case CB_TAG_FORWARD: return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1); break; case CB_TAG_MEMORY: parse_memory(ptr); break; case CB_TAG_MAINBOARD: parse_mainboard(ptr); break; case CB_TAG_VERSION: case CB_TAG_EXTRA_VERSION: case CB_TAG_BUILD: case CB_TAG_COMPILE_TIME: case CB_TAG_COMPILE_BY: case CB_TAG_COMPILE_HOST: case CB_TAG_COMPILE_DOMAIN: case CB_TAG_COMPILER: case CB_TAG_LINKER: case CB_TAG_ASSEMBLER: parse_strings(ptr); break; case CB_TAG_SERIAL: parse_serial(ptr); break; case CB_TAG_CONSOLE: parse_console(ptr); break; default: break; } ptr += rec->size; } return 1; }
//针对系统变量中有些集合形式的参数,取出来,存入集合中 void parse_env(string param_name,vector<string>& v,string delims){ string params(getenv(param_name.c_str())); parse_strings(params,v,delims); }