+static void sprint_pp_short(const struct parsed_proto *pp, char *buf,
+ size_t buf_size)
+{
+ char *p = buf;
+ size_t l;
+ int i;
+
+ if (pp->ret_type.is_ptr)
+ *p++ = 'p';
+ else if (IS(pp->ret_type.name, "void"))
+ *p++ = 'v';
+ else
+ *p++ = 'i';
+ *p++ = '(';
+ l = 2;
+
+ for (i = 0; i < pp->argc; i++) {
+ if (pp->arg[i].reg != NULL)
+ snprintf(buf + l, buf_size - l, "%s%s",
+ i == 0 ? "" : ",", pp->arg[i].reg);
+ else
+ snprintf(buf + l, buf_size - l, "%sa%d",
+ i == 0 ? "" : ",", i + 1);
+ l = strlen(buf);
+ }
+ snprintf(buf + l, buf_size - l, ")");
+}
+
+static const struct parsed_proto *check_var(FILE *fhdr,
+ const char *sym, const char *varname)
+{
+ const struct parsed_proto *pp, *pp_sym;
+ char fp_sym[256], fp_var[256];
+ int i, bad = 0;
+
+ pp = proto_parse(fhdr, varname, 1);
+ if (pp == NULL) {
+ if (IS_START(varname, "sub_"))
+ awarn("sub_ sym missing proto: '%s'\n", varname);
+ return NULL;
+ }
+
+ if (!pp->is_func && !pp->is_fptr)
+ return NULL;
+
+ pp_print(fp_var, sizeof(fp_var), pp);
+
+ if (pp->argc_reg == 0)
+ goto check_sym;
+ if (pp->argc_reg == 1 && pp->argc_stack == 0
+ && IS(pp->arg[0].reg, "ecx"))
+ {
+ goto check_sym;
+ }
+ if (pp->argc_reg != 2
+ || !IS(pp->arg[0].reg, "ecx")
+ || !IS(pp->arg[1].reg, "edx"))
+ {
+ awarn("unhandled reg call: %s\n", fp_var);
+ }
+
+check_sym:
+ sprint_pp_short(pp, g_comment, sizeof(g_comment));
+
+ if (sym != NULL) {
+ g_func_sym_pp = NULL;
+ pp_sym = proto_parse(fhdr, sym, 1);
+ if (pp_sym == NULL)
+ return pp;
+ if (!pp_sym->is_fptr)
+ aerr("func ptr data, but label '%s' !is_fptr\n", pp_sym->name);
+ g_func_sym_pp = pp_sym;
+ }
+ else {
+ pp_sym = g_func_sym_pp;
+ if (pp_sym == NULL)
+ return pp;
+ }
+
+ if (pp->argc != pp_sym->argc || pp->argc_reg != pp_sym->argc_reg)
+ bad = 1;
+ else {
+ for (i = 0; i < pp->argc; i++) {
+ if ((pp->arg[i].reg != NULL) != (pp_sym->arg[i].reg != NULL)) {
+ bad = 1;
+ break;
+ }
+ if ((pp->arg[i].reg != NULL)
+ && !IS(pp->arg[i].reg, pp_sym->arg[i].reg))
+ {
+ bad = 1;
+ break;
+ }
+ }
+ }
+
+ if (bad) {
+ pp_print(fp_sym, sizeof(fp_sym), pp_sym);
+ anote("var: %s\n", fp_var);
+ anote("sym: %s\n", fp_sym);
+ awarn("^ mismatch\n");
+ }
+
+ return pp;
+}
+
+static void output_decorated_pp(FILE *fout,
+ const struct parsed_proto *pp)
+{
+ if (pp->name[0] != '_')
+ fprintf(fout, pp->is_fastcall ? "@" : "_");
+ fprintf(fout, "%s", pp->name);
+ if (pp->is_stdcall && pp->argc > 0)
+ fprintf(fout, "@%d", pp->argc * 4);
+}
+
+static int cmpstringp(const void *p1, const void *p2)
+{
+ return strcmp(*(char * const *)p1, *(char * const *)p2);
+}
+