diff options
| author | Paul Eggert | 2016-02-10 11:40:09 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-02-10 11:41:10 -0800 |
| commit | 456c0a3137bf58ee61a8e442cff0ca5d808e8d32 (patch) | |
| tree | 398587e97c202c638ce360e5bba1ba636955e097 /lib-src | |
| parent | 25ec995c064d4e658fe3f9af084f120ae21a021a (diff) | |
| download | emacs-456c0a3137bf58ee61a8e442cff0ca5d808e8d32.tar.gz emacs-456c0a3137bf58ee61a8e442cff0ca5d808e8d32.zip | |
make-docfile cleanup for I/O, etc.
* lib-src/make-docfile.c (progname, generate_globals, num_globals)
(num_globals_allocated, globals): Now static.
(generate_globals, struct rcsoc_state, read_c_string_or_comment):
(write_c_args, scan_c_stream, search_lisp_doc_at_eol, scan_lisp_file):
Use bool for boolean.
(verror): New function.
(fatal, error): Use it. API is now like printf. All callers changed.
(main): Remove err_count local that was always 0.
(main, scan_c_stream, scan_lisp_file): Check for I/O error.
(scan_file, scan_c_file, scan_c_stream, scan_lisp_file):
Return void, not 0.
(put_char, scan_keyword_or_put_char, scan_c_file): Use char for byte.
(scan_keyword_or_put_char): Check for missing ( and unexpected EOF.
(close_emacs_globals): Use ptrdiff_t for index, not int.
(scan_c_file, scan_lisp_file): Exit with failure if file cannot be
opened, rather than diagnosing but exiting with status 0.
(search_lisp_doc_at_eol): Don't worry about ungetc of EOF; it's
portable now.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/make-docfile.c | 200 |
1 files changed, 110 insertions, 90 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 4ab3729bad0..12222c3db3c 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c | |||
| @@ -65,46 +65,58 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 65 | #define IS_SLASH(c) ((c) == '/') | 65 | #define IS_SLASH(c) ((c) == '/') |
| 66 | #endif /* not DOS_NT */ | 66 | #endif /* not DOS_NT */ |
| 67 | 67 | ||
| 68 | static int scan_file (char *filename); | 68 | static void scan_file (char *filename); |
| 69 | static int scan_lisp_file (const char *filename, const char *mode); | 69 | static void scan_lisp_file (const char *filename, const char *mode); |
| 70 | static int scan_c_file (char *filename, const char *mode); | 70 | static void scan_c_file (char *filename, const char *mode); |
| 71 | static int scan_c_stream (FILE *infile); | 71 | static void scan_c_stream (FILE *infile); |
| 72 | static void start_globals (void); | 72 | static void start_globals (void); |
| 73 | static void write_globals (void); | 73 | static void write_globals (void); |
| 74 | 74 | ||
| 75 | #include <unistd.h> | 75 | #include <unistd.h> |
| 76 | 76 | ||
| 77 | /* Name this program was invoked with. */ | 77 | /* Name this program was invoked with. */ |
| 78 | char *progname; | 78 | static char *progname; |
| 79 | 79 | ||
| 80 | /* Nonzero if this invocation is generating globals.h. */ | 80 | /* True if this invocation is generating globals.h. */ |
| 81 | int generate_globals; | 81 | static bool generate_globals; |
| 82 | 82 | ||
| 83 | /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | 83 | /* Print error message. Args are like vprintf. */ |
| 84 | 84 | ||
| 85 | /* VARARGS1 */ | 85 | static void ATTRIBUTE_FORMAT_PRINTF (1, 0) |
| 86 | static void | 86 | verror (char const *m, va_list ap) |
| 87 | error (const char *s1, const char *s2) | ||
| 88 | { | 87 | { |
| 89 | fprintf (stderr, "%s: ", progname); | 88 | fprintf (stderr, "%s: ", progname); |
| 90 | fprintf (stderr, s1, s2); | 89 | vfprintf (stderr, m, ap); |
| 91 | fprintf (stderr, "\n"); | 90 | fprintf (stderr, "\n"); |
| 92 | } | 91 | } |
| 93 | 92 | ||
| 94 | /* Print error message and exit. */ | 93 | /* Print error message. Args are like printf. */ |
| 95 | 94 | ||
| 96 | /* VARARGS1 */ | 95 | static void ATTRIBUTE_FORMAT_PRINTF (1, 2) |
| 97 | static _Noreturn void | 96 | error (char const *m, ...) |
| 98 | fatal (const char *s1, const char *s2) | 97 | { |
| 98 | va_list ap; | ||
| 99 | va_start (ap, m); | ||
| 100 | verror (m, ap); | ||
| 101 | va_end (ap); | ||
| 102 | } | ||
| 103 | |||
| 104 | /* Print error message and exit. Args are like printf. */ | ||
| 105 | |||
| 106 | static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (1, 2) | ||
| 107 | fatal (char const *m, ...) | ||
| 99 | { | 108 | { |
| 100 | error (s1, s2); | 109 | va_list ap; |
| 110 | va_start (ap, m); | ||
| 111 | verror (m, ap); | ||
| 112 | va_end (ap); | ||
| 101 | exit (EXIT_FAILURE); | 113 | exit (EXIT_FAILURE); |
| 102 | } | 114 | } |
| 103 | 115 | ||
| 104 | static _Noreturn void | 116 | static _Noreturn void |
| 105 | memory_exhausted (void) | 117 | memory_exhausted (void) |
| 106 | { | 118 | { |
| 107 | fatal ("virtual memory exhausted", 0); | 119 | fatal ("virtual memory exhausted"); |
| 108 | } | 120 | } |
| 109 | 121 | ||
| 110 | /* Like malloc but get fatal error if memory is exhausted. */ | 122 | /* Like malloc but get fatal error if memory is exhausted. */ |
| @@ -134,7 +146,6 @@ int | |||
| 134 | main (int argc, char **argv) | 146 | main (int argc, char **argv) |
| 135 | { | 147 | { |
| 136 | int i; | 148 | int i; |
| 137 | int err_count = 0; | ||
| 138 | 149 | ||
| 139 | progname = argv[0]; | 150 | progname = argv[0]; |
| 140 | 151 | ||
| @@ -169,7 +180,7 @@ main (int argc, char **argv) | |||
| 169 | } | 180 | } |
| 170 | if (argc > i && !strcmp (argv[i], "-g")) | 181 | if (argc > i && !strcmp (argv[i], "-g")) |
| 171 | { | 182 | { |
| 172 | generate_globals = 1; | 183 | generate_globals = true; |
| 173 | ++i; | 184 | ++i; |
| 174 | } | 185 | } |
| 175 | 186 | ||
| @@ -191,14 +202,17 @@ main (int argc, char **argv) | |||
| 191 | if (strcmp (argv[i], argv[j]) == 0) | 202 | if (strcmp (argv[i], argv[j]) == 0) |
| 192 | break; | 203 | break; |
| 193 | if (j == i) | 204 | if (j == i) |
| 194 | err_count += scan_file (argv[i]); | 205 | scan_file (argv[i]); |
| 195 | } | 206 | } |
| 196 | } | 207 | } |
| 197 | 208 | ||
| 198 | if (err_count == 0 && generate_globals) | 209 | if (generate_globals) |
| 199 | write_globals (); | 210 | write_globals (); |
| 200 | 211 | ||
| 201 | return (err_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); | 212 | if (ferror (stdout) || fclose (stdout) != 0) |
| 213 | fatal ("write error"); | ||
| 214 | |||
| 215 | return EXIT_SUCCESS; | ||
| 202 | } | 216 | } |
| 203 | 217 | ||
| 204 | /* Add a source file name boundary marker in the output file. */ | 218 | /* Add a source file name boundary marker in the output file. */ |
| @@ -217,9 +231,9 @@ put_filename (char *filename) | |||
| 217 | } | 231 | } |
| 218 | 232 | ||
| 219 | /* Read file FILENAME and output its doc strings to stdout. | 233 | /* Read file FILENAME and output its doc strings to stdout. |
| 220 | Return 1 if file is not found, 0 if it is found. */ | 234 | Return true if file is found, false otherwise. */ |
| 221 | 235 | ||
| 222 | static int | 236 | static void |
| 223 | scan_file (char *filename) | 237 | scan_file (char *filename) |
| 224 | { | 238 | { |
| 225 | ptrdiff_t len = strlen (filename); | 239 | ptrdiff_t len = strlen (filename); |
| @@ -227,11 +241,11 @@ scan_file (char *filename) | |||
| 227 | if (!generate_globals) | 241 | if (!generate_globals) |
| 228 | put_filename (filename); | 242 | put_filename (filename); |
| 229 | if (len > 4 && !strcmp (filename + len - 4, ".elc")) | 243 | if (len > 4 && !strcmp (filename + len - 4, ".elc")) |
| 230 | return scan_lisp_file (filename, "rb"); | 244 | scan_lisp_file (filename, "rb"); |
| 231 | else if (len > 3 && !strcmp (filename + len - 3, ".el")) | 245 | else if (len > 3 && !strcmp (filename + len - 3, ".el")) |
| 232 | return scan_lisp_file (filename, "r"); | 246 | scan_lisp_file (filename, "r"); |
| 233 | else | 247 | else |
| 234 | return scan_c_file (filename, "r"); | 248 | scan_c_file (filename, "r"); |
| 235 | } | 249 | } |
| 236 | 250 | ||
| 237 | static void | 251 | static void |
| @@ -265,16 +279,16 @@ struct rcsoc_state | |||
| 265 | the input stream. */ | 279 | the input stream. */ |
| 266 | const char *cur_keyword_ptr; | 280 | const char *cur_keyword_ptr; |
| 267 | /* Set to true if we saw an occurrence of KEYWORD. */ | 281 | /* Set to true if we saw an occurrence of KEYWORD. */ |
| 268 | int saw_keyword; | 282 | bool saw_keyword; |
| 269 | }; | 283 | }; |
| 270 | 284 | ||
| 271 | /* Output CH to the file or buffer in STATE. Any pending newlines or | 285 | /* Output CH to the file or buffer in STATE. Any pending newlines or |
| 272 | spaces are output first. */ | 286 | spaces are output first. */ |
| 273 | 287 | ||
| 274 | static void | 288 | static void |
| 275 | put_char (int ch, struct rcsoc_state *state) | 289 | put_char (char ch, struct rcsoc_state *state) |
| 276 | { | 290 | { |
| 277 | int out_ch; | 291 | char out_ch; |
| 278 | do | 292 | do |
| 279 | { | 293 | { |
| 280 | if (state->pending_newlines > 0) | 294 | if (state->pending_newlines > 0) |
| @@ -305,7 +319,7 @@ put_char (int ch, struct rcsoc_state *state) | |||
| 305 | keyword, but were in fact not. */ | 319 | keyword, but were in fact not. */ |
| 306 | 320 | ||
| 307 | static void | 321 | static void |
| 308 | scan_keyword_or_put_char (int ch, struct rcsoc_state *state) | 322 | scan_keyword_or_put_char (char ch, struct rcsoc_state *state) |
| 309 | { | 323 | { |
| 310 | if (state->keyword | 324 | if (state->keyword |
| 311 | && *state->cur_keyword_ptr == ch | 325 | && *state->cur_keyword_ptr == ch |
| @@ -317,7 +331,7 @@ scan_keyword_or_put_char (int ch, struct rcsoc_state *state) | |||
| 317 | if (*++state->cur_keyword_ptr == '\0') | 331 | if (*++state->cur_keyword_ptr == '\0') |
| 318 | /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */ | 332 | /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */ |
| 319 | { | 333 | { |
| 320 | state->saw_keyword = 1; | 334 | state->saw_keyword = true; |
| 321 | 335 | ||
| 322 | /* Reset the scanning pointer. */ | 336 | /* Reset the scanning pointer. */ |
| 323 | state->cur_keyword_ptr = state->keyword; | 337 | state->cur_keyword_ptr = state->keyword; |
| @@ -328,22 +342,29 @@ scan_keyword_or_put_char (int ch, struct rcsoc_state *state) | |||
| 328 | 342 | ||
| 329 | /* Skip any whitespace between the keyword and the | 343 | /* Skip any whitespace between the keyword and the |
| 330 | usage string. */ | 344 | usage string. */ |
| 345 | int c; | ||
| 331 | do | 346 | do |
| 332 | ch = getc (state->in_file); | 347 | c = getc (state->in_file); |
| 333 | while (ch == ' ' || ch == '\n'); | 348 | while (c == ' ' || c == '\n'); |
| 334 | 349 | ||
| 335 | /* Output the open-paren we just read. */ | 350 | /* Output the open-paren we just read. */ |
| 336 | put_char (ch, state); | 351 | if (c != '(') |
| 352 | fatal ("Missing '(' after keyword"); | ||
| 353 | put_char (c, state); | ||
| 337 | 354 | ||
| 338 | /* Skip the function name and replace it with `fn'. */ | 355 | /* Skip the function name and replace it with `fn'. */ |
| 339 | do | 356 | do |
| 340 | ch = getc (state->in_file); | 357 | { |
| 341 | while (ch != ' ' && ch != ')'); | 358 | c = getc (state->in_file); |
| 359 | if (c == EOF) | ||
| 360 | fatal ("Unexpected EOF after keyword"); | ||
| 361 | } | ||
| 362 | while (c != ' ' && c != ')'); | ||
| 342 | put_char ('f', state); | 363 | put_char ('f', state); |
| 343 | put_char ('n', state); | 364 | put_char ('n', state); |
| 344 | 365 | ||
| 345 | /* Put back the last character. */ | 366 | /* Put back the last character. */ |
| 346 | ungetc (ch, state->in_file); | 367 | ungetc (c, state->in_file); |
| 347 | } | 368 | } |
| 348 | } | 369 | } |
| 349 | else | 370 | else |
| @@ -367,18 +388,19 @@ scan_keyword_or_put_char (int ch, struct rcsoc_state *state) | |||
| 367 | 388 | ||
| 368 | 389 | ||
| 369 | /* Skip a C string or C-style comment from INFILE, and return the | 390 | /* Skip a C string or C-style comment from INFILE, and return the |
| 370 | character that follows. COMMENT non-zero means skip a comment. If | 391 | byte that follows, or EOF. COMMENT means skip a comment. If |
| 371 | PRINTFLAG is positive, output string contents to stdout. If it is | 392 | PRINTFLAG is positive, output string contents to stdout. If it is |
| 372 | negative, store contents in buf. Convert escape sequences \n and | 393 | negative, store contents in buf. Convert escape sequences \n and |
| 373 | \t to newline and tab; discard \ followed by newline. | 394 | \t to newline and tab; discard \ followed by newline. |
| 374 | If SAW_USAGE is non-zero, then any occurrences of the string `usage:' | 395 | If SAW_USAGE is non-null, then any occurrences of the string "usage:" |
| 375 | at the beginning of a line will be removed, and *SAW_USAGE set to | 396 | at the beginning of a line will be removed, and *SAW_USAGE set to |
| 376 | true if any were encountered. */ | 397 | true if any were encountered. */ |
| 377 | 398 | ||
| 378 | static int | 399 | static int |
| 379 | read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usage) | 400 | read_c_string_or_comment (FILE *infile, int printflag, bool comment, |
| 401 | bool *saw_usage) | ||
| 380 | { | 402 | { |
| 381 | register int c; | 403 | int c; |
| 382 | struct rcsoc_state state; | 404 | struct rcsoc_state state; |
| 383 | 405 | ||
| 384 | state.in_file = infile; | 406 | state.in_file = infile; |
| @@ -388,7 +410,7 @@ read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usa | |||
| 388 | state.pending_newlines = 0; | 410 | state.pending_newlines = 0; |
| 389 | state.keyword = (saw_usage ? "usage:" : 0); | 411 | state.keyword = (saw_usage ? "usage:" : 0); |
| 390 | state.cur_keyword_ptr = state.keyword; | 412 | state.cur_keyword_ptr = state.keyword; |
| 391 | state.saw_keyword = 0; | 413 | state.saw_keyword = false; |
| 392 | 414 | ||
| 393 | c = getc (infile); | 415 | c = getc (infile); |
| 394 | if (comment) | 416 | if (comment) |
| @@ -467,7 +489,7 @@ static void | |||
| 467 | write_c_args (char *func, char *buf, int minargs, int maxargs) | 489 | write_c_args (char *func, char *buf, int minargs, int maxargs) |
| 468 | { | 490 | { |
| 469 | char *p; | 491 | char *p; |
| 470 | int in_ident = 0; | 492 | bool in_ident = false; |
| 471 | char *ident_start IF_LINT (= NULL); | 493 | char *ident_start IF_LINT (= NULL); |
| 472 | ptrdiff_t ident_length = 0; | 494 | ptrdiff_t ident_length = 0; |
| 473 | 495 | ||
| @@ -489,12 +511,12 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) | |||
| 489 | { | 511 | { |
| 490 | if (!in_ident) | 512 | if (!in_ident) |
| 491 | { | 513 | { |
| 492 | in_ident = 1; | 514 | in_ident = true; |
| 493 | ident_start = p; | 515 | ident_start = p; |
| 494 | } | 516 | } |
| 495 | else | 517 | else |
| 496 | { | 518 | { |
| 497 | in_ident = 0; | 519 | in_ident = false; |
| 498 | ident_length = p - ident_start; | 520 | ident_length = p - ident_start; |
| 499 | } | 521 | } |
| 500 | } | 522 | } |
| @@ -573,9 +595,9 @@ enum { DEFUN_noreturn = 1, DEFUN_const = 2 }; | |||
| 573 | 595 | ||
| 574 | /* All the variable names we saw while scanning C sources in `-g' | 596 | /* All the variable names we saw while scanning C sources in `-g' |
| 575 | mode. */ | 597 | mode. */ |
| 576 | ptrdiff_t num_globals; | 598 | static ptrdiff_t num_globals; |
| 577 | ptrdiff_t num_globals_allocated; | 599 | static ptrdiff_t num_globals_allocated; |
| 578 | struct global *globals; | 600 | static struct global *globals; |
| 579 | 601 | ||
| 580 | static struct global * | 602 | static struct global * |
| 581 | add_global (enum global_type type, char const *name, int value, | 603 | add_global (enum global_type type, char const *name, int value, |
| @@ -636,7 +658,7 @@ compare_globals (const void *a, const void *b) | |||
| 636 | } | 658 | } |
| 637 | 659 | ||
| 638 | static void | 660 | static void |
| 639 | close_emacs_globals (int num_symbols) | 661 | close_emacs_globals (ptrdiff_t num_symbols) |
| 640 | { | 662 | { |
| 641 | printf (("};\n" | 663 | printf (("};\n" |
| 642 | "extern struct emacs_globals globals;\n" | 664 | "extern struct emacs_globals globals;\n" |
| @@ -644,7 +666,7 @@ close_emacs_globals (int num_symbols) | |||
| 644 | "#ifndef DEFINE_SYMBOLS\n" | 666 | "#ifndef DEFINE_SYMBOLS\n" |
| 645 | "extern\n" | 667 | "extern\n" |
| 646 | "#endif\n" | 668 | "#endif\n" |
| 647 | "struct Lisp_Symbol alignas (GCALIGNMENT) lispsym[%d];\n"), | 669 | "struct Lisp_Symbol alignas (GCALIGNMENT) lispsym[%td];\n"), |
| 648 | num_symbols); | 670 | num_symbols); |
| 649 | } | 671 | } |
| 650 | 672 | ||
| @@ -700,7 +722,7 @@ write_globals (void) | |||
| 700 | } | 722 | } |
| 701 | break; | 723 | break; |
| 702 | default: | 724 | default: |
| 703 | fatal ("not a recognized DEFVAR_", 0); | 725 | fatal ("not a recognized DEFVAR_"); |
| 704 | } | 726 | } |
| 705 | 727 | ||
| 706 | if (type) | 728 | if (type) |
| @@ -761,11 +783,11 @@ write_globals (void) | |||
| 761 | Looks for DEFUN constructs such as are defined in ../src/lisp.h. | 783 | Looks for DEFUN constructs such as are defined in ../src/lisp.h. |
| 762 | Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ | 784 | Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ |
| 763 | 785 | ||
| 764 | static int | 786 | static void |
| 765 | scan_c_file (char *filename, const char *mode) | 787 | scan_c_file (char *filename, const char *mode) |
| 766 | { | 788 | { |
| 767 | FILE *infile; | 789 | FILE *infile; |
| 768 | int extension = filename[strlen (filename) - 1]; | 790 | char extension = filename[strlen (filename) - 1]; |
| 769 | 791 | ||
| 770 | if (extension == 'o') | 792 | if (extension == 'o') |
| 771 | filename[strlen (filename) - 1] = 'c'; | 793 | filename[strlen (filename) - 1] = 'c'; |
| @@ -781,16 +803,15 @@ scan_c_file (char *filename, const char *mode) | |||
| 781 | filename[strlen (filename) - 1] = 'c'; /* Don't confuse people. */ | 803 | filename[strlen (filename) - 1] = 'c'; /* Don't confuse people. */ |
| 782 | } | 804 | } |
| 783 | 805 | ||
| 784 | /* No error if non-ex input file. */ | ||
| 785 | if (infile == NULL) | 806 | if (infile == NULL) |
| 786 | { | 807 | { |
| 787 | perror (filename); | 808 | perror (filename); |
| 788 | return 0; | 809 | exit (EXIT_FAILURE); |
| 789 | } | 810 | } |
| 790 | 811 | ||
| 791 | /* Reset extension to be able to detect duplicate files. */ | 812 | /* Reset extension to be able to detect duplicate files. */ |
| 792 | filename[strlen (filename) - 1] = extension; | 813 | filename[strlen (filename) - 1] = extension; |
| 793 | return scan_c_stream (infile); | 814 | scan_c_stream (infile); |
| 794 | } | 815 | } |
| 795 | 816 | ||
| 796 | /* Return 1 if next input from INFILE is equal to P, -1 if EOF, | 817 | /* Return 1 if next input from INFILE is equal to P, -1 if EOF, |
| @@ -810,7 +831,7 @@ stream_match (FILE *infile, const char *p) | |||
| 810 | return 1; | 831 | return 1; |
| 811 | } | 832 | } |
| 812 | 833 | ||
| 813 | static int | 834 | static void |
| 814 | scan_c_stream (FILE *infile) | 835 | scan_c_stream (FILE *infile) |
| 815 | { | 836 | { |
| 816 | int commas, minargs, maxargs; | 837 | int commas, minargs, maxargs; |
| @@ -818,10 +839,10 @@ scan_c_stream (FILE *infile) | |||
| 818 | 839 | ||
| 819 | while (!feof (infile)) | 840 | while (!feof (infile)) |
| 820 | { | 841 | { |
| 821 | int doc_keyword = 0; | 842 | bool doc_keyword = false; |
| 822 | int defunflag = 0; | 843 | bool defunflag = false; |
| 823 | int defvarperbufferflag = 0; | 844 | bool defvarperbufferflag = false; |
| 824 | int defvarflag = 0; | 845 | bool defvarflag = false; |
| 825 | enum global_type type = INVALID; | 846 | enum global_type type = INVALID; |
| 826 | static char *name; | 847 | static char *name; |
| 827 | static ptrdiff_t name_size; | 848 | static ptrdiff_t name_size; |
| @@ -870,7 +891,7 @@ scan_c_stream (FILE *infile) | |||
| 870 | if (c != '_') | 891 | if (c != '_') |
| 871 | continue; | 892 | continue; |
| 872 | 893 | ||
| 873 | defvarflag = 1; | 894 | defvarflag = true; |
| 874 | 895 | ||
| 875 | c = getc (infile); | 896 | c = getc (infile); |
| 876 | defvarperbufferflag = (c == 'P'); | 897 | defvarperbufferflag = (c == 'P'); |
| @@ -924,7 +945,7 @@ scan_c_stream (FILE *infile) | |||
| 924 | c = getc (infile); | 945 | c = getc (infile); |
| 925 | if (c != '"') | 946 | if (c != '"') |
| 926 | continue; | 947 | continue; |
| 927 | c = read_c_string_or_comment (infile, -1, 0, 0); | 948 | c = read_c_string_or_comment (infile, -1, false, 0); |
| 928 | } | 949 | } |
| 929 | 950 | ||
| 930 | if (generate_globals) | 951 | if (generate_globals) |
| @@ -970,7 +991,7 @@ scan_c_stream (FILE *infile) | |||
| 970 | while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); | 991 | while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); |
| 971 | if (c != '"') | 992 | if (c != '"') |
| 972 | continue; | 993 | continue; |
| 973 | c = read_c_string_or_comment (infile, -1, 0, 0); | 994 | c = read_c_string_or_comment (infile, -1, false, 0); |
| 974 | svalue = input_buffer; | 995 | svalue = input_buffer; |
| 975 | } | 996 | } |
| 976 | 997 | ||
| @@ -1102,7 +1123,7 @@ scan_c_stream (FILE *infile) | |||
| 1102 | c = getc (infile); | 1123 | c = getc (infile); |
| 1103 | 1124 | ||
| 1104 | if (c == '"') | 1125 | if (c == '"') |
| 1105 | c = read_c_string_or_comment (infile, 0, 0, 0); | 1126 | c = read_c_string_or_comment (infile, 0, false, 0); |
| 1106 | 1127 | ||
| 1107 | while (c != EOF && c != ',' && c != '/') | 1128 | while (c != EOF && c != ',' && c != '/') |
| 1108 | c = getc (infile); | 1129 | c = getc (infile); |
| @@ -1115,7 +1136,7 @@ scan_c_stream (FILE *infile) | |||
| 1115 | c = getc (infile); | 1136 | c = getc (infile); |
| 1116 | if (c == ':') | 1137 | if (c == ':') |
| 1117 | { | 1138 | { |
| 1118 | doc_keyword = 1; | 1139 | doc_keyword = true; |
| 1119 | c = getc (infile); | 1140 | c = getc (infile); |
| 1120 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t') | 1141 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t') |
| 1121 | c = getc (infile); | 1142 | c = getc (infile); |
| @@ -1128,8 +1149,8 @@ scan_c_stream (FILE *infile) | |||
| 1128 | ungetc (c, infile), | 1149 | ungetc (c, infile), |
| 1129 | c == '*'))) | 1150 | c == '*'))) |
| 1130 | { | 1151 | { |
| 1131 | int comment = c != '"'; | 1152 | bool comment = c != '"'; |
| 1132 | int saw_usage; | 1153 | bool saw_usage; |
| 1133 | 1154 | ||
| 1134 | printf ("\037%c%s\n", defvarflag ? 'V' : 'F', input_buffer); | 1155 | printf ("\037%c%s\n", defvarflag ? 'V' : 'F', input_buffer); |
| 1135 | 1156 | ||
| @@ -1183,8 +1204,8 @@ scan_c_stream (FILE *infile) | |||
| 1183 | } | 1204 | } |
| 1184 | } | 1205 | } |
| 1185 | eof: | 1206 | eof: |
| 1186 | fclose (infile); | 1207 | if (ferror (infile) || fclose (infile) != 0) |
| 1187 | return 0; | 1208 | fatal ("read error"); |
| 1188 | } | 1209 | } |
| 1189 | 1210 | ||
| 1190 | /* Read a file of Lisp code, compiled or interpreted. | 1211 | /* Read a file of Lisp code, compiled or interpreted. |
| @@ -1260,7 +1281,7 @@ read_lisp_symbol (FILE *infile, char *buffer) | |||
| 1260 | skip_white (infile); | 1281 | skip_white (infile); |
| 1261 | } | 1282 | } |
| 1262 | 1283 | ||
| 1263 | static int | 1284 | static bool |
| 1264 | search_lisp_doc_at_eol (FILE *infile) | 1285 | search_lisp_doc_at_eol (FILE *infile) |
| 1265 | { | 1286 | { |
| 1266 | int c = 0, c1 = 0, c2 = 0; | 1287 | int c = 0, c1 = 0, c2 = 0; |
| @@ -1280,16 +1301,15 @@ search_lisp_doc_at_eol (FILE *infile) | |||
| 1280 | #ifdef DEBUG | 1301 | #ifdef DEBUG |
| 1281 | fprintf (stderr, "## non-docstring found\n"); | 1302 | fprintf (stderr, "## non-docstring found\n"); |
| 1282 | #endif | 1303 | #endif |
| 1283 | if (c != EOF) | 1304 | ungetc (c, infile); |
| 1284 | ungetc (c, infile); | 1305 | return false; |
| 1285 | return 0; | ||
| 1286 | } | 1306 | } |
| 1287 | return 1; | 1307 | return true; |
| 1288 | } | 1308 | } |
| 1289 | 1309 | ||
| 1290 | #define DEF_ELISP_FILE(fn) { #fn, sizeof(#fn) - 1 } | 1310 | #define DEF_ELISP_FILE(fn) { #fn, sizeof(#fn) - 1 } |
| 1291 | 1311 | ||
| 1292 | static int | 1312 | static void |
| 1293 | scan_lisp_file (const char *filename, const char *mode) | 1313 | scan_lisp_file (const char *filename, const char *mode) |
| 1294 | { | 1314 | { |
| 1295 | FILE *infile; | 1315 | FILE *infile; |
| @@ -1309,22 +1329,22 @@ scan_lisp_file (const char *filename, const char *mode) | |||
| 1309 | DEF_ELISP_FILE (cp51932.el), | 1329 | DEF_ELISP_FILE (cp51932.el), |
| 1310 | DEF_ELISP_FILE (eucjp-ms.el) | 1330 | DEF_ELISP_FILE (eucjp-ms.el) |
| 1311 | }; | 1331 | }; |
| 1312 | int i, match; | 1332 | int i; |
| 1313 | int flen = strlen (filename); | 1333 | int flen = strlen (filename); |
| 1314 | 1334 | ||
| 1315 | if (generate_globals) | 1335 | if (generate_globals) |
| 1316 | fatal ("scanning lisp file when -g specified", 0); | 1336 | fatal ("scanning lisp file when -g specified"); |
| 1317 | if (flen > 3 && !strcmp (filename + flen - 3, ".el")) | 1337 | if (flen > 3 && !strcmp (filename + flen - 3, ".el")) |
| 1318 | { | 1338 | { |
| 1319 | for (i = 0, match = 0; i < sizeof (uncompiled) / sizeof (uncompiled[0]); | 1339 | bool match = false; |
| 1320 | i++) | 1340 | for (i = 0; i < sizeof (uncompiled) / sizeof (uncompiled[0]); i++) |
| 1321 | { | 1341 | { |
| 1322 | if (uncompiled[i].fl <= flen | 1342 | if (uncompiled[i].fl <= flen |
| 1323 | && !strcmp (filename + flen - uncompiled[i].fl, uncompiled[i].fn) | 1343 | && !strcmp (filename + flen - uncompiled[i].fl, uncompiled[i].fn) |
| 1324 | && (flen == uncompiled[i].fl | 1344 | && (flen == uncompiled[i].fl |
| 1325 | || IS_SLASH (filename[flen - uncompiled[i].fl - 1]))) | 1345 | || IS_SLASH (filename[flen - uncompiled[i].fl - 1]))) |
| 1326 | { | 1346 | { |
| 1327 | match = 1; | 1347 | match = true; |
| 1328 | break; | 1348 | break; |
| 1329 | } | 1349 | } |
| 1330 | } | 1350 | } |
| @@ -1336,7 +1356,7 @@ scan_lisp_file (const char *filename, const char *mode) | |||
| 1336 | if (infile == NULL) | 1356 | if (infile == NULL) |
| 1337 | { | 1357 | { |
| 1338 | perror (filename); | 1358 | perror (filename); |
| 1339 | return 0; /* No error. */ | 1359 | exit (EXIT_FAILURE); |
| 1340 | } | 1360 | } |
| 1341 | 1361 | ||
| 1342 | c = '\n'; | 1362 | c = '\n'; |
| @@ -1374,10 +1394,10 @@ scan_lisp_file (const char *filename, const char *mode) | |||
| 1374 | } | 1394 | } |
| 1375 | 1395 | ||
| 1376 | if (length <= 1) | 1396 | if (length <= 1) |
| 1377 | fatal ("invalid dynamic doc string length", ""); | 1397 | fatal ("invalid dynamic doc string length"); |
| 1378 | 1398 | ||
| 1379 | if (c != ' ') | 1399 | if (c != ' ') |
| 1380 | fatal ("space not found after dynamic doc string length", ""); | 1400 | fatal ("space not found after dynamic doc string length"); |
| 1381 | 1401 | ||
| 1382 | /* The next character is a space that is counted in the length | 1402 | /* The next character is a space that is counted in the length |
| 1383 | but not part of the doc string. | 1403 | but not part of the doc string. |
| @@ -1585,7 +1605,7 @@ scan_lisp_file (const char *filename, const char *mode) | |||
| 1585 | buffer, filename); | 1605 | buffer, filename); |
| 1586 | continue; | 1606 | continue; |
| 1587 | } | 1607 | } |
| 1588 | read_c_string_or_comment (infile, 0, 0, 0); | 1608 | read_c_string_or_comment (infile, 0, false, 0); |
| 1589 | 1609 | ||
| 1590 | if (saved_string == 0) | 1610 | if (saved_string == 0) |
| 1591 | if (!search_lisp_doc_at_eol (infile)) | 1611 | if (!search_lisp_doc_at_eol (infile)) |
| @@ -1621,11 +1641,11 @@ scan_lisp_file (const char *filename, const char *mode) | |||
| 1621 | saved_string = 0; | 1641 | saved_string = 0; |
| 1622 | } | 1642 | } |
| 1623 | else | 1643 | else |
| 1624 | read_c_string_or_comment (infile, 1, 0, 0); | 1644 | read_c_string_or_comment (infile, 1, false, 0); |
| 1625 | } | 1645 | } |
| 1626 | free (saved_string); | 1646 | free (saved_string); |
| 1627 | fclose (infile); | 1647 | if (ferror (infile) || fclose (infile) != 0) |
| 1628 | return 0; | 1648 | fatal ("%s: read error", filename); |
| 1629 | } | 1649 | } |
| 1630 | 1650 | ||
| 1631 | 1651 | ||