diff options
Diffstat (limited to 'lib-src/make-docfile.c')
-rw-r--r-- | lib-src/make-docfile.c | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 212f73e10b1..4d25b0a6b93 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -43,6 +43,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include <string.h> #include <binary-io.h> +#include <c-ctype.h> #include <intprops.h> #include <min-max.h> #include <unlocked-io.h> @@ -122,7 +123,7 @@ memory_exhausted (void) /* Like malloc but get fatal error if memory is exhausted. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (ptrdiff_t size) { void *result = malloc (size); @@ -341,7 +342,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state) state->pending_newlines = 2; state->pending_spaces = 0; - /* Skip any whitespace between the keyword and the + /* Skip any spaces and newlines between the keyword and the usage string. */ int c; do @@ -361,6 +362,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state) fatal ("Unexpected EOF after keyword"); } while (c != ' ' && c != ')'); + put_char ('f', state); put_char ('n', state); @@ -415,7 +417,7 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment, c = getc (infile); if (comment) - while (c == '\n' || c == '\r' || c == '\t' || c == ' ') + while (c_isspace (c)) c = getc (infile); while (c != EOF) @@ -425,15 +427,14 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment, if (c == '\\') { c = getc (infile); - if (c == '\n' || c == '\r') + switch (c) { + case '\n': case '\r': c = getc (infile); continue; + case 'n': c = '\n'; break; + case 't': c = '\t'; break; } - if (c == 'n') - c = '\n'; - if (c == 't') - c = '\t'; } if (c == ' ') @@ -504,10 +505,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) char c = *p; /* Notice when a new identifier starts. */ - if ((('A' <= c && c <= 'Z') - || ('a' <= c && c <= 'z') - || ('0' <= c && c <= '9') - || c == '_') + if ((c_isalnum (c) || c == '_') != in_ident) { if (!in_ident) @@ -550,11 +548,8 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) else while (ident_length-- > 0) { - c = *ident_start++; - if (c >= 'a' && c <= 'z') - /* Upcase the letter. */ - c += 'A' - 'a'; - else if (c == '_') + c = c_toupper (*ident_start++); + if (c == '_') /* Print underscore as hyphen. */ c = '-'; putchar (c); @@ -705,7 +700,7 @@ write_globals (void) switch (globals[i].type) { case EMACS_INTEGER: - type = "EMACS_INT"; + type = "intmax_t"; break; case BOOLEAN: type = "bool"; @@ -752,6 +747,8 @@ write_globals (void) printf ("%d", globals[i].v.value); putchar (')'); + if (globals[i].flags & DEFUN_noreturn) + fputs (" ATTRIBUTE_COLD", stdout); if (globals[i].flags & DEFUN_const) fputs (" ATTRIBUTE_CONST", stdout); @@ -960,7 +957,7 @@ scan_c_stream (FILE *infile) { c = getc (infile); } - while (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r'); + while (c == ',' || c_isspace (c)); /* Read in the identifier. */ do @@ -972,8 +969,8 @@ scan_c_stream (FILE *infile) fatal ("identifier too long"); c = getc (infile); } - while (! (c == ',' || c == ' ' || c == '\t' - || c == '\n' || c == '\r')); + while (! (c == ',' || c_isspace (c))); + input_buffer[i] = '\0'; memcpy (name, input_buffer, i + 1); @@ -981,7 +978,8 @@ scan_c_stream (FILE *infile) { do c = getc (infile); - while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + while (c_isspace (c)); + if (c != '"') continue; c = read_c_string_or_comment (infile, -1, false, 0); @@ -1022,7 +1020,8 @@ scan_c_stream (FILE *infile) int scanned = 0; do c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); + while (c_isspace (c)); + if (c < 0) goto eof; ungetc (c, infile); @@ -1072,7 +1071,7 @@ scan_c_stream (FILE *infile) int d = getc (infile); if (d == EOF) goto eof; - while (1) + while (true) { if (c == '*' && d == '/') break; @@ -1087,13 +1086,14 @@ scan_c_stream (FILE *infile) if (c == EOF) goto eof; } - while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); + while (c_isspace (c)); + /* Check for 'attributes:' token. */ if (c == 'a' && stream_match (infile, "ttributes:")) { char *p = input_buffer; /* Collect attributes up to ')'. */ - while (1) + while (true) { c = getc (infile); if (c == EOF) @@ -1109,13 +1109,16 @@ scan_c_stream (FILE *infile) g->flags |= DEFUN_noreturn; if (strstr (input_buffer, "const")) g->flags |= DEFUN_const; + + /* Although the noinline attribute is no longer used, + leave its support in, in case it's needed later. */ if (strstr (input_buffer, "noinline")) g->flags |= DEFUN_noinline; } continue; } - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + while (c_isspace (c)) c = getc (infile); if (c == '"') @@ -1125,17 +1128,18 @@ scan_c_stream (FILE *infile) c = getc (infile); if (c == ',') { - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + do c = getc (infile); - while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z')) + while (c_isspace (c)); + + while (c_isalpha (c)) c = getc (infile); if (c == ':') { doc_keyword = true; - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + do c = getc (infile); + while (c_isspace (c)); } } @@ -1186,8 +1190,14 @@ scan_c_stream (FILE *infile) /* Copy arguments into ARGBUF. */ *p++ = c; do - *p++ = c = getc (infile); + { + c = getc (infile); + if (c < 0) + goto eof; + *p++ = c; + } while (c != ')'); + *p = '\0'; /* Output them. */ fputs ("\n\n", stdout); @@ -1243,25 +1253,32 @@ scan_c_stream (FILE *infile) static void skip_white (FILE *infile) { - char c = ' '; - while (c == ' ' || c == '\t' || c == '\n' || c == '\r') + int c; + do c = getc (infile); + while (c_isspace (c)); + ungetc (c, infile); } static void read_lisp_symbol (FILE *infile, char *buffer) { - char c; + int c; char *fillp = buffer; skip_white (infile); - while (1) + while (true) { c = getc (infile); if (c == '\\') - *(++fillp) = getc (infile); - else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')') + { + c = getc (infile); + if (c < 0) + return; + *fillp++ = c; + } + else if (c_isspace (c) || c == '(' || c == ')' || c < 0) { ungetc (c, infile); *fillp = 0; @@ -1381,7 +1398,7 @@ scan_lisp_file (const char *filename, const char *mode) /* Read the length. */ while ((c = getc (infile), - c >= '0' && c <= '9')) + c_isdigit (c))) { if (INT_MULTIPLY_WRAPV (length, 10, &length) || INT_ADD_WRAPV (length, c - '0', &length) @@ -1413,7 +1430,7 @@ scan_lisp_file (const char *filename, const char *mode) while (c == '\n' || c == '\r') c = getc (infile); /* Skip the following line. */ - while (c != '\n' && c != '\r') + while (! (c == '\n' || c == '\r' || c < 0)) c = getc (infile); } continue; @@ -1451,7 +1468,7 @@ scan_lisp_file (const char *filename, const char *mode) continue; } else - while (c != ')') + while (! (c == ')' || c < 0)) c = getc (infile); skip_white (infile); @@ -1595,7 +1612,8 @@ scan_lisp_file (const char *filename, const char *mode) } } skip_white (infile); - if ((c = getc (infile)) != '\"') + c = getc (infile); + if (c != '\"') { fprintf (stderr, "## autoload of %s unparsable (%s)\n", buffer, filename); |