-static const char *hdrfn;
-static int pline = 0;
-
-static int parse_protostr(char *protostr, char **reglist, int *cnt_out,
- int *is_stdcall)
-{
- char regparm[16];
- char buf[256];
- char cconv[32];
- int xarg = 0;
- int ret;
- char *p;
-
- p = protostr;
- if (p[0] == '/' && p[1] == '/') {
- //printf("warning: decl for sym '%s' is commented out\n", sym);
- p = sskip(p + 2);
- }
-
- ret = check_type(p);
- if (ret <= 0) {
- printf("%s:%d:%ld: unhandled return in '%s'\n",
- hdrfn, pline, (p - protostr) + 1, protostr);
- return 1;
- }
- p += ret;
- p = sskip(p);
-
- p = next_word(cconv, sizeof(cconv), p);
- p = sskip(p);
- if (cconv[0] == 0) {
- printf("%s:%d:%ld: cconv missing\n",
- hdrfn, pline, (p - protostr) + 1);
- return 1;
- }
- if (IS(cconv, "__cdecl"))
- *is_stdcall = 0;
- else if (IS(cconv, "__stdcall"))
- *is_stdcall = 1;
- else if (IS(cconv, "__fastcall"))
- *is_stdcall = 1;
- else if (IS(cconv, "__thiscall"))
- *is_stdcall = 1;
- else if (IS(cconv, "__userpurge"))
- *is_stdcall = 1; // in all cases seen..
- else if (IS(cconv, "__usercall"))
- *is_stdcall = 0; // ..or is it?
- else {
- printf("%s:%d:%ld: unhandled cconv: '%s'\n",
- hdrfn, pline, (p - protostr) + 1, cconv);
- return 1;
- }
-
- p = next_idt(buf, sizeof(buf), p);
- p = sskip(p);
- if (buf[0] == 0) {
- printf("%s:%d:%ld: func name missing\n",
- hdrfn, pline, (p - protostr) + 1);
- return 1;
- }
-
- ret = get_regparm(regparm, sizeof(regparm), p);
- if (ret > 0) {
- if (!IS(regparm, "eax") && !IS(regparm, "ax")
- && !IS(regparm, "al"))
- {
- printf("%s:%d:%ld: bad regparm: %s\n",
- hdrfn, pline, (p - protostr) + 1, regparm);
- return 1;
- }
- p += ret;
- p = sskip(p);
- }
-
- if (*p != '(') {
- printf("%s:%d:%ld: '(' expected, got '%c'\n",
- hdrfn, pline, (p - protostr) + 1, *p);
- return 1;
- }
- p++;
-
- while (1) {
- p = sskip(p);
- if (*p == ')')
- break;
- if (*p == ',')
- p = sskip(p + 1);
-
- xarg++;
-
- ret = check_type(p);
- if (ret <= 0) {
- printf("%s:%d:%ld: unhandled type for arg%d\n",
- hdrfn, pline, (p - protostr) + 1, xarg);
- return 1;
- }
- p += ret;
- p = sskip(p);
-
- p = next_idt(buf, sizeof(buf), p);
- p = sskip(p);
-#if 0
- if (buf[0] == 0) {
- printf("%s:%d:%ld: idt missing for arg%d\n",
- hdrfn, pline, (p - protostr) + 1, xarg);
- return 1;
- }
-#endif
- reglist[xarg - 1] = NULL;
-
- ret = get_regparm(regparm, sizeof(regparm), p);
- if (ret > 0) {
- p += ret;
- p = sskip(p);
-
- reglist[xarg - 1] = strdup(map_reg(regparm));
- }
- }
-
- if (xarg > 0 && (IS(cconv, "__fastcall") || IS(cconv, "__thiscall"))) {
- if (reglist[0] != NULL) {
- printf("%s:%d: %s with arg1 spec %s?\n",
- hdrfn, pline, cconv, reglist[0]);
- }
- reglist[0] = strdup("ecx");
- }
-
- if (xarg > 1 && IS(cconv, "__fastcall")) {
- if (reglist[1] != NULL) {
- printf("%s:%d: %s with arg2 spec %s?\n",
- hdrfn, pline, cconv, reglist[1]);
- }
- reglist[1] = strdup("edx");
- }
-
- *cnt_out = xarg;
-
- return 0;
-}