1 /* Generate doc-string file for GNU Emacs from source files.
3 Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2014 Free Software
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 */
43 /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this
44 is really just insurance. */
47 #endif /* WINDOWSNT */
49 #include <binary-io.h>
52 /* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this
53 is really just insurance.
55 Similarly, msdos defines this as sys_chdir, but we're not linking with the
56 file where that function is defined. */
58 #define IS_SLASH(c) ((c) == '/' || (c) == '\\' || (c) == ':')
59 #else /* not DOS_NT */
60 #define IS_SLASH(c) ((c) == '/')
61 #endif /* not DOS_NT */
63 static int scan_file (char *filename
);
64 static int scan_lisp_file (const char *filename
, const char *mode
);
65 static int scan_c_file (char *filename
, const char *mode
);
66 static void start_globals (void);
67 static void write_globals (void);
71 /* Name this program was invoked with. */
74 /* Nonzero if this invocation is generating globals.h. */
77 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
81 error (const char *s1
, const char *s2
)
83 fprintf (stderr
, "%s: ", progname
);
84 fprintf (stderr
, s1
, s2
);
85 fprintf (stderr
, "\n");
88 /* Print error message and exit. */
92 fatal (const char *s1
, const char *s2
)
98 /* Like malloc but get fatal error if memory is exhausted. */
101 xmalloc (unsigned int size
)
103 void *result
= (void *) malloc (size
);
105 fatal ("virtual memory exhausted", 0);
109 /* Like realloc but get fatal error if memory is exhausted. */
112 xrealloc (void *arg
, unsigned int size
)
114 void *result
= (void *) realloc (arg
, size
);
116 fatal ("virtual memory exhausted", 0);
122 main (int argc
, char **argv
)
130 /* If first two args are -o FILE, output to FILE. */
132 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
134 if (! freopen (argv
[i
+ 1], "w", stdout
))
136 perror (argv
[i
+ 1]);
141 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
143 if (! freopen (argv
[i
+ 1], "a", stdout
))
145 perror (argv
[i
+ 1]);
150 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
152 if (chdir (argv
[i
+ 1]) != 0)
154 perror (argv
[i
+ 1]);
159 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
161 generate_globals
= 1;
165 set_binary_mode (fileno (stdout
), O_BINARY
);
167 if (generate_globals
)
171 for (; i
< argc
; i
++)
174 /* Don't process one file twice. */
175 for (j
= first_infile
; j
< i
; j
++)
176 if (! strcmp (argv
[i
], argv
[j
]))
179 err_count
+= scan_file (argv
[i
]);
182 if (err_count
== 0 && generate_globals
)
185 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
188 /* Add a source file name boundary marker in the output file. */
190 put_filename (char *filename
)
194 for (tmp
= filename
; *tmp
; tmp
++)
196 if (IS_DIRECTORY_SEP (*tmp
))
200 printf ("\037S%s\n", filename
);
203 /* Read file FILENAME and output its doc strings to stdout.
204 Return 1 if file is not found, 0 if it is found. */
207 scan_file (char *filename
)
210 size_t len
= strlen (filename
);
212 if (!generate_globals
)
213 put_filename (filename
);
214 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
215 return scan_lisp_file (filename
, "rb");
216 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
217 return scan_lisp_file (filename
, "r");
219 return scan_c_file (filename
, "r");
225 puts ("/* This file was auto-generated by make-docfile. */");
226 puts ("/* DO NOT EDIT. */");
227 puts ("struct emacs_globals {");
230 static char input_buffer
[128];
232 /* Some state during the execution of `read_c_string_or_comment'. */
235 /* A count of spaces and newlines that have been read, but not output. */
236 unsigned pending_spaces
, pending_newlines
;
238 /* Where we're reading from. */
241 /* If non-zero, a buffer into which to copy characters. */
243 /* If non-zero, a file into which to copy characters. */
246 /* A keyword we look for at the beginning of lines. If found, it is
247 not copied, and SAW_KEYWORD is set to true. */
249 /* The current point we've reached in an occurrence of KEYWORD in
251 const char *cur_keyword_ptr
;
252 /* Set to true if we saw an occurrence of KEYWORD. */
256 /* Output CH to the file or buffer in STATE. Any pending newlines or
257 spaces are output first. */
260 put_char (int ch
, struct rcsoc_state
*state
)
265 if (state
->pending_newlines
> 0)
267 state
->pending_newlines
--;
270 else if (state
->pending_spaces
> 0)
272 state
->pending_spaces
--;
279 putc (out_ch
, state
->out_file
);
281 *state
->buf_ptr
++ = out_ch
;
283 while (out_ch
!= ch
);
286 /* If in the middle of scanning a keyword, continue scanning with
287 character CH, otherwise output CH to the file or buffer in STATE.
288 Any pending newlines or spaces are output first, as well as any
289 previously scanned characters that were thought to be part of a
290 keyword, but were in fact not. */
293 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
296 && *state
->cur_keyword_ptr
== ch
297 && (state
->cur_keyword_ptr
> state
->keyword
298 || state
->pending_newlines
> 0))
299 /* We might be looking at STATE->keyword at some point.
300 Keep looking until we know for sure. */
302 if (*++state
->cur_keyword_ptr
== '\0')
303 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
305 state
->saw_keyword
= 1;
307 /* Reset the scanning pointer. */
308 state
->cur_keyword_ptr
= state
->keyword
;
310 /* Canonicalize whitespace preceding a usage string. */
311 state
->pending_newlines
= 2;
312 state
->pending_spaces
= 0;
314 /* Skip any whitespace between the keyword and the
317 ch
= getc (state
->in_file
);
318 while (ch
== ' ' || ch
== '\n');
320 /* Output the open-paren we just read. */
321 put_char (ch
, state
);
323 /* Skip the function name and replace it with `fn'. */
325 ch
= getc (state
->in_file
);
326 while (ch
!= ' ' && ch
!= ')');
327 put_char ('f', state
);
328 put_char ('n', state
);
330 /* Put back the last character. */
331 ungetc (ch
, state
->in_file
);
336 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
337 /* We scanned the beginning of a potential usage
338 keyword, but it was a false alarm. Output the
343 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
344 put_char (*p
, state
);
346 state
->cur_keyword_ptr
= state
->keyword
;
349 put_char (ch
, state
);
354 /* Skip a C string or C-style comment from INFILE, and return the
355 character that follows. COMMENT non-zero means skip a comment. If
356 PRINTFLAG is positive, output string contents to stdout. If it is
357 negative, store contents in buf. Convert escape sequences \n and
358 \t to newline and tab; discard \ followed by newline.
359 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
360 at the beginning of a line will be removed, and *SAW_USAGE set to
361 true if any were encountered. */
364 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
367 struct rcsoc_state state
;
369 state
.in_file
= infile
;
370 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
371 state
.out_file
= (printflag
> 0 ? stdout
: 0);
372 state
.pending_spaces
= 0;
373 state
.pending_newlines
= 0;
374 state
.keyword
= (saw_usage
? "usage:" : 0);
375 state
.cur_keyword_ptr
= state
.keyword
;
376 state
.saw_keyword
= 0;
380 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
385 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
390 if (c
== '\n' || c
== '\r')
402 state
.pending_spaces
++;
405 state
.pending_newlines
++;
406 state
.pending_spaces
= 0;
409 scan_keyword_or_put_char (c
, &state
);
425 scan_keyword_or_put_char ('*', &state
);
432 /* If we had a "", concatenate the two strings. */
441 *saw_usage
= state
.saw_keyword
;
448 /* Write to stdout the argument names of function FUNC, whose text is in BUF.
449 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
452 write_c_args (char *func
, char *buf
, int minargs
, int maxargs
)
456 char *ident_start
IF_LINT (= NULL
);
457 size_t ident_length
= 0;
459 fputs ("(fn", stdout
);
464 for (p
= buf
; *p
; p
++)
468 /* Notice when a new identifier starts. */
469 if ((('A' <= c
&& c
<= 'Z')
470 || ('a' <= c
&& c
<= 'z')
471 || ('0' <= c
&& c
<= '9')
483 ident_length
= p
- ident_start
;
487 /* Found the end of an argument, write out the last seen
489 if (c
== ',' || c
== ')')
491 if (ident_length
== 0)
493 error ("empty arg list for `%s' should be (void), not ()", func
);
497 if (strncmp (ident_start
, "void", ident_length
) == 0)
502 if (minargs
== 0 && maxargs
> 0)
503 fputs ("&optional ", stdout
);
508 /* In C code, `default' is a reserved word, so we spell it
509 `defalt'; demangle that here. */
510 if (ident_length
== 6 && memcmp (ident_start
, "defalt", 6) == 0)
511 fputs ("DEFAULT", stdout
);
513 while (ident_length
-- > 0)
516 if (c
>= 'a' && c
<= 'z')
517 /* Upcase the letter. */
520 /* Print underscore as hyphen. */
530 /* The types of globals. These are sorted roughly in decreasing alignment
531 order to avoid allocation gaps, except that functions are last. */
541 /* A single global. */
544 enum global_type type
;
549 /* All the variable names we saw while scanning C sources in `-g'
552 int num_globals_allocated
;
553 struct global
*globals
;
556 add_global (enum global_type type
, char *name
, int value
)
558 /* Ignore the one non-symbol that can occur. */
559 if (strcmp (name
, "..."))
563 if (num_globals_allocated
== 0)
565 num_globals_allocated
= 100;
566 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
568 else if (num_globals
== num_globals_allocated
)
570 num_globals_allocated
*= 2;
571 globals
= xrealloc (globals
,
572 num_globals_allocated
* sizeof (struct global
));
575 globals
[num_globals
- 1].type
= type
;
576 globals
[num_globals
- 1].name
= name
;
577 globals
[num_globals
- 1].value
= value
;
582 compare_globals (const void *a
, const void *b
)
584 const struct global
*ga
= a
;
585 const struct global
*gb
= b
;
587 if (ga
->type
!= gb
->type
)
588 return ga
->type
- gb
->type
;
590 return strcmp (ga
->name
, gb
->name
);
594 close_emacs_globals (void)
597 puts ("extern struct emacs_globals globals;");
603 int i
, seen_defun
= 0;
604 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
605 for (i
= 0; i
< num_globals
; ++i
)
607 char const *type
= 0;
609 switch (globals
[i
].type
)
618 type
= "Lisp_Object";
623 close_emacs_globals ();
629 fatal ("not a recognized DEFVAR_", 0);
634 printf (" %s f_%s;\n", type
, globals
[i
].name
);
635 printf ("#define %s globals.f_%s\n",
636 globals
[i
].name
, globals
[i
].name
);
640 /* It would be nice to have a cleaner way to deal with these
642 if (strcmp (globals
[i
].name
, "Fthrow") == 0
643 || strcmp (globals
[i
].name
, "Ftop_level") == 0
644 || strcmp (globals
[i
].name
, "Fkill_emacs") == 0
645 || strcmp (globals
[i
].name
, "Fexit_recursive_edit") == 0
646 || strcmp (globals
[i
].name
, "Fabort_recursive_edit") == 0)
647 fputs ("_Noreturn ", stdout
);
649 printf ("EXFUN (%s, ", globals
[i
].name
);
650 if (globals
[i
].value
== -1)
651 fputs ("MANY", stdout
);
652 else if (globals
[i
].value
== -2)
653 fputs ("UNEVALLED", stdout
);
655 printf ("%d", globals
[i
].value
);
658 /* It would be nice to have a cleaner way to deal with these
659 special hacks, too. */
660 if (strcmp (globals
[i
].name
, "Fbyteorder") == 0
661 || strcmp (globals
[i
].name
, "Ftool_bar_height") == 0
662 || strcmp (globals
[i
].name
, "Fmax_char") == 0
663 || strcmp (globals
[i
].name
, "Fidentity") == 0)
664 fputs (" ATTRIBUTE_CONST", stdout
);
669 while (i
+ 1 < num_globals
670 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
672 if (globals
[i
].type
== FUNCTION
673 && globals
[i
].value
!= globals
[i
+ 1].value
)
674 error ("function '%s' defined twice with differing signatures",
681 close_emacs_globals ();
685 /* Read through a c file. If a .o file is named,
686 the corresponding .c or .m file is read instead.
687 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
688 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
691 scan_c_file (char *filename
, const char *mode
)
696 int minargs
, maxargs
;
697 int extension
= filename
[strlen (filename
) - 1];
699 if (extension
== 'o')
700 filename
[strlen (filename
) - 1] = 'c';
702 infile
= fopen (filename
, mode
);
704 if (infile
== NULL
&& extension
== 'o')
707 filename
[strlen (filename
) - 1] = 'm';
708 infile
= fopen (filename
, mode
);
710 filename
[strlen (filename
) - 1] = 'c'; /* Don't confuse people. */
713 /* No error if non-ex input file. */
720 /* Reset extension to be able to detect duplicate files. */
721 filename
[strlen (filename
) - 1] = extension
;
724 while (!feof (infile
))
728 int defvarperbufferflag
= 0;
730 enum global_type type
= INVALID
;
731 char *name
IF_LINT (= 0);
733 if (c
!= '\n' && c
!= '\r')
767 defvarperbufferflag
= (c
== 'P');
768 if (generate_globals
)
771 type
= EMACS_INTEGER
;
779 /* We need to distinguish between DEFVAR_BOOL and
780 DEFVAR_BUFFER_DEFAULTS. */
781 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
793 defunflag
= c
== 'U';
798 && (!defvarflag
|| defvarperbufferflag
|| type
== INVALID
)
809 /* Lisp variable or function name. */
813 c
= read_c_string_or_comment (infile
, -1, 0, 0);
815 if (generate_globals
)
819 /* Skip "," and whitespace. */
824 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
826 /* Read in the identifier. */
829 input_buffer
[i
++] = c
;
832 while (! (c
== ',' || c
== ' ' || c
== '\t'
833 || c
== '\n' || c
== '\r'));
834 input_buffer
[i
] = '\0';
836 name
= xmalloc (i
+ 1);
837 memcpy (name
, input_buffer
, i
+ 1);
841 add_global (type
, name
, 0);
846 /* DEFVAR_LISP ("name", addr, "doc")
847 DEFVAR_LISP ("name", addr /\* doc *\/)
848 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
851 commas
= generate_globals
? 4 : 5;
852 else if (defvarperbufferflag
)
856 else /* For DEFSIMPLE and DEFPRED. */
865 if (defunflag
&& (commas
== 1 || commas
== 2))
870 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
874 if (commas
== 2) /* Pick up minargs. */
875 scanned
= fscanf (infile
, "%d", &minargs
);
876 else /* Pick up maxargs. */
877 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
879 if (generate_globals
)
880 maxargs
= (c
== 'M') ? -1 : -2;
885 scanned
= fscanf (infile
, "%d", &maxargs
);
896 if (generate_globals
)
898 add_global (FUNCTION
, name
, maxargs
);
902 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
906 c
= read_c_string_or_comment (infile
, 0, 0, 0);
908 while (c
!= EOF
&& c
!= ',' && c
!= '/')
913 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
915 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
921 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
928 && (c
= getc (infile
),
932 int comment
= c
!= '"';
935 printf ("\037%c%s\n", defvarflag
? 'V' : 'F', input_buffer
);
938 getc (infile
); /* Skip past `*'. */
939 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
941 /* If this is a defun, find the arguments and print them. If
942 this function takes MANY or UNEVALLED args, then the C source
943 won't give the names of the arguments, so we shouldn't bother
946 Various doc-string styles:
947 0: DEFUN (..., "DOC") (args) [!comment]
948 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
949 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
951 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
953 char argbuf
[1024], *p
= argbuf
;
955 if (!comment
|| doc_keyword
)
963 /* Skip into arguments. */
970 /* Copy arguments into ARGBUF. */
973 *p
++ = c
= getc (infile
);
977 fputs ("\n\n", stdout
);
978 write_c_args (input_buffer
, argbuf
, minargs
, maxargs
);
980 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
981 /* The DOC should provide the usage form. */
982 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
991 /* Read a file of Lisp code, compiled or interpreted.
993 (defun NAME ARGS DOCSTRING ...)
994 (defmacro NAME ARGS DOCSTRING ...)
995 (defsubst NAME ARGS DOCSTRING ...)
996 (autoload (quote NAME) FILE DOCSTRING ...)
997 (defvar NAME VALUE DOCSTRING)
998 (defconst NAME VALUE DOCSTRING)
999 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
1000 (fset (quote NAME) #[... DOCSTRING ...])
1001 (defalias (quote NAME) #[... DOCSTRING ...])
1002 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
1003 starting in column zero.
1004 (quote NAME) may appear as 'NAME as well.
1006 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
1007 When we find that, we save it for the following defining-form,
1008 and we use that instead of reading a doc string within that defining-form.
1010 For defvar, defconst, and fset we skip to the docstring with a kludgy
1011 formatting convention: all docstrings must appear on the same line as the
1012 initial open-paren (the one in column zero) and must contain a backslash
1013 and a newline immediately after the initial double-quote. No newlines
1014 must appear between the beginning of the form and the first double-quote.
1015 For defun, defmacro, and autoload, we know how to skip over the
1016 arglist, but the doc string must still have a backslash and newline
1017 immediately after the double quote.
1018 The only source files that must follow this convention are preloaded
1019 uncompiled ones like loaddefs.el; aside from that, it is always the .elc
1020 file that we should look at, and they are no problem because byte-compiler
1021 output follows this convention.
1022 The NAME and DOCSTRING are output.
1023 NAME is preceded by `F' for a function or `V' for a variable.
1024 An entry is output only if DOCSTRING has \ newline just after the opening ".
1028 skip_white (FILE *infile
)
1031 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
1037 read_lisp_symbol (FILE *infile
, char *buffer
)
1040 char *fillp
= buffer
;
1042 skip_white (infile
);
1047 *(++fillp
) = getc (infile
);
1048 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1059 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1061 skip_white (infile
);
1065 search_lisp_doc_at_eol (FILE *infile
)
1067 int c
= 0, c1
= 0, c2
= 0;
1069 /* Skip until the end of line; remember two previous chars. */
1070 while (c
!= '\n' && c
!= '\r' && c
!= EOF
)
1077 /* If two previous characters were " and \,
1078 this is a doc string. Otherwise, there is none. */
1079 if (c2
!= '"' || c1
!= '\\')
1082 fprintf (stderr
, "## non-docstring found\n");
1091 #define DEF_ELISP_FILE(fn) { #fn, sizeof(#fn) - 1 }
1094 scan_lisp_file (const char *filename
, const char *mode
)
1098 char *saved_string
= 0;
1099 /* These are the only files that are loaded uncompiled, and must
1100 follow the conventions of the doc strings expected by this
1101 function. These conventions are automatically followed by the
1102 byte compiler when it produces the .elc files. */
1106 } const uncompiled
[] = {
1107 DEF_ELISP_FILE (loaddefs
.el
),
1108 DEF_ELISP_FILE (loadup
.el
),
1109 DEF_ELISP_FILE (charprop
.el
),
1110 DEF_ELISP_FILE (cp51932
.el
),
1111 DEF_ELISP_FILE (eucjp
-ms
.el
)
1114 size_t flen
= strlen (filename
);
1116 if (generate_globals
)
1117 fatal ("scanning lisp file when -g specified", 0);
1118 if (flen
> 3 && !strcmp (filename
+ flen
- 3, ".el"))
1120 for (i
= 0, match
= 0; i
< sizeof (uncompiled
) / sizeof (uncompiled
[0]);
1123 if (uncompiled
[i
].fl
<= flen
1124 && !strcmp (filename
+ flen
- uncompiled
[i
].fl
, uncompiled
[i
].fn
)
1125 && (flen
== uncompiled
[i
].fl
1126 || IS_SLASH (filename
[flen
- uncompiled
[i
].fl
- 1])))
1133 fatal ("uncompiled lisp file %s is not supported", filename
);
1136 infile
= fopen (filename
, mode
);
1140 return 0; /* No error. */
1144 while (!feof (infile
))
1146 char buffer
[BUFSIZ
];
1149 /* If not at end of line, skip till we get to one. */
1150 if (c
!= '\n' && c
!= '\r')
1155 /* Skip the line break. */
1156 while (c
== '\n' || c
== '\r')
1158 /* Detect a dynamic doc string and save it for the next expression. */
1167 /* Read the length. */
1168 while ((c
= getc (infile
),
1169 c
>= '0' && c
<= '9'))
1176 fatal ("invalid dynamic doc string length", "");
1179 fatal ("space not found after dynamic doc string length", "");
1181 /* The next character is a space that is counted in the length
1182 but not part of the doc string.
1183 We already read it, so just ignore it. */
1186 /* Read in the contents. */
1187 free (saved_string
);
1188 saved_string
= (char *) xmalloc (length
);
1189 for (i
= 0; i
< length
; i
++)
1190 saved_string
[i
] = getc (infile
);
1191 /* The last character is a ^_.
1192 That is needed in the .elc file
1193 but it is redundant in DOC. So get rid of it here. */
1194 saved_string
[length
- 1] = 0;
1195 /* Skip the line break. */
1196 while (c
== '\n' || c
== '\r')
1198 /* Skip the following line. */
1199 while (c
!= '\n' && c
!= '\r')
1208 read_lisp_symbol (infile
, buffer
);
1210 if (! strcmp (buffer
, "defun")
1211 || ! strcmp (buffer
, "defmacro")
1212 || ! strcmp (buffer
, "defsubst"))
1215 read_lisp_symbol (infile
, buffer
);
1217 /* Skip the arguments: either "nil" or a list in parens. */
1220 if (c
== 'n') /* nil */
1222 if ((c
= getc (infile
)) != 'i'
1223 || (c
= getc (infile
)) != 'l')
1225 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1232 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1239 skip_white (infile
);
1241 /* If the next three characters aren't `dquote bslash newline'
1242 then we're not reading a docstring.
1244 if ((c
= getc (infile
)) != '"'
1245 || (c
= getc (infile
)) != '\\'
1246 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1249 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1256 /* defcustom can only occur in uncompiled Lisp files. */
1257 else if (! strcmp (buffer
, "defvar")
1258 || ! strcmp (buffer
, "defconst")
1259 || ! strcmp (buffer
, "defcustom"))
1262 read_lisp_symbol (infile
, buffer
);
1264 if (saved_string
== 0)
1265 if (!search_lisp_doc_at_eol (infile
))
1269 else if (! strcmp (buffer
, "custom-declare-variable")
1270 || ! strcmp (buffer
, "defvaralias")
1277 read_lisp_symbol (infile
, buffer
);
1283 "## unparsable name in custom-declare-variable in %s\n",
1287 read_lisp_symbol (infile
, buffer
);
1288 if (strcmp (buffer
, "quote"))
1291 "## unparsable name in custom-declare-variable in %s\n",
1295 read_lisp_symbol (infile
, buffer
);
1300 "## unparsable quoted name in custom-declare-variable in %s\n",
1306 if (saved_string
== 0)
1307 if (!search_lisp_doc_at_eol (infile
))
1311 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1317 read_lisp_symbol (infile
, buffer
);
1322 fprintf (stderr
, "## unparsable name in fset in %s\n",
1326 read_lisp_symbol (infile
, buffer
);
1327 if (strcmp (buffer
, "quote"))
1329 fprintf (stderr
, "## unparsable name in fset in %s\n",
1333 read_lisp_symbol (infile
, buffer
);
1338 "## unparsable quoted name in fset in %s\n",
1344 if (saved_string
== 0)
1345 if (!search_lisp_doc_at_eol (infile
))
1349 else if (! strcmp (buffer
, "autoload"))
1354 read_lisp_symbol (infile
, buffer
);
1359 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1363 read_lisp_symbol (infile
, buffer
);
1364 if (strcmp (buffer
, "quote"))
1366 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1370 read_lisp_symbol (infile
, buffer
);
1375 "## unparsable quoted name in autoload in %s\n",
1380 skip_white (infile
);
1381 if ((c
= getc (infile
)) != '\"')
1383 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1387 read_c_string_or_comment (infile
, 0, 0, 0);
1389 if (saved_string
== 0)
1390 if (!search_lisp_doc_at_eol (infile
))
1395 else if (! strcmp (buffer
, "if")
1396 || ! strcmp (buffer
, "byte-code"))
1403 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1409 /* At this point, we should either use the previous dynamic doc string in
1410 saved_string or gobble a doc string from the input file.
1411 In the latter case, the opening quote (and leading backslash-newline)
1412 have already been read. */
1414 printf ("\037%c%s\n", type
, buffer
);
1417 fputs (saved_string
, stdout
);
1418 /* Don't use one dynamic doc string twice. */
1419 free (saved_string
);
1423 read_c_string_or_comment (infile
, 1, 0, 0);
1430 /* make-docfile.c ends here */