+static void scan_variables(FILE *fasm)
+{
+ const struct parsed_proto *pp_c;
+ struct scanned_var *var;
+ char line[256] = { 0, };
+ char words[2][256];
+ char *p = NULL;
+ int wordc;
+
+ 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 ((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?
+ pp_c = proto_parse(g_fhdr, var->name, 1);
+ if (pp_c != NULL) {
+ if (pp_c->is_func)
+ aerr("func?\n");
+ else if (pp_c->is_fptr) {
+ var->lmod = OPLM_DWORD;
+ //var->is_ptr = 1;
+ }
+ else if (!guess_lmod_from_c_type(&var->lmod, &pp_c->type))
+ aerr("unhandled C type '%s' for '%s'\n",
+ pp_c->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;
+ 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;
+}
+
+static void set_label(int i, const char *name)
+{
+ const char *p;
+ int len;
+
+ len = strlen(name);
+ p = strchr(name, ':');
+ if (p != NULL)
+ len = p - name;
+
+ if (g_labels[i] != NULL && !IS_START(g_labels[i], "algn_"))
+ aerr("dupe label '%s' vs '%s'?\n", name, g_labels[i]);
+ g_labels[i] = realloc(g_labels[i], len + 1);
+ my_assert_not(g_labels[i], NULL);
+ memcpy(g_labels[i], name, len);
+ g_labels[i][len] = 0;
+}
+