Mercurial > emacs
annotate lib-src/make-docfile.c @ 6504:c867b9af8de4
(read_minibuf): Use assignment instead of initialization.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 23 Mar 1994 22:55:24 +0000 |
parents | 32ac07bd58ef |
children | d5d803ffff27 |
rev | line source |
---|---|
24 | 1 /* Generate doc-string file for GNU Emacs from source files. |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. |
24 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
38 | 6 GNU Emacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | |
638 | 8 the Free Software Foundation; either version 2, or (at your option) |
38 | 9 any later version. |
24 | 10 |
38 | 11 GNU Emacs is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
24 | 19 |
20 /* The arguments given to this program are all the C and Lisp source files | |
21 of GNU Emacs. .elc and .el and .c files are allowed. | |
22 A .o file can also be specified; the .c file it was made from is used. | |
23 This helps the makefile pass the correct list of files. | |
24 | |
25 The results, which go to standard output or to a file | |
26 specified with -a or -o (-a to append, -o to start from nothing), | |
27 are entries containing function or variable names and their documentation. | |
28 Each entry starts with a ^_ character. | |
29 Then comes F for a function or V for a variable. | |
30 Then comes the function or variable name, terminated with a newline. | |
31 Then comes the documentation for that function or variable. | |
32 */ | |
33 | |
34 #include <stdio.h> | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
35 #ifdef MSDOS |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
36 #include <fcntl.h> |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
37 #endif /* MSDOS */ |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
38 |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
39 #ifdef MSDOS |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
40 #define READ_TEXT "rt" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
41 #define READ_BINARY "rb" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
42 #else /* not MSDOS */ |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
43 #define READ_TEXT "r" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
44 #define READ_BINARY "r" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
45 #endif /* not MSDOS */ |
24 | 46 |
47 FILE *outfile; | |
48 | |
49 main (argc, argv) | |
50 int argc; | |
51 char **argv; | |
52 { | |
53 int i; | |
54 int err_count = 0; | |
55 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
56 #ifdef MSDOS |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
57 _fmode = O_BINARY; /* all of files are treated as binary files */ |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
58 (stdout)->_flag &= ~_IOTEXT; |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
59 _setmode (fileno (stdout), O_BINARY); |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
60 #endif /* MSDOS */ |
24 | 61 outfile = stdout; |
62 | |
63 /* If first two args are -o FILE, output to FILE. */ | |
64 i = 1; | |
65 if (argc > i + 1 && !strcmp (argv[i], "-o")) | |
66 { | |
67 outfile = fopen (argv[i + 1], "w"); | |
68 i += 2; | |
69 } | |
70 if (argc > i + 1 && !strcmp (argv[i], "-a")) | |
71 { | |
72 outfile = fopen (argv[i + 1], "a"); | |
73 i += 2; | |
74 } | |
2814
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
75 if (argc > i + 1 && !strcmp (argv[i], "-d")) |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
76 { |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
77 chdir (argv[i + 1]); |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
78 i += 2; |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
79 } |
24 | 80 |
81 for (; i < argc; i++) | |
82 err_count += scan_file (argv[i]); /* err_count seems to be {mis,un}used */ | |
83 #ifndef VMS | |
84 exit (err_count); /* see below - shane */ | |
3028 | 85 #endif /* VMS */ |
24 | 86 } |
87 | |
164 | 88 /* Read file FILENAME and output its doc strings to outfile. */ |
24 | 89 /* Return 1 if file is not found, 0 if it is found. */ |
90 | |
91 scan_file (filename) | |
92 char *filename; | |
93 { | |
94 int len = strlen (filename); | |
95 if (!strcmp (filename + len - 4, ".elc")) | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
96 return scan_lisp_file (filename, READ_BINARY); |
24 | 97 else if (!strcmp (filename + len - 3, ".el")) |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
98 return scan_lisp_file (filename, READ_TEXT); |
24 | 99 else |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
100 return scan_c_file (filename, READ_TEXT); |
24 | 101 } |
102 | |
103 char buf[128]; | |
104 | |
105 /* Skip a C string from INFILE, | |
106 and return the character that follows the closing ". | |
164 | 107 If printflag is positive, output string contents to outfile. |
24 | 108 If it is negative, store contents in buf. |
109 Convert escape sequences \n and \t to newline and tab; | |
110 discard \ followed by newline. */ | |
111 | |
112 read_c_string (infile, printflag) | |
113 FILE *infile; | |
114 int printflag; | |
115 { | |
116 register int c; | |
117 char *p = buf; | |
118 | |
119 c = getc (infile); | |
120 while (c != EOF) | |
121 { | |
122 while (c != '"' && c != EOF) | |
123 { | |
124 if (c == '\\') | |
125 { | |
126 c = getc (infile); | |
127 if (c == '\n') | |
128 { | |
129 c = getc (infile); | |
130 continue; | |
131 } | |
132 if (c == 'n') | |
133 c = '\n'; | |
134 if (c == 't') | |
135 c = '\t'; | |
136 } | |
137 if (printflag > 0) | |
138 putc (c, outfile); | |
139 else if (printflag < 0) | |
140 *p++ = c; | |
141 c = getc (infile); | |
142 } | |
143 c = getc (infile); | |
144 if (c != '"') | |
145 break; | |
4987
f052db139432
(read_c_string): For "", concatenate the two strings.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
146 /* If we had a "", concatenate the two strings. */ |
24 | 147 c = getc (infile); |
148 } | |
149 | |
150 if (printflag < 0) | |
151 *p = 0; | |
152 | |
153 return c; | |
154 } | |
155 | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
156 /* Write to file OUT the argument names of function FUNC, whose text is in BUF. |
24 | 157 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ |
158 | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
159 write_c_args (out, func, buf, minargs, maxargs) |
24 | 160 FILE *out; |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
161 char *func, *buf; |
24 | 162 int minargs, maxargs; |
163 { | |
1206 | 164 register char *p; |
1250 | 165 int in_ident = 0; |
166 int just_spaced = 0; | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
167 int need_space = 1; |
24 | 168 |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
169 fprintf (out, "(%s", func); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
170 |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
171 if (*buf == '(') |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
172 ++buf; |
24 | 173 |
1206 | 174 for (p = buf; *p; p++) |
24 | 175 { |
1250 | 176 char c = *p; |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
177 int ident_start = 0; |
1250 | 178 |
179 /* Notice when we start printing a new identifier. */ | |
180 if ((('A' <= c && c <= 'Z') | |
181 || ('a' <= c && c <= 'z') | |
182 || ('0' <= c && c <= '9') | |
183 || c == '_') | |
184 != in_ident) | |
24 | 185 { |
1250 | 186 if (!in_ident) |
187 { | |
188 in_ident = 1; | |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
189 ident_start = 1; |
1206 | 190 |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
191 if (need_space) |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
192 putc (' ', out); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
193 |
1250 | 194 if (minargs == 0 && maxargs > 0) |
195 fprintf (out, "&optional "); | |
196 just_spaced = 1; | |
1206 | 197 |
1250 | 198 minargs--; |
199 maxargs--; | |
200 } | |
201 else | |
202 in_ident = 0; | |
24 | 203 } |
638 | 204 |
1250 | 205 /* Print the C argument list as it would appear in lisp: |
206 print underscores as hyphens, and print commas as spaces. | |
207 Collapse adjacent spaces into one. */ | |
208 if (c == '_') c = '-'; | |
209 if (c == ',') c = ' '; | |
210 | |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
211 /* In C code, `default' is a reserved word, so we spell it |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
212 `defalt'; unmangle that here. */ |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
213 if (ident_start |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
214 && strncmp (p, "defalt", 6) == 0 |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
215 && ! (('A' <= p[6] && p[6] <= 'Z') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
216 || ('a' <= p[6] && p[6] <= 'z') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
217 || ('0' <= p[6] && p[6] <= '9') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
218 || p[6] == '_')) |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
219 { |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
220 fprintf (out, "default"); |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
221 p += 5; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
222 in_ident = 0; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
223 just_spaced = 0; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
224 } |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
225 else if (c != ' ' || ! just_spaced) |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
226 { |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
227 if (c >= 'a' && c <= 'z') |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
228 /* Upcase the letter. */ |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
229 c += 'A' - 'a'; |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
230 putc (c, out); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
231 } |
1250 | 232 |
233 just_spaced = (c == ' '); | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
234 need_space = 0; |
24 | 235 } |
236 } | |
237 | |
238 /* Read through a c file. If a .o file is named, | |
239 the corresponding .c file is read instead. | |
240 Looks for DEFUN constructs such as are defined in ../src/lisp.h. | |
241 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ | |
242 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
243 scan_c_file (filename, mode) |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
244 char *filename, *mode; |
24 | 245 { |
246 FILE *infile; | |
247 register int c; | |
248 register int commas; | |
249 register int defunflag; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
250 register int defvarperbufferflag; |
24 | 251 register int defvarflag; |
252 int minargs, maxargs; | |
253 | |
254 if (filename[strlen (filename) - 1] == 'o') | |
255 filename[strlen (filename) - 1] = 'c'; | |
256 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
257 infile = fopen (filename, mode); |
24 | 258 |
259 /* No error if non-ex input file */ | |
260 if (infile == NULL) | |
261 { | |
262 perror (filename); | |
263 return 0; | |
264 } | |
265 | |
266 c = '\n'; | |
267 while (!feof (infile)) | |
268 { | |
269 if (c != '\n') | |
270 { | |
271 c = getc (infile); | |
272 continue; | |
273 } | |
274 c = getc (infile); | |
275 if (c == ' ') | |
276 { | |
277 while (c == ' ') | |
278 c = getc (infile); | |
279 if (c != 'D') | |
280 continue; | |
281 c = getc (infile); | |
282 if (c != 'E') | |
283 continue; | |
284 c = getc (infile); | |
285 if (c != 'F') | |
286 continue; | |
287 c = getc (infile); | |
288 if (c != 'V') | |
289 continue; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
290 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
291 if (c != 'A') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
292 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
293 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
294 if (c != 'R') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
295 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
296 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
297 if (c != '_') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
298 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
299 |
24 | 300 defvarflag = 1; |
301 defunflag = 0; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
302 |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
303 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
304 defvarperbufferflag = (c == 'P'); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
305 |
24 | 306 c = getc (infile); |
307 } | |
308 else if (c == 'D') | |
309 { | |
310 c = getc (infile); | |
311 if (c != 'E') | |
312 continue; | |
313 c = getc (infile); | |
314 if (c != 'F') | |
315 continue; | |
316 c = getc (infile); | |
317 defunflag = c == 'U'; | |
318 defvarflag = 0; | |
319 } | |
320 else continue; | |
321 | |
322 while (c != '(') | |
323 { | |
324 if (c < 0) | |
325 goto eof; | |
326 c = getc (infile); | |
327 } | |
328 | |
329 c = getc (infile); | |
330 if (c != '"') | |
331 continue; | |
332 c = read_c_string (infile, -1); | |
333 | |
334 if (defunflag) | |
335 commas = 5; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
336 else if (defvarperbufferflag) |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
337 commas = 2; |
24 | 338 else if (defvarflag) |
339 commas = 1; | |
340 else /* For DEFSIMPLE and DEFPRED */ | |
341 commas = 2; | |
342 | |
343 while (commas) | |
344 { | |
345 if (c == ',') | |
346 { | |
347 commas--; | |
348 if (defunflag && (commas == 1 || commas == 2)) | |
349 { | |
350 do | |
351 c = getc (infile); | |
352 while (c == ' ' || c == '\n' || c == '\t'); | |
353 if (c < 0) | |
354 goto eof; | |
355 ungetc (c, infile); | |
356 if (commas == 2) /* pick up minargs */ | |
357 fscanf (infile, "%d", &minargs); | |
358 else /* pick up maxargs */ | |
359 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ | |
360 maxargs = -1; | |
361 else | |
362 fscanf (infile, "%d", &maxargs); | |
363 } | |
364 } | |
365 if (c < 0) | |
366 goto eof; | |
367 c = getc (infile); | |
368 } | |
369 while (c == ' ' || c == '\n' || c == '\t') | |
370 c = getc (infile); | |
371 if (c == '"') | |
372 c = read_c_string (infile, 0); | |
373 while (c != ',') | |
374 c = getc (infile); | |
375 c = getc (infile); | |
376 while (c == ' ' || c == '\n' || c == '\t') | |
377 c = getc (infile); | |
378 | |
379 if (c == '"') | |
380 { | |
381 putc (037, outfile); | |
382 putc (defvarflag ? 'V' : 'F', outfile); | |
383 fprintf (outfile, "%s\n", buf); | |
168 | 384 c = read_c_string (infile, 1); |
385 | |
386 /* If this is a defun, find the arguments and print them. If | |
387 this function takes MANY or UNEVALLED args, then the C source | |
388 won't give the names of the arguments, so we shouldn't bother | |
389 trying to find them. */ | |
390 if (defunflag && maxargs != -1) | |
24 | 391 { |
392 char argbuf[1024], *p = argbuf; | |
393 while (c != ')') | |
394 { | |
395 if (c < 0) | |
396 goto eof; | |
397 c = getc (infile); | |
398 } | |
399 /* Skip into arguments. */ | |
400 while (c != '(') | |
401 { | |
402 if (c < 0) | |
403 goto eof; | |
404 c = getc (infile); | |
405 } | |
406 /* Copy arguments into ARGBUF. */ | |
407 *p++ = c; | |
408 do | |
409 *p++ = c = getc (infile); | |
410 while (c != ')'); | |
411 *p = '\0'; | |
412 /* Output them. */ | |
413 fprintf (outfile, "\n\n"); | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
414 write_c_args (outfile, buf, argbuf, minargs, maxargs); |
24 | 415 } |
416 } | |
417 } | |
418 eof: | |
419 fclose (infile); | |
420 return 0; | |
421 } | |
422 | |
423 /* Read a file of Lisp code, compiled or interpreted. | |
424 Looks for | |
425 (defun NAME ARGS DOCSTRING ...) | |
753 | 426 (defmacro NAME ARGS DOCSTRING ...) |
427 (autoload (quote NAME) FILE DOCSTRING ...) | |
24 | 428 (defvar NAME VALUE DOCSTRING) |
429 (defconst NAME VALUE DOCSTRING) | |
753 | 430 (fset (quote NAME) (make-byte-code ... DOCSTRING ...)) |
431 (fset (quote NAME) #[... DOCSTRING ...]) | |
2966
e936d56c2354
(scan_lisp_file): Recognize defalias like fset.
Richard M. Stallman <rms@gnu.org>
parents:
2814
diff
changeset
|
432 (defalias (quote NAME) #[... DOCSTRING ...]) |
24 | 433 starting in column zero. |
753 | 434 (quote NAME) may appear as 'NAME as well. |
435 For defun, defmacro, and autoload, we know how to skip over the arglist. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3028
diff
changeset
|
436 For defvar, defconst, and fset we skip to the docstring with a kludgy |
753 | 437 formatting convention: all docstrings must appear on the same line as the |
438 initial open-paren (the one in column zero) and must contain a backslash | |
439 and a double-quote immediately after the initial double-quote. No newlines | |
440 must appear between the beginning of the form and the first double-quote. | |
441 The only source file that must follow this convention is loaddefs.el; aside | |
442 from that, it is always the .elc file that we look at, and they are no | |
443 problem because byte-compiler output follows this convention. | |
24 | 444 The NAME and DOCSTRING are output. |
445 NAME is preceded by `F' for a function or `V' for a variable. | |
446 An entry is output only if DOCSTRING has \ newline just after the opening " | |
447 */ | |
448 | |
753 | 449 void |
450 skip_white (infile) | |
451 FILE *infile; | |
452 { | |
453 char c = ' '; | |
454 while (c == ' ' || c == '\t' || c == '\n') | |
455 c = getc (infile); | |
456 ungetc (c, infile); | |
457 } | |
458 | |
459 void | |
460 read_lisp_symbol (infile, buffer) | |
461 FILE *infile; | |
462 char *buffer; | |
463 { | |
464 char c; | |
465 char *fillp = buffer; | |
466 | |
467 skip_white (infile); | |
468 while (1) | |
469 { | |
470 c = getc (infile); | |
471 if (c == '\\') | |
472 *(++fillp) = getc (infile); | |
473 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')') | |
474 { | |
475 ungetc (c, infile); | |
476 *fillp = 0; | |
477 break; | |
478 } | |
479 else | |
480 *fillp++ = c; | |
481 } | |
482 | |
483 if (! buffer[0]) | |
484 fprintf (stderr, "## expected a symbol, got '%c'\n", c); | |
485 | |
486 skip_white (infile); | |
487 } | |
488 | |
489 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
490 scan_lisp_file (filename, mode) |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
491 char *filename, *mode; |
24 | 492 { |
493 FILE *infile; | |
494 register int c; | |
495 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
496 infile = fopen (filename, mode); |
24 | 497 if (infile == NULL) |
498 { | |
499 perror (filename); | |
500 return 0; /* No error */ | |
501 } | |
502 | |
503 c = '\n'; | |
504 while (!feof (infile)) | |
505 { | |
753 | 506 char buffer [BUFSIZ]; |
507 char *fillp = buffer; | |
508 char type; | |
509 | |
24 | 510 if (c != '\n') |
511 { | |
512 c = getc (infile); | |
513 continue; | |
514 } | |
515 c = getc (infile); | |
516 if (c != '(') | |
517 continue; | |
164 | 518 |
753 | 519 read_lisp_symbol (infile, buffer); |
520 | |
521 if (! strcmp (buffer, "defun") || | |
522 ! strcmp (buffer, "defmacro")) | |
24 | 523 { |
753 | 524 type = 'F'; |
525 read_lisp_symbol (infile, buffer); | |
526 | |
527 /* Skip the arguments: either "nil" or a list in parens */ | |
24 | 528 |
529 c = getc (infile); | |
753 | 530 if (c == 'n') /* nil */ |
531 { | |
532 if ((c = getc (infile)) != 'i' || | |
533 (c = getc (infile)) != 'l') | |
534 { | |
535 fprintf (stderr, "## unparsable arglist in %s (%s)\n", | |
536 buffer, filename); | |
537 continue; | |
538 } | |
539 } | |
540 else if (c != '(') | |
541 { | |
542 fprintf (stderr, "## unparsable arglist in %s (%s)\n", | |
543 buffer, filename); | |
544 continue; | |
545 } | |
546 else | |
547 while (c != ')') | |
548 c = getc (infile); | |
549 skip_white (infile); | |
24 | 550 |
753 | 551 /* If the next three characters aren't `dquote bslash newline' |
552 then we're not reading a docstring. | |
553 */ | |
554 if ((c = getc (infile)) != '"' || | |
555 (c = getc (infile)) != '\\' || | |
556 (c = getc (infile)) != '\n') | |
24 | 557 { |
753 | 558 #ifdef DEBUG |
559 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
560 buffer, filename); | |
561 #endif | |
562 continue; | |
563 } | |
564 } | |
565 | |
566 else if (! strcmp (buffer, "defvar") || | |
567 ! strcmp (buffer, "defconst")) | |
568 { | |
569 char c1 = 0, c2 = 0; | |
570 type = 'V'; | |
571 read_lisp_symbol (infile, buffer); | |
572 | |
573 /* Skip until the first newline; remember the two previous chars. */ | |
574 while (c != '\n' && c >= 0) | |
575 { | |
576 c2 = c1; | |
577 c1 = c; | |
24 | 578 c = getc (infile); |
579 } | |
753 | 580 |
581 /* If two previous characters were " and \, | |
582 this is a doc string. Otherwise, there is none. */ | |
583 if (c2 != '"' || c1 != '\\') | |
584 { | |
585 #ifdef DEBUG | |
586 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
587 buffer, filename); | |
588 #endif | |
589 continue; | |
590 } | |
591 } | |
592 | |
2966
e936d56c2354
(scan_lisp_file): Recognize defalias like fset.
Richard M. Stallman <rms@gnu.org>
parents:
2814
diff
changeset
|
593 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias")) |
753 | 594 { |
595 char c1 = 0, c2 = 0; | |
596 type = 'F'; | |
597 | |
598 c = getc (infile); | |
599 if (c == '\'') | |
600 read_lisp_symbol (infile, buffer); | |
24 | 601 else |
602 { | |
603 if (c != '(') | |
753 | 604 { |
605 fprintf (stderr, "## unparsable name in fset in %s\n", | |
606 filename); | |
607 continue; | |
608 } | |
609 read_lisp_symbol (infile, buffer); | |
610 if (strcmp (buffer, "quote")) | |
611 { | |
612 fprintf (stderr, "## unparsable name in fset in %s\n", | |
613 filename); | |
614 continue; | |
615 } | |
616 read_lisp_symbol (infile, buffer); | |
24 | 617 c = getc (infile); |
753 | 618 if (c != ')') |
619 { | |
620 fprintf (stderr, | |
621 "## unparsable quoted name in fset in %s\n", | |
622 filename); | |
623 continue; | |
624 } | |
24 | 625 } |
164 | 626 |
753 | 627 /* Skip until the first newline; remember the two previous chars. */ |
628 while (c != '\n' && c >= 0) | |
24 | 629 { |
753 | 630 c2 = c1; |
631 c1 = c; | |
24 | 632 c = getc (infile); |
633 } | |
753 | 634 |
635 /* If two previous characters were " and \, | |
636 this is a doc string. Otherwise, there is none. */ | |
637 if (c2 != '"' || c1 != '\\') | |
24 | 638 { |
753 | 639 #ifdef DEBUG |
640 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
641 buffer, filename); | |
642 #endif | |
24 | 643 continue; |
644 } | |
645 } | |
753 | 646 |
647 else if (! strcmp (buffer, "autoload")) | |
164 | 648 { |
753 | 649 type = 'F'; |
164 | 650 c = getc (infile); |
753 | 651 if (c == '\'') |
652 read_lisp_symbol (infile, buffer); | |
653 else | |
654 { | |
655 if (c != '(') | |
656 { | |
657 fprintf (stderr, "## unparsable name in autoload in %s\n", | |
658 filename); | |
659 continue; | |
660 } | |
661 read_lisp_symbol (infile, buffer); | |
662 if (strcmp (buffer, "quote")) | |
663 { | |
664 fprintf (stderr, "## unparsable name in autoload in %s\n", | |
665 filename); | |
666 continue; | |
667 } | |
668 read_lisp_symbol (infile, buffer); | |
669 c = getc (infile); | |
670 if (c != ')') | |
671 { | |
672 fprintf (stderr, | |
673 "## unparsable quoted name in autoload in %s\n", | |
674 filename); | |
675 continue; | |
676 } | |
677 } | |
678 skip_white (infile); | |
679 if ((c = getc (infile)) != '\"') | |
680 { | |
681 fprintf (stderr, "## autoload of %s unparsable (%s)\n", | |
682 buffer, filename); | |
683 continue; | |
684 } | |
685 read_c_string (infile, 0); | |
686 skip_white (infile); | |
164 | 687 |
753 | 688 /* If the next three characters aren't `dquote bslash newline' |
689 then we're not reading a docstring. | |
690 */ | |
691 if ((c = getc (infile)) != '"' || | |
692 (c = getc (infile)) != '\\' || | |
693 (c = getc (infile)) != '\n') | |
694 { | |
695 #ifdef DEBUG | |
696 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
697 buffer, filename); | |
698 #endif | |
699 continue; | |
700 } | |
164 | 701 } |
24 | 702 |
753 | 703 #ifdef DEBUG |
704 else if (! strcmp (buffer, "if") || | |
705 ! strcmp (buffer, "byte-code")) | |
706 ; | |
707 #endif | |
24 | 708 |
753 | 709 else |
710 { | |
711 #ifdef DEBUG | |
712 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n", | |
713 buffer, filename); | |
714 #endif | |
715 continue; | |
716 } | |
24 | 717 |
753 | 718 /* At this point, there is a docstring that we should gobble. |
719 The opening quote (and leading backslash-newline) have already | |
720 been read. | |
721 */ | |
24 | 722 putc (037, outfile); |
753 | 723 putc (type, outfile); |
724 fprintf (outfile, "%s\n", buffer); | |
24 | 725 read_c_string (infile, 1); |
726 } | |
727 fclose (infile); | |
728 return 0; | |
729 } |