ST_FN char *get_line(char *line, int size, FILE *fp) { if (NULL == fgets(line, size, fp)) return NULL; trimback(line, strchr(line, 0)); return trimfront(line); }
void ebody(char *e) { char *t; t = epos; epos = trimback(e); body(); pos = e; epos = t; }
int heading(void) { char *o, *s, *e; int n; for(s = "======"; *s; s++) if(got(s)) break; if(*s == 0) return 0; n = strlen(s); e = look("=", look("\n", nil)); if(e == nil) e = look("\n", nil); if(e == nil) e = epos; eatspace(); string("<h"); output("0123456"+n, 1); string("><a name=\""); o = pos; s = trimback(e); while(pos < s){ if((*pos >= 'a' && *pos <= 'z') || (*pos >= 'A' && *pos <= 'Z') || (*pos >= '0' && *pos <= '9') || (strchr("!#$%()_+,-./{|}~:;=?@[\\]^_`", *pos) != 0)) output(pos, 1); else if(*pos == ' ' || *pos == '\t') output("_", 1); else if(*pos == '<') string("<"); else if(*pos == '>') string(">"); else if(*pos == '&') string("&"); else if(*pos == '"') string("""); else if(*pos == '\'') string("'"); pos++; } string("\"></a>"); pos = o; ebody(e); while(got("=")) ; string("</h"); output("0123456"+n, 1); string(">"); return 1; }
int pe_load_def_file(TCCState *s1, int fd) { DLLReference *dllref; int state = 0, ret = -1, hint; char line[400], dllname[80], *p, *ordinal; FILE *fp = fdopen(dup(fd), "rb"); if (fp == NULL) goto quit; for (;;) { p = get_line(line, sizeof line, fp); if (p == NULL) break; if (*p == 0 || *p == ';') continue; switch (state) { case 0: if (strncasecmp(p, "LIBRARY", 7) != 0) goto quit; strcpy(dllname, trimfront(p + 7)); ++state; continue; case 1: if (strcasecmp(p, "EXPORTS") != 0) goto quit; ++state; continue; case 2: dllref = tcc_malloc(sizeof(DLLReference) + strlen(dllname)); strcpy(dllref->name, dllname); dllref->level = 0; dynarray_add((void ***) &s1->loaded_dlls, &s1->nb_loaded_dlls, dllref); ++state; default: hint = 0; ordinal = strchr(p, '@'); if (ordinal) { *ordinal = 0; trimback(p, ordinal); ordinal++; hint = atoi(ordinal); } add_elf_sym(s1->dynsymtab_section, s1->nb_loaded_dlls, 0, ELF32_ST_INFO(STB_GLOBAL, STT_FUNC), hint, text_section->sh_num, p); continue; } } ret = 0; quit: if (fp) fclose(fp); if (ret) error_noabort("unrecognized export definition file format"); return ret; }
static char *get_line(char *line, int size, FILE *fp) { if (fgets(line, size, fp) == NULL) return NULL; trimback(line, strchr(line, 0)); return trimfront(line); }