-static int parse_protostr(char *protostr, char **reglist, int *cnt_out,
- int *is_stdcall)
-{
- char regparm[16];
- char buf[256];
- 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(buf, sizeof(buf), p);
- p = sskip(p);
- if (buf[0] == 0) {
- printf("%s:%d:%ld: cconv missing\n",
- hdrfn, pline, (p - protostr) + 1);
- return 1;
- }
- if (strcmp(buf, "__cdecl") == 0)
- *is_stdcall = 0;
- else if (strcmp(buf, "__stdcall") == 0)
- *is_stdcall = 1;
- else if (strcmp(buf, "__userpurge") == 0)
- *is_stdcall = 1; // in all cases seen..
- else if (strcmp(buf, "__usercall") == 0)
- *is_stdcall = 0; // ..or is it?
- else {
- // TODO: __thiscall needs special handling (arg1~ecx)
- printf("%s:%d:%ld: unhandled cconv: '%s'\n",
- hdrfn, pline, (p - protostr) + 1, buf);
- 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 (strcmp(regparm, "eax") && strcmp(regparm, "ax")
- && strcmp(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(regparm);
- }
- }
-
- *cnt_out = xarg;
-
- return 0;
-}