aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2014-07-13 17:45:19 -0700
committerPaul Eggert2014-07-13 17:45:19 -0700
commita705278de7c661af9b78d956af25e13055cba864 (patch)
treea8033e995ce6bfa2cd9af4cbee0700e3803e5602 /lib-src
parent4939f58d2c45062d5eac3f4c845b4494cf113f1f (diff)
downloademacs-a705278de7c661af9b78d956af25e13055cba864.tar.gz
emacs-a705278de7c661af9b78d956af25e13055cba864.zip
* make-docfile.c: Simplify a bit, to simplify further refactoring.
(outfile): Remove static var. All uses changed to use stdout, since it's always stdout anyway. While we're at it, prefer putchar/puts/fputs to printf when there are no format strings. (main): Use freopen rather than fopen, so that stdout is reused. Move O_BINARY stuff after the freopen, so it affects the reopened file. (write_c_args): Omit first arg, since it's always stdout now. All uses changed.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog12
-rw-r--r--lib-src/make-docfile.c123
2 files changed, 70 insertions, 65 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 3a7d128b905..0e0dc51f361 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,15 @@
12014-07-13 Paul Eggert <eggert@cs.ucla.edu>
2
3 * make-docfile.c: Simplify a bit, to simplify further refactoring.
4 (outfile): Remove static var. All uses changed to use stdout,
5 since it's always stdout anyway. While we're at it, prefer
6 putchar/puts/fputs to printf when there are no format strings.
7 (main): Use freopen rather than fopen, so that stdout is reused.
8 Move O_BINARY stuff after the freopen, so it affects the
9 reopened file.
10 (write_c_args): Omit first arg, since it's always stdout now.
11 All uses changed.
12
12014-07-12 Paul Eggert <eggert@cs.ucla.edu> 132014-07-12 Paul Eggert <eggert@cs.ucla.edu>
2 14
3 * etags.c (Lisp_functions): Also record cl-defun etc. (Bug#17965) 15 * etags.c (Lisp_functions): Also record cl-defun etc. (Bug#17965)
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 15ffa138b51..6692a0a6450 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -73,9 +73,6 @@ static void write_globals (void);
73 73
74#include <unistd.h> 74#include <unistd.h>
75 75
76/* Stdio stream for output to the DOC file. */
77FILE *outfile;
78
79/* Name this program was invoked with. */ 76/* Name this program was invoked with. */
80char *progname; 77char *progname;
81 78
@@ -135,33 +132,24 @@ main (int argc, char **argv)
135 132
136 progname = argv[0]; 133 progname = argv[0];
137 134
138 outfile = stdout;
139
140 /* Don't put CRs in the DOC file. */
141#ifdef MSDOS
142 _fmode = O_BINARY;
143#if 0 /* Suspicion is that this causes hanging.
144 So instead we require people to use -o on MSDOS. */
145 (stdout)->_flag &= ~_IOTEXT;
146 _setmode (fileno (stdout), O_BINARY);
147#endif
148 outfile = 0;
149#endif /* MSDOS */
150#ifdef WINDOWSNT
151 _fmode = O_BINARY;
152 _setmode (fileno (stdout), O_BINARY);
153#endif /* WINDOWSNT */
154
155 /* If first two args are -o FILE, output to FILE. */ 135 /* If first two args are -o FILE, output to FILE. */
156 i = 1; 136 i = 1;
157 if (argc > i + 1 && !strcmp (argv[i], "-o")) 137 if (argc > i + 1 && !strcmp (argv[i], "-o"))
158 { 138 {
159 outfile = fopen (argv[i + 1], "w"); 139 if (! freopen (argv[i + 1], "w", stdout))
140 {
141 perror (argv[i + 1]);
142 return EXIT_FAILURE;
143 }
160 i += 2; 144 i += 2;
161 } 145 }
162 if (argc > i + 1 && !strcmp (argv[i], "-a")) 146 if (argc > i + 1 && !strcmp (argv[i], "-a"))
163 { 147 {
164 outfile = fopen (argv[i + 1], "a"); 148 if (! freopen (argv[i + 1], "a", stdout))
149 {
150 perror (argv[i + 1]);
151 return EXIT_FAILURE;
152 }
165 i += 2; 153 i += 2;
166 } 154 }
167 if (argc > i + 1 && !strcmp (argv[i], "-d")) 155 if (argc > i + 1 && !strcmp (argv[i], "-d"))
@@ -179,8 +167,19 @@ main (int argc, char **argv)
179 ++i; 167 ++i;
180 } 168 }
181 169
182 if (outfile == 0) 170 /* Don't put CRs in the output file. */
183 fatal ("No output file specified", ""); 171#ifdef MSDOS
172 _fmode = O_BINARY;
173#if 0 /* Suspicion is that this causes hanging.
174 So instead we require people to use -o on MSDOS. */
175 (stdout)->_flag &= ~_IOTEXT;
176 _setmode (fileno (stdout), O_BINARY);
177#endif
178#endif /* MSDOS */
179#ifdef WINDOWSNT
180 _fmode = O_BINARY;
181 _setmode (fileno (stdout), O_BINARY);
182#endif /* WINDOWSNT */
184 183
185 if (generate_globals) 184 if (generate_globals)
186 start_globals (); 185 start_globals ();
@@ -215,13 +214,11 @@ put_filename (char *filename)
215 filename = tmp + 1; 214 filename = tmp + 1;
216 } 215 }
217 216
218 putc (037, outfile); 217 printf ("\037S%s\n", filename);
219 putc ('S', outfile);
220 fprintf (outfile, "%s\n", filename);
221} 218}
222 219
223/* Read file FILENAME and output its doc strings to outfile. */ 220/* Read file FILENAME and output its doc strings to stdout.
224/* Return 1 if file is not found, 0 if it is found. */ 221 Return 1 if file is not found, 0 if it is found. */
225 222
226static int 223static int
227scan_file (char *filename) 224scan_file (char *filename)
@@ -242,9 +239,9 @@ scan_file (char *filename)
242static void 239static void
243start_globals (void) 240start_globals (void)
244{ 241{
245 fprintf (outfile, "/* This file was auto-generated by make-docfile. */\n"); 242 puts ("/* This file was auto-generated by make-docfile. */");
246 fprintf (outfile, "/* DO NOT EDIT. */\n"); 243 puts ("/* DO NOT EDIT. */");
247 fprintf (outfile, "struct emacs_globals {\n"); 244 puts ("struct emacs_globals {");
248} 245}
249 246
250static char input_buffer[128]; 247static char input_buffer[128];
@@ -373,7 +370,7 @@ scan_keyword_or_put_char (int ch, struct rcsoc_state *state)
373 370
374/* Skip a C string or C-style comment from INFILE, and return the 371/* Skip a C string or C-style comment from INFILE, and return the
375 character that follows. COMMENT non-zero means skip a comment. If 372 character that follows. COMMENT non-zero means skip a comment. If
376 PRINTFLAG is positive, output string contents to outfile. If it is 373 PRINTFLAG is positive, output string contents to stdout. If it is
377 negative, store contents in buf. Convert escape sequences \n and 374 negative, store contents in buf. Convert escape sequences \n and
378 \t to newline and tab; discard \ followed by newline. 375 \t to newline and tab; discard \ followed by newline.
379 If SAW_USAGE is non-zero, then any occurrences of the string `usage:' 376 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
@@ -388,7 +385,7 @@ read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usa
388 385
389 state.in_file = infile; 386 state.in_file = infile;
390 state.buf_ptr = (printflag < 0 ? input_buffer : 0); 387 state.buf_ptr = (printflag < 0 ? input_buffer : 0);
391 state.out_file = (printflag > 0 ? outfile : 0); 388 state.out_file = (printflag > 0 ? stdout : 0);
392 state.pending_spaces = 0; 389 state.pending_spaces = 0;
393 state.pending_newlines = 0; 390 state.pending_newlines = 0;
394 state.keyword = (saw_usage ? "usage:" : 0); 391 state.keyword = (saw_usage ? "usage:" : 0);
@@ -465,18 +462,18 @@ read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usa
465 462
466 463
467 464
468/* Write to file OUT the argument names of function FUNC, whose text is in BUF. 465/* Write to stdout the argument names of function FUNC, whose text is in BUF.
469 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ 466 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
470 467
471static void 468static void
472write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs) 469write_c_args (char *func, char *buf, int minargs, int maxargs)
473{ 470{
474 register char *p; 471 register char *p;
475 int in_ident = 0; 472 int in_ident = 0;
476 char *ident_start IF_LINT (= NULL); 473 char *ident_start IF_LINT (= NULL);
477 size_t ident_length = 0; 474 size_t ident_length = 0;
478 475
479 fprintf (out, "(fn"); 476 fputs ("(fn", stdout);
480 477
481 if (*buf == '(') 478 if (*buf == '(')
482 ++buf; 479 ++buf;
@@ -517,10 +514,10 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
517 if (strncmp (ident_start, "void", ident_length) == 0) 514 if (strncmp (ident_start, "void", ident_length) == 0)
518 continue; 515 continue;
519 516
520 putc (' ', out); 517 putchar (' ');
521 518
522 if (minargs == 0 && maxargs > 0) 519 if (minargs == 0 && maxargs > 0)
523 fprintf (out, "&optional "); 520 fputs ("&optional ", stdout);
524 521
525 minargs--; 522 minargs--;
526 maxargs--; 523 maxargs--;
@@ -528,7 +525,7 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
528 /* In C code, `default' is a reserved word, so we spell it 525 /* In C code, `default' is a reserved word, so we spell it
529 `defalt'; demangle that here. */ 526 `defalt'; demangle that here. */
530 if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0) 527 if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0)
531 fprintf (out, "DEFAULT"); 528 fputs ("DEFAULT", stdout);
532 else 529 else
533 while (ident_length-- > 0) 530 while (ident_length-- > 0)
534 { 531 {
@@ -539,12 +536,12 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
539 else if (c == '_') 536 else if (c == '_')
540 /* Print underscore as hyphen. */ 537 /* Print underscore as hyphen. */
541 c = '-'; 538 c = '-';
542 putc (c, out); 539 putchar (c);
543 } 540 }
544 } 541 }
545 } 542 }
546 543
547 putc (')', out); 544 putchar (')');
548} 545}
549 546
550/* The types of globals. These are sorted roughly in decreasing alignment 547/* The types of globals. These are sorted roughly in decreasing alignment
@@ -613,8 +610,8 @@ compare_globals (const void *a, const void *b)
613static void 610static void
614close_emacs_globals (void) 611close_emacs_globals (void)
615{ 612{
616 fprintf (outfile, "};\n"); 613 puts ("};");
617 fprintf (outfile, "extern struct emacs_globals globals;\n"); 614 puts ("extern struct emacs_globals globals;");
618} 615}
619 616
620static void 617static void
@@ -641,7 +638,7 @@ write_globals (void)
641 if (!seen_defun) 638 if (!seen_defun)
642 { 639 {
643 close_emacs_globals (); 640 close_emacs_globals ();
644 fprintf (outfile, "\n"); 641 putchar ('\n');
645 seen_defun = 1; 642 seen_defun = 1;
646 } 643 }
647 break; 644 break;
@@ -651,9 +648,9 @@ write_globals (void)
651 648
652 if (type) 649 if (type)
653 { 650 {
654 fprintf (outfile, " %s f_%s;\n", type, globals[i].name); 651 printf (" %s f_%s;\n", type, globals[i].name);
655 fprintf (outfile, "#define %s globals.f_%s\n", 652 printf ("#define %s globals.f_%s\n",
656 globals[i].name, globals[i].name); 653 globals[i].name, globals[i].name);
657 } 654 }
658 else 655 else
659 { 656 {
@@ -664,16 +661,16 @@ write_globals (void)
664 || strcmp (globals[i].name, "Fkill_emacs") == 0 661 || strcmp (globals[i].name, "Fkill_emacs") == 0
665 || strcmp (globals[i].name, "Fexit_recursive_edit") == 0 662 || strcmp (globals[i].name, "Fexit_recursive_edit") == 0
666 || strcmp (globals[i].name, "Fabort_recursive_edit") == 0) 663 || strcmp (globals[i].name, "Fabort_recursive_edit") == 0)
667 fprintf (outfile, "_Noreturn "); 664 fputs ("_Noreturn ", stdout);
668 665
669 fprintf (outfile, "EXFUN (%s, ", globals[i].name); 666 printf ("EXFUN (%s, ", globals[i].name);
670 if (globals[i].value == -1) 667 if (globals[i].value == -1)
671 fprintf (outfile, "MANY"); 668 fputs ("MANY", stdout);
672 else if (globals[i].value == -2) 669 else if (globals[i].value == -2)
673 fprintf (outfile, "UNEVALLED"); 670 fputs ("UNEVALLED", stdout);
674 else 671 else
675 fprintf (outfile, "%d", globals[i].value); 672 printf ("%d", globals[i].value);
676 fprintf (outfile, ")"); 673 putchar (')');
677 674
678 /* It would be nice to have a cleaner way to deal with these 675 /* It would be nice to have a cleaner way to deal with these
679 special hacks, too. */ 676 special hacks, too. */
@@ -681,9 +678,9 @@ write_globals (void)
681 || strcmp (globals[i].name, "Ftool_bar_height") == 0 678 || strcmp (globals[i].name, "Ftool_bar_height") == 0
682 || strcmp (globals[i].name, "Fmax_char") == 0 679 || strcmp (globals[i].name, "Fmax_char") == 0
683 || strcmp (globals[i].name, "Fidentity") == 0) 680 || strcmp (globals[i].name, "Fidentity") == 0)
684 fprintf (outfile, " ATTRIBUTE_CONST"); 681 fputs (" ATTRIBUTE_CONST", stdout);
685 682
686 fprintf (outfile, ";\n"); 683 puts (";");
687 } 684 }
688 685
689 while (i + 1 < num_globals 686 while (i + 1 < num_globals
@@ -952,9 +949,7 @@ scan_c_file (char *filename, const char *mode)
952 int comment = c != '"'; 949 int comment = c != '"';
953 int saw_usage; 950 int saw_usage;
954 951
955 putc (037, outfile); 952 printf ("\037%c%s\n", defvarflag ? 'V' : 'F', input_buffer);
956 putc (defvarflag ? 'V' : 'F', outfile);
957 fprintf (outfile, "%s\n", input_buffer);
958 953
959 if (comment) 954 if (comment)
960 getc (infile); /* Skip past `*'. */ 955 getc (infile); /* Skip past `*'. */
@@ -996,8 +991,8 @@ scan_c_file (char *filename, const char *mode)
996 while (c != ')'); 991 while (c != ')');
997 *p = '\0'; 992 *p = '\0';
998 /* Output them. */ 993 /* Output them. */
999 fprintf (outfile, "\n\n"); 994 fputs ("\n\n", stdout);
1000 write_c_args (outfile, input_buffer, argbuf, minargs, maxargs); 995 write_c_args (input_buffer, argbuf, minargs, maxargs);
1001 } 996 }
1002 else if (defunflag && maxargs == -1 && !saw_usage) 997 else if (defunflag && maxargs == -1 && !saw_usage)
1003 /* The DOC should provide the usage form. */ 998 /* The DOC should provide the usage form. */
@@ -1433,12 +1428,10 @@ scan_lisp_file (const char *filename, const char *mode)
1433 In the latter case, the opening quote (and leading backslash-newline) 1428 In the latter case, the opening quote (and leading backslash-newline)
1434 have already been read. */ 1429 have already been read. */
1435 1430
1436 putc (037, outfile); 1431 printf ("\037%c%s\n", type, buffer);
1437 putc (type, outfile);
1438 fprintf (outfile, "%s\n", buffer);
1439 if (saved_string) 1432 if (saved_string)
1440 { 1433 {
1441 fputs (saved_string, outfile); 1434 fputs (saved_string, stdout);
1442 /* Don't use one dynamic doc string twice. */ 1435 /* Don't use one dynamic doc string twice. */
1443 free (saved_string); 1436 free (saved_string);
1444 saved_string = 0; 1437 saved_string = 0;