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.
40 #include <stdlib.h> /* config.h unconditionally includes this anyway */
45 /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this
46 is really just insurance. */
50 #endif /* WINDOWSNT */
53 /* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this
54 is really just insurance.
56 Similarly, msdos defines this as sys_chdir, but we're not linking with the
57 file where that function is defined. */
59 #define READ_TEXT "rt"
60 #define READ_BINARY "rb"
61 #else /* not DOS_NT */
63 #define READ_BINARY "r"
64 #endif /* not DOS_NT */
66 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
68 # define IF_LINT(Code) Code
70 # define IF_LINT(Code) /* empty */
73 static int scan_file (char *filename
);
74 static int scan_lisp_file (const char *filename
, const char *mode
);
75 static int scan_c_file (char *filename
, const char *mode
);
76 static void start_globals (void);
77 static void write_globals (void);
81 /* Stdio stream for output to the DOC file. */
84 /* Name this program was invoked with. */
87 /* Nonzero if this invocation is generating globals.h. */
90 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
94 error (const char *s1
, const char *s2
)
96 fprintf (stderr
, "%s: ", progname
);
97 fprintf (stderr
, s1
, s2
);
98 fprintf (stderr
, "\n");
101 /* Print error message and exit. */
104 static _Noreturn
void
105 fatal (const char *s1
, const char *s2
)
111 /* Like malloc but get fatal error if memory is exhausted. */
114 xmalloc (unsigned int size
)
116 void *result
= (void *) malloc (size
);
118 fatal ("virtual memory exhausted", 0);
122 /* Like realloc but get fatal error if memory is exhausted. */
125 xrealloc (void *arg
, unsigned int size
)
127 void *result
= (void *) realloc (arg
, size
);
129 fatal ("virtual memory exhausted", 0);
135 main (int argc
, char **argv
)
145 /* Don't put CRs in the DOC file. */
148 #if 0 /* Suspicion is that this causes hanging.
149 So instead we require people to use -o on MSDOS. */
150 (stdout
)->_flag
&= ~_IOTEXT
;
151 _setmode (fileno (stdout
), O_BINARY
);
157 _setmode (fileno (stdout
), O_BINARY
);
158 #endif /* WINDOWSNT */
160 /* If first two args are -o FILE, output to FILE. */
162 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
164 outfile
= fopen (argv
[i
+ 1], "w");
167 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
169 outfile
= fopen (argv
[i
+ 1], "a");
172 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
174 if (chdir (argv
[i
+ 1]) != 0)
176 perror (argv
[i
+ 1]);
181 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
183 generate_globals
= 1;
188 fatal ("No output file specified", "");
190 if (generate_globals
)
194 for (; i
< argc
; i
++)
197 /* Don't process one file twice. */
198 for (j
= first_infile
; j
< i
; j
++)
199 if (! strcmp (argv
[i
], argv
[j
]))
202 err_count
+= scan_file (argv
[i
]);
205 if (err_count
== 0 && generate_globals
)
208 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
211 /* Add a source file name boundary marker in the output file. */
213 put_filename (char *filename
)
217 for (tmp
= filename
; *tmp
; tmp
++)
219 if (IS_DIRECTORY_SEP (*tmp
))
225 fprintf (outfile
, "%s\n", filename
);
228 /* Read file FILENAME and output its doc strings to outfile. */
229 /* Return 1 if file is not found, 0 if it is found. */
232 scan_file (char *filename
)
235 size_t len
= strlen (filename
);
237 if (!generate_globals
)
238 put_filename (filename
);
239 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
240 return scan_lisp_file (filename
, READ_BINARY
);
241 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
242 return scan_lisp_file (filename
, READ_TEXT
);
244 return scan_c_file (filename
, READ_TEXT
);
250 fprintf (outfile
, "/* This file was auto-generated by make-docfile. */\n");
251 fprintf (outfile
, "/* DO NOT EDIT. */\n");
252 fprintf (outfile
, "struct emacs_globals {\n");
255 static char input_buffer
[128];
257 /* Some state during the execution of `read_c_string_or_comment'. */
260 /* A count of spaces and newlines that have been read, but not output. */
261 unsigned pending_spaces
, pending_newlines
;
263 /* Where we're reading from. */
266 /* If non-zero, a buffer into which to copy characters. */
268 /* If non-zero, a file into which to copy characters. */
271 /* A keyword we look for at the beginning of lines. If found, it is
272 not copied, and SAW_KEYWORD is set to true. */
274 /* The current point we've reached in an occurrence of KEYWORD in
276 const char *cur_keyword_ptr
;
277 /* Set to true if we saw an occurrence of KEYWORD. */
281 /* Output CH to the file or buffer in STATE. Any pending newlines or
282 spaces are output first. */
285 put_char (int ch
, struct rcsoc_state
*state
)
290 if (state
->pending_newlines
> 0)
292 state
->pending_newlines
--;
295 else if (state
->pending_spaces
> 0)
297 state
->pending_spaces
--;
304 putc (out_ch
, state
->out_file
);
306 *state
->buf_ptr
++ = out_ch
;
308 while (out_ch
!= ch
);
311 /* If in the middle of scanning a keyword, continue scanning with
312 character CH, otherwise output CH to the file or buffer in STATE.
313 Any pending newlines or spaces are output first, as well as any
314 previously scanned characters that were thought to be part of a
315 keyword, but were in fact not. */
318 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
321 && *state
->cur_keyword_ptr
== ch
322 && (state
->cur_keyword_ptr
> state
->keyword
323 || state
->pending_newlines
> 0))
324 /* We might be looking at STATE->keyword at some point.
325 Keep looking until we know for sure. */
327 if (*++state
->cur_keyword_ptr
== '\0')
328 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
330 state
->saw_keyword
= 1;
332 /* Reset the scanning pointer. */
333 state
->cur_keyword_ptr
= state
->keyword
;
335 /* Canonicalize whitespace preceding a usage string. */
336 state
->pending_newlines
= 2;
337 state
->pending_spaces
= 0;
339 /* Skip any whitespace between the keyword and the
342 ch
= getc (state
->in_file
);
343 while (ch
== ' ' || ch
== '\n');
345 /* Output the open-paren we just read. */
346 put_char (ch
, state
);
348 /* Skip the function name and replace it with `fn'. */
350 ch
= getc (state
->in_file
);
351 while (ch
!= ' ' && ch
!= ')');
352 put_char ('f', state
);
353 put_char ('n', state
);
355 /* Put back the last character. */
356 ungetc (ch
, state
->in_file
);
361 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
362 /* We scanned the beginning of a potential usage
363 keyword, but it was a false alarm. Output the
368 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
369 put_char (*p
, state
);
371 state
->cur_keyword_ptr
= state
->keyword
;
374 put_char (ch
, state
);
379 /* Skip a C string or C-style comment from INFILE, and return the
380 character that follows. COMMENT non-zero means skip a comment. If
381 PRINTFLAG is positive, output string contents to outfile. If it is
382 negative, store contents in buf. Convert escape sequences \n and
383 \t to newline and tab; discard \ followed by newline.
384 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
385 at the beginning of a line will be removed, and *SAW_USAGE set to
386 true if any were encountered. */
389 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
392 struct rcsoc_state state
;
394 state
.in_file
= infile
;
395 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
396 state
.out_file
= (printflag
> 0 ? outfile
: 0);
397 state
.pending_spaces
= 0;
398 state
.pending_newlines
= 0;
399 state
.keyword
= (saw_usage
? "usage:" : 0);
400 state
.cur_keyword_ptr
= state
.keyword
;
401 state
.saw_keyword
= 0;
405 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
410 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
415 if (c
== '\n' || c
== '\r')
427 state
.pending_spaces
++;
430 state
.pending_newlines
++;
431 state
.pending_spaces
= 0;
434 scan_keyword_or_put_char (c
, &state
);
450 scan_keyword_or_put_char ('*', &state
);
457 /* If we had a "", concatenate the two strings. */
466 *saw_usage
= state
.saw_keyword
;
473 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
474 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
477 write_c_args (FILE *out
, char *func
, char *buf
, int minargs
, int maxargs
)
481 char *ident_start
IF_LINT (= NULL
);
482 size_t ident_length
= 0;
484 fprintf (out
, "(fn");
489 for (p
= buf
; *p
; p
++)
493 /* Notice when a new identifier starts. */
494 if ((('A' <= c
&& c
<= 'Z')
495 || ('a' <= c
&& c
<= 'z')
496 || ('0' <= c
&& c
<= '9')
508 ident_length
= p
- ident_start
;
512 /* Found the end of an argument, write out the last seen
514 if (c
== ',' || c
== ')')
516 if (ident_length
== 0)
518 error ("empty arg list for `%s' should be (void), not ()", func
);
522 if (strncmp (ident_start
, "void", ident_length
) == 0)
527 if (minargs
== 0 && maxargs
> 0)
528 fprintf (out
, "&optional ");
533 /* In C code, `default' is a reserved word, so we spell it
534 `defalt'; demangle that here. */
535 if (ident_length
== 6 && memcmp (ident_start
, "defalt", 6) == 0)
536 fprintf (out
, "DEFAULT");
538 while (ident_length
-- > 0)
541 if (c
>= 'a' && c
<= 'z')
542 /* Upcase the letter. */
545 /* Print underscore as hyphen. */
555 /* The types of globals. */
565 /* A single global. */
568 enum global_type type
;
573 /* All the variable names we saw while scanning C sources in `-g'
576 int num_globals_allocated
;
577 struct global
*globals
;
580 add_global (enum global_type type
, char *name
, int value
)
582 /* Ignore the one non-symbol that can occur. */
583 if (strcmp (name
, "..."))
587 if (num_globals_allocated
== 0)
589 num_globals_allocated
= 100;
590 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
592 else if (num_globals
== num_globals_allocated
)
594 num_globals_allocated
*= 2;
595 globals
= xrealloc (globals
,
596 num_globals_allocated
* sizeof (struct global
));
599 globals
[num_globals
- 1].type
= type
;
600 globals
[num_globals
- 1].name
= name
;
601 globals
[num_globals
- 1].value
= value
;
606 compare_globals (const void *a
, const void *b
)
608 const struct global
*ga
= a
;
609 const struct global
*gb
= b
;
611 if (ga
->type
== FUNCTION
)
613 if (gb
->type
!= FUNCTION
)
616 else if (gb
->type
== FUNCTION
)
619 return strcmp (ga
->name
, gb
->name
);
623 close_emacs_globals (void)
625 fprintf (outfile
, "};\n");
626 fprintf (outfile
, "extern struct emacs_globals globals;\n");
632 int i
, seen_defun
= 0;
633 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
634 for (i
= 0; i
< num_globals
; ++i
)
638 switch (globals
[i
].type
)
647 type
= "Lisp_Object";
652 close_emacs_globals ();
653 fprintf (outfile
, "\n");
658 fatal ("not a recognized DEFVAR_", 0);
661 if (globals
[i
].type
!= FUNCTION
)
663 fprintf (outfile
, " %s f_%s;\n", type
, globals
[i
].name
);
664 fprintf (outfile
, "#define %s globals.f_%s\n",
665 globals
[i
].name
, globals
[i
].name
);
669 /* It would be nice to have a cleaner way to deal with these
671 if (strcmp (globals
[i
].name
, "Fthrow") == 0
672 || strcmp (globals
[i
].name
, "Ftop_level") == 0
673 || strcmp (globals
[i
].name
, "Fkill_emacs") == 0)
674 fprintf (outfile
, "_Noreturn ");
675 fprintf (outfile
, "EXFUN (%s, ", globals
[i
].name
);
676 if (globals
[i
].value
== -1)
677 fprintf (outfile
, "MANY");
678 else if (globals
[i
].value
== -2)
679 fprintf (outfile
, "UNEVALLED");
681 fprintf (outfile
, "%d", globals
[i
].value
);
682 fprintf (outfile
, ");\n");
685 while (i
+ 1 < num_globals
686 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
688 if (globals
[i
].type
== FUNCTION
689 && globals
[i
].value
!= globals
[i
+ 1].value
)
690 error ("function '%s' defined twice with differing signatures",
697 close_emacs_globals ();
701 /* Read through a c file. If a .o file is named,
702 the corresponding .c or .m file is read instead.
703 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
704 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
707 scan_c_file (char *filename
, const char *mode
)
712 int minargs
, maxargs
;
713 int extension
= filename
[strlen (filename
) - 1];
715 if (extension
== 'o')
716 filename
[strlen (filename
) - 1] = 'c';
718 infile
= fopen (filename
, mode
);
720 if (infile
== NULL
&& extension
== 'o')
723 filename
[strlen (filename
) - 1] = 'm';
724 infile
= fopen (filename
, mode
);
726 filename
[strlen (filename
) - 1] = 'c'; /* Don't confuse people. */
729 /* No error if non-ex input file. */
736 /* Reset extension to be able to detect duplicate files. */
737 filename
[strlen (filename
) - 1] = extension
;
740 while (!feof (infile
))
744 int defvarperbufferflag
= 0;
746 enum global_type type
= INVALID
;
747 char *name
IF_LINT (= 0);
749 if (c
!= '\n' && c
!= '\r')
783 defvarperbufferflag
= (c
== 'P');
784 if (generate_globals
)
787 type
= EMACS_INTEGER
;
795 /* We need to distinguish between DEFVAR_BOOL and
796 DEFVAR_BUFFER_DEFAULTS. */
797 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
809 defunflag
= c
== 'U';
814 && (!defvarflag
|| defvarperbufferflag
|| type
== INVALID
)
825 /* Lisp variable or function name. */
829 c
= read_c_string_or_comment (infile
, -1, 0, 0);
831 if (generate_globals
)
835 /* Skip "," and whitespace. */
840 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
842 /* Read in the identifier. */
845 input_buffer
[i
++] = c
;
848 while (! (c
== ',' || c
== ' ' || c
== '\t'
849 || c
== '\n' || c
== '\r'));
850 input_buffer
[i
] = '\0';
852 name
= xmalloc (i
+ 1);
853 memcpy (name
, input_buffer
, i
+ 1);
857 add_global (type
, name
, 0);
862 /* DEFVAR_LISP ("name", addr, "doc")
863 DEFVAR_LISP ("name", addr /\* doc *\/)
864 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
867 commas
= generate_globals
? 4 : 5;
868 else if (defvarperbufferflag
)
872 else /* For DEFSIMPLE and DEFPRED. */
881 if (defunflag
&& (commas
== 1 || commas
== 2))
886 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
890 if (commas
== 2) /* Pick up minargs. */
891 scanned
= fscanf (infile
, "%d", &minargs
);
892 else /* Pick up maxargs. */
893 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
895 if (generate_globals
)
896 maxargs
= (c
== 'M') ? -1 : -2;
901 scanned
= fscanf (infile
, "%d", &maxargs
);
912 if (generate_globals
)
914 add_global (FUNCTION
, name
, maxargs
);
918 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
922 c
= read_c_string_or_comment (infile
, 0, 0, 0);
924 while (c
!= EOF
&& c
!= ',' && c
!= '/')
929 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
931 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
937 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
944 && (c
= getc (infile
),
948 int comment
= c
!= '"';
952 putc (defvarflag
? 'V' : 'F', outfile
);
953 fprintf (outfile
, "%s\n", input_buffer
);
956 getc (infile
); /* Skip past `*'. */
957 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
959 /* If this is a defun, find the arguments and print them. If
960 this function takes MANY or UNEVALLED args, then the C source
961 won't give the names of the arguments, so we shouldn't bother
964 Various doc-string styles:
965 0: DEFUN (..., "DOC") (args) [!comment]
966 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
967 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
969 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
971 char argbuf
[1024], *p
= argbuf
;
973 if (!comment
|| doc_keyword
)
981 /* Skip into arguments. */
988 /* Copy arguments into ARGBUF. */
991 *p
++ = c
= getc (infile
);
995 fprintf (outfile
, "\n\n");
996 write_c_args (outfile
, input_buffer
, argbuf
, minargs
, maxargs
);
998 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
999 /* The DOC should provide the usage form. */
1000 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
1009 /* Read a file of Lisp code, compiled or interpreted.
1011 (defun NAME ARGS DOCSTRING ...)
1012 (defmacro NAME ARGS DOCSTRING ...)
1013 (defsubst NAME ARGS DOCSTRING ...)
1014 (autoload (quote NAME) FILE DOCSTRING ...)
1015 (defvar NAME VALUE DOCSTRING)
1016 (defconst NAME VALUE DOCSTRING)
1017 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
1018 (fset (quote NAME) #[... DOCSTRING ...])
1019 (defalias (quote NAME) #[... DOCSTRING ...])
1020 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
1021 starting in column zero.
1022 (quote NAME) may appear as 'NAME as well.
1024 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
1025 When we find that, we save it for the following defining-form,
1026 and we use that instead of reading a doc string within that defining-form.
1028 For defvar, defconst, and fset we skip to the docstring with a kludgy
1029 formatting convention: all docstrings must appear on the same line as the
1030 initial open-paren (the one in column zero) and must contain a backslash
1031 and a newline immediately after the initial double-quote. No newlines
1032 must appear between the beginning of the form and the first double-quote.
1033 For defun, defmacro, and autoload, we know how to skip over the
1034 arglist, but the doc string must still have a backslash and newline
1035 immediately after the double quote.
1036 The only source files that must follow this convention are preloaded
1037 uncompiled ones like loaddefs.el and bindings.el; aside
1038 from that, it is always the .elc file that we look at, and they are no
1039 problem because byte-compiler output follows this convention.
1040 The NAME and DOCSTRING are output.
1041 NAME is preceded by `F' for a function or `V' for a variable.
1042 An entry is output only if DOCSTRING has \ newline just after the opening ".
1046 skip_white (FILE *infile
)
1049 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
1055 read_lisp_symbol (FILE *infile
, char *buffer
)
1058 char *fillp
= buffer
;
1060 skip_white (infile
);
1065 *(++fillp
) = getc (infile
);
1066 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1077 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1079 skip_white (infile
);
1083 search_lisp_doc_at_eol (FILE *infile
)
1085 char c
= 0, c1
= 0, c2
= 0;
1087 /* Skip until the end of line; remember two previous chars. */
1088 while (c
!= '\n' && c
!= '\r' && c
!= EOF
)
1095 /* If two previous characters were " and \,
1096 this is a doc string. Otherwise, there is none. */
1097 if (c2
!= '"' || c1
!= '\\')
1100 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1111 scan_lisp_file (const char *filename
, const char *mode
)
1115 char *saved_string
= 0;
1117 if (generate_globals
)
1118 fatal ("scanning lisp file when -g specified", 0);
1120 infile
= fopen (filename
, mode
);
1124 return 0; /* No error. */
1128 while (!feof (infile
))
1130 char buffer
[BUFSIZ
];
1133 /* If not at end of line, skip till we get to one. */
1134 if (c
!= '\n' && c
!= '\r')
1139 /* Skip the line break. */
1140 while (c
== '\n' || c
== '\r')
1142 /* Detect a dynamic doc string and save it for the next expression. */
1151 /* Read the length. */
1152 while ((c
= getc (infile
),
1153 c
>= '0' && c
<= '9'))
1160 fatal ("invalid dynamic doc string length", "");
1163 fatal ("space not found after dynamic doc string length", "");
1165 /* The next character is a space that is counted in the length
1166 but not part of the doc string.
1167 We already read it, so just ignore it. */
1170 /* Read in the contents. */
1171 free (saved_string
);
1172 saved_string
= (char *) xmalloc (length
);
1173 for (i
= 0; i
< length
; i
++)
1174 saved_string
[i
] = getc (infile
);
1175 /* The last character is a ^_.
1176 That is needed in the .elc file
1177 but it is redundant in DOC. So get rid of it here. */
1178 saved_string
[length
- 1] = 0;
1179 /* Skip the line break. */
1180 while (c
== '\n' || c
== '\r')
1182 /* Skip the following line. */
1183 while (c
!= '\n' && c
!= '\r')
1192 read_lisp_symbol (infile
, buffer
);
1194 if (! strcmp (buffer
, "defun")
1195 || ! strcmp (buffer
, "defmacro")
1196 || ! strcmp (buffer
, "defsubst"))
1199 read_lisp_symbol (infile
, buffer
);
1201 /* Skip the arguments: either "nil" or a list in parens. */
1204 if (c
== 'n') /* nil */
1206 if ((c
= getc (infile
)) != 'i'
1207 || (c
= getc (infile
)) != 'l')
1209 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1216 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1223 skip_white (infile
);
1225 /* If the next three characters aren't `dquote bslash newline'
1226 then we're not reading a docstring.
1228 if ((c
= getc (infile
)) != '"'
1229 || (c
= getc (infile
)) != '\\'
1230 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1233 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1240 /* defcustom can only occur in uncompiled Lisp files. */
1241 else if (! strcmp (buffer
, "defvar")
1242 || ! strcmp (buffer
, "defconst")
1243 || ! strcmp (buffer
, "defcustom"))
1246 read_lisp_symbol (infile
, buffer
);
1248 if (saved_string
== 0)
1249 if (!search_lisp_doc_at_eol (infile
))
1253 else if (! strcmp (buffer
, "custom-declare-variable")
1254 || ! strcmp (buffer
, "defvaralias")
1261 read_lisp_symbol (infile
, buffer
);
1267 "## unparsable name in custom-declare-variable in %s\n",
1271 read_lisp_symbol (infile
, buffer
);
1272 if (strcmp (buffer
, "quote"))
1275 "## unparsable name in custom-declare-variable in %s\n",
1279 read_lisp_symbol (infile
, buffer
);
1284 "## unparsable quoted name in custom-declare-variable in %s\n",
1290 if (saved_string
== 0)
1291 if (!search_lisp_doc_at_eol (infile
))
1295 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1301 read_lisp_symbol (infile
, buffer
);
1306 fprintf (stderr
, "## unparsable name in fset in %s\n",
1310 read_lisp_symbol (infile
, buffer
);
1311 if (strcmp (buffer
, "quote"))
1313 fprintf (stderr
, "## unparsable name in fset in %s\n",
1317 read_lisp_symbol (infile
, buffer
);
1322 "## unparsable quoted name in fset in %s\n",
1328 if (saved_string
== 0)
1329 if (!search_lisp_doc_at_eol (infile
))
1333 else if (! strcmp (buffer
, "autoload"))
1338 read_lisp_symbol (infile
, buffer
);
1343 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1347 read_lisp_symbol (infile
, buffer
);
1348 if (strcmp (buffer
, "quote"))
1350 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1354 read_lisp_symbol (infile
, buffer
);
1359 "## unparsable quoted name in autoload in %s\n",
1364 skip_white (infile
);
1365 if ((c
= getc (infile
)) != '\"')
1367 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1371 read_c_string_or_comment (infile
, 0, 0, 0);
1373 if (saved_string
== 0)
1374 if (!search_lisp_doc_at_eol (infile
))
1379 else if (! strcmp (buffer
, "if")
1380 || ! strcmp (buffer
, "byte-code"))
1387 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1393 /* At this point, we should either use the previous dynamic doc string in
1394 saved_string or gobble a doc string from the input file.
1395 In the latter case, the opening quote (and leading backslash-newline)
1396 have already been read. */
1398 putc (037, outfile
);
1399 putc (type
, outfile
);
1400 fprintf (outfile
, "%s\n", buffer
);
1403 fputs (saved_string
, outfile
);
1404 /* Don't use one dynamic doc string twice. */
1405 free (saved_string
);
1409 read_c_string_or_comment (infile
, 1, 0, 0);
1416 /* make-docfile.c ends here */