void sortSymbols (void) { sSymbol *p = NULL, *c = t_sym; while (c != NULL) { if (c->alias[0] != 0) { sSymbol *r = t_sym; while (r != NULL && r->sym != c->alias) { r = r->next; } if (!r) { addSymbol (r->alias, unifyStr (""), unifyStr (""), unifyStr (""), 1); r = t_lastsym; } if (!p) t_sym = c->next; else p->next = c->next; c->next = r->subs; r->subs = c; c = t_sym; p = NULL; continue; } p = c; c = c->next; } }
const char * unifyCat (const char *s, const char *t) { char *h; const char *r; if (!t || *t == 0) return unifyStr (s); if (!s || *s == 0) return unifyStr (t); h = (char *) malloc (strlen (s) + strlen (t) + 1); strcpy (h, s); strcat (h, t); r = unifyStr (h); free (h); return r; }
static void init_curIAT (void) { char *h; char *r; h = (char *) strdup (cur_libname); while ((r = strchr (h, '.')) != NULL) *r = '_'; cur_dllsym = unifyStr (h); free (h); cur_IAT = unifyCat ("__IAT_", cur_dllsym); }
static int parseit (void) { int r; char *dot = NULL; if (!exports_seen) { if ((r = lexit2 ()) == -1) return 0; if (r == TK_EXPORTS) { r = expect_newline ("EXPORTS"); return (r != -1 ? 1 : 0); } if (r == TK_LIBRARY) { r = lexit2 (); if (r != TK_STRING && r != TK_NAME) { fprintf (stderr, "Expect name/string after LIBRARY keyword.\n"); return (r != -1 ? 1 : 0); } cur_libname = unifyStr (t_buf); if ((dot = strchr (t_buf, '.')) != NULL) { *dot = '\0'; cur_libbasename = unifyStr (t_buf); } fprintf (stderr, "Current library-name set to %s'\n", cur_libname); cur_outlibbasename = unifyCat (cur_libbasename, SUFFIX); r = expect_newline ("LIBRARY"); return (r != -1 ? 1 : 0); } } else { if ((r = lexit2 ()) == -1) return 0; if (r != TK_NAME) { fprintf (stderr, "Unexpected token ,%s'. Would have expected a string/name.\n", t_buf); return (expect_newline ("UNKNOWN") == -1 ? 0 : 1); } cur_symbol = unifyStr (t_buf); cur_alias = ""; cur_libsymbol = ""; cur_srcfile = ""; cur_data = 0; while ((r = lexit2 ()) != -1 && r != TK_NL) { if (r == TK_DATA) cur_data = 1; else if (r == TK_EQUAL) { r = lexit2 (); if (r != TK_NAME) { fprintf (stderr, "Expected name after = expression.\n"); if (r != -1 && r != TK_NL) r = expect_newline ("SYMBOL"); return (r == -1 ? 0 : 1); } cur_libsymbol = unifyStr (t_buf); } else if (r == TK_EQUALEQUAL) { r = lexit2 (); if (r != TK_NAME) { fprintf (stderr, "Expected name after == expression.\n"); if (r != -1 && r != TK_NL) r = expect_newline ("SYMBOL"); return (r == -1 ? 0 : 1); } cur_alias = unifyStr (t_buf); } else if (r == TK_SOURCEFILENAME) { cur_srcfile = unifyStr (t_buf); } else { fprintf (stderr, "Unknown token ,%s'.\n", t_buf); } } addSymbol (cur_symbol, cur_libsymbol, cur_alias, cur_srcfile, cur_data); } return (r != -1 ? 1 : 0); }