1 /* Generate doc-string file for GNU Emacs from source files.
3 Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2012
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 of the License, or
11 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
22 /* The arguments given to this program are all the C and Lisp source files
23 of GNU Emacs. .elc and .el and .c files are allowed.
24 A .o file can also be specified; the .c file it was made from is used.
25 This helps the makefile pass the correct list of files.
26 Option -d DIR means change to DIR before looking for files.
28 The results, which go to standard output or to a file
29 specified with -a or -o (-a to append, -o to start from nothing),
30 are entries containing function or variable names and their documentation.
31 Each entry starts with a ^_ character.
32 Then comes F for a function or V for a variable.
33 Then comes the function or variable name, terminated with a newline.
34 Then comes the documentation for that function or variable.
39 /* Defined to be emacs_main, sys_fopen, etc. in config.h. */
40 /* FIXME Not for ages? */
46 #include <stdlib.h> /* FIXME config.h unconditionally includes this */
53 #endif /* WINDOWSNT */
56 #define READ_TEXT "rt"
57 #define READ_BINARY "rb"
58 #else /* not DOS_NT */
60 #define READ_BINARY "r"
61 #endif /* not DOS_NT */
63 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
65 # define IF_LINT(Code) Code
67 # define IF_LINT(Code) /* empty */
70 static int scan_file (char *filename
);
71 static int scan_lisp_file (const char *filename
, const char *mode
);
72 static int scan_c_file (char *filename
, const char *mode
);
73 static void start_globals (void);
74 static void write_globals (void);
76 /* FIXME msdos does not define this any more, and in any case we
77 undefined it for everyone just above. */
79 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
80 file where that function is defined. */
86 /* Stdio stream for output to the DOC file. */
89 /* Name this program was invoked with. */
92 /* Nonzero if this invocation is generating globals.h. */
95 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
99 error (const char *s1
, const char *s2
)
101 fprintf (stderr
, "%s: ", progname
);
102 fprintf (stderr
, s1
, s2
);
103 fprintf (stderr
, "\n");
106 /* Print error message and exit. */
109 static _Noreturn
void
110 fatal (const char *s1
, const char *s2
)
116 /* Like malloc but get fatal error if memory is exhausted. */
119 xmalloc (unsigned int size
)
121 void *result
= (void *) malloc (size
);
123 fatal ("virtual memory exhausted", 0);
127 /* Like realloc but get fatal error if memory is exhausted. */
130 xrealloc (void *arg
, unsigned int size
)
132 void *result
= (void *) realloc (arg
, size
);
134 fatal ("virtual memory exhausted", 0);
140 main (int argc
, char **argv
)
150 /* Don't put CRs in the DOC file. */
153 #if 0 /* Suspicion is that this causes hanging.
154 So instead we require people to use -o on MSDOS. */
155 (stdout
)->_flag
&= ~_IOTEXT
;
156 _setmode (fileno (stdout
), O_BINARY
);
162 _setmode (fileno (stdout
), O_BINARY
);
163 #endif /* WINDOWSNT */
165 /* If first two args are -o FILE, output to FILE. */
167 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
169 outfile
= fopen (argv
[i
+ 1], "w");
172 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
174 outfile
= fopen (argv
[i
+ 1], "a");
177 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
179 if (chdir (argv
[i
+ 1]) != 0)
181 perror (argv
[i
+ 1]);
186 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
188 generate_globals
= 1;
193 fatal ("No output file specified", "");
195 if (generate_globals
)
199 for (; i
< argc
; i
++)
202 /* Don't process one file twice. */
203 for (j
= first_infile
; j
< i
; j
++)
204 if (! strcmp (argv
[i
], argv
[j
]))
207 err_count
+= scan_file (argv
[i
]);
210 if (err_count
== 0 && generate_globals
)
213 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
216 /* Add a source file name boundary marker in the output file. */
218 put_filename (char *filename
)
222 for (tmp
= filename
; *tmp
; tmp
++)
224 if (IS_DIRECTORY_SEP (*tmp
))
230 fprintf (outfile
, "%s\n", filename
);
233 /* Read file FILENAME and output its doc strings to outfile. */
234 /* Return 1 if file is not found, 0 if it is found. */
237 scan_file (char *filename
)
240 size_t len
= strlen (filename
);
242 if (!generate_globals
)
243 put_filename (filename
);
244 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
245 return scan_lisp_file (filename
, READ_BINARY
);
246 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
247 return scan_lisp_file (filename
, READ_TEXT
);
249 return scan_c_file (filename
, READ_TEXT
);
255 fprintf (outfile
, "/* This file was auto-generated by make-docfile. */\n");
256 fprintf (outfile
, "/* DO NOT EDIT. */\n");
257 fprintf (outfile
, "struct emacs_globals {\n");
260 static char input_buffer
[128];
262 /* Some state during the execution of `read_c_string_or_comment'. */
265 /* A count of spaces and newlines that have been read, but not output. */
266 unsigned pending_spaces
, pending_newlines
;
268 /* Where we're reading from. */
271 /* If non-zero, a buffer into which to copy characters. */
273 /* If non-zero, a file into which to copy characters. */
276 /* A keyword we look for at the beginning of lines. If found, it is
277 not copied, and SAW_KEYWORD is set to true. */
279 /* The current point we've reached in an occurrence of KEYWORD in
281 const char *cur_keyword_ptr
;
282 /* Set to true if we saw an occurrence of KEYWORD. */
286 /* Output CH to the file or buffer in STATE. Any pending newlines or
287 spaces are output first. */
290 put_char (int ch
, struct rcsoc_state
*state
)
295 if (state
->pending_newlines
> 0)
297 state
->pending_newlines
--;
300 else if (state
->pending_spaces
> 0)
302 state
->pending_spaces
--;
309 putc (out_ch
, state
->out_file
);
311 *state
->buf_ptr
++ = out_ch
;
313 while (out_ch
!= ch
);
316 /* If in the middle of scanning a keyword, continue scanning with
317 character CH, otherwise output CH to the file or buffer in STATE.
318 Any pending newlines or spaces are output first, as well as any
319 previously scanned characters that were thought to be part of a
320 keyword, but were in fact not. */
323 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
326 && *state
->cur_keyword_ptr
== ch
327 && (state
->cur_keyword_ptr
> state
->keyword
328 || state
->pending_newlines
> 0))
329 /* We might be looking at STATE->keyword at some point.
330 Keep looking until we know for sure. */
332 if (*++state
->cur_keyword_ptr
== '\0')
333 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
335 state
->saw_keyword
= 1;
337 /* Reset the scanning pointer. */
338 state
->cur_keyword_ptr
= state
->keyword
;
340 /* Canonicalize whitespace preceding a usage string. */
341 state
->pending_newlines
= 2;
342 state
->pending_spaces
= 0;
344 /* Skip any whitespace between the keyword and the
347 ch
= getc (state
->in_file
);
348 while (ch
== ' ' || ch
== '\n');
350 /* Output the open-paren we just read. */
351 put_char (ch
, state
);
353 /* Skip the function name and replace it with `fn'. */
355 ch
= getc (state
->in_file
);
356 while (ch
!= ' ' && ch
!= ')');
357 put_char ('f', state
);
358 put_char ('n', state
);
360 /* Put back the last character. */
361 ungetc (ch
, state
->in_file
);
366 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
367 /* We scanned the beginning of a potential usage
368 keyword, but it was a false alarm. Output the
373 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
374 put_char (*p
, state
);
376 state
->cur_keyword_ptr
= state
->keyword
;
379 put_char (ch
, state
);
384 /* Skip a C string or C-style comment from INFILE, and return the
385 character that follows. COMMENT non-zero means skip a comment. If
386 PRINTFLAG is positive, output string contents to outfile. If it is
387 negative, store contents in buf. Convert escape sequences \n and
388 \t to newline and tab; discard \ followed by newline.
389 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
390 at the beginning of a line will be removed, and *SAW_USAGE set to
391 true if any were encountered. */
394 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
397 struct rcsoc_state state
;
399 state
.in_file
= infile
;
400 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
401 state
.out_file
= (printflag
> 0 ? outfile
: 0);
402 state
.pending_spaces
= 0;
403 state
.pending_newlines
= 0;
404 state
.keyword
= (saw_usage
? "usage:" : 0);
405 state
.cur_keyword_ptr
= state
.keyword
;
406 state
.saw_keyword
= 0;
410 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
415 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
420 if (c
== '\n' || c
== '\r')
432 state
.pending_spaces
++;
435 state
.pending_newlines
++;
436 state
.pending_spaces
= 0;
439 scan_keyword_or_put_char (c
, &state
);
455 scan_keyword_or_put_char ('*', &state
);
462 /* If we had a "", concatenate the two strings. */
471 *saw_usage
= state
.saw_keyword
;
478 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
479 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
482 write_c_args (FILE *out
, char *func
, char *buf
, int minargs
, int maxargs
)
486 char *ident_start
IF_LINT (= NULL
);
487 size_t ident_length
= 0;
489 fprintf (out
, "(fn");
494 for (p
= buf
; *p
; p
++)
498 /* Notice when a new identifier starts. */
499 if ((('A' <= c
&& c
<= 'Z')
500 || ('a' <= c
&& c
<= 'z')
501 || ('0' <= c
&& c
<= '9')
513 ident_length
= p
- ident_start
;
517 /* Found the end of an argument, write out the last seen
519 if (c
== ',' || c
== ')')
521 if (ident_length
== 0)
523 error ("empty arg list for `%s' should be (void), not ()", func
);
527 if (strncmp (ident_start
, "void", ident_length
) == 0)
532 if (minargs
== 0 && maxargs
> 0)
533 fprintf (out
, "&optional ");
538 /* In C code, `default' is a reserved word, so we spell it
539 `defalt'; demangle that here. */
540 if (ident_length
== 6 && memcmp (ident_start
, "defalt", 6) == 0)
541 fprintf (out
, "DEFAULT");
543 while (ident_length
-- > 0)
546 if (c
>= 'a' && c
<= 'z')
547 /* Upcase the letter. */
550 /* Print underscore as hyphen. */
560 /* The types of globals. */
570 /* A single global. */
573 enum global_type type
;
578 /* All the variable names we saw while scanning C sources in `-g'
581 int num_globals_allocated
;
582 struct global
*globals
;
585 add_global (enum global_type type
, char *name
, int value
)
587 /* Ignore the one non-symbol that can occur. */
588 if (strcmp (name
, "..."))
592 if (num_globals_allocated
== 0)
594 num_globals_allocated
= 100;
595 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
597 else if (num_globals
== num_globals_allocated
)
599 num_globals_allocated
*= 2;
600 globals
= xrealloc (globals
,
601 num_globals_allocated
* sizeof (struct global
));
604 globals
[num_globals
- 1].type
= type
;
605 globals
[num_globals
- 1].name
= name
;
606 globals
[num_globals
- 1].value
= value
;
611 compare_globals (const void *a
, const void *b
)
613 const struct global
*ga
= a
;
614 const struct global
*gb
= b
;
616 if (ga
->type
== FUNCTION
)
618 if (gb
->type
!= FUNCTION
)
621 else if (gb
->type
== FUNCTION
)
624 return strcmp (ga
->name
, gb
->name
);
628 close_emacs_globals (void)
630 fprintf (outfile
, "};\n");
631 fprintf (outfile
, "extern struct emacs_globals globals;\n");
637 int i
, seen_defun
= 0;
638 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
639 for (i
= 0; i
< num_globals
; ++i
)
643 switch (globals
[i
].type
)
652 type
= "Lisp_Object";
657 close_emacs_globals ();
658 fprintf (outfile
, "\n");
663 fatal ("not a recognized DEFVAR_", 0);
666 if (globals
[i
].type
!= FUNCTION
)
668 fprintf (outfile
, " %s f_%s;\n", type
, globals
[i
].name
);
669 fprintf (outfile
, "#define %s globals.f_%s\n",
670 globals
[i
].name
, globals
[i
].name
);
674 /* It would be nice to have a cleaner way to deal with these
676 if (strcmp (globals
[i
].name
, "Fthrow") == 0
677 || strcmp (globals
[i
].name
, "Ftop_level") == 0
678 || strcmp (globals
[i
].name
, "Fkill_emacs") == 0)
679 fprintf (outfile
, "_Noreturn ");
680 fprintf (outfile
, "EXFUN (%s, ", globals
[i
].name
);
681 if (globals
[i
].value
== -1)
682 fprintf (outfile
, "MANY");
683 else if (globals
[i
].value
== -2)
684 fprintf (outfile
, "UNEVALLED");
686 fprintf (outfile
, "%d", globals
[i
].value
);
687 fprintf (outfile
, ");\n");
690 while (i
+ 1 < num_globals
691 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
693 if (globals
[i
].type
== FUNCTION
694 && globals
[i
].value
!= globals
[i
+ 1].value
)
695 error ("function '%s' defined twice with differing signatures",
702 close_emacs_globals ();
706 /* Read through a c file. If a .o file is named,
707 the corresponding .c or .m file is read instead.
708 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
709 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
712 scan_c_file (char *filename
, const char *mode
)
717 int minargs
, maxargs
;
718 int extension
= filename
[strlen (filename
) - 1];
720 if (extension
== 'o')
721 filename
[strlen (filename
) - 1] = 'c';
723 infile
= fopen (filename
, mode
);
725 if (infile
== NULL
&& extension
== 'o')
728 filename
[strlen (filename
) - 1] = 'm';
729 infile
= fopen (filename
, mode
);
731 filename
[strlen (filename
) - 1] = 'c'; /* Don't confuse people. */
734 /* No error if non-ex input file. */
741 /* Reset extension to be able to detect duplicate files. */
742 filename
[strlen (filename
) - 1] = extension
;
745 while (!feof (infile
))
749 int defvarperbufferflag
= 0;
751 enum global_type type
= INVALID
;
752 char *name
IF_LINT (= 0);
754 if (c
!= '\n' && c
!= '\r')
788 defvarperbufferflag
= (c
== 'P');
789 if (generate_globals
)
792 type
= EMACS_INTEGER
;
800 /* We need to distinguish between DEFVAR_BOOL and
801 DEFVAR_BUFFER_DEFAULTS. */
802 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
814 defunflag
= c
== 'U';
819 && (!defvarflag
|| defvarperbufferflag
|| type
== INVALID
)
830 /* Lisp variable or function name. */
834 c
= read_c_string_or_comment (infile
, -1, 0, 0);
836 if (generate_globals
)
840 /* Skip "," and whitespace. */
845 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
847 /* Read in the identifier. */
850 input_buffer
[i
++] = c
;
853 while (! (c
== ',' || c
== ' ' || c
== '\t'
854 || c
== '\n' || c
== '\r'));
855 input_buffer
[i
] = '\0';
857 name
= xmalloc (i
+ 1);
858 memcpy (name
, input_buffer
, i
+ 1);
862 add_global (type
, name
, 0);
867 /* DEFVAR_LISP ("name", addr, "doc")
868 DEFVAR_LISP ("name", addr /\* doc *\/)
869 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
872 commas
= generate_globals
? 4 : 5;
873 else if (defvarperbufferflag
)
877 else /* For DEFSIMPLE and DEFPRED. */
886 if (defunflag
&& (commas
== 1 || commas
== 2))
891 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
895 if (commas
== 2) /* Pick up minargs. */
896 scanned
= fscanf (infile
, "%d", &minargs
);
897 else /* Pick up maxargs. */
898 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
900 if (generate_globals
)
901 maxargs
= (c
== 'M') ? -1 : -2;
906 scanned
= fscanf (infile
, "%d", &maxargs
);
917 if (generate_globals
)
919 add_global (FUNCTION
, name
, maxargs
);
923 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
927 c
= read_c_string_or_comment (infile
, 0, 0, 0);
929 while (c
!= EOF
&& c
!= ',' && c
!= '/')
934 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
936 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
942 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
949 && (c
= getc (infile
),
953 int comment
= c
!= '"';
957 putc (defvarflag
? 'V' : 'F', outfile
);
958 fprintf (outfile
, "%s\n", input_buffer
);
961 getc (infile
); /* Skip past `*'. */
962 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
964 /* If this is a defun, find the arguments and print them. If
965 this function takes MANY or UNEVALLED args, then the C source
966 won't give the names of the arguments, so we shouldn't bother
969 Various doc-string styles:
970 0: DEFUN (..., "DOC") (args) [!comment]
971 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
972 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
974 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
976 char argbuf
[1024], *p
= argbuf
;
978 if (!comment
|| doc_keyword
)
986 /* Skip into arguments. */
993 /* Copy arguments into ARGBUF. */
996 *p
++ = c
= getc (infile
);
1000 fprintf (outfile
, "\n\n");
1001 write_c_args (outfile
, input_buffer
, argbuf
, minargs
, maxargs
);
1003 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
1004 /* The DOC should provide the usage form. */
1005 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
1014 /* Read a file of Lisp code, compiled or interpreted.
1016 (defun NAME ARGS DOCSTRING ...)
1017 (defmacro NAME ARGS DOCSTRING ...)
1018 (defsubst NAME ARGS DOCSTRING ...)
1019 (autoload (quote NAME) FILE DOCSTRING ...)
1020 (defvar NAME VALUE DOCSTRING)
1021 (defconst NAME VALUE DOCSTRING)
1022 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
1023 (fset (quote NAME) #[... DOCSTRING ...])
1024 (defalias (quote NAME) #[... DOCSTRING ...])
1025 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
1026 starting in column zero.
1027 (quote NAME) may appear as 'NAME as well.
1029 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
1030 When we find that, we save it for the following defining-form,
1031 and we use that instead of reading a doc string within that defining-form.
1033 For defvar, defconst, and fset we skip to the docstring with a kludgy
1034 formatting convention: all docstrings must appear on the same line as the
1035 initial open-paren (the one in column zero) and must contain a backslash
1036 and a newline immediately after the initial double-quote. No newlines
1037 must appear between the beginning of the form and the first double-quote.
1038 For defun, defmacro, and autoload, we know how to skip over the
1039 arglist, but the doc string must still have a backslash and newline
1040 immediately after the double quote.
1041 The only source files that must follow this convention are preloaded
1042 uncompiled ones like loaddefs.el and bindings.el; aside
1043 from that, it is always the .elc file that we look at, and they are no
1044 problem because byte-compiler output follows this convention.
1045 The NAME and DOCSTRING are output.
1046 NAME is preceded by `F' for a function or `V' for a variable.
1047 An entry is output only if DOCSTRING has \ newline just after the opening ".
1051 skip_white (FILE *infile
)
1054 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
1060 read_lisp_symbol (FILE *infile
, char *buffer
)
1063 char *fillp
= buffer
;
1065 skip_white (infile
);
1070 *(++fillp
) = getc (infile
);
1071 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1082 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1084 skip_white (infile
);
1088 search_lisp_doc_at_eol (FILE *infile
)
1090 char c
= 0, c1
= 0, c2
= 0;
1092 /* Skip until the end of line; remember two previous chars. */
1093 while (c
!= '\n' && c
!= '\r' && c
!= EOF
)
1100 /* If two previous characters were " and \,
1101 this is a doc string. Otherwise, there is none. */
1102 if (c2
!= '"' || c1
!= '\\')
1105 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1116 scan_lisp_file (const char *filename
, const char *mode
)
1120 char *saved_string
= 0;
1122 if (generate_globals
)
1123 fatal ("scanning lisp file when -g specified", 0);
1125 infile
= fopen (filename
, mode
);
1129 return 0; /* No error. */
1133 while (!feof (infile
))
1135 char buffer
[BUFSIZ
];
1138 /* If not at end of line, skip till we get to one. */
1139 if (c
!= '\n' && c
!= '\r')
1144 /* Skip the line break. */
1145 while (c
== '\n' || c
== '\r')
1147 /* Detect a dynamic doc string and save it for the next expression. */
1156 /* Read the length. */
1157 while ((c
= getc (infile
),
1158 c
>= '0' && c
<= '9'))
1165 fatal ("invalid dynamic doc string length", "");
1168 fatal ("space not found after dynamic doc string length", "");
1170 /* The next character is a space that is counted in the length
1171 but not part of the doc string.
1172 We already read it, so just ignore it. */
1175 /* Read in the contents. */
1176 free (saved_string
);
1177 saved_string
= (char *) xmalloc (length
);
1178 for (i
= 0; i
< length
; i
++)
1179 saved_string
[i
] = getc (infile
);
1180 /* The last character is a ^_.
1181 That is needed in the .elc file
1182 but it is redundant in DOC. So get rid of it here. */
1183 saved_string
[length
- 1] = 0;
1184 /* Skip the line break. */
1185 while (c
== '\n' || c
== '\r')
1187 /* Skip the following line. */
1188 while (c
!= '\n' && c
!= '\r')
1197 read_lisp_symbol (infile
, buffer
);
1199 if (! strcmp (buffer
, "defun")
1200 || ! strcmp (buffer
, "defmacro")
1201 || ! strcmp (buffer
, "defsubst"))
1204 read_lisp_symbol (infile
, buffer
);
1206 /* Skip the arguments: either "nil" or a list in parens. */
1209 if (c
== 'n') /* nil */
1211 if ((c
= getc (infile
)) != 'i'
1212 || (c
= getc (infile
)) != 'l')
1214 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1221 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1228 skip_white (infile
);
1230 /* If the next three characters aren't `dquote bslash newline'
1231 then we're not reading a docstring.
1233 if ((c
= getc (infile
)) != '"'
1234 || (c
= getc (infile
)) != '\\'
1235 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1238 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1245 /* defcustom can only occur in uncompiled Lisp files. */
1246 else if (! strcmp (buffer
, "defvar")
1247 || ! strcmp (buffer
, "defconst")
1248 || ! strcmp (buffer
, "defcustom"))
1251 read_lisp_symbol (infile
, buffer
);
1253 if (saved_string
== 0)
1254 if (!search_lisp_doc_at_eol (infile
))
1258 else if (! strcmp (buffer
, "custom-declare-variable")
1259 || ! strcmp (buffer
, "defvaralias")
1266 read_lisp_symbol (infile
, buffer
);
1272 "## unparsable name in custom-declare-variable in %s\n",
1276 read_lisp_symbol (infile
, buffer
);
1277 if (strcmp (buffer
, "quote"))
1280 "## unparsable name in custom-declare-variable in %s\n",
1284 read_lisp_symbol (infile
, buffer
);
1289 "## unparsable quoted name in custom-declare-variable in %s\n",
1295 if (saved_string
== 0)
1296 if (!search_lisp_doc_at_eol (infile
))
1300 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1306 read_lisp_symbol (infile
, buffer
);
1311 fprintf (stderr
, "## unparsable name in fset in %s\n",
1315 read_lisp_symbol (infile
, buffer
);
1316 if (strcmp (buffer
, "quote"))
1318 fprintf (stderr
, "## unparsable name in fset in %s\n",
1322 read_lisp_symbol (infile
, buffer
);
1327 "## unparsable quoted name in fset in %s\n",
1333 if (saved_string
== 0)
1334 if (!search_lisp_doc_at_eol (infile
))
1338 else if (! strcmp (buffer
, "autoload"))
1343 read_lisp_symbol (infile
, buffer
);
1348 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1352 read_lisp_symbol (infile
, buffer
);
1353 if (strcmp (buffer
, "quote"))
1355 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1359 read_lisp_symbol (infile
, buffer
);
1364 "## unparsable quoted name in autoload in %s\n",
1369 skip_white (infile
);
1370 if ((c
= getc (infile
)) != '\"')
1372 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1376 read_c_string_or_comment (infile
, 0, 0, 0);
1378 if (saved_string
== 0)
1379 if (!search_lisp_doc_at_eol (infile
))
1384 else if (! strcmp (buffer
, "if")
1385 || ! strcmp (buffer
, "byte-code"))
1392 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1398 /* At this point, we should either use the previous dynamic doc string in
1399 saved_string or gobble a doc string from the input file.
1400 In the latter case, the opening quote (and leading backslash-newline)
1401 have already been read. */
1403 putc (037, outfile
);
1404 putc (type
, outfile
);
1405 fprintf (outfile
, "%s\n", buffer
);
1408 fputs (saved_string
, outfile
);
1409 /* Don't use one dynamic doc string twice. */
1410 free (saved_string
);
1414 read_c_string_or_comment (infile
, 1, 0, 0);
1421 /* make-docfile.c ends here */