1 /* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2011
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 static int scan_file (char *filename
);
70 static int scan_lisp_file (const char *filename
, const char *mode
);
71 static int scan_c_file (char *filename
, const char *mode
);
72 static void fatal (const char *s1
, const char *s2
) NO_RETURN
;
73 static void start_globals (void);
74 static void write_globals (void);
77 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
78 file where that function is defined. */
84 /* Stdio stream for output to the DOC file. */
87 /* Name this program was invoked with. */
90 /* Nonzero if this invocation is generating globals.h. */
93 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
97 error (const char *s1
, const char *s2
)
99 fprintf (stderr
, "%s: ", progname
);
100 fprintf (stderr
, s1
, s2
);
101 fprintf (stderr
, "\n");
104 /* Print error message and exit. */
108 fatal (const char *s1
, const char *s2
)
114 /* Like malloc but get fatal error if memory is exhausted. */
117 xmalloc (unsigned int size
)
119 void *result
= (void *) malloc (size
);
121 fatal ("virtual memory exhausted", 0);
125 /* Like realloc but get fatal error if memory is exhausted. */
128 xrealloc (void *arg
, unsigned int size
)
130 void *result
= (void *) realloc (arg
, size
);
132 fatal ("virtual memory exhausted", 0);
138 main (int argc
, char **argv
)
148 /* Don't put CRs in the DOC file. */
151 #if 0 /* Suspicion is that this causes hanging.
152 So instead we require people to use -o on MSDOS. */
153 (stdout
)->_flag
&= ~_IOTEXT
;
154 _setmode (fileno (stdout
), O_BINARY
);
160 _setmode (fileno (stdout
), O_BINARY
);
161 #endif /* WINDOWSNT */
163 /* If first two args are -o FILE, output to FILE. */
165 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
167 outfile
= fopen (argv
[i
+ 1], "w");
170 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
172 outfile
= fopen (argv
[i
+ 1], "a");
175 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
177 if (chdir (argv
[i
+ 1]) != 0)
179 perror (argv
[i
+ 1]);
184 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
186 generate_globals
= 1;
191 fatal ("No output file specified", "");
193 if (generate_globals
)
197 for (; i
< argc
; i
++)
200 /* Don't process one file twice. */
201 for (j
= first_infile
; j
< i
; j
++)
202 if (! strcmp (argv
[i
], argv
[j
]))
205 err_count
+= scan_file (argv
[i
]);
208 if (err_count
== 0 && generate_globals
)
211 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
214 /* Add a source file name boundary marker in the output file. */
216 put_filename (char *filename
)
220 for (tmp
= filename
; *tmp
; tmp
++)
222 if (IS_DIRECTORY_SEP(*tmp
))
228 fprintf (outfile
, "%s\n", filename
);
231 /* Read file FILENAME and output its doc strings to outfile. */
232 /* Return 1 if file is not found, 0 if it is found. */
235 scan_file (char *filename
)
238 size_t len
= strlen (filename
);
240 if (!generate_globals
)
241 put_filename (filename
);
242 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
243 return scan_lisp_file (filename
, READ_BINARY
);
244 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
245 return scan_lisp_file (filename
, READ_TEXT
);
247 return scan_c_file (filename
, READ_TEXT
);
253 fprintf (outfile
, "/* This file was auto-generated by make-docfile. */\n");
254 fprintf (outfile
, "/* DO NOT EDIT. */\n");
255 fprintf (outfile
, "struct emacs_globals {\n");
258 static char input_buffer
[128];
260 /* Some state during the execution of `read_c_string_or_comment'. */
263 /* A count of spaces and newlines that have been read, but not output. */
264 unsigned pending_spaces
, pending_newlines
;
266 /* Where we're reading from. */
269 /* If non-zero, a buffer into which to copy characters. */
271 /* If non-zero, a file into which to copy characters. */
274 /* A keyword we look for at the beginning of lines. If found, it is
275 not copied, and SAW_KEYWORD is set to true. */
277 /* The current point we've reached in an occurrence of KEYWORD in
279 const char *cur_keyword_ptr
;
280 /* Set to true if we saw an occurrence of KEYWORD. */
284 /* Output CH to the file or buffer in STATE. Any pending newlines or
285 spaces are output first. */
288 put_char (int ch
, struct rcsoc_state
*state
)
293 if (state
->pending_newlines
> 0)
295 state
->pending_newlines
--;
298 else if (state
->pending_spaces
> 0)
300 state
->pending_spaces
--;
307 putc (out_ch
, state
->out_file
);
309 *state
->buf_ptr
++ = out_ch
;
311 while (out_ch
!= ch
);
314 /* If in the middle of scanning a keyword, continue scanning with
315 character CH, otherwise output CH to the file or buffer in STATE.
316 Any pending newlines or spaces are output first, as well as any
317 previously scanned characters that were thought to be part of a
318 keyword, but were in fact not. */
321 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
324 && *state
->cur_keyword_ptr
== ch
325 && (state
->cur_keyword_ptr
> state
->keyword
326 || state
->pending_newlines
> 0))
327 /* We might be looking at STATE->keyword at some point.
328 Keep looking until we know for sure. */
330 if (*++state
->cur_keyword_ptr
== '\0')
331 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
333 state
->saw_keyword
= 1;
335 /* Reset the scanning pointer. */
336 state
->cur_keyword_ptr
= state
->keyword
;
338 /* Canonicalize whitespace preceding a usage string. */
339 state
->pending_newlines
= 2;
340 state
->pending_spaces
= 0;
342 /* Skip any whitespace between the keyword and the
345 ch
= getc (state
->in_file
);
346 while (ch
== ' ' || ch
== '\n');
348 /* Output the open-paren we just read. */
349 put_char (ch
, state
);
351 /* Skip the function name and replace it with `fn'. */
353 ch
= getc (state
->in_file
);
354 while (ch
!= ' ' && ch
!= ')');
355 put_char ('f', state
);
356 put_char ('n', state
);
358 /* Put back the last character. */
359 ungetc (ch
, state
->in_file
);
364 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
365 /* We scanned the beginning of a potential usage
366 keyword, but it was a false alarm. Output the
371 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
372 put_char (*p
, state
);
374 state
->cur_keyword_ptr
= state
->keyword
;
377 put_char (ch
, state
);
382 /* Skip a C string or C-style comment from INFILE, and return the
383 character that follows. COMMENT non-zero means skip a comment. If
384 PRINTFLAG is positive, output string contents to outfile. If it is
385 negative, store contents in buf. Convert escape sequences \n and
386 \t to newline and tab; discard \ followed by newline.
387 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
388 at the beginning of a line will be removed, and *SAW_USAGE set to
389 true if any were encountered. */
392 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
395 struct rcsoc_state state
;
397 state
.in_file
= infile
;
398 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
399 state
.out_file
= (printflag
> 0 ? outfile
: 0);
400 state
.pending_spaces
= 0;
401 state
.pending_newlines
= 0;
402 state
.keyword
= (saw_usage
? "usage:" : 0);
403 state
.cur_keyword_ptr
= state
.keyword
;
404 state
.saw_keyword
= 0;
408 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
413 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
418 if (c
== '\n' || c
== '\r')
430 state
.pending_spaces
++;
433 state
.pending_newlines
++;
434 state
.pending_spaces
= 0;
437 scan_keyword_or_put_char (c
, &state
);
453 scan_keyword_or_put_char ('*', &state
);
460 /* If we had a "", concatenate the two strings. */
469 *saw_usage
= state
.saw_keyword
;
476 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
477 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
480 write_c_args (FILE *out
, char *func
, char *buf
, int minargs
, int maxargs
)
485 size_t ident_length
= 0;
487 fprintf (out
, "(fn");
492 for (p
= buf
; *p
; p
++)
496 /* Notice when a new identifier starts. */
497 if ((('A' <= c
&& c
<= 'Z')
498 || ('a' <= c
&& c
<= 'z')
499 || ('0' <= c
&& c
<= '9')
511 ident_length
= p
- ident_start
;
515 /* Found the end of an argument, write out the last seen
517 if (c
== ',' || c
== ')')
519 if (ident_length
== 0)
521 error ("empty arg list for `%s' should be (void), not ()", func
);
525 if (strncmp (ident_start
, "void", ident_length
) == 0)
530 if (minargs
== 0 && maxargs
> 0)
531 fprintf (out
, "&optional ");
536 /* In C code, `default' is a reserved word, so we spell it
537 `defalt'; unmangle that here. */
538 if (ident_length
== 6 && strncmp (ident_start
, "defalt", 6) == 0)
539 fprintf (out
, "DEFAULT");
541 while (ident_length
-- > 0)
544 if (c
>= 'a' && c
<= 'z')
545 /* Upcase the letter. */
548 /* Print underscore as hyphen. */
558 /* The types of globals. */
567 /* A single global. */
570 enum global_type type
;
574 /* All the variable names we saw while scanning C sources in `-g'
577 int num_globals_allocated
;
578 struct global
*globals
;
581 add_global (enum global_type type
, char *name
)
583 /* Ignore the one non-symbol that can occur. */
584 if (strcmp (name
, "..."))
588 if (num_globals_allocated
== 0)
590 num_globals_allocated
= 100;
591 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
593 else if (num_globals
== num_globals_allocated
)
595 num_globals_allocated
*= 2;
596 globals
= xrealloc (globals
,
597 num_globals_allocated
* sizeof (struct global
));
600 globals
[num_globals
- 1].type
= type
;
601 globals
[num_globals
- 1].name
= name
;
606 compare_globals (const void *a
, const void *b
)
608 const struct global
*ga
= a
;
609 const struct global
*gb
= b
;
610 return strcmp (ga
->name
, gb
->name
);
617 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
618 for (i
= 0; i
< num_globals
; ++i
)
622 switch (globals
[i
].type
)
631 type
= "Lisp_Object";
634 fatal ("not a recognized DEFVAR_", 0);
637 fprintf (outfile
, " %s f_%s;\n", type
, globals
[i
].name
);
638 fprintf (outfile
, "#define %s globals.f_%s\n",
639 globals
[i
].name
, globals
[i
].name
);
640 while (i
+ 1 < num_globals
641 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
645 fprintf (outfile
, "};\n");
646 fprintf (outfile
, "extern struct emacs_globals globals;\n");
650 /* Read through a c file. If a .o file is named,
651 the corresponding .c or .m file is read instead.
652 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
653 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
656 scan_c_file (char *filename
, const char *mode
)
661 register int defunflag
;
662 register int defvarperbufferflag
;
663 register int defvarflag
;
664 int minargs
, maxargs
;
665 int extension
= filename
[strlen (filename
) - 1];
666 enum global_type type
;
668 if (extension
== 'o')
669 filename
[strlen (filename
) - 1] = 'c';
671 infile
= fopen (filename
, mode
);
673 if (infile
== NULL
&& extension
== 'o')
676 filename
[strlen (filename
) - 1] = 'm';
677 infile
= fopen (filename
, mode
);
679 filename
[strlen (filename
) - 1] = 'c'; /* don't confuse people */
682 /* No error if non-ex input file */
689 /* Reset extension to be able to detect duplicate files. */
690 filename
[strlen (filename
) - 1] = extension
;
693 while (!feof (infile
))
697 if (c
!= '\n' && c
!= '\r')
732 defvarperbufferflag
= (c
== 'P');
733 if (generate_globals
)
736 type
= EMACS_INTEGER
;
746 /* We need to distinguish between DEFVAR_BOOL and
747 DEFVAR_BUFFER_DEFAULTS. */
748 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
760 defunflag
= c
== 'U';
762 defvarperbufferflag
= 0;
766 if (generate_globals
&& (!defvarflag
|| defvarperbufferflag
777 /* Lisp variable or function name. */
781 c
= read_c_string_or_comment (infile
, -1, 0, 0);
783 if (generate_globals
)
788 /* Skip "," and whitespace. */
793 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
795 /* Read in the identifier. */
798 input_buffer
[i
++] = c
;
801 while (! (c
== ',' || c
== ' ' || c
== '\t' ||
802 c
== '\n' || c
== '\r'));
803 input_buffer
[i
] = '\0';
805 name
= xmalloc (i
+ 1);
806 memcpy (name
, input_buffer
, i
+ 1);
807 add_global (type
, name
);
811 /* DEFVAR_LISP ("name", addr, "doc")
812 DEFVAR_LISP ("name", addr /\* doc *\/)
813 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
817 else if (defvarperbufferflag
)
821 else /* For DEFSIMPLE and DEFPRED */
830 if (defunflag
&& (commas
== 1 || commas
== 2))
835 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
839 if (commas
== 2) /* pick up minargs */
840 scanned
= fscanf (infile
, "%d", &minargs
);
841 else /* pick up maxargs */
842 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
845 scanned
= fscanf (infile
, "%d", &maxargs
);
856 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
860 c
= read_c_string_or_comment (infile
, 0, 0, 0);
862 while (c
!= EOF
&& c
!= ',' && c
!= '/')
867 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
869 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
875 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
882 && (c
= getc (infile
),
886 int comment
= c
!= '"';
890 putc (defvarflag
? 'V' : 'F', outfile
);
891 fprintf (outfile
, "%s\n", input_buffer
);
894 getc (infile
); /* Skip past `*' */
895 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
897 /* If this is a defun, find the arguments and print them. If
898 this function takes MANY or UNEVALLED args, then the C source
899 won't give the names of the arguments, so we shouldn't bother
902 Various doc-string styles:
903 0: DEFUN (..., "DOC") (args) [!comment]
904 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
905 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
907 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
909 char argbuf
[1024], *p
= argbuf
;
911 if (!comment
|| doc_keyword
)
919 /* Skip into arguments. */
926 /* Copy arguments into ARGBUF. */
929 *p
++ = c
= getc (infile
);
933 fprintf (outfile
, "\n\n");
934 write_c_args (outfile
, input_buffer
, argbuf
, minargs
, maxargs
);
936 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
937 /* The DOC should provide the usage form. */
938 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
947 /* Read a file of Lisp code, compiled or interpreted.
949 (defun NAME ARGS DOCSTRING ...)
950 (defmacro NAME ARGS DOCSTRING ...)
951 (defsubst NAME ARGS DOCSTRING ...)
952 (autoload (quote NAME) FILE DOCSTRING ...)
953 (defvar NAME VALUE DOCSTRING)
954 (defconst NAME VALUE DOCSTRING)
955 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
956 (fset (quote NAME) #[... DOCSTRING ...])
957 (defalias (quote NAME) #[... DOCSTRING ...])
958 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
959 starting in column zero.
960 (quote NAME) may appear as 'NAME as well.
962 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
963 When we find that, we save it for the following defining-form,
964 and we use that instead of reading a doc string within that defining-form.
966 For defvar, defconst, and fset we skip to the docstring with a kludgy
967 formatting convention: all docstrings must appear on the same line as the
968 initial open-paren (the one in column zero) and must contain a backslash
969 and a newline immediately after the initial double-quote. No newlines
970 must appear between the beginning of the form and the first double-quote.
971 For defun, defmacro, and autoload, we know how to skip over the
972 arglist, but the doc string must still have a backslash and newline
973 immediately after the double quote.
974 The only source files that must follow this convention are preloaded
975 uncompiled ones like loaddefs.el and bindings.el; aside
976 from that, it is always the .elc file that we look at, and they are no
977 problem because byte-compiler output follows this convention.
978 The NAME and DOCSTRING are output.
979 NAME is preceded by `F' for a function or `V' for a variable.
980 An entry is output only if DOCSTRING has \ newline just after the opening "
984 skip_white (FILE *infile
)
987 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
993 read_lisp_symbol (FILE *infile
, char *buffer
)
996 char *fillp
= buffer
;
1003 *(++fillp
) = getc (infile
);
1004 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1015 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1017 skip_white (infile
);
1021 scan_lisp_file (const char *filename
, const char *mode
)
1025 char *saved_string
= 0;
1027 if (generate_globals
)
1028 fatal ("scanning lisp file when -g specified", 0);
1030 infile
= fopen (filename
, mode
);
1034 return 0; /* No error */
1038 while (!feof (infile
))
1040 char buffer
[BUFSIZ
];
1043 /* If not at end of line, skip till we get to one. */
1044 if (c
!= '\n' && c
!= '\r')
1049 /* Skip the line break. */
1050 while (c
== '\n' || c
== '\r')
1052 /* Detect a dynamic doc string and save it for the next expression. */
1061 /* Read the length. */
1062 while ((c
= getc (infile
),
1063 c
>= '0' && c
<= '9'))
1070 fatal ("invalid dynamic doc string length", "");
1073 fatal ("space not found after dynamic doc string length", "");
1075 /* The next character is a space that is counted in the length
1076 but not part of the doc string.
1077 We already read it, so just ignore it. */
1080 /* Read in the contents. */
1081 free (saved_string
);
1082 saved_string
= (char *) xmalloc (length
);
1083 for (i
= 0; i
< length
; i
++)
1084 saved_string
[i
] = getc (infile
);
1085 /* The last character is a ^_.
1086 That is needed in the .elc file
1087 but it is redundant in DOC. So get rid of it here. */
1088 saved_string
[length
- 1] = 0;
1089 /* Skip the line break. */
1090 while (c
== '\n' || c
== '\r')
1092 /* Skip the following line. */
1093 while (c
!= '\n' && c
!= '\r')
1102 read_lisp_symbol (infile
, buffer
);
1104 if (! strcmp (buffer
, "defun")
1105 || ! strcmp (buffer
, "defmacro")
1106 || ! strcmp (buffer
, "defsubst"))
1109 read_lisp_symbol (infile
, buffer
);
1111 /* Skip the arguments: either "nil" or a list in parens */
1114 if (c
== 'n') /* nil */
1116 if ((c
= getc (infile
)) != 'i'
1117 || (c
= getc (infile
)) != 'l')
1119 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1126 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1133 skip_white (infile
);
1135 /* If the next three characters aren't `dquote bslash newline'
1136 then we're not reading a docstring.
1138 if ((c
= getc (infile
)) != '"'
1139 || (c
= getc (infile
)) != '\\'
1140 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1143 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1150 else if (! strcmp (buffer
, "defvar")
1151 || ! strcmp (buffer
, "defconst"))
1153 char c1
= 0, c2
= 0;
1155 read_lisp_symbol (infile
, buffer
);
1157 if (saved_string
== 0)
1160 /* Skip until the end of line; remember two previous chars. */
1161 while (c
!= '\n' && c
!= '\r' && c
>= 0)
1168 /* If two previous characters were " and \,
1169 this is a doc string. Otherwise, there is none. */
1170 if (c2
!= '"' || c1
!= '\\')
1173 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1181 else if (! strcmp (buffer
, "custom-declare-variable")
1182 || ! strcmp (buffer
, "defvaralias")
1185 char c1
= 0, c2
= 0;
1190 read_lisp_symbol (infile
, buffer
);
1196 "## unparsable name in custom-declare-variable in %s\n",
1200 read_lisp_symbol (infile
, buffer
);
1201 if (strcmp (buffer
, "quote"))
1204 "## unparsable name in custom-declare-variable in %s\n",
1208 read_lisp_symbol (infile
, buffer
);
1213 "## unparsable quoted name in custom-declare-variable in %s\n",
1219 if (saved_string
== 0)
1221 /* Skip to end of line; remember the two previous chars. */
1222 while (c
!= '\n' && c
!= '\r' && c
>= 0)
1229 /* If two previous characters were " and \,
1230 this is a doc string. Otherwise, there is none. */
1231 if (c2
!= '"' || c1
!= '\\')
1234 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1242 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1244 char c1
= 0, c2
= 0;
1249 read_lisp_symbol (infile
, buffer
);
1254 fprintf (stderr
, "## unparsable name in fset in %s\n",
1258 read_lisp_symbol (infile
, buffer
);
1259 if (strcmp (buffer
, "quote"))
1261 fprintf (stderr
, "## unparsable name in fset in %s\n",
1265 read_lisp_symbol (infile
, buffer
);
1270 "## unparsable quoted name in fset in %s\n",
1276 if (saved_string
== 0)
1278 /* Skip to end of line; remember the two previous chars. */
1279 while (c
!= '\n' && c
!= '\r' && c
>= 0)
1286 /* If two previous characters were " and \,
1287 this is a doc string. Otherwise, there is none. */
1288 if (c2
!= '"' || c1
!= '\\')
1291 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1299 else if (! strcmp (buffer
, "autoload"))
1304 read_lisp_symbol (infile
, buffer
);
1309 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1313 read_lisp_symbol (infile
, buffer
);
1314 if (strcmp (buffer
, "quote"))
1316 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1320 read_lisp_symbol (infile
, buffer
);
1325 "## unparsable quoted name in autoload in %s\n",
1330 skip_white (infile
);
1331 if ((c
= getc (infile
)) != '\"')
1333 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1337 read_c_string_or_comment (infile
, 0, 0, 0);
1338 skip_white (infile
);
1340 if (saved_string
== 0)
1342 /* If the next three characters aren't `dquote bslash newline'
1343 then we're not reading a docstring. */
1344 if ((c
= getc (infile
)) != '"'
1345 || (c
= getc (infile
)) != '\\'
1346 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1349 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1358 else if (! strcmp (buffer
, "if")
1359 || ! strcmp (buffer
, "byte-code"))
1366 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1372 /* At this point, we should either use the previous
1373 dynamic doc string in saved_string
1374 or gobble a doc string from the input file.
1376 In the latter case, the opening quote (and leading
1377 backslash-newline) have already been read. */
1379 putc (037, outfile
);
1380 putc (type
, outfile
);
1381 fprintf (outfile
, "%s\n", buffer
);
1384 fputs (saved_string
, outfile
);
1385 /* Don't use one dynamic doc string twice. */
1386 free (saved_string
);
1390 read_c_string_or_comment (infile
, 1, 0, 0);
1397 /* make-docfile.c ends here */