1 /* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2012
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* The arguments given to this program are all the C and Lisp source files
22 of GNU Emacs. .elc and .el and .c files are allowed.
23 A .o file can also be specified; the .c file it was made from is used.
24 This helps the makefile pass the correct list of files.
25 Option -d DIR means change to DIR before looking for files.
27 The results, which go to standard output or to a file
28 specified with -a or -o (-a to append, -o to start from nothing),
29 are entries containing function or variable names and their documentation.
30 Each entry starts with a ^_ character.
31 Then comes F for a function or V for a variable.
32 Then comes the function or variable name, terminated with a newline.
33 Then comes the documentation for that function or variable.
38 /* Defined to be emacs_main, sys_fopen, etc. in config.h. */
51 #endif /* WINDOWSNT */
54 #define READ_TEXT "rt"
55 #define READ_BINARY "rb"
56 #else /* not DOS_NT */
58 #define READ_BINARY "r"
59 #endif /* not DOS_NT */
62 #define DIRECTORY_SEP '/'
65 #ifndef IS_DIRECTORY_SEP
66 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
69 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
71 # define IF_LINT(Code) Code
73 # define IF_LINT(Code) /* empty */
76 static int scan_file (char *filename
);
77 static int scan_lisp_file (const char *filename
, const char *mode
);
78 static int scan_c_file (char *filename
, const char *mode
);
79 static void start_globals (void);
80 static void write_globals (void);
83 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
84 file where that function is defined. */
90 /* Stdio stream for output to the DOC file. */
93 /* Name this program was invoked with. */
96 /* Nonzero if this invocation is generating globals.h. */
99 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
103 error (const char *s1
, const char *s2
)
105 fprintf (stderr
, "%s: ", progname
);
106 fprintf (stderr
, s1
, s2
);
107 fprintf (stderr
, "\n");
110 /* Print error message and exit. */
113 static _Noreturn
void
114 fatal (const char *s1
, const char *s2
)
120 /* Like malloc but get fatal error if memory is exhausted. */
123 xmalloc (unsigned int size
)
125 void *result
= (void *) malloc (size
);
127 fatal ("virtual memory exhausted", 0);
131 /* Like realloc but get fatal error if memory is exhausted. */
134 xrealloc (void *arg
, unsigned int size
)
136 void *result
= (void *) realloc (arg
, size
);
138 fatal ("virtual memory exhausted", 0);
144 main (int argc
, char **argv
)
154 /* Don't put CRs in the DOC file. */
157 #if 0 /* Suspicion is that this causes hanging.
158 So instead we require people to use -o on MSDOS. */
159 (stdout
)->_flag
&= ~_IOTEXT
;
160 _setmode (fileno (stdout
), O_BINARY
);
166 _setmode (fileno (stdout
), O_BINARY
);
167 #endif /* WINDOWSNT */
169 /* If first two args are -o FILE, output to FILE. */
171 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
173 outfile
= fopen (argv
[i
+ 1], "w");
176 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
178 outfile
= fopen (argv
[i
+ 1], "a");
181 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
183 if (chdir (argv
[i
+ 1]) != 0)
185 perror (argv
[i
+ 1]);
190 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
192 generate_globals
= 1;
197 fatal ("No output file specified", "");
199 if (generate_globals
)
203 for (; i
< argc
; i
++)
206 /* Don't process one file twice. */
207 for (j
= first_infile
; j
< i
; j
++)
208 if (! strcmp (argv
[i
], argv
[j
]))
211 err_count
+= scan_file (argv
[i
]);
214 if (err_count
== 0 && generate_globals
)
217 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
220 /* Add a source file name boundary marker in the output file. */
222 put_filename (char *filename
)
226 for (tmp
= filename
; *tmp
; tmp
++)
228 if (IS_DIRECTORY_SEP (*tmp
))
234 fprintf (outfile
, "%s\n", filename
);
237 /* Read file FILENAME and output its doc strings to outfile. */
238 /* Return 1 if file is not found, 0 if it is found. */
241 scan_file (char *filename
)
244 size_t len
= strlen (filename
);
246 if (!generate_globals
)
247 put_filename (filename
);
248 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
249 return scan_lisp_file (filename
, READ_BINARY
);
250 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
251 return scan_lisp_file (filename
, READ_TEXT
);
253 return scan_c_file (filename
, READ_TEXT
);
259 fprintf (outfile
, "/* This file was auto-generated by make-docfile. */\n");
260 fprintf (outfile
, "/* DO NOT EDIT. */\n");
261 fprintf (outfile
, "struct emacs_globals {\n");
264 static char input_buffer
[128];
266 /* Some state during the execution of `read_c_string_or_comment'. */
269 /* A count of spaces and newlines that have been read, but not output. */
270 unsigned pending_spaces
, pending_newlines
;
272 /* Where we're reading from. */
275 /* If non-zero, a buffer into which to copy characters. */
277 /* If non-zero, a file into which to copy characters. */
280 /* A keyword we look for at the beginning of lines. If found, it is
281 not copied, and SAW_KEYWORD is set to true. */
283 /* The current point we've reached in an occurrence of KEYWORD in
285 const char *cur_keyword_ptr
;
286 /* Set to true if we saw an occurrence of KEYWORD. */
290 /* Output CH to the file or buffer in STATE. Any pending newlines or
291 spaces are output first. */
294 put_char (int ch
, struct rcsoc_state
*state
)
299 if (state
->pending_newlines
> 0)
301 state
->pending_newlines
--;
304 else if (state
->pending_spaces
> 0)
306 state
->pending_spaces
--;
313 putc (out_ch
, state
->out_file
);
315 *state
->buf_ptr
++ = out_ch
;
317 while (out_ch
!= ch
);
320 /* If in the middle of scanning a keyword, continue scanning with
321 character CH, otherwise output CH to the file or buffer in STATE.
322 Any pending newlines or spaces are output first, as well as any
323 previously scanned characters that were thought to be part of a
324 keyword, but were in fact not. */
327 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
330 && *state
->cur_keyword_ptr
== ch
331 && (state
->cur_keyword_ptr
> state
->keyword
332 || state
->pending_newlines
> 0))
333 /* We might be looking at STATE->keyword at some point.
334 Keep looking until we know for sure. */
336 if (*++state
->cur_keyword_ptr
== '\0')
337 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
339 state
->saw_keyword
= 1;
341 /* Reset the scanning pointer. */
342 state
->cur_keyword_ptr
= state
->keyword
;
344 /* Canonicalize whitespace preceding a usage string. */
345 state
->pending_newlines
= 2;
346 state
->pending_spaces
= 0;
348 /* Skip any whitespace between the keyword and the
351 ch
= getc (state
->in_file
);
352 while (ch
== ' ' || ch
== '\n');
354 /* Output the open-paren we just read. */
355 put_char (ch
, state
);
357 /* Skip the function name and replace it with `fn'. */
359 ch
= getc (state
->in_file
);
360 while (ch
!= ' ' && ch
!= ')');
361 put_char ('f', state
);
362 put_char ('n', state
);
364 /* Put back the last character. */
365 ungetc (ch
, state
->in_file
);
370 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
371 /* We scanned the beginning of a potential usage
372 keyword, but it was a false alarm. Output the
377 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
378 put_char (*p
, state
);
380 state
->cur_keyword_ptr
= state
->keyword
;
383 put_char (ch
, state
);
388 /* Skip a C string or C-style comment from INFILE, and return the
389 character that follows. COMMENT non-zero means skip a comment. If
390 PRINTFLAG is positive, output string contents to outfile. If it is
391 negative, store contents in buf. Convert escape sequences \n and
392 \t to newline and tab; discard \ followed by newline.
393 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
394 at the beginning of a line will be removed, and *SAW_USAGE set to
395 true if any were encountered. */
398 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
401 struct rcsoc_state state
;
403 state
.in_file
= infile
;
404 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
405 state
.out_file
= (printflag
> 0 ? outfile
: 0);
406 state
.pending_spaces
= 0;
407 state
.pending_newlines
= 0;
408 state
.keyword
= (saw_usage
? "usage:" : 0);
409 state
.cur_keyword_ptr
= state
.keyword
;
410 state
.saw_keyword
= 0;
414 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
419 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
424 if (c
== '\n' || c
== '\r')
436 state
.pending_spaces
++;
439 state
.pending_newlines
++;
440 state
.pending_spaces
= 0;
443 scan_keyword_or_put_char (c
, &state
);
459 scan_keyword_or_put_char ('*', &state
);
466 /* If we had a "", concatenate the two strings. */
475 *saw_usage
= state
.saw_keyword
;
482 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
483 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
486 write_c_args (FILE *out
, char *func
, char *buf
, int minargs
, int maxargs
)
490 char *ident_start
IF_LINT (= NULL
);
491 size_t ident_length
= 0;
493 fprintf (out
, "(fn");
498 for (p
= buf
; *p
; p
++)
502 /* Notice when a new identifier starts. */
503 if ((('A' <= c
&& c
<= 'Z')
504 || ('a' <= c
&& c
<= 'z')
505 || ('0' <= c
&& c
<= '9')
517 ident_length
= p
- ident_start
;
521 /* Found the end of an argument, write out the last seen
523 if (c
== ',' || c
== ')')
525 if (ident_length
== 0)
527 error ("empty arg list for `%s' should be (void), not ()", func
);
531 if (strncmp (ident_start
, "void", ident_length
) == 0)
536 if (minargs
== 0 && maxargs
> 0)
537 fprintf (out
, "&optional ");
542 /* In C code, `default' is a reserved word, so we spell it
543 `defalt'; demangle that here. */
544 if (ident_length
== 6 && memcmp (ident_start
, "defalt", 6) == 0)
545 fprintf (out
, "DEFAULT");
547 while (ident_length
-- > 0)
550 if (c
>= 'a' && c
<= 'z')
551 /* Upcase the letter. */
554 /* Print underscore as hyphen. */
564 /* The types of globals. */
574 /* A single global. */
577 enum global_type type
;
582 /* All the variable names we saw while scanning C sources in `-g'
585 int num_globals_allocated
;
586 struct global
*globals
;
589 add_global (enum global_type type
, char *name
, int value
)
591 /* Ignore the one non-symbol that can occur. */
592 if (strcmp (name
, "..."))
596 if (num_globals_allocated
== 0)
598 num_globals_allocated
= 100;
599 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
601 else if (num_globals
== num_globals_allocated
)
603 num_globals_allocated
*= 2;
604 globals
= xrealloc (globals
,
605 num_globals_allocated
* sizeof (struct global
));
608 globals
[num_globals
- 1].type
= type
;
609 globals
[num_globals
- 1].name
= name
;
610 globals
[num_globals
- 1].value
= value
;
615 compare_globals (const void *a
, const void *b
)
617 const struct global
*ga
= a
;
618 const struct global
*gb
= b
;
620 if (ga
->type
== FUNCTION
)
622 if (gb
->type
!= FUNCTION
)
625 else if (gb
->type
== FUNCTION
)
628 return strcmp (ga
->name
, gb
->name
);
632 close_emacs_globals (void)
634 fprintf (outfile
, "};\n");
635 fprintf (outfile
, "extern struct emacs_globals globals;\n");
641 int i
, seen_defun
= 0;
642 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
643 for (i
= 0; i
< num_globals
; ++i
)
647 switch (globals
[i
].type
)
656 type
= "Lisp_Object";
661 close_emacs_globals ();
662 fprintf (outfile
, "\n");
667 fatal ("not a recognized DEFVAR_", 0);
670 if (globals
[i
].type
!= FUNCTION
)
672 fprintf (outfile
, " %s f_%s;\n", type
, globals
[i
].name
);
673 fprintf (outfile
, "#define %s globals.f_%s\n",
674 globals
[i
].name
, globals
[i
].name
);
678 /* It would be nice to have a cleaner way to deal with these
680 if (strcmp (globals
[i
].name
, "Fthrow") == 0
681 || strcmp (globals
[i
].name
, "Ftop_level") == 0
682 || strcmp (globals
[i
].name
, "Fkill_emacs") == 0)
683 fprintf (outfile
, "_Noreturn ");
684 fprintf (outfile
, "EXFUN (%s, ", globals
[i
].name
);
685 if (globals
[i
].value
== -1)
686 fprintf (outfile
, "MANY");
687 else if (globals
[i
].value
== -2)
688 fprintf (outfile
, "UNEVALLED");
690 fprintf (outfile
, "%d", globals
[i
].value
);
691 fprintf (outfile
, ");\n");
694 while (i
+ 1 < num_globals
695 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
697 if (globals
[i
].type
== FUNCTION
698 && globals
[i
].value
!= globals
[i
+ 1].value
)
699 error ("function '%s' defined twice with differing signatures",
706 close_emacs_globals ();
710 /* Read through a c file. If a .o file is named,
711 the corresponding .c or .m file is read instead.
712 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
713 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
716 scan_c_file (char *filename
, const char *mode
)
721 int minargs
, maxargs
;
722 int extension
= filename
[strlen (filename
) - 1];
724 if (extension
== 'o')
725 filename
[strlen (filename
) - 1] = 'c';
727 infile
= fopen (filename
, mode
);
729 if (infile
== NULL
&& extension
== 'o')
732 filename
[strlen (filename
) - 1] = 'm';
733 infile
= fopen (filename
, mode
);
735 filename
[strlen (filename
) - 1] = 'c'; /* Don't confuse people. */
738 /* No error if non-ex input file. */
745 /* Reset extension to be able to detect duplicate files. */
746 filename
[strlen (filename
) - 1] = extension
;
749 while (!feof (infile
))
753 int defvarperbufferflag
= 0;
755 enum global_type type
= INVALID
;
756 char *name
IF_LINT (= 0);
758 if (c
!= '\n' && c
!= '\r')
792 defvarperbufferflag
= (c
== 'P');
793 if (generate_globals
)
796 type
= EMACS_INTEGER
;
804 /* We need to distinguish between DEFVAR_BOOL and
805 DEFVAR_BUFFER_DEFAULTS. */
806 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
818 defunflag
= c
== 'U';
823 && (!defvarflag
|| defvarperbufferflag
|| type
== INVALID
)
834 /* Lisp variable or function name. */
838 c
= read_c_string_or_comment (infile
, -1, 0, 0);
840 if (generate_globals
)
844 /* Skip "," and whitespace. */
849 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
851 /* Read in the identifier. */
854 input_buffer
[i
++] = c
;
857 while (! (c
== ',' || c
== ' ' || c
== '\t'
858 || c
== '\n' || c
== '\r'));
859 input_buffer
[i
] = '\0';
861 name
= xmalloc (i
+ 1);
862 memcpy (name
, input_buffer
, i
+ 1);
866 add_global (type
, name
, 0);
871 /* DEFVAR_LISP ("name", addr, "doc")
872 DEFVAR_LISP ("name", addr /\* doc *\/)
873 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
876 commas
= generate_globals
? 4 : 5;
877 else if (defvarperbufferflag
)
881 else /* For DEFSIMPLE and DEFPRED. */
890 if (defunflag
&& (commas
== 1 || commas
== 2))
895 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
899 if (commas
== 2) /* Pick up minargs. */
900 scanned
= fscanf (infile
, "%d", &minargs
);
901 else /* Pick up maxargs. */
902 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
904 if (generate_globals
)
905 maxargs
= (c
== 'M') ? -1 : -2;
910 scanned
= fscanf (infile
, "%d", &maxargs
);
921 if (generate_globals
)
923 add_global (FUNCTION
, name
, maxargs
);
927 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
931 c
= read_c_string_or_comment (infile
, 0, 0, 0);
933 while (c
!= EOF
&& c
!= ',' && c
!= '/')
938 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
940 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
946 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
953 && (c
= getc (infile
),
957 int comment
= c
!= '"';
961 putc (defvarflag
? 'V' : 'F', outfile
);
962 fprintf (outfile
, "%s\n", input_buffer
);
965 getc (infile
); /* Skip past `*'. */
966 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
968 /* If this is a defun, find the arguments and print them. If
969 this function takes MANY or UNEVALLED args, then the C source
970 won't give the names of the arguments, so we shouldn't bother
973 Various doc-string styles:
974 0: DEFUN (..., "DOC") (args) [!comment]
975 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
976 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
978 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
980 char argbuf
[1024], *p
= argbuf
;
982 if (!comment
|| doc_keyword
)
990 /* Skip into arguments. */
997 /* Copy arguments into ARGBUF. */
1000 *p
++ = c
= getc (infile
);
1004 fprintf (outfile
, "\n\n");
1005 write_c_args (outfile
, input_buffer
, argbuf
, minargs
, maxargs
);
1007 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
1008 /* The DOC should provide the usage form. */
1009 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
1018 /* Read a file of Lisp code, compiled or interpreted.
1020 (defun NAME ARGS DOCSTRING ...)
1021 (defmacro NAME ARGS DOCSTRING ...)
1022 (defsubst NAME ARGS DOCSTRING ...)
1023 (autoload (quote NAME) FILE DOCSTRING ...)
1024 (defvar NAME VALUE DOCSTRING)
1025 (defconst NAME VALUE DOCSTRING)
1026 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
1027 (fset (quote NAME) #[... DOCSTRING ...])
1028 (defalias (quote NAME) #[... DOCSTRING ...])
1029 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
1030 starting in column zero.
1031 (quote NAME) may appear as 'NAME as well.
1033 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
1034 When we find that, we save it for the following defining-form,
1035 and we use that instead of reading a doc string within that defining-form.
1037 For defvar, defconst, and fset we skip to the docstring with a kludgy
1038 formatting convention: all docstrings must appear on the same line as the
1039 initial open-paren (the one in column zero) and must contain a backslash
1040 and a newline immediately after the initial double-quote. No newlines
1041 must appear between the beginning of the form and the first double-quote.
1042 For defun, defmacro, and autoload, we know how to skip over the
1043 arglist, but the doc string must still have a backslash and newline
1044 immediately after the double quote.
1045 The only source files that must follow this convention are preloaded
1046 uncompiled ones like loaddefs.el and bindings.el; aside
1047 from that, it is always the .elc file that we look at, and they are no
1048 problem because byte-compiler output follows this convention.
1049 The NAME and DOCSTRING are output.
1050 NAME is preceded by `F' for a function or `V' for a variable.
1051 An entry is output only if DOCSTRING has \ newline just after the opening ".
1055 skip_white (FILE *infile
)
1058 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
1064 read_lisp_symbol (FILE *infile
, char *buffer
)
1067 char *fillp
= buffer
;
1069 skip_white (infile
);
1074 *(++fillp
) = getc (infile
);
1075 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1086 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1088 skip_white (infile
);
1092 search_lisp_doc_at_eol (FILE *infile
)
1094 char c
= 0, c1
= 0, c2
= 0;
1096 /* Skip until the end of line; remember two previous chars. */
1097 while (c
!= '\n' && c
!= '\r' && c
!= EOF
)
1104 /* If two previous characters were " and \,
1105 this is a doc string. Otherwise, there is none. */
1106 if (c2
!= '"' || c1
!= '\\')
1109 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1120 scan_lisp_file (const char *filename
, const char *mode
)
1124 char *saved_string
= 0;
1126 if (generate_globals
)
1127 fatal ("scanning lisp file when -g specified", 0);
1129 infile
= fopen (filename
, mode
);
1133 return 0; /* No error. */
1137 while (!feof (infile
))
1139 char buffer
[BUFSIZ
];
1142 /* If not at end of line, skip till we get to one. */
1143 if (c
!= '\n' && c
!= '\r')
1148 /* Skip the line break. */
1149 while (c
== '\n' || c
== '\r')
1151 /* Detect a dynamic doc string and save it for the next expression. */
1160 /* Read the length. */
1161 while ((c
= getc (infile
),
1162 c
>= '0' && c
<= '9'))
1169 fatal ("invalid dynamic doc string length", "");
1172 fatal ("space not found after dynamic doc string length", "");
1174 /* The next character is a space that is counted in the length
1175 but not part of the doc string.
1176 We already read it, so just ignore it. */
1179 /* Read in the contents. */
1180 free (saved_string
);
1181 saved_string
= (char *) xmalloc (length
);
1182 for (i
= 0; i
< length
; i
++)
1183 saved_string
[i
] = getc (infile
);
1184 /* The last character is a ^_.
1185 That is needed in the .elc file
1186 but it is redundant in DOC. So get rid of it here. */
1187 saved_string
[length
- 1] = 0;
1188 /* Skip the line break. */
1189 while (c
== '\n' || c
== '\r')
1191 /* Skip the following line. */
1192 while (c
!= '\n' && c
!= '\r')
1201 read_lisp_symbol (infile
, buffer
);
1203 if (! strcmp (buffer
, "defun")
1204 || ! strcmp (buffer
, "defmacro")
1205 || ! strcmp (buffer
, "defsubst"))
1208 read_lisp_symbol (infile
, buffer
);
1210 /* Skip the arguments: either "nil" or a list in parens. */
1213 if (c
== 'n') /* nil */
1215 if ((c
= getc (infile
)) != 'i'
1216 || (c
= getc (infile
)) != 'l')
1218 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1225 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1232 skip_white (infile
);
1234 /* If the next three characters aren't `dquote bslash newline'
1235 then we're not reading a docstring.
1237 if ((c
= getc (infile
)) != '"'
1238 || (c
= getc (infile
)) != '\\'
1239 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1242 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1249 /* defcustom can only occur in uncompiled Lisp files. */
1250 else if (! strcmp (buffer
, "defvar")
1251 || ! strcmp (buffer
, "defconst")
1252 || ! strcmp (buffer
, "defcustom"))
1255 read_lisp_symbol (infile
, buffer
);
1257 if (saved_string
== 0)
1258 if (!search_lisp_doc_at_eol (infile
))
1262 else if (! strcmp (buffer
, "custom-declare-variable")
1263 || ! strcmp (buffer
, "defvaralias")
1270 read_lisp_symbol (infile
, buffer
);
1276 "## unparsable name in custom-declare-variable in %s\n",
1280 read_lisp_symbol (infile
, buffer
);
1281 if (strcmp (buffer
, "quote"))
1284 "## unparsable name in custom-declare-variable in %s\n",
1288 read_lisp_symbol (infile
, buffer
);
1293 "## unparsable quoted name in custom-declare-variable in %s\n",
1299 if (saved_string
== 0)
1300 if (!search_lisp_doc_at_eol (infile
))
1304 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1310 read_lisp_symbol (infile
, buffer
);
1315 fprintf (stderr
, "## unparsable name in fset in %s\n",
1319 read_lisp_symbol (infile
, buffer
);
1320 if (strcmp (buffer
, "quote"))
1322 fprintf (stderr
, "## unparsable name in fset in %s\n",
1326 read_lisp_symbol (infile
, buffer
);
1331 "## unparsable quoted name in fset in %s\n",
1337 if (saved_string
== 0)
1338 if (!search_lisp_doc_at_eol (infile
))
1342 else if (! strcmp (buffer
, "autoload"))
1347 read_lisp_symbol (infile
, buffer
);
1352 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1356 read_lisp_symbol (infile
, buffer
);
1357 if (strcmp (buffer
, "quote"))
1359 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1363 read_lisp_symbol (infile
, buffer
);
1368 "## unparsable quoted name in autoload in %s\n",
1373 skip_white (infile
);
1374 if ((c
= getc (infile
)) != '\"')
1376 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1380 read_c_string_or_comment (infile
, 0, 0, 0);
1382 if (saved_string
== 0)
1383 if (!search_lisp_doc_at_eol (infile
))
1388 else if (! strcmp (buffer
, "if")
1389 || ! strcmp (buffer
, "byte-code"))
1396 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1402 /* At this point, we should either use the previous dynamic doc string in
1403 saved_string or gobble a doc string from the input file.
1404 In the latter case, the opening quote (and leading backslash-newline)
1405 have already been read. */
1407 putc (037, outfile
);
1408 putc (type
, outfile
);
1409 fprintf (outfile
, "%s\n", buffer
);
1412 fputs (saved_string
, outfile
);
1413 /* Don't use one dynamic doc string twice. */
1414 free (saved_string
);
1418 read_c_string_or_comment (infile
, 1, 0, 0);
1425 /* make-docfile.c ends here */