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 */
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 #define IS_SLASH(c) ((c) == '/' || (c) == '\\' || (c) == ':')
62 #else /* not DOS_NT */
64 #define READ_BINARY "r"
65 #define IS_SLASH(c) ((c) == '/')
66 #endif /* not DOS_NT */
68 static int scan_file (char *filename
);
69 static int scan_lisp_file (const char *filename
, const char *mode
);
70 static int scan_c_file (char *filename
, const char *mode
);
71 static void start_globals (void);
72 static void write_globals (void);
76 /* Stdio stream for output to the DOC file. */
79 /* Name this program was invoked with. */
82 /* Nonzero if this invocation is generating globals.h. */
85 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
89 error (const char *s1
, const char *s2
)
91 fprintf (stderr
, "%s: ", progname
);
92 fprintf (stderr
, s1
, s2
);
93 fprintf (stderr
, "\n");
96 /* Print error message and exit. */
100 fatal (const char *s1
, const char *s2
)
106 /* Like malloc but get fatal error if memory is exhausted. */
109 xmalloc (unsigned int size
)
111 void *result
= (void *) malloc (size
);
113 fatal ("virtual memory exhausted", 0);
117 /* Like realloc but get fatal error if memory is exhausted. */
120 xrealloc (void *arg
, unsigned int size
)
122 void *result
= (void *) realloc (arg
, size
);
124 fatal ("virtual memory exhausted", 0);
130 main (int argc
, char **argv
)
140 /* Don't put CRs in the DOC file. */
143 #if 0 /* Suspicion is that this causes hanging.
144 So instead we require people to use -o on MSDOS. */
145 (stdout
)->_flag
&= ~_IOTEXT
;
146 _setmode (fileno (stdout
), O_BINARY
);
152 _setmode (fileno (stdout
), O_BINARY
);
153 #endif /* WINDOWSNT */
155 /* If first two args are -o FILE, output to FILE. */
157 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
159 outfile
= fopen (argv
[i
+ 1], "w");
162 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
164 outfile
= fopen (argv
[i
+ 1], "a");
167 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-d"))
169 if (chdir (argv
[i
+ 1]) != 0)
171 perror (argv
[i
+ 1]);
176 if (argc
> i
&& !strcmp (argv
[i
], "-g"))
178 generate_globals
= 1;
183 fatal ("No output file specified", "");
185 if (generate_globals
)
189 for (; i
< argc
; i
++)
192 /* Don't process one file twice. */
193 for (j
= first_infile
; j
< i
; j
++)
194 if (! strcmp (argv
[i
], argv
[j
]))
197 err_count
+= scan_file (argv
[i
]);
200 if (err_count
== 0 && generate_globals
)
203 return (err_count
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
);
206 /* Add a source file name boundary marker in the output file. */
208 put_filename (char *filename
)
212 for (tmp
= filename
; *tmp
; tmp
++)
214 if (IS_DIRECTORY_SEP (*tmp
))
220 fprintf (outfile
, "%s\n", filename
);
223 /* Read file FILENAME and output its doc strings to outfile. */
224 /* Return 1 if file is not found, 0 if it is found. */
227 scan_file (char *filename
)
230 size_t len
= strlen (filename
);
232 if (!generate_globals
)
233 put_filename (filename
);
234 if (len
> 4 && !strcmp (filename
+ len
- 4, ".elc"))
235 return scan_lisp_file (filename
, READ_BINARY
);
236 else if (len
> 3 && !strcmp (filename
+ len
- 3, ".el"))
237 return scan_lisp_file (filename
, READ_TEXT
);
239 return scan_c_file (filename
, READ_TEXT
);
245 fprintf (outfile
, "/* This file was auto-generated by make-docfile. */\n");
246 fprintf (outfile
, "/* DO NOT EDIT. */\n");
247 fprintf (outfile
, "struct emacs_globals {\n");
250 static char input_buffer
[128];
252 /* Some state during the execution of `read_c_string_or_comment'. */
255 /* A count of spaces and newlines that have been read, but not output. */
256 unsigned pending_spaces
, pending_newlines
;
258 /* Where we're reading from. */
261 /* If non-zero, a buffer into which to copy characters. */
263 /* If non-zero, a file into which to copy characters. */
266 /* A keyword we look for at the beginning of lines. If found, it is
267 not copied, and SAW_KEYWORD is set to true. */
269 /* The current point we've reached in an occurrence of KEYWORD in
271 const char *cur_keyword_ptr
;
272 /* Set to true if we saw an occurrence of KEYWORD. */
276 /* Output CH to the file or buffer in STATE. Any pending newlines or
277 spaces are output first. */
280 put_char (int ch
, struct rcsoc_state
*state
)
285 if (state
->pending_newlines
> 0)
287 state
->pending_newlines
--;
290 else if (state
->pending_spaces
> 0)
292 state
->pending_spaces
--;
299 putc (out_ch
, state
->out_file
);
301 *state
->buf_ptr
++ = out_ch
;
303 while (out_ch
!= ch
);
306 /* If in the middle of scanning a keyword, continue scanning with
307 character CH, otherwise output CH to the file or buffer in STATE.
308 Any pending newlines or spaces are output first, as well as any
309 previously scanned characters that were thought to be part of a
310 keyword, but were in fact not. */
313 scan_keyword_or_put_char (int ch
, struct rcsoc_state
*state
)
316 && *state
->cur_keyword_ptr
== ch
317 && (state
->cur_keyword_ptr
> state
->keyword
318 || state
->pending_newlines
> 0))
319 /* We might be looking at STATE->keyword at some point.
320 Keep looking until we know for sure. */
322 if (*++state
->cur_keyword_ptr
== '\0')
323 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
325 state
->saw_keyword
= 1;
327 /* Reset the scanning pointer. */
328 state
->cur_keyword_ptr
= state
->keyword
;
330 /* Canonicalize whitespace preceding a usage string. */
331 state
->pending_newlines
= 2;
332 state
->pending_spaces
= 0;
334 /* Skip any whitespace between the keyword and the
337 ch
= getc (state
->in_file
);
338 while (ch
== ' ' || ch
== '\n');
340 /* Output the open-paren we just read. */
341 put_char (ch
, state
);
343 /* Skip the function name and replace it with `fn'. */
345 ch
= getc (state
->in_file
);
346 while (ch
!= ' ' && ch
!= ')');
347 put_char ('f', state
);
348 put_char ('n', state
);
350 /* Put back the last character. */
351 ungetc (ch
, state
->in_file
);
356 if (state
->keyword
&& state
->cur_keyword_ptr
> state
->keyword
)
357 /* We scanned the beginning of a potential usage
358 keyword, but it was a false alarm. Output the
363 for (p
= state
->keyword
; p
< state
->cur_keyword_ptr
; p
++)
364 put_char (*p
, state
);
366 state
->cur_keyword_ptr
= state
->keyword
;
369 put_char (ch
, state
);
374 /* Skip a C string or C-style comment from INFILE, and return the
375 character that follows. COMMENT non-zero means skip a comment. If
376 PRINTFLAG is positive, output string contents to outfile. If it is
377 negative, store contents in buf. Convert escape sequences \n and
378 \t to newline and tab; discard \ followed by newline.
379 If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
380 at the beginning of a line will be removed, and *SAW_USAGE set to
381 true if any were encountered. */
384 read_c_string_or_comment (FILE *infile
, int printflag
, int comment
, int *saw_usage
)
387 struct rcsoc_state state
;
389 state
.in_file
= infile
;
390 state
.buf_ptr
= (printflag
< 0 ? input_buffer
: 0);
391 state
.out_file
= (printflag
> 0 ? outfile
: 0);
392 state
.pending_spaces
= 0;
393 state
.pending_newlines
= 0;
394 state
.keyword
= (saw_usage
? "usage:" : 0);
395 state
.cur_keyword_ptr
= state
.keyword
;
396 state
.saw_keyword
= 0;
400 while (c
== '\n' || c
== '\r' || c
== '\t' || c
== ' ')
405 while (c
!= EOF
&& (comment
? c
!= '*' : c
!= '"'))
410 if (c
== '\n' || c
== '\r')
422 state
.pending_spaces
++;
425 state
.pending_newlines
++;
426 state
.pending_spaces
= 0;
429 scan_keyword_or_put_char (c
, &state
);
445 scan_keyword_or_put_char ('*', &state
);
452 /* If we had a "", concatenate the two strings. */
461 *saw_usage
= state
.saw_keyword
;
468 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
469 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
472 write_c_args (FILE *out
, char *func
, char *buf
, int minargs
, int maxargs
)
476 char *ident_start
IF_LINT (= NULL
);
477 size_t ident_length
= 0;
479 fprintf (out
, "(fn");
484 for (p
= buf
; *p
; p
++)
488 /* Notice when a new identifier starts. */
489 if ((('A' <= c
&& c
<= 'Z')
490 || ('a' <= c
&& c
<= 'z')
491 || ('0' <= c
&& c
<= '9')
503 ident_length
= p
- ident_start
;
507 /* Found the end of an argument, write out the last seen
509 if (c
== ',' || c
== ')')
511 if (ident_length
== 0)
513 error ("empty arg list for `%s' should be (void), not ()", func
);
517 if (strncmp (ident_start
, "void", ident_length
) == 0)
522 if (minargs
== 0 && maxargs
> 0)
523 fprintf (out
, "&optional ");
528 /* In C code, `default' is a reserved word, so we spell it
529 `defalt'; demangle that here. */
530 if (ident_length
== 6 && memcmp (ident_start
, "defalt", 6) == 0)
531 fprintf (out
, "DEFAULT");
533 while (ident_length
-- > 0)
536 if (c
>= 'a' && c
<= 'z')
537 /* Upcase the letter. */
540 /* Print underscore as hyphen. */
550 /* The types of globals. These are sorted roughly in decreasing alignment
551 order to avoid allocation gaps, except that functions are last. */
561 /* A single global. */
564 enum global_type type
;
569 /* All the variable names we saw while scanning C sources in `-g'
572 int num_globals_allocated
;
573 struct global
*globals
;
576 add_global (enum global_type type
, char *name
, int value
)
578 /* Ignore the one non-symbol that can occur. */
579 if (strcmp (name
, "..."))
583 if (num_globals_allocated
== 0)
585 num_globals_allocated
= 100;
586 globals
= xmalloc (num_globals_allocated
* sizeof (struct global
));
588 else if (num_globals
== num_globals_allocated
)
590 num_globals_allocated
*= 2;
591 globals
= xrealloc (globals
,
592 num_globals_allocated
* sizeof (struct global
));
595 globals
[num_globals
- 1].type
= type
;
596 globals
[num_globals
- 1].name
= name
;
597 globals
[num_globals
- 1].value
= value
;
602 compare_globals (const void *a
, const void *b
)
604 const struct global
*ga
= a
;
605 const struct global
*gb
= b
;
607 if (ga
->type
!= gb
->type
)
608 return ga
->type
- gb
->type
;
610 return strcmp (ga
->name
, gb
->name
);
614 close_emacs_globals (void)
616 fprintf (outfile
, "};\n");
617 fprintf (outfile
, "extern struct emacs_globals globals;\n");
623 int i
, seen_defun
= 0;
624 qsort (globals
, num_globals
, sizeof (struct global
), compare_globals
);
625 for (i
= 0; i
< num_globals
; ++i
)
627 char const *type
= 0;
629 switch (globals
[i
].type
)
638 type
= "Lisp_Object";
643 close_emacs_globals ();
644 fprintf (outfile
, "\n");
649 fatal ("not a recognized DEFVAR_", 0);
654 fprintf (outfile
, " %s f_%s;\n", type
, globals
[i
].name
);
655 fprintf (outfile
, "#define %s globals.f_%s\n",
656 globals
[i
].name
, globals
[i
].name
);
660 /* It would be nice to have a cleaner way to deal with these
662 if (strcmp (globals
[i
].name
, "Fthrow") == 0
663 || strcmp (globals
[i
].name
, "Ftop_level") == 0
664 || strcmp (globals
[i
].name
, "Fkill_emacs") == 0
665 || strcmp (globals
[i
].name
, "Fexit_recursive_edit") == 0
666 || strcmp (globals
[i
].name
, "Fabort_recursive_edit") == 0)
667 fprintf (outfile
, "_Noreturn ");
669 fprintf (outfile
, "EXFUN (%s, ", globals
[i
].name
);
670 if (globals
[i
].value
== -1)
671 fprintf (outfile
, "MANY");
672 else if (globals
[i
].value
== -2)
673 fprintf (outfile
, "UNEVALLED");
675 fprintf (outfile
, "%d", globals
[i
].value
);
676 fprintf (outfile
, ")");
678 /* It would be nice to have a cleaner way to deal with these
679 special hacks, too. */
680 if (strcmp (globals
[i
].name
, "Fbyteorder") == 0
681 || strcmp (globals
[i
].name
, "Ftool_bar_height") == 0
682 || strcmp (globals
[i
].name
, "Fmax_char") == 0
683 || strcmp (globals
[i
].name
, "Fidentity") == 0)
684 fprintf (outfile
, " ATTRIBUTE_CONST");
686 fprintf (outfile
, ";\n");
689 while (i
+ 1 < num_globals
690 && !strcmp (globals
[i
].name
, globals
[i
+ 1].name
))
692 if (globals
[i
].type
== FUNCTION
693 && globals
[i
].value
!= globals
[i
+ 1].value
)
694 error ("function '%s' defined twice with differing signatures",
701 close_emacs_globals ();
705 /* Read through a c file. If a .o file is named,
706 the corresponding .c or .m file is read instead.
707 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
708 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
711 scan_c_file (char *filename
, const char *mode
)
716 int minargs
, maxargs
;
717 int extension
= filename
[strlen (filename
) - 1];
719 if (extension
== 'o')
720 filename
[strlen (filename
) - 1] = 'c';
722 infile
= fopen (filename
, mode
);
724 if (infile
== NULL
&& extension
== 'o')
727 filename
[strlen (filename
) - 1] = 'm';
728 infile
= fopen (filename
, mode
);
730 filename
[strlen (filename
) - 1] = 'c'; /* Don't confuse people. */
733 /* No error if non-ex input file. */
740 /* Reset extension to be able to detect duplicate files. */
741 filename
[strlen (filename
) - 1] = extension
;
744 while (!feof (infile
))
748 int defvarperbufferflag
= 0;
750 enum global_type type
= INVALID
;
751 char *name
IF_LINT (= 0);
753 if (c
!= '\n' && c
!= '\r')
787 defvarperbufferflag
= (c
== 'P');
788 if (generate_globals
)
791 type
= EMACS_INTEGER
;
799 /* We need to distinguish between DEFVAR_BOOL and
800 DEFVAR_BUFFER_DEFAULTS. */
801 if (generate_globals
&& type
== BOOLEAN
&& c
!= 'O')
813 defunflag
= c
== 'U';
818 && (!defvarflag
|| defvarperbufferflag
|| type
== INVALID
)
829 /* Lisp variable or function name. */
833 c
= read_c_string_or_comment (infile
, -1, 0, 0);
835 if (generate_globals
)
839 /* Skip "," and whitespace. */
844 while (c
== ',' || c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r');
846 /* Read in the identifier. */
849 input_buffer
[i
++] = c
;
852 while (! (c
== ',' || c
== ' ' || c
== '\t'
853 || c
== '\n' || c
== '\r'));
854 input_buffer
[i
] = '\0';
856 name
= xmalloc (i
+ 1);
857 memcpy (name
, input_buffer
, i
+ 1);
861 add_global (type
, name
, 0);
866 /* DEFVAR_LISP ("name", addr, "doc")
867 DEFVAR_LISP ("name", addr /\* doc *\/)
868 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
871 commas
= generate_globals
? 4 : 5;
872 else if (defvarperbufferflag
)
876 else /* For DEFSIMPLE and DEFPRED. */
885 if (defunflag
&& (commas
== 1 || commas
== 2))
890 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t');
894 if (commas
== 2) /* Pick up minargs. */
895 scanned
= fscanf (infile
, "%d", &minargs
);
896 else /* Pick up maxargs. */
897 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
899 if (generate_globals
)
900 maxargs
= (c
== 'M') ? -1 : -2;
905 scanned
= fscanf (infile
, "%d", &maxargs
);
916 if (generate_globals
)
918 add_global (FUNCTION
, name
, maxargs
);
922 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
926 c
= read_c_string_or_comment (infile
, 0, 0, 0);
928 while (c
!= EOF
&& c
!= ',' && c
!= '/')
933 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
935 while ((c
>= 'a' && c
<= 'z') || (c
>= 'Z' && c
<= 'Z'))
941 while (c
== ' ' || c
== '\n' || c
== '\r' || c
== '\t')
948 && (c
= getc (infile
),
952 int comment
= c
!= '"';
956 putc (defvarflag
? 'V' : 'F', outfile
);
957 fprintf (outfile
, "%s\n", input_buffer
);
960 getc (infile
); /* Skip past `*'. */
961 c
= read_c_string_or_comment (infile
, 1, comment
, &saw_usage
);
963 /* If this is a defun, find the arguments and print them. If
964 this function takes MANY or UNEVALLED args, then the C source
965 won't give the names of the arguments, so we shouldn't bother
968 Various doc-string styles:
969 0: DEFUN (..., "DOC") (args) [!comment]
970 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
971 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
973 if (defunflag
&& maxargs
!= -1 && !saw_usage
)
975 char argbuf
[1024], *p
= argbuf
;
977 if (!comment
|| doc_keyword
)
985 /* Skip into arguments. */
992 /* Copy arguments into ARGBUF. */
995 *p
++ = c
= getc (infile
);
999 fprintf (outfile
, "\n\n");
1000 write_c_args (outfile
, input_buffer
, argbuf
, minargs
, maxargs
);
1002 else if (defunflag
&& maxargs
== -1 && !saw_usage
)
1003 /* The DOC should provide the usage form. */
1004 fprintf (stderr
, "Missing `usage' for function `%s'.\n",
1013 /* Read a file of Lisp code, compiled or interpreted.
1015 (defun NAME ARGS DOCSTRING ...)
1016 (defmacro NAME ARGS DOCSTRING ...)
1017 (defsubst NAME ARGS DOCSTRING ...)
1018 (autoload (quote NAME) FILE DOCSTRING ...)
1019 (defvar NAME VALUE DOCSTRING)
1020 (defconst NAME VALUE DOCSTRING)
1021 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
1022 (fset (quote NAME) #[... DOCSTRING ...])
1023 (defalias (quote NAME) #[... DOCSTRING ...])
1024 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
1025 starting in column zero.
1026 (quote NAME) may appear as 'NAME as well.
1028 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
1029 When we find that, we save it for the following defining-form,
1030 and we use that instead of reading a doc string within that defining-form.
1032 For defvar, defconst, and fset we skip to the docstring with a kludgy
1033 formatting convention: all docstrings must appear on the same line as the
1034 initial open-paren (the one in column zero) and must contain a backslash
1035 and a newline immediately after the initial double-quote. No newlines
1036 must appear between the beginning of the form and the first double-quote.
1037 For defun, defmacro, and autoload, we know how to skip over the
1038 arglist, but the doc string must still have a backslash and newline
1039 immediately after the double quote.
1040 The only source files that must follow this convention are preloaded
1041 uncompiled ones like loaddefs.el; aside from that, it is always the .elc
1042 file that we should look at, and they are no problem because byte-compiler
1043 output follows this convention.
1044 The NAME and DOCSTRING are output.
1045 NAME is preceded by `F' for a function or `V' for a variable.
1046 An entry is output only if DOCSTRING has \ newline just after the opening ".
1050 skip_white (FILE *infile
)
1053 while (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
1059 read_lisp_symbol (FILE *infile
, char *buffer
)
1062 char *fillp
= buffer
;
1064 skip_white (infile
);
1069 *(++fillp
) = getc (infile
);
1070 else if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '(' || c
== ')')
1081 fprintf (stderr
, "## expected a symbol, got '%c'\n", c
);
1083 skip_white (infile
);
1087 search_lisp_doc_at_eol (FILE *infile
)
1089 int c
= 0, c1
= 0, c2
= 0;
1091 /* Skip until the end of line; remember two previous chars. */
1092 while (c
!= '\n' && c
!= '\r' && c
!= EOF
)
1099 /* If two previous characters were " and \,
1100 this is a doc string. Otherwise, there is none. */
1101 if (c2
!= '"' || c1
!= '\\')
1104 fprintf (stderr
, "## non-docstring found\n");
1113 #define DEF_ELISP_FILE(fn) { #fn, sizeof(#fn) - 1 }
1116 scan_lisp_file (const char *filename
, const char *mode
)
1120 char *saved_string
= 0;
1121 /* These are the only files that are loaded uncompiled, and must
1122 follow the conventions of the doc strings expected by this
1123 function. These conventions are automatically followed by the
1124 byte compiler when it produces the .elc files. */
1128 } const uncompiled
[] = {
1129 DEF_ELISP_FILE (loaddefs
.el
),
1130 DEF_ELISP_FILE (loadup
.el
),
1131 DEF_ELISP_FILE (charprop
.el
),
1132 DEF_ELISP_FILE (cp51932
.el
),
1133 DEF_ELISP_FILE (eucjp
-ms
.el
)
1136 size_t flen
= strlen (filename
);
1138 if (generate_globals
)
1139 fatal ("scanning lisp file when -g specified", 0);
1140 if (flen
> 3 && !strcmp (filename
+ flen
- 3, ".el"))
1142 for (i
= 0, match
= 0; i
< sizeof (uncompiled
) / sizeof (uncompiled
[0]);
1145 if (uncompiled
[i
].fl
<= flen
1146 && !strcmp (filename
+ flen
- uncompiled
[i
].fl
, uncompiled
[i
].fn
)
1147 && (flen
== uncompiled
[i
].fl
1148 || IS_SLASH (filename
[flen
- uncompiled
[i
].fl
- 1])))
1155 fatal ("uncompiled lisp file %s is not supported", filename
);
1158 infile
= fopen (filename
, mode
);
1162 return 0; /* No error. */
1166 while (!feof (infile
))
1168 char buffer
[BUFSIZ
];
1171 /* If not at end of line, skip till we get to one. */
1172 if (c
!= '\n' && c
!= '\r')
1177 /* Skip the line break. */
1178 while (c
== '\n' || c
== '\r')
1180 /* Detect a dynamic doc string and save it for the next expression. */
1189 /* Read the length. */
1190 while ((c
= getc (infile
),
1191 c
>= '0' && c
<= '9'))
1198 fatal ("invalid dynamic doc string length", "");
1201 fatal ("space not found after dynamic doc string length", "");
1203 /* The next character is a space that is counted in the length
1204 but not part of the doc string.
1205 We already read it, so just ignore it. */
1208 /* Read in the contents. */
1209 free (saved_string
);
1210 saved_string
= (char *) xmalloc (length
);
1211 for (i
= 0; i
< length
; i
++)
1212 saved_string
[i
] = getc (infile
);
1213 /* The last character is a ^_.
1214 That is needed in the .elc file
1215 but it is redundant in DOC. So get rid of it here. */
1216 saved_string
[length
- 1] = 0;
1217 /* Skip the line break. */
1218 while (c
== '\n' || c
== '\r')
1220 /* Skip the following line. */
1221 while (c
!= '\n' && c
!= '\r')
1230 read_lisp_symbol (infile
, buffer
);
1232 if (! strcmp (buffer
, "defun")
1233 || ! strcmp (buffer
, "defmacro")
1234 || ! strcmp (buffer
, "defsubst"))
1237 read_lisp_symbol (infile
, buffer
);
1239 /* Skip the arguments: either "nil" or a list in parens. */
1242 if (c
== 'n') /* nil */
1244 if ((c
= getc (infile
)) != 'i'
1245 || (c
= getc (infile
)) != 'l')
1247 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1254 fprintf (stderr
, "## unparsable arglist in %s (%s)\n",
1261 skip_white (infile
);
1263 /* If the next three characters aren't `dquote bslash newline'
1264 then we're not reading a docstring.
1266 if ((c
= getc (infile
)) != '"'
1267 || (c
= getc (infile
)) != '\\'
1268 || ((c
= getc (infile
)) != '\n' && c
!= '\r'))
1271 fprintf (stderr
, "## non-docstring in %s (%s)\n",
1278 /* defcustom can only occur in uncompiled Lisp files. */
1279 else if (! strcmp (buffer
, "defvar")
1280 || ! strcmp (buffer
, "defconst")
1281 || ! strcmp (buffer
, "defcustom"))
1284 read_lisp_symbol (infile
, buffer
);
1286 if (saved_string
== 0)
1287 if (!search_lisp_doc_at_eol (infile
))
1291 else if (! strcmp (buffer
, "custom-declare-variable")
1292 || ! strcmp (buffer
, "defvaralias")
1299 read_lisp_symbol (infile
, buffer
);
1305 "## unparsable name in custom-declare-variable in %s\n",
1309 read_lisp_symbol (infile
, buffer
);
1310 if (strcmp (buffer
, "quote"))
1313 "## unparsable name in custom-declare-variable in %s\n",
1317 read_lisp_symbol (infile
, buffer
);
1322 "## unparsable quoted name in custom-declare-variable in %s\n",
1328 if (saved_string
== 0)
1329 if (!search_lisp_doc_at_eol (infile
))
1333 else if (! strcmp (buffer
, "fset") || ! strcmp (buffer
, "defalias"))
1339 read_lisp_symbol (infile
, buffer
);
1344 fprintf (stderr
, "## unparsable name in fset in %s\n",
1348 read_lisp_symbol (infile
, buffer
);
1349 if (strcmp (buffer
, "quote"))
1351 fprintf (stderr
, "## unparsable name in fset in %s\n",
1355 read_lisp_symbol (infile
, buffer
);
1360 "## unparsable quoted name in fset in %s\n",
1366 if (saved_string
== 0)
1367 if (!search_lisp_doc_at_eol (infile
))
1371 else if (! strcmp (buffer
, "autoload"))
1376 read_lisp_symbol (infile
, buffer
);
1381 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1385 read_lisp_symbol (infile
, buffer
);
1386 if (strcmp (buffer
, "quote"))
1388 fprintf (stderr
, "## unparsable name in autoload in %s\n",
1392 read_lisp_symbol (infile
, buffer
);
1397 "## unparsable quoted name in autoload in %s\n",
1402 skip_white (infile
);
1403 if ((c
= getc (infile
)) != '\"')
1405 fprintf (stderr
, "## autoload of %s unparsable (%s)\n",
1409 read_c_string_or_comment (infile
, 0, 0, 0);
1411 if (saved_string
== 0)
1412 if (!search_lisp_doc_at_eol (infile
))
1417 else if (! strcmp (buffer
, "if")
1418 || ! strcmp (buffer
, "byte-code"))
1425 fprintf (stderr
, "## unrecognized top-level form, %s (%s)\n",
1431 /* At this point, we should either use the previous dynamic doc string in
1432 saved_string or gobble a doc string from the input file.
1433 In the latter case, the opening quote (and leading backslash-newline)
1434 have already been read. */
1436 putc (037, outfile
);
1437 putc (type
, outfile
);
1438 fprintf (outfile
, "%s\n", buffer
);
1441 fputs (saved_string
, outfile
);
1442 /* Don't use one dynamic doc string twice. */
1443 free (saved_string
);
1447 read_c_string_or_comment (infile
, 1, 0, 0);
1454 /* make-docfile.c ends here */