(ispell-insert-word): Revert previous change.
[emacs.git] / lib-src / make-docfile.c
blob1f5dff29fb483f55c5de23b37c35b53c930d25cc
1 /* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1997, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* The arguments given to this program are all the C and Lisp source files
24 of GNU Emacs. .elc and .el and .c files are allowed.
25 A .o file can also be specified; the .c file it was made from is used.
26 This helps the makefile pass the correct list of files.
27 Option -d DIR means change to DIR before looking for files.
29 The results, which go to standard output or to a file
30 specified with -a or -o (-a to append, -o to start from nothing),
31 are entries containing function or variable names and their documentation.
32 Each entry starts with a ^_ character.
33 Then comes F for a function or V for a variable.
34 Then comes the function or variable name, terminated with a newline.
35 Then comes the documentation for that function or variable.
38 #include <config.h>
40 /* defined to be emacs_main, sys_fopen, etc. in config.h */
41 #undef main
42 #undef fopen
43 #undef chdir
45 #include <stdio.h>
46 #ifdef MSDOS
47 #include <fcntl.h>
48 #endif /* MSDOS */
49 #ifdef WINDOWSNT
50 #include <stdlib.h>
51 #include <fcntl.h>
52 #include <direct.h>
53 #endif /* WINDOWSNT */
55 #ifdef DOS_NT
56 #define READ_TEXT "rt"
57 #define READ_BINARY "rb"
58 #else /* not DOS_NT */
59 #define READ_TEXT "r"
60 #define READ_BINARY "r"
61 #endif /* not DOS_NT */
63 #ifndef DIRECTORY_SEP
64 #define DIRECTORY_SEP '/'
65 #endif
67 #ifndef IS_DIRECTORY_SEP
68 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
69 #endif
71 int scan_file ();
72 int scan_lisp_file ();
73 int scan_c_file ();
75 #ifdef MSDOS
76 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
77 file where that function is defined. */
78 #undef chdir
79 #endif
81 #ifdef HAVE_UNISTD_H
82 #include <unistd.h>
83 #endif
85 /* Stdio stream for output to the DOC file. */
86 FILE *outfile;
88 /* Name this program was invoked with. */
89 char *progname;
91 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
93 /* VARARGS1 */
94 void
95 error (s1, s2)
96 char *s1, *s2;
98 fprintf (stderr, "%s: ", progname);
99 fprintf (stderr, s1, s2);
100 fprintf (stderr, "\n");
103 /* Print error message and exit. */
105 /* VARARGS1 */
106 void
107 fatal (s1, s2)
108 char *s1, *s2;
110 error (s1, s2);
111 exit (EXIT_FAILURE);
114 /* Like malloc but get fatal error if memory is exhausted. */
116 void *
117 xmalloc (size)
118 unsigned int size;
120 void *result = (void *) malloc (size);
121 if (result == NULL)
122 fatal ("virtual memory exhausted", 0);
123 return result;
127 main (argc, argv)
128 int argc;
129 char **argv;
131 int i;
132 int err_count = 0;
133 int first_infile;
135 progname = argv[0];
137 outfile = stdout;
139 /* Don't put CRs in the DOC file. */
140 #ifdef MSDOS
141 _fmode = O_BINARY;
142 #if 0 /* Suspicion is that this causes hanging.
143 So instead we require people to use -o on MSDOS. */
144 (stdout)->_flag &= ~_IOTEXT;
145 _setmode (fileno (stdout), O_BINARY);
146 #endif
147 outfile = 0;
148 #endif /* MSDOS */
149 #ifdef WINDOWSNT
150 _fmode = O_BINARY;
151 _setmode (fileno (stdout), O_BINARY);
152 #endif /* WINDOWSNT */
154 /* If first two args are -o FILE, output to FILE. */
155 i = 1;
156 if (argc > i + 1 && !strcmp (argv[i], "-o"))
158 outfile = fopen (argv[i + 1], "w");
159 i += 2;
161 if (argc > i + 1 && !strcmp (argv[i], "-a"))
163 outfile = fopen (argv[i + 1], "a");
164 i += 2;
166 if (argc > i + 1 && !strcmp (argv[i], "-d"))
168 chdir (argv[i + 1]);
169 i += 2;
172 if (outfile == 0)
173 fatal ("No output file specified", "");
175 first_infile = i;
176 for (; i < argc; i++)
178 int j;
179 /* Don't process one file twice. */
180 for (j = first_infile; j < i; j++)
181 if (! strcmp (argv[i], argv[j]))
182 break;
183 if (j == i)
184 err_count += scan_file (argv[i]);
186 return (err_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
189 /* Add a source file name boundary marker in the output file. */
190 void
191 put_filename (filename)
192 char *filename;
194 char *tmp;
196 for (tmp = filename; *tmp; tmp++)
198 if (IS_DIRECTORY_SEP(*tmp))
199 filename = tmp + 1;
202 putc (037, outfile);
203 putc ('S', outfile);
204 fprintf (outfile, "%s\n", filename);
207 /* Read file FILENAME and output its doc strings to outfile. */
208 /* Return 1 if file is not found, 0 if it is found. */
211 scan_file (filename)
212 char *filename;
214 int len = strlen (filename);
216 put_filename (filename);
217 if (len > 4 && !strcmp (filename + len - 4, ".elc"))
218 return scan_lisp_file (filename, READ_BINARY);
219 else if (len > 3 && !strcmp (filename + len - 3, ".el"))
220 return scan_lisp_file (filename, READ_TEXT);
221 else
222 return scan_c_file (filename, READ_TEXT);
225 char buf[128];
227 /* Some state during the execution of `read_c_string_or_comment'. */
228 struct rcsoc_state
230 /* A count of spaces and newlines that have been read, but not output. */
231 unsigned pending_spaces, pending_newlines;
233 /* Where we're reading from. */
234 FILE *in_file;
236 /* If non-zero, a buffer into which to copy characters. */
237 char *buf_ptr;
238 /* If non-zero, a file into which to copy characters. */
239 FILE *out_file;
241 /* A keyword we look for at the beginning of lines. If found, it is
242 not copied, and SAW_KEYWORD is set to true. */
243 char *keyword;
244 /* The current point we've reached in an occurance of KEYWORD in
245 the input stream. */
246 char *cur_keyword_ptr;
247 /* Set to true if we saw an occurance of KEYWORD. */
248 int saw_keyword;
251 /* Output CH to the file or buffer in STATE. Any pending newlines or
252 spaces are output first. */
254 static INLINE void
255 put_char (ch, state)
256 int ch;
257 struct rcsoc_state *state;
259 int out_ch;
262 if (state->pending_newlines > 0)
264 state->pending_newlines--;
265 out_ch = '\n';
267 else if (state->pending_spaces > 0)
269 state->pending_spaces--;
270 out_ch = ' ';
272 else
273 out_ch = ch;
275 if (state->out_file)
276 putc (out_ch, state->out_file);
277 if (state->buf_ptr)
278 *state->buf_ptr++ = out_ch;
280 while (out_ch != ch);
283 /* If in the middle of scanning a keyword, continue scanning with
284 character CH, otherwise output CH to the file or buffer in STATE.
285 Any pending newlines or spaces are output first, as well as any
286 previously scanned characters that were thought to be part of a
287 keyword, but were in fact not. */
289 static void
290 scan_keyword_or_put_char (ch, state)
291 int ch;
292 struct rcsoc_state *state;
294 if (state->keyword
295 && *state->cur_keyword_ptr == ch
296 && (state->cur_keyword_ptr > state->keyword
297 || state->pending_newlines > 0))
298 /* We might be looking at STATE->keyword at some point.
299 Keep looking until we know for sure. */
301 if (*++state->cur_keyword_ptr == '\0')
302 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
304 state->saw_keyword = 1;
306 /* Reset the scanning pointer. */
307 state->cur_keyword_ptr = state->keyword;
309 /* Canonicalize whitespace preceding a usage string. */
310 state->pending_newlines = 2;
311 state->pending_spaces = 0;
313 /* Skip any whitespace between the keyword and the
314 usage string. */
316 ch = getc (state->in_file);
317 while (ch == ' ' || ch == '\n');
319 /* Output the open-paren we just read. */
320 put_char (ch, state);
322 /* Skip the function name and replace it with `fn'. */
324 ch = getc (state->in_file);
325 while (ch != ' ' && ch != ')');
326 put_char ('f', state);
327 put_char ('n', state);
329 /* Put back the last character. */
330 ungetc (ch, state->in_file);
333 else
335 if (state->keyword && state->cur_keyword_ptr > state->keyword)
336 /* We scanned the beginning of a potential usage
337 keyword, but it was a false alarm. Output the
338 part we scanned. */
340 char *p;
342 for (p = state->keyword; p < state->cur_keyword_ptr; p++)
343 put_char (*p, state);
345 state->cur_keyword_ptr = state->keyword;
348 put_char (ch, state);
353 /* Skip a C string or C-style comment from INFILE, and return the
354 character that follows. COMMENT non-zero means skip a comment. If
355 PRINTFLAG is positive, output string contents to outfile. If it is
356 negative, store contents in buf. Convert escape sequences \n and
357 \t to newline and tab; discard \ followed by newline.
358 If SAW_USAGE is non-zero, then any occurances of the string `usage:'
359 at the beginning of a line will be removed, and *SAW_USAGE set to
360 true if any were encountered. */
363 read_c_string_or_comment (infile, printflag, comment, saw_usage)
364 FILE *infile;
365 int printflag;
366 int *saw_usage;
367 int comment;
369 register int c;
370 struct rcsoc_state state;
372 state.in_file = infile;
373 state.buf_ptr = (printflag < 0 ? buf : 0);
374 state.out_file = (printflag > 0 ? outfile : 0);
375 state.pending_spaces = 0;
376 state.pending_newlines = 0;
377 state.keyword = (saw_usage ? "usage:" : 0);
378 state.cur_keyword_ptr = state.keyword;
379 state.saw_keyword = 0;
381 c = getc (infile);
382 if (comment)
383 while (c == '\n' || c == '\r' || c == '\t' || c == ' ')
384 c = getc (infile);
386 while (c != EOF)
388 while (c != EOF && (comment ? c != '*' : c != '"'))
390 if (c == '\\')
392 c = getc (infile);
393 if (c == '\n' || c == '\r')
395 c = getc (infile);
396 continue;
398 if (c == 'n')
399 c = '\n';
400 if (c == 't')
401 c = '\t';
404 if (c == ' ')
405 state.pending_spaces++;
406 else if (c == '\n')
408 state.pending_newlines++;
409 state.pending_spaces = 0;
411 else
412 scan_keyword_or_put_char (c, &state);
414 c = getc (infile);
417 if (c != EOF)
418 c = getc (infile);
420 if (comment)
422 if (c == '/')
424 c = getc (infile);
425 break;
428 scan_keyword_or_put_char ('*', &state);
430 else
432 if (c != '"')
433 break;
435 /* If we had a "", concatenate the two strings. */
436 c = getc (infile);
440 if (printflag < 0)
441 *state.buf_ptr = 0;
443 if (saw_usage)
444 *saw_usage = state.saw_keyword;
446 return c;
451 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
452 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
454 void
455 write_c_args (out, func, buf, minargs, maxargs)
456 FILE *out;
457 char *func, *buf;
458 int minargs, maxargs;
460 register char *p;
461 int in_ident = 0;
462 int just_spaced = 0;
463 int need_space = 1;
465 fprintf (out, "(fn");
467 if (*buf == '(')
468 ++buf;
470 for (p = buf; *p; p++)
472 char c = *p;
473 int ident_start = 0;
475 /* Notice when we start printing a new identifier. */
476 if ((('A' <= c && c <= 'Z')
477 || ('a' <= c && c <= 'z')
478 || ('0' <= c && c <= '9')
479 || c == '_')
480 != in_ident)
482 if (!in_ident)
484 in_ident = 1;
485 ident_start = 1;
487 if (need_space)
488 putc (' ', out);
490 if (minargs == 0 && maxargs > 0)
491 fprintf (out, "&optional ");
492 just_spaced = 1;
494 minargs--;
495 maxargs--;
497 else
498 in_ident = 0;
501 /* Print the C argument list as it would appear in lisp:
502 print underscores as hyphens, and print commas and newlines
503 as spaces. Collapse adjacent spaces into one. */
504 if (c == '_')
505 c = '-';
506 else if (c == ',' || c == '\n')
507 c = ' ';
509 /* In C code, `default' is a reserved word, so we spell it
510 `defalt'; unmangle that here. */
511 if (ident_start
512 && strncmp (p, "defalt", 6) == 0
513 && ! (('A' <= p[6] && p[6] <= 'Z')
514 || ('a' <= p[6] && p[6] <= 'z')
515 || ('0' <= p[6] && p[6] <= '9')
516 || p[6] == '_'))
518 fprintf (out, "DEFAULT");
519 p += 5;
520 in_ident = 0;
521 just_spaced = 0;
523 else if (c != ' ' || !just_spaced)
525 if (c >= 'a' && c <= 'z')
526 /* Upcase the letter. */
527 c += 'A' - 'a';
528 putc (c, out);
531 just_spaced = c == ' ';
532 need_space = 0;
536 /* Read through a c file. If a .o file is named,
537 the corresponding .c file is read instead.
538 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
539 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
542 scan_c_file (filename, mode)
543 char *filename, *mode;
545 FILE *infile;
546 register int c;
547 register int commas;
548 register int defunflag;
549 register int defvarperbufferflag;
550 register int defvarflag;
551 int minargs, maxargs;
552 int extension = filename[strlen (filename) - 1];
554 if (extension == 'o')
555 filename[strlen (filename) - 1] = 'c';
557 infile = fopen (filename, mode);
559 /* No error if non-ex input file */
560 if (infile == NULL)
562 perror (filename);
563 return 0;
566 /* Reset extension to be able to detect duplicate files. */
567 filename[strlen (filename) - 1] = extension;
569 c = '\n';
570 while (!feof (infile))
572 int doc_keyword = 0;
574 if (c != '\n' && c != '\r')
576 c = getc (infile);
577 continue;
579 c = getc (infile);
580 if (c == ' ')
582 while (c == ' ')
583 c = getc (infile);
584 if (c != 'D')
585 continue;
586 c = getc (infile);
587 if (c != 'E')
588 continue;
589 c = getc (infile);
590 if (c != 'F')
591 continue;
592 c = getc (infile);
593 if (c != 'V')
594 continue;
595 c = getc (infile);
596 if (c != 'A')
597 continue;
598 c = getc (infile);
599 if (c != 'R')
600 continue;
601 c = getc (infile);
602 if (c != '_')
603 continue;
605 defvarflag = 1;
606 defunflag = 0;
608 c = getc (infile);
609 defvarperbufferflag = (c == 'P');
611 c = getc (infile);
613 else if (c == 'D')
615 c = getc (infile);
616 if (c != 'E')
617 continue;
618 c = getc (infile);
619 if (c != 'F')
620 continue;
621 c = getc (infile);
622 defunflag = c == 'U';
623 defvarflag = 0;
624 defvarperbufferflag = 0;
626 else continue;
628 while (c != '(')
630 if (c < 0)
631 goto eof;
632 c = getc (infile);
635 /* Lisp variable or function name. */
636 c = getc (infile);
637 if (c != '"')
638 continue;
639 c = read_c_string_or_comment (infile, -1, 0, 0);
641 /* DEFVAR_LISP ("name", addr, "doc")
642 DEFVAR_LISP ("name", addr /\* doc *\/)
643 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
645 if (defunflag)
646 commas = 5;
647 else if (defvarperbufferflag)
648 commas = 2;
649 else if (defvarflag)
650 commas = 1;
651 else /* For DEFSIMPLE and DEFPRED */
652 commas = 2;
654 while (commas)
656 if (c == ',')
658 commas--;
660 if (defunflag && (commas == 1 || commas == 2))
663 c = getc (infile);
664 while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
665 if (c < 0)
666 goto eof;
667 ungetc (c, infile);
668 if (commas == 2) /* pick up minargs */
669 fscanf (infile, "%d", &minargs);
670 else /* pick up maxargs */
671 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
672 maxargs = -1;
673 else
674 fscanf (infile, "%d", &maxargs);
678 if (c == EOF)
679 goto eof;
680 c = getc (infile);
683 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
684 c = getc (infile);
686 if (c == '"')
687 c = read_c_string_or_comment (infile, 0, 0, 0);
689 while (c != EOF && c != ',' && c != '/')
690 c = getc (infile);
691 if (c == ',')
693 c = getc (infile);
694 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
695 c = getc (infile);
696 while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z'))
697 c = getc (infile);
698 if (c == ':')
700 doc_keyword = 1;
701 c = getc (infile);
702 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
703 c = getc (infile);
707 if (c == '"'
708 || (c == '/'
709 && (c = getc (infile),
710 ungetc (c, infile),
711 c == '*')))
713 int comment = c != '"';
714 int saw_usage;
716 putc (037, outfile);
717 putc (defvarflag ? 'V' : 'F', outfile);
718 fprintf (outfile, "%s\n", buf);
720 if (comment)
721 getc (infile); /* Skip past `*' */
722 c = read_c_string_or_comment (infile, 1, comment, &saw_usage);
724 /* If this is a defun, find the arguments and print them. If
725 this function takes MANY or UNEVALLED args, then the C source
726 won't give the names of the arguments, so we shouldn't bother
727 trying to find them.
729 Various doc-string styles:
730 0: DEFUN (..., "DOC") (args) [!comment]
731 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
732 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
734 if (defunflag && maxargs != -1 && !saw_usage)
736 char argbuf[1024], *p = argbuf;
738 if (!comment || doc_keyword)
739 while (c != ')')
741 if (c < 0)
742 goto eof;
743 c = getc (infile);
746 /* Skip into arguments. */
747 while (c != '(')
749 if (c < 0)
750 goto eof;
751 c = getc (infile);
753 /* Copy arguments into ARGBUF. */
754 *p++ = c;
756 *p++ = c = getc (infile);
757 while (c != ')');
758 *p = '\0';
759 /* Output them. */
760 fprintf (outfile, "\n\n");
761 write_c_args (outfile, buf, argbuf, minargs, maxargs);
763 else if (defunflag && maxargs == -1 && !saw_usage)
764 /* The DOC should provide the usage form. */
765 fprintf (stderr, "Missing `usage' for function `%s'.\n", buf);
768 eof:
769 fclose (infile);
770 return 0;
773 /* Read a file of Lisp code, compiled or interpreted.
774 Looks for
775 (defun NAME ARGS DOCSTRING ...)
776 (defmacro NAME ARGS DOCSTRING ...)
777 (defsubst NAME ARGS DOCSTRING ...)
778 (autoload (quote NAME) FILE DOCSTRING ...)
779 (defvar NAME VALUE DOCSTRING)
780 (defconst NAME VALUE DOCSTRING)
781 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
782 (fset (quote NAME) #[... DOCSTRING ...])
783 (defalias (quote NAME) #[... DOCSTRING ...])
784 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
785 starting in column zero.
786 (quote NAME) may appear as 'NAME as well.
788 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
789 When we find that, we save it for the following defining-form,
790 and we use that instead of reading a doc string within that defining-form.
792 For defvar, defconst, and fset we skip to the docstring with a kludgy
793 formatting convention: all docstrings must appear on the same line as the
794 initial open-paren (the one in column zero) and must contain a backslash
795 and a newline immediately after the initial double-quote. No newlines
796 must appear between the beginning of the form and the first double-quote.
797 For defun, defmacro, and autoload, we know how to skip over the
798 arglist, but the doc string must still have a backslash and newline
799 immediately after the double quote.
800 The only source files that must follow this convention are preloaded
801 uncompiled ones like loaddefs.el and bindings.el; aside
802 from that, it is always the .elc file that we look at, and they are no
803 problem because byte-compiler output follows this convention.
804 The NAME and DOCSTRING are output.
805 NAME is preceded by `F' for a function or `V' for a variable.
806 An entry is output only if DOCSTRING has \ newline just after the opening "
809 void
810 skip_white (infile)
811 FILE *infile;
813 char c = ' ';
814 while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
815 c = getc (infile);
816 ungetc (c, infile);
819 void
820 read_lisp_symbol (infile, buffer)
821 FILE *infile;
822 char *buffer;
824 char c;
825 char *fillp = buffer;
827 skip_white (infile);
828 while (1)
830 c = getc (infile);
831 if (c == '\\')
832 *(++fillp) = getc (infile);
833 else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')')
835 ungetc (c, infile);
836 *fillp = 0;
837 break;
839 else
840 *fillp++ = c;
843 if (! buffer[0])
844 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
846 skip_white (infile);
850 scan_lisp_file (filename, mode)
851 char *filename, *mode;
853 FILE *infile;
854 register int c;
855 char *saved_string = 0;
857 infile = fopen (filename, mode);
858 if (infile == NULL)
860 perror (filename);
861 return 0; /* No error */
864 c = '\n';
865 while (!feof (infile))
867 char buffer[BUFSIZ];
868 char type;
870 /* If not at end of line, skip till we get to one. */
871 if (c != '\n' && c != '\r')
873 c = getc (infile);
874 continue;
876 /* Skip the line break. */
877 while (c == '\n' || c == '\r')
878 c = getc (infile);
879 /* Detect a dynamic doc string and save it for the next expression. */
880 if (c == '#')
882 c = getc (infile);
883 if (c == '@')
885 int length = 0;
886 int i;
888 /* Read the length. */
889 while ((c = getc (infile),
890 c >= '0' && c <= '9'))
892 length *= 10;
893 length += c - '0';
896 /* The next character is a space that is counted in the length
897 but not part of the doc string.
898 We already read it, so just ignore it. */
899 length--;
901 /* Read in the contents. */
902 if (saved_string != 0)
903 free (saved_string);
904 saved_string = (char *) malloc (length);
905 for (i = 0; i < length; i++)
906 saved_string[i] = getc (infile);
907 /* The last character is a ^_.
908 That is needed in the .elc file
909 but it is redundant in DOC. So get rid of it here. */
910 saved_string[length - 1] = 0;
911 /* Skip the line break. */
912 while (c == '\n' && c == '\r')
913 c = getc (infile);
914 /* Skip the following line. */
915 while (c != '\n' && c != '\r')
916 c = getc (infile);
918 continue;
921 if (c != '(')
922 continue;
924 read_lisp_symbol (infile, buffer);
926 if (! strcmp (buffer, "defun")
927 || ! strcmp (buffer, "defmacro")
928 || ! strcmp (buffer, "defsubst"))
930 type = 'F';
931 read_lisp_symbol (infile, buffer);
933 /* Skip the arguments: either "nil" or a list in parens */
935 c = getc (infile);
936 if (c == 'n') /* nil */
938 if ((c = getc (infile)) != 'i'
939 || (c = getc (infile)) != 'l')
941 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
942 buffer, filename);
943 continue;
946 else if (c != '(')
948 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
949 buffer, filename);
950 continue;
952 else
953 while (c != ')')
954 c = getc (infile);
955 skip_white (infile);
957 /* If the next three characters aren't `dquote bslash newline'
958 then we're not reading a docstring.
960 if ((c = getc (infile)) != '"'
961 || (c = getc (infile)) != '\\'
962 || ((c = getc (infile)) != '\n' && c != '\r'))
964 #ifdef DEBUG
965 fprintf (stderr, "## non-docstring in %s (%s)\n",
966 buffer, filename);
967 #endif
968 continue;
972 else if (! strcmp (buffer, "defvar")
973 || ! strcmp (buffer, "defconst"))
975 char c1 = 0, c2 = 0;
976 type = 'V';
977 read_lisp_symbol (infile, buffer);
979 if (saved_string == 0)
982 /* Skip until the end of line; remember two previous chars. */
983 while (c != '\n' && c != '\r' && c >= 0)
985 c2 = c1;
986 c1 = c;
987 c = getc (infile);
990 /* If two previous characters were " and \,
991 this is a doc string. Otherwise, there is none. */
992 if (c2 != '"' || c1 != '\\')
994 #ifdef DEBUG
995 fprintf (stderr, "## non-docstring in %s (%s)\n",
996 buffer, filename);
997 #endif
998 continue;
1003 else if (! strcmp (buffer, "custom-declare-variable"))
1005 char c1 = 0, c2 = 0;
1006 type = 'V';
1008 c = getc (infile);
1009 if (c == '\'')
1010 read_lisp_symbol (infile, buffer);
1011 else
1013 if (c != '(')
1015 fprintf (stderr,
1016 "## unparsable name in custom-declare-variable in %s\n",
1017 filename);
1018 continue;
1020 read_lisp_symbol (infile, buffer);
1021 if (strcmp (buffer, "quote"))
1023 fprintf (stderr,
1024 "## unparsable name in custom-declare-variable in %s\n",
1025 filename);
1026 continue;
1028 read_lisp_symbol (infile, buffer);
1029 c = getc (infile);
1030 if (c != ')')
1032 fprintf (stderr,
1033 "## unparsable quoted name in custom-declare-variable in %s\n",
1034 filename);
1035 continue;
1039 if (saved_string == 0)
1041 /* Skip to end of line; remember the two previous chars. */
1042 while (c != '\n' && c != '\r' && c >= 0)
1044 c2 = c1;
1045 c1 = c;
1046 c = getc (infile);
1049 /* If two previous characters were " and \,
1050 this is a doc string. Otherwise, there is none. */
1051 if (c2 != '"' || c1 != '\\')
1053 #ifdef DEBUG
1054 fprintf (stderr, "## non-docstring in %s (%s)\n",
1055 buffer, filename);
1056 #endif
1057 continue;
1062 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
1064 char c1 = 0, c2 = 0;
1065 type = 'F';
1067 c = getc (infile);
1068 if (c == '\'')
1069 read_lisp_symbol (infile, buffer);
1070 else
1072 if (c != '(')
1074 fprintf (stderr, "## unparsable name in fset in %s\n",
1075 filename);
1076 continue;
1078 read_lisp_symbol (infile, buffer);
1079 if (strcmp (buffer, "quote"))
1081 fprintf (stderr, "## unparsable name in fset in %s\n",
1082 filename);
1083 continue;
1085 read_lisp_symbol (infile, buffer);
1086 c = getc (infile);
1087 if (c != ')')
1089 fprintf (stderr,
1090 "## unparsable quoted name in fset in %s\n",
1091 filename);
1092 continue;
1096 if (saved_string == 0)
1098 /* Skip to end of line; remember the two previous chars. */
1099 while (c != '\n' && c != '\r' && c >= 0)
1101 c2 = c1;
1102 c1 = c;
1103 c = getc (infile);
1106 /* If two previous characters were " and \,
1107 this is a doc string. Otherwise, there is none. */
1108 if (c2 != '"' || c1 != '\\')
1110 #ifdef DEBUG
1111 fprintf (stderr, "## non-docstring in %s (%s)\n",
1112 buffer, filename);
1113 #endif
1114 continue;
1119 else if (! strcmp (buffer, "autoload"))
1121 type = 'F';
1122 c = getc (infile);
1123 if (c == '\'')
1124 read_lisp_symbol (infile, buffer);
1125 else
1127 if (c != '(')
1129 fprintf (stderr, "## unparsable name in autoload in %s\n",
1130 filename);
1131 continue;
1133 read_lisp_symbol (infile, buffer);
1134 if (strcmp (buffer, "quote"))
1136 fprintf (stderr, "## unparsable name in autoload in %s\n",
1137 filename);
1138 continue;
1140 read_lisp_symbol (infile, buffer);
1141 c = getc (infile);
1142 if (c != ')')
1144 fprintf (stderr,
1145 "## unparsable quoted name in autoload in %s\n",
1146 filename);
1147 continue;
1150 skip_white (infile);
1151 if ((c = getc (infile)) != '\"')
1153 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
1154 buffer, filename);
1155 continue;
1157 read_c_string_or_comment (infile, 0, 0, 0);
1158 skip_white (infile);
1160 if (saved_string == 0)
1162 /* If the next three characters aren't `dquote bslash newline'
1163 then we're not reading a docstring. */
1164 if ((c = getc (infile)) != '"'
1165 || (c = getc (infile)) != '\\'
1166 || ((c = getc (infile)) != '\n' && c != '\r'))
1168 #ifdef DEBUG
1169 fprintf (stderr, "## non-docstring in %s (%s)\n",
1170 buffer, filename);
1171 #endif
1172 continue;
1177 #ifdef DEBUG
1178 else if (! strcmp (buffer, "if")
1179 || ! strcmp (buffer, "byte-code"))
1181 #endif
1183 else
1185 #ifdef DEBUG
1186 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n",
1187 buffer, filename);
1188 #endif
1189 continue;
1192 /* At this point, we should either use the previous
1193 dynamic doc string in saved_string
1194 or gobble a doc string from the input file.
1196 In the latter case, the opening quote (and leading
1197 backslash-newline) have already been read. */
1199 putc (037, outfile);
1200 putc (type, outfile);
1201 fprintf (outfile, "%s\n", buffer);
1202 if (saved_string)
1204 fputs (saved_string, outfile);
1205 /* Don't use one dynamic doc string twice. */
1206 free (saved_string);
1207 saved_string = 0;
1209 else
1210 read_c_string_or_comment (infile, 1, 0, 0);
1212 fclose (infile);
1213 return 0;
1216 /* arch-tag: f7203aaf-991a-4238-acb5-601db56f2894
1217 (do not change this comment) */
1219 /* make-docfile.c ends here */