-static int find_protostr(char *dst, size_t dlen, FILE *fhdr,
- const char *sym, int *pline)
-{
- int line = 0;
- char *p;
-
- rewind(fhdr);
-
- while (fgets(dst, dlen, fhdr))
- {
- line++;
- if (strstr(dst, sym) != NULL)
- break;
- }
- *pline = line;
-
- if (feof(fhdr))
- return -1;
-
- p = dst + strlen(dst);
- for (p--; p > dst && my_isblank(*p); --p)
- *p = 0;
-
- return 0;
-}
-
-static int get_regparm(char *dst, size_t dlen, char *p)
-{
- int i, o;
-
- if (*p != '<')
- return 0;
-
- for (o = 0, i = 1; o < dlen; i++) {
- if (p[i] == 0)
- return 0;
- if (p[i] == '>')
- break;
- dst[o++] = p[i];
- }
- dst[o] = 0;
- return i + 1;
-}
-
-// hmh..
-static const char *known_types[] = {
- "char",
- "unsigned __int8",
- "int",
- "signed int",
- "unsigned int",
- "void",
- "BYTE",
- "WORD",
- "DWORD",
- "HMODULE",
- "HANDLE",
- "HWND",
- "LPCSTR",
- "size_t",
- "void *",
- "const void *",
- "FILE *",
-};
-
-static int check_type(const char *name)
-{
- int i, l;
-
- for (i = 0; i < ARRAY_SIZE(known_types); i++) {
- l = strlen(known_types[i]);
- if (strncmp(known_types[i], name, l) == 0)
- return l;
- }
-
- return 0;
-}
-
-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];
- 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;