aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/make-docfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src/make-docfile.c')
-rw-r--r--lib-src/make-docfile.c128
1 files changed, 52 insertions, 76 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 15ffa138b51..884b6c1001e 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -38,17 +38,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
38 38
39#include <stdio.h> 39#include <stdio.h>
40#include <stdlib.h> /* config.h unconditionally includes this anyway */ 40#include <stdlib.h> /* config.h unconditionally includes this anyway */
41#ifdef MSDOS 41
42#include <fcntl.h>
43#endif /* MSDOS */
44#ifdef WINDOWSNT 42#ifdef WINDOWSNT
45/* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this 43/* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this
46 is really just insurance. */ 44 is really just insurance. */
47#undef fopen 45#undef fopen
48#include <fcntl.h>
49#include <direct.h> 46#include <direct.h>
50#endif /* WINDOWSNT */ 47#endif /* WINDOWSNT */
51 48
49#include <binary-io.h>
50
52#ifdef DOS_NT 51#ifdef DOS_NT
53/* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this 52/* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this
54 is really just insurance. 53 is really just insurance.
@@ -56,12 +55,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
56 Similarly, msdos defines this as sys_chdir, but we're not linking with the 55 Similarly, msdos defines this as sys_chdir, but we're not linking with the
57 file where that function is defined. */ 56 file where that function is defined. */
58#undef chdir 57#undef chdir
59#define READ_TEXT "rt"
60#define READ_BINARY "rb"
61#define IS_SLASH(c) ((c) == '/' || (c) == '\\' || (c) == ':') 58#define IS_SLASH(c) ((c) == '/' || (c) == '\\' || (c) == ':')
62#else /* not DOS_NT */ 59#else /* not DOS_NT */
63#define READ_TEXT "r"
64#define READ_BINARY "r"
65#define IS_SLASH(c) ((c) == '/') 60#define IS_SLASH(c) ((c) == '/')
66#endif /* not DOS_NT */ 61#endif /* not DOS_NT */
67 62
@@ -73,9 +68,6 @@ static void write_globals (void);
73 68
74#include <unistd.h> 69#include <unistd.h>
75 70
76/* Stdio stream for output to the DOC file. */
77FILE *outfile;
78
79/* Name this program was invoked with. */ 71/* Name this program was invoked with. */
80char *progname; 72char *progname;
81 73
@@ -135,33 +127,24 @@ main (int argc, char **argv)
135 127
136 progname = argv[0]; 128 progname = argv[0];
137 129
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. */ 130 /* If first two args are -o FILE, output to FILE. */
156 i = 1; 131 i = 1;
157 if (argc > i + 1 && !strcmp (argv[i], "-o")) 132 if (argc > i + 1 && !strcmp (argv[i], "-o"))
158 { 133 {
159 outfile = fopen (argv[i + 1], "w"); 134 if (! freopen (argv[i + 1], "w", stdout))
135 {
136 perror (argv[i + 1]);
137 return EXIT_FAILURE;
138 }
160 i += 2; 139 i += 2;
161 } 140 }
162 if (argc > i + 1 && !strcmp (argv[i], "-a")) 141 if (argc > i + 1 && !strcmp (argv[i], "-a"))
163 { 142 {
164 outfile = fopen (argv[i + 1], "a"); 143 if (! freopen (argv[i + 1], "a", stdout))
144 {
145 perror (argv[i + 1]);
146 return EXIT_FAILURE;
147 }
165 i += 2; 148 i += 2;
166 } 149 }
167 if (argc > i + 1 && !strcmp (argv[i], "-d")) 150 if (argc > i + 1 && !strcmp (argv[i], "-d"))
@@ -179,8 +162,7 @@ main (int argc, char **argv)
179 ++i; 162 ++i;
180 } 163 }
181 164
182 if (outfile == 0) 165 set_binary_mode (fileno (stdout), O_BINARY);
183 fatal ("No output file specified", "");
184 166
185 if (generate_globals) 167 if (generate_globals)
186 start_globals (); 168 start_globals ();
@@ -215,13 +197,11 @@ put_filename (char *filename)
215 filename = tmp + 1; 197 filename = tmp + 1;
216 } 198 }
217 199
218 putc (037, outfile); 200 printf ("\037S%s\n", filename);
219 putc ('S', outfile);
220 fprintf (outfile, "%s\n", filename);
221} 201}
222 202
223/* Read file FILENAME and output its doc strings to outfile. */ 203/* Read file FILENAME and output its doc strings to stdout.
224/* Return 1 if file is not found, 0 if it is found. */ 204 Return 1 if file is not found, 0 if it is found. */
225 205
226static int 206static int
227scan_file (char *filename) 207scan_file (char *filename)
@@ -232,19 +212,19 @@ scan_file (char *filename)
232 if (!generate_globals) 212 if (!generate_globals)
233 put_filename (filename); 213 put_filename (filename);
234 if (len > 4 && !strcmp (filename + len - 4, ".elc")) 214 if (len > 4 && !strcmp (filename + len - 4, ".elc"))
235 return scan_lisp_file (filename, READ_BINARY); 215 return scan_lisp_file (filename, "rb");
236 else if (len > 3 && !strcmp (filename + len - 3, ".el")) 216 else if (len > 3 && !strcmp (filename + len - 3, ".el"))
237 return scan_lisp_file (filename, READ_TEXT); 217 return scan_lisp_file (filename, "r");
238 else 218 else
239 return scan_c_file (filename, READ_TEXT); 219 return scan_c_file (filename, "r");
240} 220}
241 221
242static void 222static void
243start_globals (void) 223start_globals (void)
244{ 224{
245 fprintf (outfile, "/* This file was auto-generated by make-docfile. */\n"); 225 puts ("/* This file was auto-generated by make-docfile. */");
246 fprintf (outfile, "/* DO NOT EDIT. */\n"); 226 puts ("/* DO NOT EDIT. */");
247 fprintf (outfile, "struct emacs_globals {\n"); 227 puts ("struct emacs_globals {");
248} 228}
249 229
250static char input_buffer[128]; 230static char input_buffer[128];
@@ -373,7 +353,7 @@ scan_keyword_or_put_char (int ch, struct rcsoc_state *state)
373 353
374/* Skip a C string or C-style comment from INFILE, and return the 354/* 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 355 character that follows. COMMENT non-zero means skip a comment. If
376 PRINTFLAG is positive, output string contents to outfile. If it is 356 PRINTFLAG is positive, output string contents to stdout. If it is
377 negative, store contents in buf. Convert escape sequences \n and 357 negative, store contents in buf. Convert escape sequences \n and
378 \t to newline and tab; discard \ followed by newline. 358 \t to newline and tab; discard \ followed by newline.
379 If SAW_USAGE is non-zero, then any occurrences of the string `usage:' 359 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
@@ -388,7 +368,7 @@ read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usa
388 368
389 state.in_file = infile; 369 state.in_file = infile;
390 state.buf_ptr = (printflag < 0 ? input_buffer : 0); 370 state.buf_ptr = (printflag < 0 ? input_buffer : 0);
391 state.out_file = (printflag > 0 ? outfile : 0); 371 state.out_file = (printflag > 0 ? stdout : 0);
392 state.pending_spaces = 0; 372 state.pending_spaces = 0;
393 state.pending_newlines = 0; 373 state.pending_newlines = 0;
394 state.keyword = (saw_usage ? "usage:" : 0); 374 state.keyword = (saw_usage ? "usage:" : 0);
@@ -465,18 +445,18 @@ read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usa
465 445
466 446
467 447
468/* Write to file OUT the argument names of function FUNC, whose text is in BUF. 448/* 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. */ 449 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
470 450
471static void 451static void
472write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs) 452write_c_args (char *func, char *buf, int minargs, int maxargs)
473{ 453{
474 register char *p; 454 register char *p;
475 int in_ident = 0; 455 int in_ident = 0;
476 char *ident_start IF_LINT (= NULL); 456 char *ident_start IF_LINT (= NULL);
477 size_t ident_length = 0; 457 size_t ident_length = 0;
478 458
479 fprintf (out, "(fn"); 459 fputs ("(fn", stdout);
480 460
481 if (*buf == '(') 461 if (*buf == '(')
482 ++buf; 462 ++buf;
@@ -517,10 +497,10 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
517 if (strncmp (ident_start, "void", ident_length) == 0) 497 if (strncmp (ident_start, "void", ident_length) == 0)
518 continue; 498 continue;
519 499
520 putc (' ', out); 500 putchar (' ');
521 501
522 if (minargs == 0 && maxargs > 0) 502 if (minargs == 0 && maxargs > 0)
523 fprintf (out, "&optional "); 503 fputs ("&optional ", stdout);
524 504
525 minargs--; 505 minargs--;
526 maxargs--; 506 maxargs--;
@@ -528,7 +508,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 508 /* In C code, `default' is a reserved word, so we spell it
529 `defalt'; demangle that here. */ 509 `defalt'; demangle that here. */
530 if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0) 510 if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0)
531 fprintf (out, "DEFAULT"); 511 fputs ("DEFAULT", stdout);
532 else 512 else
533 while (ident_length-- > 0) 513 while (ident_length-- > 0)
534 { 514 {
@@ -539,12 +519,12 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
539 else if (c == '_') 519 else if (c == '_')
540 /* Print underscore as hyphen. */ 520 /* Print underscore as hyphen. */
541 c = '-'; 521 c = '-';
542 putc (c, out); 522 putchar (c);
543 } 523 }
544 } 524 }
545 } 525 }
546 526
547 putc (')', out); 527 putchar (')');
548} 528}
549 529
550/* The types of globals. These are sorted roughly in decreasing alignment 530/* The types of globals. These are sorted roughly in decreasing alignment
@@ -613,8 +593,8 @@ compare_globals (const void *a, const void *b)
613static void 593static void
614close_emacs_globals (void) 594close_emacs_globals (void)
615{ 595{
616 fprintf (outfile, "};\n"); 596 puts ("};");
617 fprintf (outfile, "extern struct emacs_globals globals;\n"); 597 puts ("extern struct emacs_globals globals;");
618} 598}
619 599
620static void 600static void
@@ -641,7 +621,7 @@ write_globals (void)
641 if (!seen_defun) 621 if (!seen_defun)
642 { 622 {
643 close_emacs_globals (); 623 close_emacs_globals ();
644 fprintf (outfile, "\n"); 624 putchar ('\n');
645 seen_defun = 1; 625 seen_defun = 1;
646 } 626 }
647 break; 627 break;
@@ -651,9 +631,9 @@ write_globals (void)
651 631
652 if (type) 632 if (type)
653 { 633 {
654 fprintf (outfile, " %s f_%s;\n", type, globals[i].name); 634 printf (" %s f_%s;\n", type, globals[i].name);
655 fprintf (outfile, "#define %s globals.f_%s\n", 635 printf ("#define %s globals.f_%s\n",
656 globals[i].name, globals[i].name); 636 globals[i].name, globals[i].name);
657 } 637 }
658 else 638 else
659 { 639 {
@@ -664,16 +644,16 @@ write_globals (void)
664 || strcmp (globals[i].name, "Fkill_emacs") == 0 644 || strcmp (globals[i].name, "Fkill_emacs") == 0
665 || strcmp (globals[i].name, "Fexit_recursive_edit") == 0 645 || strcmp (globals[i].name, "Fexit_recursive_edit") == 0
666 || strcmp (globals[i].name, "Fabort_recursive_edit") == 0) 646 || strcmp (globals[i].name, "Fabort_recursive_edit") == 0)
667 fprintf (outfile, "_Noreturn "); 647 fputs ("_Noreturn ", stdout);
668 648
669 fprintf (outfile, "EXFUN (%s, ", globals[i].name); 649 printf ("EXFUN (%s, ", globals[i].name);
670 if (globals[i].value == -1) 650 if (globals[i].value == -1)
671 fprintf (outfile, "MANY"); 651 fputs ("MANY", stdout);
672 else if (globals[i].value == -2) 652 else if (globals[i].value == -2)
673 fprintf (outfile, "UNEVALLED"); 653 fputs ("UNEVALLED", stdout);
674 else 654 else
675 fprintf (outfile, "%d", globals[i].value); 655 printf ("%d", globals[i].value);
676 fprintf (outfile, ")"); 656 putchar (')');
677 657
678 /* It would be nice to have a cleaner way to deal with these 658 /* It would be nice to have a cleaner way to deal with these
679 special hacks, too. */ 659 special hacks, too. */
@@ -681,9 +661,9 @@ write_globals (void)
681 || strcmp (globals[i].name, "Ftool_bar_height") == 0 661 || strcmp (globals[i].name, "Ftool_bar_height") == 0
682 || strcmp (globals[i].name, "Fmax_char") == 0 662 || strcmp (globals[i].name, "Fmax_char") == 0
683 || strcmp (globals[i].name, "Fidentity") == 0) 663 || strcmp (globals[i].name, "Fidentity") == 0)
684 fprintf (outfile, " ATTRIBUTE_CONST"); 664 fputs (" ATTRIBUTE_CONST", stdout);
685 665
686 fprintf (outfile, ";\n"); 666 puts (";");
687 } 667 }
688 668
689 while (i + 1 < num_globals 669 while (i + 1 < num_globals
@@ -952,9 +932,7 @@ scan_c_file (char *filename, const char *mode)
952 int comment = c != '"'; 932 int comment = c != '"';
953 int saw_usage; 933 int saw_usage;
954 934
955 putc (037, outfile); 935 printf ("\037%c%s\n", defvarflag ? 'V' : 'F', input_buffer);
956 putc (defvarflag ? 'V' : 'F', outfile);
957 fprintf (outfile, "%s\n", input_buffer);
958 936
959 if (comment) 937 if (comment)
960 getc (infile); /* Skip past `*'. */ 938 getc (infile); /* Skip past `*'. */
@@ -996,8 +974,8 @@ scan_c_file (char *filename, const char *mode)
996 while (c != ')'); 974 while (c != ')');
997 *p = '\0'; 975 *p = '\0';
998 /* Output them. */ 976 /* Output them. */
999 fprintf (outfile, "\n\n"); 977 fputs ("\n\n", stdout);
1000 write_c_args (outfile, input_buffer, argbuf, minargs, maxargs); 978 write_c_args (input_buffer, argbuf, minargs, maxargs);
1001 } 979 }
1002 else if (defunflag && maxargs == -1 && !saw_usage) 980 else if (defunflag && maxargs == -1 && !saw_usage)
1003 /* The DOC should provide the usage form. */ 981 /* The DOC should provide the usage form. */
@@ -1433,12 +1411,10 @@ scan_lisp_file (const char *filename, const char *mode)
1433 In the latter case, the opening quote (and leading backslash-newline) 1411 In the latter case, the opening quote (and leading backslash-newline)
1434 have already been read. */ 1412 have already been read. */
1435 1413
1436 putc (037, outfile); 1414 printf ("\037%c%s\n", type, buffer);
1437 putc (type, outfile);
1438 fprintf (outfile, "%s\n", buffer);
1439 if (saved_string) 1415 if (saved_string)
1440 { 1416 {
1441 fputs (saved_string, outfile); 1417 fputs (saved_string, stdout);
1442 /* Don't use one dynamic doc string twice. */ 1418 /* Don't use one dynamic doc string twice. */
1443 free (saved_string); 1419 free (saved_string);
1444 saved_string = 0; 1420 saved_string = 0;