+
+ // seed passthrough
+ fprintf(fout, "\n// - seed -\n");
+
+ rewind(g_fhdr);
+ while (fgets(line, sizeof(line), g_fhdr))
+ fwrite(line, 1, strlen(line), fout);
+}
+
+// '=' needs special treatment
+// also ' quote
+static char *next_word_s(char *w, size_t wsize, char *s)
+{
+ size_t i;
+
+ s = sskip(s);
+
+ i = 0;
+ if (*s == '\'') {
+ w[0] = s[0];
+ for (i = 1; i < wsize - 1; i++) {
+ if (s[i] == 0) {
+ printf("warning: missing closing quote: \"%s\"\n", s);
+ break;
+ }
+ if (s[i] == '\'')
+ break;
+ w[i] = s[i];
+ }
+ }
+
+ for (; i < wsize - 1; i++) {
+ if (s[i] == 0 || my_isblank(s[i]) || (s[i] == '=' && i > 0))
+ break;
+ w[i] = s[i];
+ }
+ w[i] = 0;
+
+ if (s[i] != 0 && !my_isblank(s[i]) && s[i] != '=')
+ printf("warning: '%s' truncated\n", w);
+
+ return s + i;
+}
+
+static void scan_variables(FILE *fasm)
+{
+ struct scanned_var *var;
+ char line[256] = { 0, };
+ char words[3][256];
+ char *p = NULL;
+ int wordc;
+ int l;
+
+ while (!feof(fasm))
+ {
+ // skip to next data section
+ while (my_fgets(line, sizeof(line), fasm))
+ {
+ asmln++;
+
+ p = sskip(line);
+ if (*p == 0 || *p == ';')
+ continue;
+
+ p = sskip(next_word_s(words[0], sizeof(words[0]), p));
+ if (*p == 0 || *p == ';')
+ continue;
+
+ if (*p != 's' || !IS_START(p, "segment para public"))
+ continue;
+
+ break;
+ }
+
+ if (p == NULL || !IS_START(p, "segment para public"))
+ break;
+ p = sskip(p + 19);
+
+ if (!IS_START(p, "'DATA'"))
+ continue;
+
+ // now process it
+ while (my_fgets(line, sizeof(line), fasm))
+ {
+ asmln++;
+
+ p = line;
+ if (my_isblank(*p))
+ continue;
+
+ p = sskip(p);
+ if (*p == 0 || *p == ';')
+ continue;
+
+ for (wordc = 0; wordc < ARRAY_SIZE(words); wordc++) {
+ words[wordc][0] = 0;
+ p = sskip(next_word_s(words[wordc], sizeof(words[0]), p));
+ if (*p == 0 || *p == ';') {
+ wordc++;
+ break;
+ }
+ }
+
+ if (wordc == 2 && IS(words[1], "ends"))
+ break;
+ if (wordc < 2)
+ continue;
+
+ if (IS_START(words[0], "__IMPORT_DESCRIPTOR_")) {
+ // when this starts, we don't need anything from this section
+ break;
+ }
+
+ if ((hg_var_cnt & 0xff) == 0) {
+ hg_vars = realloc(hg_vars, sizeof(hg_vars[0])
+ * (hg_var_cnt + 0x100));
+ my_assert_not(hg_vars, NULL);
+ memset(hg_vars + hg_var_cnt, 0, sizeof(hg_vars[0]) * 0x100);
+ }
+
+ var = &hg_vars[hg_var_cnt++];
+ snprintf(var->name, sizeof(var->name), "%s", words[0]);
+
+ // maybe already in seed header?
+ var->pp = proto_parse(g_fhdr, var->name, 1);
+ if (var->pp != NULL) {
+ if (var->pp->is_fptr) {
+ var->lmod = OPLM_DWORD;
+ //var->is_ptr = 1;
+ }
+ else if (var->pp->is_func)
+ aerr("func?\n");
+ else if (!guess_lmod_from_c_type(&var->lmod, &var->pp->type))
+ aerr("unhandled C type '%s' for '%s'\n",
+ var->pp->type.name, var->name);
+
+ var->is_seeded = 1;
+ continue;
+ }
+
+ if (IS(words[1], "dd"))
+ var->lmod = OPLM_DWORD;
+ else if (IS(words[1], "dw"))
+ var->lmod = OPLM_WORD;
+ else if (IS(words[1], "db")) {
+ var->lmod = OPLM_BYTE;
+ if (wordc >= 3 && (l = strlen(words[2])) > 4) {
+ if (words[2][0] == '\'' && IS(words[2] + l - 2, ",0"))
+ var->is_c_str = 1;
+ }
+ }
+ else if (IS(words[1], "dq"))
+ var->lmod = OPLM_QWORD;
+ //else if (IS(words[1], "dt"))
+ else
+ aerr("type '%s' not known\n", words[1]);
+ }
+ }
+
+ rewind(fasm);
+ asmln = 0;