0
|
1 /* Generate doc-string file for XEmacs from source files.
|
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30. */
|
|
23
|
|
24 /* The arguments given to this program are all the C and Lisp source files
|
|
25 of XEmacs. .elc and .el and .c files are allowed.
|
|
26 A .o file can also be specified; the .c file it was made from is used.
|
|
27 This helps the makefile pass the correct list of files.
|
|
28
|
|
29 The results, which go to standard output or to a file
|
|
30 specified with -a or -o (-a to append, -o to start from nothing),
|
|
31 are entries containing function or variable names and their documentation.
|
|
32 Each entry starts with a ^_ character.
|
|
33 Then comes F for a function or V for a variable.
|
|
34 Then comes the function or variable name, terminated with a newline.
|
|
35 Then comes the documentation for that function or variable.
|
102
|
36
|
|
37 Added 19.15/20.1: `-i site-packages' allow installer to dump extra packages
|
|
38 without modifying Makefiles, etc.
|
0
|
39 */
|
|
40
|
|
41 #define NO_SHORTNAMES /* Tell config not to load remap.h */
|
|
42 #include <../src/config.h>
|
|
43
|
|
44 #include <stdio.h>
|
|
45 #include <errno.h>
|
|
46 #if __STDC__ || defined(STDC_HEADERS)
|
|
47 #include <stdlib.h>
|
|
48 #include <unistd.h>
|
|
49 #include <string.h>
|
|
50 #include <ctype.h>
|
|
51 #endif
|
|
52
|
|
53 #include <sys/param.h>
|
|
54
|
|
55 #ifdef MSDOS
|
|
56 #include <fcntl.h>
|
|
57 #endif /* MSDOS */
|
|
58 #ifdef WINDOWSNT
|
|
59 #include <stdlib.h>
|
|
60 #include <fcntl.h>
|
|
61 #include <direct.h>
|
|
62 #endif /* WINDOWSNT */
|
|
63
|
|
64 #ifdef DOS_NT
|
|
65 #define READ_TEXT "rt"
|
|
66 #define READ_BINARY "rb"
|
|
67 #else /* not DOS_NT */
|
|
68 #define READ_TEXT "r"
|
|
69 #define READ_BINARY "r"
|
|
70 #endif /* not DOS_NT */
|
|
71
|
|
72 #ifdef MSDOS
|
|
73 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
|
|
74 file where that function is defined. */
|
|
75 #undef chdir
|
|
76 #endif
|
|
77
|
|
78 /* Stdio stream for output to the DOC file. */
|
|
79 static FILE *outfile;
|
|
80
|
|
81 enum
|
|
82 {
|
|
83 el_file,
|
|
84 elc_file,
|
|
85 c_file
|
|
86 } Current_file_type;
|
|
87
|
|
88 static int scan_file (CONST char *filename);
|
|
89 static int read_c_string (FILE *, int, int);
|
|
90 static void write_c_args (FILE *out, CONST char *func, char *buf, int minargs,
|
|
91 int maxargs);
|
|
92 static int scan_c_file (CONST char *filename, CONST char *mode);
|
|
93 static void skip_white (FILE *);
|
|
94 static void read_lisp_symbol (FILE *, char *);
|
|
95 static int scan_lisp_file (CONST char *filename, CONST char *mode);
|
|
96
|
20
|
97 #define C_IDENTIFIER_CHAR_P(c) \
|
|
98 (('A' <= c && c <= 'Z') || \
|
|
99 ('a' <= c && c <= 'z') || \
|
|
100 ('0' <= c && c <= '9') || \
|
|
101 (c == '_'))
|
|
102
|
0
|
103 /* Name this program was invoked with. */
|
|
104 char *progname;
|
|
105
|
|
106 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
|
|
107
|
|
108 static void
|
|
109 error (CONST char *s1, CONST char *s2)
|
|
110 {
|
|
111 fprintf (stderr, "%s: ", progname);
|
|
112 fprintf (stderr, s1, s2);
|
|
113 fprintf (stderr, "\n");
|
|
114 }
|
|
115
|
|
116 /* Print error message and exit. */
|
|
117
|
|
118 static void
|
|
119 fatal (CONST char *s1, CONST char *s2)
|
|
120 {
|
|
121 error (s1, s2);
|
|
122 exit (1);
|
|
123 }
|
|
124
|
|
125 /* Like malloc but get fatal error if memory is exhausted. */
|
|
126
|
|
127 static long *
|
|
128 xmalloc (unsigned int size)
|
|
129 {
|
|
130 long *result = (long *) malloc (size);
|
|
131 if (result == NULL)
|
|
132 fatal ("virtual memory exhausted", 0);
|
|
133 return result;
|
|
134 }
|
|
135
|
102
|
136 static char *
|
|
137 next_extra_elc(char *extra_elcs)
|
|
138 {
|
|
139 static FILE *fp = NULL;
|
|
140 static char line_buf[BUFSIZ];
|
|
141 char *p = line_buf+1;
|
|
142
|
|
143 if (!fp) {
|
|
144 if (!extra_elcs) {
|
|
145 return NULL;
|
|
146 } else if (!(fp = fopen(extra_elcs, "r"))) {
|
|
147 /* It is not an error if this file doesn't exist. */
|
|
148 /*fatal("error opening site package file list", 0);*/
|
|
149 return NULL;
|
|
150 }
|
|
151 fgets(line_buf, BUFSIZ, fp);
|
|
152 }
|
|
153
|
|
154 again:
|
|
155 if (!fgets(line_buf, BUFSIZ, fp)) {
|
|
156 fclose(fp);
|
|
157 fp = NULL;
|
|
158 return NULL;
|
|
159 }
|
|
160 line_buf[0] = '\0';
|
|
161 if (strlen(p) <= 2 || strlen(p) >= (BUFSIZ - 5)) {
|
|
162 /* reject too short or too long lines */
|
|
163 goto again;
|
|
164 }
|
|
165 p[strlen(p) - 2] = '\0';
|
|
166 strcat(p, ".elc");
|
|
167
|
|
168 return p;
|
|
169 }
|
|
170
|
0
|
171
|
|
172 int
|
|
173 main (int argc, char **argv)
|
|
174 {
|
|
175 int i;
|
|
176 int err_count = 0;
|
|
177 int first_infile;
|
173
|
178 char *extra_elcs = NULL;
|
0
|
179
|
|
180 progname = argv[0];
|
|
181
|
|
182 outfile = stdout;
|
|
183
|
|
184 /* Don't put CRs in the DOC file. */
|
|
185 #ifdef MSDOS
|
|
186 _fmode = O_BINARY;
|
|
187 #if 0 /* Suspicion is that this causes hanging.
|
|
188 So instead we require people to use -o on MSDOS. */
|
|
189 (stdout)->_flag &= ~_IOTEXT;
|
|
190 _setmode (fileno (stdout), O_BINARY);
|
|
191 #endif
|
|
192 outfile = 0;
|
|
193 #endif /* MSDOS */
|
|
194 #ifdef WINDOWSNT
|
|
195 _fmode = O_BINARY;
|
|
196 _setmode (fileno (stdout), O_BINARY);
|
|
197 #endif /* WINDOWSNT */
|
|
198
|
|
199 /* If first two args are -o FILE, output to FILE. */
|
|
200 i = 1;
|
|
201 if (argc > i + 1 && !strcmp (argv[i], "-o"))
|
|
202 {
|
|
203 outfile = fopen (argv[i + 1], "w");
|
|
204 i += 2;
|
|
205 }
|
|
206 if (argc > i + 1 && !strcmp (argv[i], "-a"))
|
|
207 {
|
|
208 outfile = fopen (argv[i + 1], "a");
|
|
209 i += 2;
|
|
210 }
|
|
211 if (argc > i + 1 && !strcmp (argv[i], "-d"))
|
|
212 {
|
|
213 chdir (argv[i + 1]);
|
|
214 i += 2;
|
|
215 }
|
|
216
|
102
|
217 if (argc > (i + 1) && !strcmp(argv[i], "-i")) {
|
|
218 extra_elcs = argv[i + 1];
|
|
219 i += 2;
|
|
220 }
|
|
221
|
0
|
222 if (outfile == 0)
|
|
223 fatal ("No output file specified", "");
|
|
224
|
|
225 first_infile = i;
|
|
226 for (; i < argc; i++)
|
|
227 {
|
|
228 int j;
|
|
229 /* Don't process one file twice. */
|
|
230 for (j = first_infile; j < i; j++)
|
|
231 if (! strcmp (argv[i], argv[j]))
|
|
232 break;
|
|
233 if (j == i)
|
|
234 /* err_count seems to be {mis,un}used */
|
|
235 err_count += scan_file (argv[i]);
|
|
236 }
|
102
|
237
|
|
238 if (extra_elcs) {
|
|
239 char *p;
|
|
240
|
|
241 while ((p = next_extra_elc(extra_elcs)) != NULL) {
|
|
242 err_count += scan_file(p);
|
|
243 }
|
|
244 }
|
|
245
|
0
|
246 putc ('\n', outfile);
|
|
247 #ifndef VMS
|
|
248 exit (err_count > 0);
|
|
249 #endif /* VMS */
|
|
250 return err_count > 0;
|
|
251 }
|
|
252
|
|
253 /* Read file FILENAME and output its doc strings to outfile. */
|
|
254 /* Return 1 if file is not found, 0 if it is found. */
|
|
255
|
|
256 static int
|
|
257 scan_file (CONST char *filename)
|
|
258 {
|
|
259 int len = strlen (filename);
|
|
260 if (len > 4 && !strcmp (filename + len - 4, ".elc"))
|
|
261 {
|
|
262 Current_file_type = elc_file;
|
|
263 return scan_lisp_file (filename, READ_BINARY);
|
|
264 }
|
|
265 else if (len > 3 && !strcmp (filename + len - 3, ".el"))
|
|
266 {
|
|
267 Current_file_type = el_file;
|
|
268 return scan_lisp_file (filename, READ_TEXT);
|
|
269 }
|
|
270 else
|
|
271 {
|
|
272 Current_file_type = c_file;
|
|
273 return scan_c_file (filename, READ_TEXT);
|
|
274 }
|
|
275 }
|
|
276
|
|
277 char buf[128];
|
|
278
|
|
279 /* Skip a C string from INFILE,
|
|
280 and return the character that follows the closing ".
|
|
281 If printflag is positive, output string contents to outfile.
|
|
282 If it is negative, store contents in buf.
|
|
283 Convert escape sequences \n and \t to newline and tab;
|
|
284 discard \ followed by newline. */
|
|
285
|
|
286 static int
|
|
287 read_c_string (FILE *infile, int printflag, int c_docstring)
|
|
288 {
|
|
289 register int c;
|
|
290 char *p = buf;
|
|
291 int start = -1;
|
|
292
|
|
293 c = getc (infile);
|
|
294 while (c != EOF)
|
|
295 {
|
|
296 while ((c_docstring || c != '"') && c != EOF)
|
|
297 {
|
|
298 if (start)
|
|
299 {
|
|
300 if (c == '*')
|
|
301 {
|
|
302 int cc = getc (infile);
|
|
303 if (cc == '/')
|
|
304 break;
|
|
305 else
|
|
306 ungetc (cc, infile);
|
|
307 }
|
|
308
|
|
309 if (start != -1)
|
|
310 {
|
|
311 if (printflag > 0)
|
|
312 putc ('\n', outfile);
|
|
313 else if (printflag < 0)
|
|
314 *p++ = '\n';
|
|
315 }
|
|
316 }
|
|
317
|
|
318 if (c == '\\')
|
|
319 {
|
|
320 c = getc (infile);
|
|
321 if (c == '\n')
|
|
322 {
|
|
323 c = getc (infile);
|
|
324 start = 1;
|
|
325 continue;
|
|
326 }
|
|
327 if (!c_docstring && c == 'n')
|
|
328 c = '\n';
|
|
329 if (c == 't')
|
|
330 c = '\t';
|
|
331 }
|
|
332 if (c == '\n')
|
|
333 start = 1;
|
|
334 else
|
|
335 {
|
|
336 start = 0;
|
|
337 if (printflag > 0)
|
|
338 putc (c, outfile);
|
|
339 else if (printflag < 0)
|
|
340 *p++ = c;
|
|
341 }
|
|
342 c = getc (infile);
|
|
343 }
|
|
344 /* look for continuation of string */
|
|
345 if (Current_file_type == c_file)
|
|
346 {
|
|
347 while (isspace (c = getc (infile)))
|
|
348 ;
|
|
349 if (c != '"')
|
|
350 break;
|
|
351 }
|
|
352 else
|
|
353 {
|
|
354 c = getc (infile);
|
|
355 if (c != '"')
|
|
356 break;
|
|
357 /* If we had a "", concatenate the two strings. */
|
|
358 }
|
|
359 c = getc (infile);
|
|
360 }
|
|
361
|
|
362 if (printflag < 0)
|
|
363 *p = 0;
|
|
364
|
|
365 return c;
|
|
366 }
|
|
367
|
|
368 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
|
|
369 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
|
|
370
|
|
371 static void
|
|
372 write_c_args (FILE *out, CONST char *func, char *buff, int minargs,
|
|
373 int maxargs)
|
|
374 {
|
|
375 register char *p;
|
|
376 int in_ident = 0;
|
|
377 int just_spaced = 0;
|
|
378 #if 0
|
|
379 int need_space = 1;
|
|
380
|
173
|
381 fprintf (out, "(%s", func);
|
|
382 #else
|
0
|
383 /* XEmacs - "arguments:" is for parsing the docstring. FSF's help system
|
|
384 doesn't parse the docstring for arguments like we do, so we're also
|
|
385 going to omit the function name to preserve compatibility with elisp
|
|
386 that parses the docstring. Finally, not prefixing the arglist with
|
|
387 anything is asking for trouble because it's not uncommon to have an
|
|
388 unescaped parenthesis at the beginning of a line. --Stig */
|
173
|
389 fprintf (out, "arguments: (");
|
|
390 #endif
|
0
|
391
|
|
392 if (*buff == '(')
|
|
393 ++buff;
|
|
394
|
|
395 for (p = buff; *p; p++)
|
|
396 {
|
|
397 char c = *p;
|
|
398 int ident_start = 0;
|
|
399
|
20
|
400 /* Add support for ANSI prototypes. Hop over
|
|
401 "Lisp_Object" string (the only C type allowed in DEFUNs) */
|
|
402 static char lo[] = "Lisp_Object";
|
|
403 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
|
|
404 (strncmp (p, lo, sizeof (lo) - 1) == 0) &&
|
|
405 isspace(*(p + sizeof (lo) - 1)))
|
|
406 {
|
|
407 p += (sizeof (lo) - 1);
|
|
408 while (isspace (*p))
|
|
409 p++;
|
|
410 c = *p;
|
|
411 }
|
173
|
412
|
0
|
413 /* Notice when we start printing a new identifier. */
|
20
|
414 if (C_IDENTIFIER_CHAR_P (c) != in_ident)
|
0
|
415 {
|
|
416 if (!in_ident)
|
|
417 {
|
|
418 in_ident = 1;
|
|
419 ident_start = 1;
|
|
420 #if 0
|
|
421 /* XEmacs - This goes along with the change above. */
|
|
422 if (need_space)
|
|
423 putc (' ', out);
|
20
|
424 #endif
|
0
|
425 if (minargs == 0 && maxargs > 0)
|
|
426 fprintf (out, "&optional ");
|
|
427 just_spaced = 1;
|
|
428
|
|
429 minargs--;
|
|
430 maxargs--;
|
|
431 }
|
|
432 else
|
|
433 in_ident = 0;
|
|
434 }
|
|
435
|
|
436 /* Print the C argument list as it would appear in lisp:
|
|
437 print underscores as hyphens, and print commas as spaces.
|
173
|
438 Collapse adjacent spaces into one. */
|
0
|
439 if (c == '_') c = '-';
|
|
440 if (c == ',') c = ' ';
|
|
441
|
173
|
442 /* If the C argument name ends with `_', change it to ' ',
|
|
443 to allow use of C reserved words or global symbols as Lisp args. */
|
|
444 if (c == '-' && ! C_IDENTIFIER_CHAR_P (p[1]))
|
0
|
445 {
|
|
446 in_ident = 0;
|
|
447 just_spaced = 0;
|
|
448 }
|
|
449 else if (c != ' ' || ! just_spaced)
|
|
450 {
|
|
451 if (c >= 'a' && c <= 'z')
|
|
452 /* Upcase the letter. */
|
|
453 c += 'A' - 'a';
|
|
454 putc (c, out);
|
|
455 }
|
|
456
|
|
457 just_spaced = (c == ' ');
|
|
458 #if 0
|
|
459 need_space = 0;
|
|
460 #endif
|
|
461 }
|
|
462 putc ('\n', out); /* XEmacs addition */
|
|
463 }
|
|
464
|
|
465 /* Read through a c file. If a .o file is named,
|
|
466 the corresponding .c file is read instead.
|
|
467 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
|
|
468 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
|
|
469
|
|
470 static int
|
|
471 scan_c_file (CONST char *filename, CONST char *mode)
|
|
472 {
|
|
473 FILE *infile;
|
|
474 register int c;
|
|
475 register int commas;
|
|
476 register int defunflag;
|
|
477 register int defvarperbufferflag = 0;
|
|
478 register int defvarflag;
|
|
479 int minargs, maxargs;
|
|
480 int l = strlen (filename);
|
|
481 char f[MAXPATHLEN];
|
|
482
|
|
483 if (l > sizeof (f))
|
|
484 {
|
|
485 #ifdef ENAMETOOLONG
|
|
486 errno = ENAMETOOLONG;
|
|
487 #else
|
|
488 errno = EINVAL;
|
|
489 #endif
|
|
490 return (0);
|
|
491 }
|
|
492
|
|
493 strcpy (f, filename);
|
|
494 if (f[l - 1] == 'o')
|
|
495 f[l - 1] = 'c';
|
|
496 infile = fopen (f, mode);
|
|
497
|
|
498 /* No error if non-ex input file */
|
|
499 if (infile == NULL)
|
|
500 {
|
|
501 perror (f);
|
|
502 return 0;
|
|
503 }
|
|
504
|
|
505 c = '\n';
|
|
506 while (!feof (infile))
|
|
507 {
|
|
508 if (c != '\n')
|
|
509 {
|
|
510 c = getc (infile);
|
|
511 continue;
|
|
512 }
|
|
513 c = getc (infile);
|
|
514 if (c == ' ')
|
|
515 {
|
|
516 while (c == ' ')
|
|
517 c = getc (infile);
|
|
518 if (c != 'D')
|
|
519 continue;
|
|
520 c = getc (infile);
|
|
521 if (c != 'E')
|
|
522 continue;
|
|
523 c = getc (infile);
|
|
524 if (c != 'F')
|
|
525 continue;
|
|
526 c = getc (infile);
|
|
527 if (c != 'V')
|
|
528 continue;
|
|
529 c = getc (infile);
|
|
530 if (c != 'A')
|
|
531 continue;
|
|
532 c = getc (infile);
|
|
533 if (c != 'R')
|
|
534 continue;
|
|
535 c = getc (infile);
|
|
536 if (c != '_')
|
|
537 continue;
|
|
538
|
|
539 defvarflag = 1;
|
|
540 defunflag = 0;
|
|
541
|
|
542 c = getc (infile);
|
|
543 /* Note that this business doesn't apply under XEmacs.
|
|
544 DEFVAR_BUFFER_LOCAL in XEmacs behaves normally. */
|
|
545 defvarperbufferflag = (c == 'P');
|
|
546
|
|
547 c = getc (infile);
|
|
548 }
|
|
549 else if (c == 'D')
|
|
550 {
|
|
551 c = getc (infile);
|
|
552 if (c != 'E')
|
|
553 continue;
|
|
554 c = getc (infile);
|
|
555 if (c != 'F')
|
|
556 continue;
|
|
557 c = getc (infile);
|
20
|
558 defunflag = (c == 'U');
|
0
|
559 defvarflag = 0;
|
20
|
560 c = getc (infile);
|
0
|
561 }
|
|
562 else continue;
|
|
563
|
|
564 while (c != '(')
|
|
565 {
|
|
566 if (c < 0)
|
|
567 goto eof;
|
|
568 c = getc (infile);
|
|
569 }
|
|
570
|
|
571 c = getc (infile);
|
|
572 if (c != '"')
|
|
573 continue;
|
|
574 c = read_c_string (infile, -1, 0);
|
|
575
|
|
576 if (defunflag)
|
20
|
577 commas = 4;
|
0
|
578 else if (defvarperbufferflag)
|
|
579 commas = 2;
|
|
580 else if (defvarflag)
|
|
581 commas = 1;
|
|
582 else /* For DEFSIMPLE and DEFPRED */
|
|
583 commas = 2;
|
|
584
|
|
585 while (commas)
|
|
586 {
|
|
587 if (c == ',')
|
|
588 {
|
|
589 commas--;
|
|
590 if (defunflag && (commas == 1 || commas == 2))
|
|
591 {
|
|
592 do
|
|
593 c = getc (infile);
|
20
|
594 while (c == ' ' || c == '\n' || c == '\t')
|
|
595 ;
|
0
|
596 if (c < 0)
|
|
597 goto eof;
|
|
598 ungetc (c, infile);
|
|
599 if (commas == 2) /* pick up minargs */
|
|
600 fscanf (infile, "%d", &minargs);
|
|
601 else /* pick up maxargs */
|
|
602 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
|
|
603 maxargs = -1;
|
|
604 else
|
|
605 fscanf (infile, "%d", &maxargs);
|
|
606 }
|
|
607 }
|
|
608 if (c < 0)
|
|
609 goto eof;
|
|
610 c = getc (infile);
|
|
611 }
|
|
612 while (c == ' ' || c == '\n' || c == '\t')
|
|
613 c = getc (infile);
|
|
614 if (c == '"')
|
|
615 c = read_c_string (infile, 0, 0);
|
|
616 if (defunflag | defvarflag)
|
|
617 {
|
|
618 while (c != '/')
|
|
619 c = getc (infile);
|
|
620 c = getc (infile);
|
|
621 while (c == '*')
|
|
622 c = getc (infile);
|
|
623 }
|
|
624 else
|
|
625 {
|
|
626 while (c != ',')
|
|
627 c = getc (infile);
|
|
628 c = getc (infile);
|
|
629 }
|
|
630 while (c == ' ' || c == '\n' || c == '\t')
|
|
631 c = getc (infile);
|
|
632 if (defunflag | defvarflag)
|
|
633 ungetc (c, infile);
|
|
634
|
|
635 if (defunflag || defvarflag || c == '"')
|
|
636 {
|
|
637 putc (037, outfile);
|
|
638 putc (defvarflag ? 'V' : 'F', outfile);
|
|
639 fprintf (outfile, "%s\n", buf);
|
|
640 c = read_c_string (infile, 1, (defunflag || defvarflag));
|
|
641
|
|
642 /* If this is a defun, find the arguments and print them. If
|
|
643 this function takes MANY or UNEVALLED args, then the C source
|
|
644 won't give the names of the arguments, so we shouldn't bother
|
|
645 trying to find them. */
|
|
646 if (defunflag && maxargs != -1)
|
|
647 {
|
|
648 char argbuf[1024], *p = argbuf;
|
20
|
649 #if 0 /* For old DEFUN's only */
|
0
|
650 while (c != ')')
|
|
651 {
|
|
652 if (c < 0)
|
|
653 goto eof;
|
|
654 c = getc (infile);
|
|
655 }
|
20
|
656 #endif
|
0
|
657 /* Skip into arguments. */
|
|
658 while (c != '(')
|
|
659 {
|
|
660 if (c < 0)
|
|
661 goto eof;
|
|
662 c = getc (infile);
|
|
663 }
|
|
664 /* Copy arguments into ARGBUF. */
|
|
665 *p++ = c;
|
|
666 do
|
|
667 *p++ = c = getc (infile);
|
|
668 while (c != ')');
|
|
669 *p = '\0';
|
|
670 /* Output them. */
|
|
671 fprintf (outfile, "\n\n");
|
|
672 write_c_args (outfile, buf, argbuf, minargs, maxargs);
|
|
673 }
|
|
674 }
|
|
675 }
|
|
676 eof:
|
|
677 fclose (infile);
|
|
678 return 0;
|
|
679 }
|
|
680
|
|
681 /* Read a file of Lisp code, compiled or interpreted.
|
|
682 Looks for
|
|
683 (defun NAME ARGS DOCSTRING ...)
|
|
684 (defmacro NAME ARGS DOCSTRING ...)
|
|
685 (autoload (quote NAME) FILE DOCSTRING ...)
|
|
686 (defvar NAME VALUE DOCSTRING)
|
|
687 (defconst NAME VALUE DOCSTRING)
|
|
688 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
|
|
689 (fset (quote NAME) #[... DOCSTRING ...])
|
|
690 (defalias (quote NAME) #[... DOCSTRING ...])
|
|
691 starting in column zero.
|
|
692 (quote NAME) may appear as 'NAME as well.
|
|
693
|
|
694 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
|
|
695 When we find that, we save it for the following defining-form,
|
|
696 and we use that instead of reading a doc string within that defining-form.
|
|
697
|
|
698 For defun, defmacro, and autoload, we know how to skip over the arglist.
|
173
|
699 For defvar, defconst, and fset we skip to the docstring with a kludgy
|
0
|
700 formatting convention: all docstrings must appear on the same line as the
|
173
|
701 initial open-paren (the one in column zero) and must contain a backslash
|
0
|
702 and a double-quote immediately after the initial double-quote. No newlines
|
|
703 must appear between the beginning of the form and the first double-quote.
|
|
704 The only source file that must follow this convention is loaddefs.el; aside
|
|
705 from that, it is always the .elc file that we look at, and they are no
|
|
706 problem because byte-compiler output follows this convention.
|
|
707 The NAME and DOCSTRING are output.
|
|
708 NAME is preceded by `F' for a function or `V' for a variable.
|
|
709 An entry is output only if DOCSTRING has \ newline just after the opening "
|
|
710 */
|
|
711
|
|
712 static void
|
|
713 skip_white (FILE *infile)
|
|
714 {
|
|
715 char c = ' ';
|
|
716 while (c == ' ' || c == '\t' || c == '\n')
|
|
717 c = getc (infile);
|
|
718 ungetc (c, infile);
|
|
719 }
|
|
720
|
|
721 static void
|
|
722 read_lisp_symbol (FILE *infile, char *buffer)
|
|
723 {
|
|
724 char c;
|
|
725 char *fillp = buffer;
|
|
726
|
|
727 skip_white (infile);
|
|
728 while (1)
|
|
729 {
|
|
730 c = getc (infile);
|
|
731 if (c == '\\')
|
|
732 /* FSF has *(++fillp), which is wrong. */
|
|
733 *fillp++ = getc (infile);
|
|
734 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')')
|
|
735 {
|
|
736 ungetc (c, infile);
|
|
737 *fillp = 0;
|
|
738 break;
|
|
739 }
|
|
740 else
|
|
741 *fillp++ = c;
|
|
742 }
|
|
743
|
|
744 if (! buffer[0])
|
|
745 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
|
173
|
746
|
0
|
747 skip_white (infile);
|
|
748 }
|
|
749
|
|
750 static int
|
|
751 scan_lisp_file (CONST char *filename, CONST char *mode)
|
|
752 {
|
|
753 FILE *infile;
|
|
754 register int c;
|
|
755 char *saved_string = 0;
|
|
756
|
|
757 infile = fopen (filename, mode);
|
|
758 if (infile == NULL)
|
|
759 {
|
|
760 perror (filename);
|
|
761 return 0; /* No error */
|
|
762 }
|
|
763
|
|
764 c = '\n';
|
|
765 while (!feof (infile))
|
|
766 {
|
|
767 char buffer[BUFSIZ];
|
|
768 char type;
|
|
769
|
|
770 if (c != '\n')
|
|
771 {
|
|
772 c = getc (infile);
|
|
773 continue;
|
|
774 }
|
|
775 c = getc (infile);
|
|
776 /* Detect a dynamic doc string and save it for the next expression. */
|
|
777 if (c == '#')
|
|
778 {
|
|
779 c = getc (infile);
|
|
780 if (c == '@')
|
|
781 {
|
|
782 int length = 0;
|
|
783 int i;
|
|
784
|
|
785 /* Read the length. */
|
|
786 while ((c = getc (infile),
|
|
787 c >= '0' && c <= '9'))
|
|
788 {
|
|
789 length *= 10;
|
|
790 length += c - '0';
|
|
791 }
|
|
792
|
|
793 /* The next character is a space that is counted in the length
|
|
794 but not part of the doc string.
|
|
795 We already read it, so just ignore it. */
|
|
796 length--;
|
|
797
|
|
798 /* Read in the contents. */
|
|
799 if (saved_string != 0)
|
|
800 free (saved_string);
|
|
801 saved_string = (char *) xmalloc (length);
|
|
802 for (i = 0; i < length; i++)
|
|
803 saved_string[i] = getc (infile);
|
|
804 /* The last character is a ^_.
|
|
805 That is needed in the .elc file
|
|
806 but it is redundant in DOC. So get rid of it here. */
|
|
807 saved_string[length - 1] = 0;
|
|
808 /* Skip the newline. */
|
|
809 c = getc (infile);
|
|
810 while (c != '\n')
|
|
811 c = getc (infile);
|
|
812 }
|
|
813 continue;
|
|
814 }
|
|
815
|
|
816 if (c != '(')
|
|
817 continue;
|
|
818
|
|
819 read_lisp_symbol (infile, buffer);
|
|
820
|
|
821 if (! strcmp (buffer, "defun") ||
|
|
822 ! strcmp (buffer, "defmacro"))
|
|
823 {
|
|
824 type = 'F';
|
|
825 read_lisp_symbol (infile, buffer);
|
|
826
|
|
827 /* Skip the arguments: either "nil" or a list in parens */
|
|
828
|
|
829 c = getc (infile);
|
|
830 if (c == 'n') /* nil */
|
|
831 {
|
|
832 if ((c = getc (infile)) != 'i' ||
|
|
833 (c = getc (infile)) != 'l')
|
|
834 {
|
|
835 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
|
|
836 buffer, filename);
|
|
837 continue;
|
|
838 }
|
|
839 }
|
|
840 else if (c != '(')
|
|
841 {
|
|
842 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
|
|
843 buffer, filename);
|
|
844 continue;
|
|
845 }
|
|
846 else
|
|
847 while (c != ')')
|
|
848 c = getc (infile);
|
|
849 skip_white (infile);
|
|
850
|
|
851 /* If the next three characters aren't `dquote bslash newline'
|
|
852 then we're not reading a docstring.
|
|
853 */
|
|
854 if ((c = getc (infile)) != '"' ||
|
|
855 (c = getc (infile)) != '\\' ||
|
|
856 (c = getc (infile)) != '\n')
|
|
857 {
|
|
858 #ifdef DEBUG
|
|
859 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
860 buffer, filename);
|
|
861 #endif
|
|
862 continue;
|
|
863 }
|
|
864 }
|
|
865
|
|
866 else if (! strcmp (buffer, "defvar") ||
|
|
867 ! strcmp (buffer, "defconst"))
|
|
868 {
|
|
869 char c1 = 0, c2 = 0;
|
|
870 type = 'V';
|
|
871 read_lisp_symbol (infile, buffer);
|
|
872
|
|
873 if (saved_string == 0)
|
|
874 {
|
|
875
|
|
876 /* Skip until the first newline; remember the two previous chars. */
|
|
877 while (c != '\n' && c >= 0)
|
|
878 {
|
82
|
879 /* ### Kludge -- Ignore any ESC x x ISO2022 sequences */
|
|
880 if (c == 27)
|
|
881 {
|
|
882 getc (infile);
|
|
883 getc (infile);
|
|
884 goto nextchar;
|
|
885 }
|
173
|
886
|
0
|
887 c2 = c1;
|
|
888 c1 = c;
|
82
|
889 nextchar:
|
0
|
890 c = getc (infile);
|
|
891 }
|
173
|
892
|
0
|
893 /* If two previous characters were " and \,
|
|
894 this is a doc string. Otherwise, there is none. */
|
|
895 if (c2 != '"' || c1 != '\\')
|
|
896 {
|
|
897 #ifdef DEBUG
|
|
898 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
899 buffer, filename);
|
|
900 #endif
|
|
901 continue;
|
|
902 }
|
|
903 }
|
|
904 }
|
|
905
|
|
906 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
|
|
907 {
|
|
908 char c1 = 0, c2 = 0;
|
|
909 type = 'F';
|
|
910
|
|
911 c = getc (infile);
|
|
912 if (c == '\'')
|
|
913 read_lisp_symbol (infile, buffer);
|
|
914 else
|
|
915 {
|
|
916 if (c != '(')
|
|
917 {
|
|
918 fprintf (stderr, "## unparsable name in fset in %s\n",
|
|
919 filename);
|
|
920 continue;
|
|
921 }
|
|
922 read_lisp_symbol (infile, buffer);
|
|
923 if (strcmp (buffer, "quote"))
|
|
924 {
|
|
925 fprintf (stderr, "## unparsable name in fset in %s\n",
|
|
926 filename);
|
|
927 continue;
|
|
928 }
|
|
929 read_lisp_symbol (infile, buffer);
|
|
930 c = getc (infile);
|
|
931 if (c != ')')
|
|
932 {
|
|
933 fprintf (stderr,
|
|
934 "## unparsable quoted name in fset in %s\n",
|
|
935 filename);
|
|
936 continue;
|
|
937 }
|
|
938 }
|
|
939
|
|
940 if (saved_string == 0)
|
|
941 {
|
|
942 /* Skip until the first newline; remember the two previous chars. */
|
|
943 while (c != '\n' && c >= 0)
|
|
944 {
|
|
945 c2 = c1;
|
|
946 c1 = c;
|
|
947 c = getc (infile);
|
|
948 }
|
173
|
949
|
0
|
950 /* If two previous characters were " and \,
|
|
951 this is a doc string. Otherwise, there is none. */
|
|
952 if (c2 != '"' || c1 != '\\')
|
|
953 {
|
|
954 #ifdef DEBUG
|
|
955 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
956 buffer, filename);
|
|
957 #endif
|
|
958 continue;
|
|
959 }
|
|
960 }
|
|
961 }
|
|
962
|
|
963 else if (! strcmp (buffer, "autoload"))
|
|
964 {
|
|
965 type = 'F';
|
|
966 c = getc (infile);
|
|
967 if (c == '\'')
|
|
968 read_lisp_symbol (infile, buffer);
|
|
969 else
|
|
970 {
|
|
971 if (c != '(')
|
|
972 {
|
|
973 fprintf (stderr, "## unparsable name in autoload in %s\n",
|
|
974 filename);
|
|
975 continue;
|
|
976 }
|
|
977 read_lisp_symbol (infile, buffer);
|
|
978 if (strcmp (buffer, "quote"))
|
|
979 {
|
|
980 fprintf (stderr, "## unparsable name in autoload in %s\n",
|
|
981 filename);
|
|
982 continue;
|
|
983 }
|
|
984 read_lisp_symbol (infile, buffer);
|
|
985 c = getc (infile);
|
|
986 if (c != ')')
|
|
987 {
|
|
988 fprintf (stderr,
|
|
989 "## unparsable quoted name in autoload in %s\n",
|
|
990 filename);
|
|
991 continue;
|
|
992 }
|
|
993 }
|
|
994 skip_white (infile);
|
|
995 if ((c = getc (infile)) != '\"')
|
|
996 {
|
|
997 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
|
|
998 buffer, filename);
|
|
999 continue;
|
|
1000 }
|
|
1001 read_c_string (infile, 0, 0);
|
|
1002 skip_white (infile);
|
|
1003
|
|
1004 if (saved_string == 0)
|
|
1005 {
|
|
1006 /* If the next three characters aren't `dquote bslash newline'
|
|
1007 then we're not reading a docstring. */
|
20
|
1008 if ((c = getc (infile)) != '"' ||
|
0
|
1009 (c = getc (infile)) != '\\' ||
|
|
1010 (c = getc (infile)) != '\n')
|
|
1011 {
|
|
1012 #ifdef DEBUG
|
|
1013 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1014 buffer, filename);
|
|
1015 #endif
|
|
1016 continue;
|
|
1017 }
|
|
1018 }
|
|
1019 }
|
|
1020
|
82
|
1021 #if 0 /* causes crash */
|
0
|
1022 else if (! strcmp (buffer, "if") ||
|
|
1023 ! strcmp (buffer, "byte-code"))
|
|
1024 ;
|
|
1025 #endif
|
|
1026
|
|
1027 else
|
|
1028 {
|
|
1029 #ifdef DEBUG
|
|
1030 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n",
|
|
1031 buffer, filename);
|
|
1032 #endif
|
|
1033 continue;
|
|
1034 }
|
|
1035
|
|
1036 /* At this point, we should either use the previous
|
|
1037 dynamic doc string in saved_string
|
|
1038 or gobble a doc string from the input file.
|
|
1039
|
|
1040 In the latter case, the opening quote (and leading
|
|
1041 backslash-newline) have already been read. */
|
|
1042 putc ('\n', outfile); /* XEmacs addition */
|
|
1043 putc (037, outfile);
|
|
1044 putc (type, outfile);
|
|
1045 fprintf (outfile, "%s\n", buffer);
|
|
1046 if (saved_string)
|
|
1047 {
|
|
1048 fputs (saved_string, outfile);
|
|
1049 /* Don't use one dynamic doc string twice. */
|
|
1050 free (saved_string);
|
|
1051 saved_string = 0;
|
|
1052 }
|
|
1053 else
|
|
1054 read_c_string (infile, 1, 0);
|
|
1055 }
|
|
1056 fclose (infile);
|
|
1057 return 0;
|
|
1058 }
|