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.c156
1 files changed, 67 insertions, 89 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index eb15342ca5b..4824731672b 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -67,9 +67,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
67#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) 67#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
68#endif 68#endif
69 69
70int scan_file (); 70int scan_file (char *filename);
71int scan_lisp_file (); 71int scan_lisp_file (const char *filename, const char *mode);
72int scan_c_file (); 72int scan_c_file (char *filename, const char *mode);
73void fatal (const char *s1, const char *s2) NO_RETURN;
73 74
74#ifdef MSDOS 75#ifdef MSDOS
75/* s/msdos.h defines this as sys_chdir, but we're not linking with the 76/* s/msdos.h defines this as sys_chdir, but we're not linking with the
@@ -91,8 +92,7 @@ char *progname;
91 92
92/* VARARGS1 */ 93/* VARARGS1 */
93void 94void
94error (s1, s2) 95error (const char *s1, const char *s2)
95 char *s1, *s2;
96{ 96{
97 fprintf (stderr, "%s: ", progname); 97 fprintf (stderr, "%s: ", progname);
98 fprintf (stderr, s1, s2); 98 fprintf (stderr, s1, s2);
@@ -103,8 +103,7 @@ error (s1, s2)
103 103
104/* VARARGS1 */ 104/* VARARGS1 */
105void 105void
106fatal (s1, s2) 106fatal (const char *s1, const char *s2)
107 char *s1, *s2;
108{ 107{
109 error (s1, s2); 108 error (s1, s2);
110 exit (EXIT_FAILURE); 109 exit (EXIT_FAILURE);
@@ -113,8 +112,7 @@ fatal (s1, s2)
113/* Like malloc but get fatal error if memory is exhausted. */ 112/* Like malloc but get fatal error if memory is exhausted. */
114 113
115void * 114void *
116xmalloc (size) 115xmalloc (unsigned int size)
117 unsigned int size;
118{ 116{
119 void *result = (void *) malloc (size); 117 void *result = (void *) malloc (size);
120 if (result == NULL) 118 if (result == NULL)
@@ -123,9 +121,7 @@ xmalloc (size)
123} 121}
124 122
125int 123int
126main (argc, argv) 124main (int argc, char **argv)
127 int argc;
128 char **argv;
129{ 125{
130 int i; 126 int i;
131 int err_count = 0; 127 int err_count = 0;
@@ -187,8 +183,7 @@ main (argc, argv)
187 183
188/* Add a source file name boundary marker in the output file. */ 184/* Add a source file name boundary marker in the output file. */
189void 185void
190put_filename (filename) 186put_filename (char *filename)
191 char *filename;
192{ 187{
193 char *tmp; 188 char *tmp;
194 189
@@ -207,8 +202,7 @@ put_filename (filename)
207/* Return 1 if file is not found, 0 if it is found. */ 202/* Return 1 if file is not found, 0 if it is found. */
208 203
209int 204int
210scan_file (filename) 205scan_file (char *filename)
211 char *filename;
212{ 206{
213 int len = strlen (filename); 207 int len = strlen (filename);
214 208
@@ -239,10 +233,10 @@ struct rcsoc_state
239 233
240 /* A keyword we look for at the beginning of lines. If found, it is 234 /* A keyword we look for at the beginning of lines. If found, it is
241 not copied, and SAW_KEYWORD is set to true. */ 235 not copied, and SAW_KEYWORD is set to true. */
242 char *keyword; 236 const char *keyword;
243 /* The current point we've reached in an occurrence of KEYWORD in 237 /* The current point we've reached in an occurrence of KEYWORD in
244 the input stream. */ 238 the input stream. */
245 char *cur_keyword_ptr; 239 const char *cur_keyword_ptr;
246 /* Set to true if we saw an occurrence of KEYWORD. */ 240 /* Set to true if we saw an occurrence of KEYWORD. */
247 int saw_keyword; 241 int saw_keyword;
248}; 242};
@@ -251,9 +245,7 @@ struct rcsoc_state
251 spaces are output first. */ 245 spaces are output first. */
252 246
253static INLINE void 247static INLINE void
254put_char (ch, state) 248put_char (int ch, struct rcsoc_state *state)
255 int ch;
256 struct rcsoc_state *state;
257{ 249{
258 int out_ch; 250 int out_ch;
259 do 251 do
@@ -286,9 +278,7 @@ put_char (ch, state)
286 keyword, but were in fact not. */ 278 keyword, but were in fact not. */
287 279
288static void 280static void
289scan_keyword_or_put_char (ch, state) 281scan_keyword_or_put_char (int ch, struct rcsoc_state *state)
290 int ch;
291 struct rcsoc_state *state;
292{ 282{
293 if (state->keyword 283 if (state->keyword
294 && *state->cur_keyword_ptr == ch 284 && *state->cur_keyword_ptr == ch
@@ -336,7 +326,7 @@ scan_keyword_or_put_char (ch, state)
336 keyword, but it was a false alarm. Output the 326 keyword, but it was a false alarm. Output the
337 part we scanned. */ 327 part we scanned. */
338 { 328 {
339 char *p; 329 const char *p;
340 330
341 for (p = state->keyword; p < state->cur_keyword_ptr; p++) 331 for (p = state->keyword; p < state->cur_keyword_ptr; p++)
342 put_char (*p, state); 332 put_char (*p, state);
@@ -359,11 +349,7 @@ scan_keyword_or_put_char (ch, state)
359 true if any were encountered. */ 349 true if any were encountered. */
360 350
361int 351int
362read_c_string_or_comment (infile, printflag, comment, saw_usage) 352read_c_string_or_comment (FILE *infile, int printflag, int comment, int *saw_usage)
363 FILE *infile;
364 int printflag;
365 int *saw_usage;
366 int comment;
367{ 353{
368 register int c; 354 register int c;
369 struct rcsoc_state state; 355 struct rcsoc_state state;
@@ -451,15 +437,12 @@ read_c_string_or_comment (infile, printflag, comment, saw_usage)
451 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ 437 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
452 438
453void 439void
454write_c_args (out, func, buf, minargs, maxargs) 440write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
455 FILE *out;
456 char *func, *buf;
457 int minargs, maxargs;
458{ 441{
459 register char *p; 442 register char *p;
460 int in_ident = 0; 443 int in_ident = 0;
461 int just_spaced = 0; 444 char *ident_start;
462 int need_space = 1; 445 int ident_length = 0;
463 446
464 fprintf (out, "(fn"); 447 fprintf (out, "(fn");
465 448
@@ -469,9 +452,8 @@ write_c_args (out, func, buf, minargs, maxargs)
469 for (p = buf; *p; p++) 452 for (p = buf; *p; p++)
470 { 453 {
471 char c = *p; 454 char c = *p;
472 int ident_start = 0;
473 455
474 /* Notice when we start printing a new identifier. */ 456 /* Notice when a new identifier starts. */
475 if ((('A' <= c && c <= 'Z') 457 if ((('A' <= c && c <= 'Z')
476 || ('a' <= c && c <= 'z') 458 || ('a' <= c && c <= 'z')
477 || ('0' <= c && c <= '9') 459 || ('0' <= c && c <= '9')
@@ -481,55 +463,56 @@ write_c_args (out, func, buf, minargs, maxargs)
481 if (!in_ident) 463 if (!in_ident)
482 { 464 {
483 in_ident = 1; 465 in_ident = 1;
484 ident_start = 1; 466 ident_start = p;
485
486 if (need_space)
487 putc (' ', out);
488
489 if (minargs == 0 && maxargs > 0)
490 fprintf (out, "&optional ");
491 just_spaced = 1;
492
493 minargs--;
494 maxargs--;
495 } 467 }
496 else 468 else
497 in_ident = 0; 469 {
470 in_ident = 0;
471 ident_length = p - ident_start;
472 }
498 } 473 }
499 474
500 /* Print the C argument list as it would appear in lisp: 475 /* Found the end of an argument, write out the last seen
501 print underscores as hyphens, and print commas and newlines 476 identifier. */
502 as spaces. Collapse adjacent spaces into one. */ 477 if (c == ',' || c == ')')
503 if (c == '_')
504 c = '-';
505 else if (c == ',' || c == '\n')
506 c = ' ';
507
508 /* In C code, `default' is a reserved word, so we spell it
509 `defalt'; unmangle that here. */
510 if (ident_start
511 && strncmp (p, "defalt", 6) == 0
512 && ! (('A' <= p[6] && p[6] <= 'Z')
513 || ('a' <= p[6] && p[6] <= 'z')
514 || ('0' <= p[6] && p[6] <= '9')
515 || p[6] == '_'))
516 { 478 {
517 fprintf (out, "DEFAULT"); 479 if (ident_length == 0)
518 p += 5; 480 {
519 in_ident = 0; 481 error ("empty arg list for `%s' should be (void), not ()", func);
520 just_spaced = 0; 482 continue;
521 } 483 }
522 else if (c != ' ' || !just_spaced) 484
523 { 485 if (strncmp (ident_start, "void", ident_length) == 0)
524 if (c >= 'a' && c <= 'z') 486 continue;
525 /* Upcase the letter. */ 487
526 c += 'A' - 'a'; 488 putc (' ', out);
527 putc (c, out); 489
528 } 490 if (minargs == 0 && maxargs > 0)
491 fprintf (out, "&optional ");
529 492
530 just_spaced = c == ' '; 493 minargs--;
531 need_space = 0; 494 maxargs--;
495
496 /* In C code, `default' is a reserved word, so we spell it
497 `defalt'; unmangle that here. */
498 if (ident_length == 6 && strncmp (ident_start, "defalt", 6) == 0)
499 fprintf (out, "DEFAULT");
500 else
501 while (ident_length-- > 0)
502 {
503 c = *ident_start++;
504 if (c >= 'a' && c <= 'z')
505 /* Upcase the letter. */
506 c += 'A' - 'a';
507 else if (c == '_')
508 /* Print underscore as hyphen. */
509 c = '-';
510 putc (c, out);
511 }
512 }
532 } 513 }
514
515 putc (')', out);
533} 516}
534 517
535/* Read through a c file. If a .o file is named, 518/* Read through a c file. If a .o file is named,
@@ -538,8 +521,7 @@ write_c_args (out, func, buf, minargs, maxargs)
538 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ 521 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
539 522
540int 523int
541scan_c_file (filename, mode) 524scan_c_file (char *filename, const char *mode)
542 char *filename, *mode;
543{ 525{
544 FILE *infile; 526 FILE *infile;
545 register int c; 527 register int c;
@@ -815,8 +797,7 @@ scan_c_file (filename, mode)
815 */ 797 */
816 798
817void 799void
818skip_white (infile) 800skip_white (FILE *infile)
819 FILE *infile;
820{ 801{
821 char c = ' '; 802 char c = ' ';
822 while (c == ' ' || c == '\t' || c == '\n' || c == '\r') 803 while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
@@ -825,9 +806,7 @@ skip_white (infile)
825} 806}
826 807
827void 808void
828read_lisp_symbol (infile, buffer) 809read_lisp_symbol (FILE *infile, char *buffer)
829 FILE *infile;
830 char *buffer;
831{ 810{
832 char c; 811 char c;
833 char *fillp = buffer; 812 char *fillp = buffer;
@@ -855,8 +834,7 @@ read_lisp_symbol (infile, buffer)
855} 834}
856 835
857int 836int
858scan_lisp_file (filename, mode) 837scan_lisp_file (const char *filename, const char *mode)
859 char *filename, *mode;
860{ 838{
861 FILE *infile; 839 FILE *infile;
862 register int c; 840 register int c;