{
register char *p;
int in_ident = 0;
- int just_spaced = 0;
- int need_space = 1;
+ char *ident_start;
+ int ident_length;
fprintf (out, "(fn");
for (p = buf; *p; p++)
{
- char c;
- int ident_start = 0;
+ char c = *p;
- /* FIXME: this must be made a bit more robust*/
-
- /* Skip "register Lisp_Object", this can be removed when we get
- rid of "register" for DEFUNs. */
- if (strncmp ("register Lisp_Object", p, 20) == 0)
- p += 20;
-
- if (strncmp ("Lisp_Object", p, 11) == 0)
- p += 11;
-
- if (strncmp ("void", p, 4) == 0)
- p += 4;
-
- c = *p;
-
- /* Notice when we start printing a new identifier. */
+ /* Notice when a new identifier starts. */
if ((('A' <= c && c <= 'Z')
|| ('a' <= c && c <= 'z')
|| ('0' <= c && c <= '9')
if (!in_ident)
{
in_ident = 1;
- ident_start = 1;
-
- if (need_space)
- putc (' ', out);
-
- if (minargs == 0 && maxargs > 0)
- fprintf (out, "&optional ");
- just_spaced = 1;
-
- minargs--;
- maxargs--;
+ ident_start = p;
}
else
- in_ident = 0;
+ {
+ in_ident = 0;
+ ident_length = p - ident_start;
+ }
}
- /* Print the C argument list as it would appear in lisp:
- print underscores as hyphens, and print commas and newlines
- as spaces. Collapse adjacent spaces into one. */
- if (c == '_')
- c = '-';
- else if (c == ',' || c == '\n')
- c = ' ';
-
- /* In C code, `default' is a reserved word, so we spell it
- `defalt'; unmangle that here. */
- if (ident_start
- && strncmp (p, "defalt", 6) == 0
- && ! (('A' <= p[6] && p[6] <= 'Z')
- || ('a' <= p[6] && p[6] <= 'z')
- || ('0' <= p[6] && p[6] <= '9')
- || p[6] == '_'))
- {
- fprintf (out, "DEFAULT");
- p += 5;
- in_ident = 0;
- just_spaced = 0;
- }
- else if (c != ' ' || !just_spaced)
+ /* Found the end of an argument, write out the last seen
+ identifier. */
+ if (c == ',' || c == ')')
{
- if (c >= 'a' && c <= 'z')
- /* Upcase the letter. */
- c += 'A' - 'a';
- putc (c, out);
- }
+ if (strncmp (ident_start, "void", ident_length) == 0)
+ continue;
+
+ putc (' ', out);
+
+ if (minargs == 0 && maxargs > 0)
+ fprintf (out, "&optional ");
- just_spaced = c == ' ';
- need_space = 0;
+ minargs--;
+ maxargs--;
+
+ /* In C code, `default' is a reserved word, so we spell it
+ `defalt'; unmangle that here. */
+ if (strncmp (ident_start, "defalt", ident_length) == 0)
+ fprintf (out, "DEFAULT");
+ else
+ while (ident_length-- > 0)
+ {
+ c = *ident_start++;
+ if (c >= 'a' && c <= 'z')
+ /* Upcase the letter. */
+ c += 'A' - 'a';
+ else if (c == '_')
+ /* Print underscore as hyphen. */
+ c = '-';
+ putc (c, out);
+ }
+ }
}
+
+ putc (')', out);
}
\f
/* Read through a c file. If a .o file is named,