|
24
|
1 /* Generate doc-string file for GNU Emacs from source files.
|
|
|
2 Copyright (C) 1985, 1986 Free Software Foundation, Inc.
|
|
|
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
|
|
|
8 the Free Software Foundation; either version 1, or (at your option)
|
|
|
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>
|
|
|
35
|
|
|
36 FILE *outfile;
|
|
|
37
|
|
|
38 main (argc, argv)
|
|
|
39 int argc;
|
|
|
40 char **argv;
|
|
|
41 {
|
|
|
42 int i;
|
|
|
43 int err_count = 0;
|
|
|
44
|
|
|
45 outfile = stdout;
|
|
|
46
|
|
|
47 /* If first two args are -o FILE, output to FILE. */
|
|
|
48 i = 1;
|
|
|
49 if (argc > i + 1 && !strcmp (argv[i], "-o"))
|
|
|
50 {
|
|
|
51 outfile = fopen (argv[i + 1], "w");
|
|
|
52 i += 2;
|
|
|
53 }
|
|
|
54 if (argc > i + 1 && !strcmp (argv[i], "-a"))
|
|
|
55 {
|
|
|
56 outfile = fopen (argv[i + 1], "a");
|
|
|
57 i += 2;
|
|
|
58 }
|
|
|
59
|
|
|
60 for (; i < argc; i++)
|
|
|
61 err_count += scan_file (argv[i]); /* err_count seems to be {mis,un}used */
|
|
|
62 #ifndef VMS
|
|
|
63 exit (err_count); /* see below - shane */
|
|
|
64 #endif VMS
|
|
|
65 }
|
|
|
66
|
|
|
67 /* Read file FILENAME and output its doc strings to stdout. */
|
|
|
68 /* Return 1 if file is not found, 0 if it is found. */
|
|
|
69
|
|
|
70 scan_file (filename)
|
|
|
71 char *filename;
|
|
|
72 {
|
|
|
73 int len = strlen (filename);
|
|
|
74 if (!strcmp (filename + len - 4, ".elc"))
|
|
|
75 return scan_lisp_file (filename);
|
|
|
76 else if (!strcmp (filename + len - 3, ".el"))
|
|
|
77 return scan_lisp_file (filename);
|
|
|
78 else
|
|
|
79 return scan_c_file (filename);
|
|
|
80 }
|
|
|
81
|
|
|
82 char buf[128];
|
|
|
83
|
|
|
84 /* Skip a C string from INFILE,
|
|
|
85 and return the character that follows the closing ".
|
|
|
86 If printflag is positive, output string contents to stdout.
|
|
|
87 If it is negative, store contents in buf.
|
|
|
88 Convert escape sequences \n and \t to newline and tab;
|
|
|
89 discard \ followed by newline. */
|
|
|
90
|
|
|
91 read_c_string (infile, printflag)
|
|
|
92 FILE *infile;
|
|
|
93 int printflag;
|
|
|
94 {
|
|
|
95 register int c;
|
|
|
96 char *p = buf;
|
|
|
97
|
|
|
98 c = getc (infile);
|
|
|
99 while (c != EOF)
|
|
|
100 {
|
|
|
101 while (c != '"' && c != EOF)
|
|
|
102 {
|
|
|
103 if (c == '\\')
|
|
|
104 {
|
|
|
105 c = getc (infile);
|
|
|
106 if (c == '\n')
|
|
|
107 {
|
|
|
108 c = getc (infile);
|
|
|
109 continue;
|
|
|
110 }
|
|
|
111 if (c == 'n')
|
|
|
112 c = '\n';
|
|
|
113 if (c == 't')
|
|
|
114 c = '\t';
|
|
|
115 }
|
|
|
116 if (printflag > 0)
|
|
|
117 putc (c, outfile);
|
|
|
118 else if (printflag < 0)
|
|
|
119 *p++ = c;
|
|
|
120 c = getc (infile);
|
|
|
121 }
|
|
|
122 c = getc (infile);
|
|
|
123 if (c != '"')
|
|
|
124 break;
|
|
|
125 if (printflag > 0)
|
|
|
126 putc (c, outfile);
|
|
|
127 else if (printflag < 0)
|
|
|
128 *p++ = c;
|
|
|
129 c = getc (infile);
|
|
|
130 }
|
|
|
131
|
|
|
132 if (printflag < 0)
|
|
|
133 *p = 0;
|
|
|
134
|
|
|
135 return c;
|
|
|
136 }
|
|
|
137
|
|
|
138 /* Write to file OUT the argument names of the function whose text is in BUF.
|
|
|
139 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
|
|
|
140
|
|
|
141 write_c_args (out, buf, minargs, maxargs)
|
|
|
142 FILE *out;
|
|
|
143 char *buf;
|
|
|
144 int minargs, maxargs;
|
|
|
145 {
|
|
|
146 register int c;
|
|
|
147 register char *p = buf;
|
|
|
148 int space = 0;
|
|
|
149
|
|
|
150 fprintf (out, "arguments:");
|
|
|
151
|
|
|
152 while (*p)
|
|
|
153 {
|
|
|
154 c = *p++;
|
|
|
155 if (c == ',')
|
|
|
156 {
|
|
|
157 minargs--;
|
|
|
158 maxargs--;
|
|
|
159 if (!space)
|
|
|
160 putc (' ', out);
|
|
|
161 if (minargs == 0 && maxargs > 0)
|
|
|
162 fprintf (out, "&optional ");
|
|
|
163 space = 1;
|
|
|
164 continue;
|
|
|
165 }
|
|
|
166 else if (c == ' ' && space)
|
|
|
167 continue;
|
|
|
168 space = (c == ' ');
|
|
|
169 putc (c, out);
|
|
|
170 }
|
|
|
171 putc ('\n', out);
|
|
|
172 }
|
|
|
173
|
|
|
174 /* Read through a c file. If a .o file is named,
|
|
|
175 the corresponding .c file is read instead.
|
|
|
176 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
|
|
|
177 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
|
|
|
178
|
|
|
179 scan_c_file (filename)
|
|
|
180 char *filename;
|
|
|
181 {
|
|
|
182 FILE *infile;
|
|
|
183 register int c;
|
|
|
184 register int commas;
|
|
|
185 register int defunflag;
|
|
|
186 register int defvarflag;
|
|
|
187 int minargs, maxargs;
|
|
|
188
|
|
|
189 if (filename[strlen (filename) - 1] == 'o')
|
|
|
190 filename[strlen (filename) - 1] = 'c';
|
|
|
191
|
|
|
192 infile = fopen (filename, "r");
|
|
|
193
|
|
|
194 /* No error if non-ex input file */
|
|
|
195 if (infile == NULL)
|
|
|
196 {
|
|
|
197 perror (filename);
|
|
|
198 return 0;
|
|
|
199 }
|
|
|
200
|
|
|
201 c = '\n';
|
|
|
202 while (!feof (infile))
|
|
|
203 {
|
|
|
204 if (c != '\n')
|
|
|
205 {
|
|
|
206 c = getc (infile);
|
|
|
207 continue;
|
|
|
208 }
|
|
|
209 c = getc (infile);
|
|
|
210 if (c == ' ')
|
|
|
211 {
|
|
|
212 while (c == ' ')
|
|
|
213 c = getc (infile);
|
|
|
214 if (c != 'D')
|
|
|
215 continue;
|
|
|
216 c = getc (infile);
|
|
|
217 if (c != 'E')
|
|
|
218 continue;
|
|
|
219 c = getc (infile);
|
|
|
220 if (c != 'F')
|
|
|
221 continue;
|
|
|
222 c = getc (infile);
|
|
|
223 if (c != 'V')
|
|
|
224 continue;
|
|
|
225 defvarflag = 1;
|
|
|
226 defunflag = 0;
|
|
|
227 c = getc (infile);
|
|
|
228 }
|
|
|
229 else if (c == 'D')
|
|
|
230 {
|
|
|
231 c = getc (infile);
|
|
|
232 if (c != 'E')
|
|
|
233 continue;
|
|
|
234 c = getc (infile);
|
|
|
235 if (c != 'F')
|
|
|
236 continue;
|
|
|
237 c = getc (infile);
|
|
|
238 defunflag = c == 'U';
|
|
|
239 defvarflag = 0;
|
|
|
240 }
|
|
|
241 else continue;
|
|
|
242
|
|
|
243 while (c != '(')
|
|
|
244 {
|
|
|
245 if (c < 0)
|
|
|
246 goto eof;
|
|
|
247 c = getc (infile);
|
|
|
248 }
|
|
|
249
|
|
|
250 c = getc (infile);
|
|
|
251 if (c != '"')
|
|
|
252 continue;
|
|
|
253 c = read_c_string (infile, -1);
|
|
|
254
|
|
|
255 if (defunflag)
|
|
|
256 commas = 5;
|
|
|
257 else if (defvarflag)
|
|
|
258 commas = 1;
|
|
|
259 else /* For DEFSIMPLE and DEFPRED */
|
|
|
260 commas = 2;
|
|
|
261
|
|
|
262 while (commas)
|
|
|
263 {
|
|
|
264 if (c == ',')
|
|
|
265 {
|
|
|
266 commas--;
|
|
|
267 if (defunflag && (commas == 1 || commas == 2))
|
|
|
268 {
|
|
|
269 do
|
|
|
270 c = getc (infile);
|
|
|
271 while (c == ' ' || c == '\n' || c == '\t');
|
|
|
272 if (c < 0)
|
|
|
273 goto eof;
|
|
|
274 ungetc (c, infile);
|
|
|
275 if (commas == 2) /* pick up minargs */
|
|
|
276 fscanf (infile, "%d", &minargs);
|
|
|
277 else /* pick up maxargs */
|
|
|
278 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
|
|
|
279 maxargs = -1;
|
|
|
280 else
|
|
|
281 fscanf (infile, "%d", &maxargs);
|
|
|
282 }
|
|
|
283 }
|
|
|
284 if (c < 0)
|
|
|
285 goto eof;
|
|
|
286 c = getc (infile);
|
|
|
287 }
|
|
|
288 while (c == ' ' || c == '\n' || c == '\t')
|
|
|
289 c = getc (infile);
|
|
|
290 if (c == '"')
|
|
|
291 c = read_c_string (infile, 0);
|
|
|
292 while (c != ',')
|
|
|
293 c = getc (infile);
|
|
|
294 c = getc (infile);
|
|
|
295 while (c == ' ' || c == '\n' || c == '\t')
|
|
|
296 c = getc (infile);
|
|
|
297
|
|
|
298 if (c == '"')
|
|
|
299 {
|
|
|
300 putc (037, outfile);
|
|
|
301 putc (defvarflag ? 'V' : 'F', outfile);
|
|
|
302 fprintf (outfile, "%s\n", buf);
|
|
|
303 read_c_string (infile, 1);
|
|
|
304 if (defunflag)
|
|
|
305 {
|
|
|
306 char argbuf[1024], *p = argbuf;
|
|
|
307 while (c != ')')
|
|
|
308 {
|
|
|
309 if (c < 0)
|
|
|
310 goto eof;
|
|
|
311 c = getc (infile);
|
|
|
312 }
|
|
|
313 /* Skip into arguments. */
|
|
|
314 while (c != '(')
|
|
|
315 {
|
|
|
316 if (c < 0)
|
|
|
317 goto eof;
|
|
|
318 c = getc (infile);
|
|
|
319 }
|
|
|
320 /* Copy arguments into ARGBUF. */
|
|
|
321 *p++ = c;
|
|
|
322 do
|
|
|
323 *p++ = c = getc (infile);
|
|
|
324 while (c != ')');
|
|
|
325 *p = '\0';
|
|
|
326 /* Output them. */
|
|
|
327 fprintf (outfile, "\n\n");
|
|
|
328 write_c_args (outfile, argbuf, minargs, maxargs);
|
|
|
329 }
|
|
|
330 }
|
|
|
331 }
|
|
|
332 eof:
|
|
|
333 fclose (infile);
|
|
|
334 return 0;
|
|
|
335 }
|
|
|
336
|
|
|
337 /* Read a file of Lisp code, compiled or interpreted.
|
|
|
338 Looks for
|
|
|
339 (defun NAME ARGS DOCSTRING ...)
|
|
|
340 (autoload 'NAME FILE DOCSTRING ...)
|
|
|
341 (defvar NAME VALUE DOCSTRING)
|
|
|
342 (defconst NAME VALUE DOCSTRING)
|
|
162
|
343 (fset (quote NAME) (make-byte-code (quote ARGS) ... "\
|
|
24
|
344 starting in column zero.
|
|
|
345 ARGS, FILE or VALUE is ignored. We do not know how to parse Lisp code
|
|
|
346 so we use a kludge to skip them:
|
|
|
347 In a function definition, the form of ARGS of FILE is known, and we
|
|
|
348 can skip it.
|
|
|
349 In a variable definition, we use a formatting convention:
|
|
|
350 the DOCSTRING, if present, must be followed by a closeparen and a newline,
|
|
|
351 and no newline must appear between the defvar or defconst and the docstring,
|
|
|
352 The only source file that must follow this convention is loaddefs.el;
|
|
|
353 aside from that, it is always the .elc file that we look at, and
|
|
|
354 they are no problem because byte-compiler output follows this convention.
|
|
|
355 The NAME and DOCSTRING are output.
|
|
|
356 NAME is preceded by `F' for a function or `V' for a variable.
|
|
|
357 An entry is output only if DOCSTRING has \ newline just after the opening "
|
|
|
358 */
|
|
|
359
|
|
|
360 scan_lisp_file (filename)
|
|
|
361 char *filename;
|
|
|
362 {
|
|
|
363 FILE *infile;
|
|
|
364 register int c;
|
|
|
365 register int commas;
|
|
|
366 register char *p;
|
|
|
367 int defvarflag;
|
|
|
368
|
|
|
369 infile = fopen (filename, "r");
|
|
|
370 if (infile == NULL)
|
|
|
371 {
|
|
|
372 perror (filename);
|
|
|
373 return 0; /* No error */
|
|
|
374 }
|
|
|
375
|
|
|
376 c = '\n';
|
|
|
377 while (!feof (infile))
|
|
|
378 {
|
|
|
379 if (c != '\n')
|
|
|
380 {
|
|
|
381 c = getc (infile);
|
|
|
382 continue;
|
|
|
383 }
|
|
|
384 c = getc (infile);
|
|
|
385 if (c != '(')
|
|
|
386 continue;
|
|
|
387 c = getc (infile);
|
|
|
388 if (c == 'a')
|
|
|
389 {
|
|
|
390 c = getc (infile);
|
|
|
391 if (c != 'u')
|
|
|
392 continue;
|
|
|
393 c = getc (infile);
|
|
|
394 if (c != 't')
|
|
|
395 continue;
|
|
|
396 c = getc (infile);
|
|
|
397 if (c != 'o')
|
|
|
398 continue;
|
|
|
399 c = getc (infile);
|
|
|
400 if (c != 'l')
|
|
|
401 continue;
|
|
|
402 c = getc (infile);
|
|
|
403 if (c != 'o')
|
|
|
404 continue;
|
|
|
405 c = getc (infile);
|
|
|
406 if (c != 'a')
|
|
|
407 continue;
|
|
|
408 c = getc (infile);
|
|
|
409 if (c != 'd')
|
|
|
410 continue;
|
|
|
411
|
|
|
412 c = getc (infile);
|
|
|
413 while (c == ' ')
|
|
|
414 c = getc (infile);
|
|
|
415
|
|
|
416 if (c == '\'')
|
|
|
417 {
|
|
|
418 c = getc (infile);
|
|
|
419 }
|
|
|
420 else
|
|
|
421 {
|
|
|
422 if (c != '(')
|
|
|
423 continue;
|
|
|
424 c = getc (infile);
|
|
|
425 if (c != 'q')
|
|
|
426 continue;
|
|
|
427 c = getc (infile);
|
|
|
428 if (c != 'u')
|
|
|
429 continue;
|
|
|
430 c = getc (infile);
|
|
|
431 if (c != 'o')
|
|
|
432 continue;
|
|
|
433 c = getc (infile);
|
|
|
434 if (c != 't')
|
|
|
435 continue;
|
|
|
436 c = getc (infile);
|
|
|
437 if (c != 'e')
|
|
|
438 continue;
|
|
|
439 c = getc (infile);
|
|
|
440 if (c != ' ')
|
|
|
441 continue;
|
|
|
442 while (c == ' ')
|
|
|
443 c = getc (infile);
|
|
|
444 }
|
|
|
445
|
|
|
446 p = buf;
|
|
|
447 while (c != ' ' && c != ')')
|
|
|
448 {
|
|
|
449 if (c == EOF)
|
|
|
450 return 1;
|
|
|
451 if (c == '\\')
|
|
|
452 c = getc (infile);
|
|
|
453 *p++ = c;
|
|
|
454 c = getc (infile);
|
|
|
455 }
|
|
|
456 *p = 0;
|
|
|
457
|
|
|
458 while (c != '"')
|
|
|
459 {
|
|
|
460 if (c == EOF)
|
|
|
461 return 1;
|
|
|
462 c = getc (infile);
|
|
|
463 }
|
|
|
464 c = read_c_string (infile, 0);
|
|
|
465 }
|
|
|
466 else if (c == 'd')
|
|
|
467 {
|
|
|
468 c = getc (infile);
|
|
|
469 if (c != 'e')
|
|
|
470 continue;
|
|
|
471 c = getc (infile);
|
|
|
472 if (c != 'f')
|
|
|
473 continue;
|
|
|
474 c = getc (infile);
|
|
|
475 if (c == 'u')
|
|
|
476 {
|
|
|
477 c = getc (infile);
|
|
|
478 if (c != 'n')
|
|
|
479 continue;
|
|
|
480 defvarflag = 0;
|
|
|
481 }
|
|
|
482 else if (c == 'v')
|
|
|
483 {
|
|
|
484 c = getc (infile);
|
|
|
485 if (c != 'a')
|
|
|
486 continue;
|
|
|
487 c = getc (infile);
|
|
|
488 if (c != 'r')
|
|
|
489 continue;
|
|
|
490 defvarflag = 1;
|
|
|
491 }
|
|
|
492 else if (c == 'c')
|
|
|
493 {
|
|
|
494 c = getc (infile);
|
|
|
495 if (c != 'o')
|
|
|
496 continue;
|
|
|
497 c = getc (infile);
|
|
|
498 if (c != 'n')
|
|
|
499 continue;
|
|
|
500 c = getc (infile);
|
|
|
501 if (c != 's')
|
|
|
502 continue;
|
|
|
503 c = getc (infile);
|
|
|
504 if (c != 't')
|
|
|
505 continue;
|
|
|
506 defvarflag = 1;
|
|
|
507 }
|
|
|
508 else
|
|
|
509 continue;
|
|
|
510
|
|
|
511 /* Now we have seen "defun" or "defvar" or "defconst". */
|
|
|
512
|
|
|
513 while (c != ' ' && c != '\n' && c != '\t')
|
|
|
514 c = getc (infile);
|
|
|
515
|
|
|
516 while (c == ' ' || c == '\n' || c == '\t')
|
|
|
517 c = getc (infile);
|
|
|
518
|
|
|
519 /* Read and store name of function or variable being defined
|
|
|
520 Discard backslashes that are for quoting. */
|
|
|
521 p = buf;
|
|
|
522 while (c != ' ' && c != '\n' && c != '\t')
|
|
|
523 {
|
|
|
524 if (c == '\\')
|
|
|
525 c = getc (infile);
|
|
|
526 *p++ = c;
|
|
|
527 c = getc (infile);
|
|
|
528 }
|
|
|
529 *p = 0;
|
|
|
530
|
|
|
531 while (c == ' ' || c == '\n' || c == '\t')
|
|
|
532 c = getc (infile);
|
|
|
533
|
|
|
534 if (! defvarflag)
|
|
|
535 {
|
|
|
536 /* A function: */
|
|
|
537 /* Skip the arguments: either "nil" or a list in parens */
|
|
|
538 if (c == 'n')
|
|
|
539 {
|
|
|
540 while (c != ' ' && c != '\n' && c != '\t')
|
|
|
541 c = getc (infile);
|
|
|
542 }
|
|
|
543 else
|
|
|
544 {
|
|
|
545 while (c != '(')
|
|
|
546 c = getc (infile);
|
|
|
547 while (c != ')')
|
|
|
548 c = getc (infile);
|
|
|
549 }
|
|
|
550 c = getc (infile);
|
|
|
551 }
|
|
|
552 else
|
|
|
553 {
|
|
|
554 /* A variable: */
|
|
|
555
|
|
|
556 /* Skip until the first newline; remember
|
|
|
557 the two previous characters. */
|
|
|
558 char c1 = 0, c2 = 0;
|
|
|
559
|
|
|
560 while (c != '\n' && c >= 0)
|
|
|
561 {
|
|
|
562 c2 = c1;
|
|
|
563 c1 = c;
|
|
|
564 c = getc (infile);
|
|
|
565 }
|
|
|
566
|
|
|
567 /* If two previous characters were " and \,
|
|
|
568 this is a doc string. Otherwise, there is none. */
|
|
|
569 if (c2 == '"' && c1 == '\\')
|
|
|
570 {
|
|
|
571 putc (037, outfile);
|
|
|
572 putc ('V', outfile);
|
|
|
573 fprintf (outfile, "%s\n", buf);
|
|
|
574 read_c_string (infile, 1);
|
|
|
575 }
|
|
|
576 continue;
|
|
|
577 }
|
|
|
578 }
|
|
|
579 else
|
|
|
580 continue;
|
|
|
581
|
|
|
582 /* Here for a function definition.
|
|
|
583 We have skipped the file name or arguments
|
|
|
584 and arrived at where the doc string is,
|
|
|
585 if there is a doc string. */
|
|
|
586
|
|
|
587 /* Skip whitespace */
|
|
|
588
|
|
|
589 while (c == ' ' || c == '\n' || c == '\t')
|
|
|
590 c = getc (infile);
|
|
|
591
|
|
|
592 /* " followed by \ and newline means a doc string we should gobble */
|
|
|
593 if (c != '"')
|
|
|
594 continue;
|
|
|
595 c = getc (infile);
|
|
|
596 if (c != '\\')
|
|
|
597 continue;
|
|
|
598 c = getc (infile);
|
|
|
599 if (c != '\n')
|
|
|
600 continue;
|
|
|
601
|
|
|
602 putc (037, outfile);
|
|
|
603 putc ('F', outfile);
|
|
|
604 fprintf (outfile, "%s\n", buf);
|
|
|
605 read_c_string (infile, 1);
|
|
|
606 }
|
|
|
607 fclose (infile);
|
|
|
608 return 0;
|
|
|
609 }
|