From 91a7f76db4acfe760e667c61faad83e1125d659f Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Fri, 9 Jul 2010 19:00:04 +0200 Subject: [PATCH] * make-docfile.c (write_c_args): Restructure scanning loop. --- lib-src/ChangeLog | 4 ++ lib-src/make-docfile.c | 103 ++++++++++++++++++++----------------------------- 2 files changed, 45 insertions(+), 62 deletions(-) diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 4cbf5dd50f1..9477811fe3c 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,7 @@ +2010-07-09 Andreas Schwab + + * make-docfile.c (write_c_args): Restructure scanning loop. + 2010-07-09 Dan Nicolaescu * make-docfile.c (write_c_args): Deal with type names in DEFUN diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 3df7ec607d9..51c30f91d8f 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -440,8 +440,8 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs) { register char *p; int in_ident = 0; - int just_spaced = 0; - int need_space = 1; + char *ident_start; + int ident_length; fprintf (out, "(fn"); @@ -450,25 +450,9 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs) 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') @@ -478,55 +462,50 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs) 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); } /* Read through a c file. If a .o file is named, -- 2.11.4.GIT