428
|
1 /* Generate doc-string file for XEmacs from source files.
|
930
|
2 Copyright (C) 1985, 86, 92, 93, 94, 97, 1999, 2000, 2001
|
|
3 Free Software Foundation, Inc.
|
428
|
4 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
5 Copyright (C) 1998, 1999 J. Kean Johnston.
|
814
|
6 Copyright (C) 2001, 2002 Ben Wing.
|
930
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify
|
|
11 it under the terms of the GNU General Public License as published by
|
|
12 the Free Software Foundation; either version 2, or (at your option)
|
|
13 any later version.
|
428
|
14
|
930
|
15 XEmacs is distributed in the hope that it will be useful,
|
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 GNU General Public License for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
1618
|
25 /* Synched up with: FSF 21.3. */
|
428
|
26
|
|
27 /* The arguments given to this program are all the C and Lisp source files
|
930
|
28 of XEmacs. .elc and .el and .c files are allowed.
|
|
29 A .o or .obj file can also be specified; the .c file it was made from is used.
|
|
30 This helps the makefile pass the correct list of files.
|
|
31
|
|
32 The results, which go to standard output or to a file
|
|
33 specified with -a or -o (-a to append, -o to start from nothing),
|
|
34 are entries containing function or variable names and their documentation.
|
|
35 Each entry starts with a ^_ character.
|
|
36 Then comes F for a function or V for a variable.
|
|
37 Then comes the function or variable name, terminated with a newline.
|
|
38 Then comes the documentation for that function or variable.
|
|
39
|
|
40 Added 19.15/20.1: `-i site-packages' allow installer to dump extra packages
|
|
41 without modifying Makefiles, etc.
|
428
|
42 */
|
|
43
|
438
|
44 #include <config.h>
|
930
|
45 #include <sysfile.h>
|
428
|
46
|
|
47 #include <stdio.h>
|
|
48 #include <stdlib.h>
|
|
49 #include <string.h>
|
|
50 #include <ctype.h>
|
|
51
|
2286
|
52 #include "compiler.h"
|
|
53
|
930
|
54 /* XEmacs addition */
|
|
55 #define C_IDENTIFIER_CHAR_P(c) \
|
|
56 (('A' <= c && c <= 'Z') || \
|
|
57 ('a' <= c && c <= 'z') || \
|
|
58 ('0' <= c && c <= '9') || \
|
|
59 (c == '_'))
|
428
|
60
|
442
|
61 static int scan_file (const char *filename);
|
428
|
62 static int read_c_string (FILE *, int, int);
|
442
|
63 static void write_c_args (FILE *out, const char *func, char *buf, int minargs,
|
428
|
64 int maxargs);
|
442
|
65 static int scan_c_file (const char *filename, const char *mode);
|
428
|
66 static void skip_white (FILE *);
|
|
67 static void read_lisp_symbol (FILE *, char *);
|
442
|
68 static int scan_lisp_file (const char *filename, const char *mode);
|
428
|
69
|
930
|
70 /* Stdio stream for output to the DOC file. */
|
|
71 static FILE *outfile;
|
|
72
|
|
73 /* XEmacs addition */
|
|
74 enum
|
|
75 {
|
|
76 el_file,
|
|
77 elc_file,
|
|
78 c_file
|
|
79 } Current_file_type;
|
428
|
80
|
|
81 /* Name this program was invoked with. */
|
|
82 char *progname;
|
|
83
|
930
|
84 /* XEmacs addition: set to 1 if this was invoked by ellcc */
|
428
|
85 int ellcc = 0;
|
|
86
|
|
87 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
|
|
88
|
|
89 static void
|
442
|
90 error (const char *s1, const char *s2)
|
428
|
91 {
|
|
92 fprintf (stderr, "%s: ", progname);
|
|
93 fprintf (stderr, s1, s2);
|
|
94 fprintf (stderr, "\n");
|
|
95 }
|
|
96
|
|
97 /* Print error message and exit. */
|
|
98
|
|
99 static void
|
442
|
100 fatal (const char *s1, const char *s2)
|
428
|
101 {
|
|
102 error (s1, s2);
|
|
103 exit (1);
|
|
104 }
|
|
105
|
|
106 /* Like malloc but get fatal error if memory is exhausted. */
|
|
107
|
|
108 static long *
|
|
109 xmalloc (unsigned int size)
|
|
110 {
|
|
111 long *result = (long *) malloc (size);
|
|
112 if (result == NULL)
|
|
113 fatal ("virtual memory exhausted", 0);
|
|
114 return result;
|
|
115 }
|
|
116
|
930
|
117 /* XEmacs addition */
|
428
|
118 static char *
|
814
|
119 next_extra_elc (char *extra_elcs)
|
428
|
120 {
|
|
121 static FILE *fp = NULL;
|
|
122 static char line_buf[BUFSIZ];
|
|
123 char *p = line_buf+1;
|
|
124
|
814
|
125 if (!fp)
|
|
126 {
|
|
127 if (!extra_elcs)
|
|
128 return NULL;
|
|
129 else if (!(fp = fopen (extra_elcs, READ_BINARY)))
|
|
130 {
|
|
131 /* It is not an error if this file doesn't exist. */
|
|
132 /*fatal ("error opening site package file list", 0);*/
|
|
133 return NULL;
|
|
134 }
|
|
135 fgets (line_buf, BUFSIZ, fp);
|
|
136 }
|
|
137
|
930
|
138 do
|
814
|
139 {
|
930
|
140 if (!fgets (line_buf, BUFSIZ, fp))
|
|
141 {
|
|
142 fclose (fp);
|
|
143 fp = NULL;
|
|
144 return NULL;
|
|
145 }
|
|
146 line_buf[0] = '\0';
|
814
|
147 /* reject too short or too long lines */
|
930
|
148 } while (strlen (p) <= 2 || strlen (p) >= (BUFSIZ - 5));
|
|
149
|
814
|
150 p[strlen (p) - 2] = '\0';
|
|
151 strcat (p, ".elc");
|
428
|
152
|
|
153 return p;
|
|
154 }
|
|
155
|
|
156
|
|
157 int
|
|
158 main (int argc, char **argv)
|
|
159 {
|
|
160 int i;
|
|
161 int err_count = 0;
|
|
162 int first_infile;
|
930
|
163 char *extra_elcs = NULL; /* XEmacs addition */
|
428
|
164
|
|
165 progname = argv[0];
|
|
166
|
|
167 outfile = stdout;
|
|
168
|
|
169 /* Don't put CRs in the DOC file. */
|
442
|
170 #ifdef WIN32_NATIVE
|
428
|
171 _fmode = O_BINARY;
|
|
172 _setmode (fileno (stdout), O_BINARY);
|
442
|
173 #endif /* WIN32_NATIVE */
|
428
|
174
|
|
175 /* If first two args are -o FILE, output to FILE. */
|
|
176 i = 1;
|
|
177 if (argc > i + 1 && !strcmp (argv[i], "-o"))
|
|
178 {
|
|
179 outfile = fopen (argv[i + 1], WRITE_BINARY);
|
|
180 i += 2;
|
|
181 }
|
|
182 if (argc > i + 1 && !strcmp (argv[i], "-a"))
|
|
183 {
|
|
184 outfile = fopen (argv[i + 1], APPEND_BINARY);
|
|
185 i += 2;
|
|
186 }
|
930
|
187 if (argc > i + 1 && !strcmp (argv[i], "-d"))
|
|
188 {
|
|
189 chdir (argv[i + 1]);
|
|
190 i += 2;
|
|
191 }
|
|
192
|
|
193 /* Additional command line arguments for XEmacs */
|
428
|
194 if (argc > i + 1 && !strcmp (argv[i], "-E"))
|
|
195 {
|
|
196 outfile = fopen (argv[i + 1], APPEND_BINARY);
|
|
197 i += 2;
|
|
198 ellcc = 1;
|
|
199 }
|
814
|
200 if (argc > (i + 1) && !strcmp (argv[i], "-i"))
|
|
201 {
|
|
202 extra_elcs = argv[i + 1];
|
|
203 i += 2;
|
|
204 }
|
428
|
205
|
|
206 if (outfile == 0)
|
|
207 fatal ("No output file specified", "");
|
|
208
|
930
|
209 /* XEmacs addition */
|
428
|
210 if (ellcc)
|
|
211 fprintf (outfile, "{\n");
|
|
212
|
|
213 first_infile = i;
|
|
214 for (; i < argc; i++)
|
|
215 {
|
930
|
216 /* XEmacs addition: the "if" clause is new; the "else" clause is the
|
|
217 original FSF Emacs code */
|
771
|
218 if (argv[i][0] == '@')
|
|
219 {
|
|
220 /* Allow a file containing files to process, for use w/MS Windows
|
|
221 (where command-line length limits are more problematic) */
|
|
222 FILE *argfile = fopen (argv[i] + 1, READ_TEXT);
|
2421
|
223 char arg[QXE_PATH_MAX];
|
771
|
224
|
|
225 if (!argfile)
|
|
226 fatal ("Unable to open argument file %s", argv[i] + 1);
|
2421
|
227 while (fgets (arg, QXE_PATH_MAX, argfile))
|
771
|
228 {
|
|
229 if (arg[strlen (arg) - 1] == '\n')
|
|
230 arg[strlen (arg) - 1] = '\0'; /* chop \n */
|
|
231 err_count += scan_file (arg);
|
|
232 }
|
|
233 }
|
|
234 else
|
|
235 {
|
|
236 int j;
|
|
237 /* Don't process one file twice. */
|
|
238 for (j = first_infile; j < i; j++)
|
|
239 if (! strcmp (argv[i], argv[j]))
|
|
240 break;
|
|
241 if (j == i)
|
|
242 err_count += scan_file (argv[i]);
|
|
243 }
|
428
|
244 }
|
|
245
|
930
|
246 /* XEmacs addition */
|
814
|
247 if (extra_elcs)
|
|
248 {
|
|
249 char *p;
|
428
|
250
|
814
|
251 while ((p = next_extra_elc (extra_elcs)) != NULL)
|
|
252 err_count += scan_file (p);
|
428
|
253 }
|
|
254
|
|
255 putc ('\n', outfile);
|
|
256 if (ellcc)
|
|
257 fprintf (outfile, "}\n\n");
|
930
|
258 /* End XEmacs addition */
|
|
259
|
428
|
260 #ifndef VMS
|
|
261 exit (err_count > 0);
|
|
262 #endif /* VMS */
|
|
263 return err_count > 0;
|
|
264 }
|
|
265
|
|
266 /* Read file FILENAME and output its doc strings to outfile. */
|
|
267 /* Return 1 if file is not found, 0 if it is found. */
|
|
268
|
|
269 static int
|
442
|
270 scan_file (const char *filename)
|
428
|
271 {
|
|
272 int len = strlen (filename);
|
930
|
273
|
|
274 /* XEmacs change: test ellcc and set Current_file_type in each case */
|
428
|
275 if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc"))
|
|
276 {
|
|
277 Current_file_type = elc_file;
|
|
278 return scan_lisp_file (filename, READ_BINARY);
|
|
279 }
|
|
280 else if (ellcc == 0 && len > 3 && !strcmp (filename + len - 3, ".el"))
|
|
281 {
|
|
282 Current_file_type = el_file;
|
|
283 return scan_lisp_file (filename, READ_TEXT);
|
|
284 }
|
|
285 else
|
|
286 {
|
|
287 Current_file_type = c_file;
|
|
288 return scan_c_file (filename, READ_TEXT);
|
|
289 }
|
|
290 }
|
930
|
291
|
|
292 /* XEmacs addition: ISO 2022 handling */
|
814
|
293 static int
|
|
294 getc_skipping_iso2022 (FILE *file)
|
|
295 {
|
|
296 register int c;
|
|
297 /* #### Kludge -- Ignore any ISO2022 sequences */
|
|
298 c = getc (file);
|
|
299 while (c == 27)
|
|
300 {
|
|
301 c = getc (file);
|
|
302 if (c == '$')
|
|
303 c = getc (file);
|
|
304 if (c >= '(' && c <= '/')
|
|
305 c = getc (file);
|
|
306 c = getc (file);
|
|
307 }
|
|
308 return c;
|
|
309 }
|
|
310
|
|
311 enum iso2022_state
|
|
312 {
|
|
313 ISO_NOTHING,
|
|
314 ISO_ESC,
|
|
315 ISO_DOLLAR,
|
|
316 ISO_FINAL_IS_NEXT,
|
|
317 ISO_DOLLAR_AND_FINAL_IS_NEXT
|
|
318 };
|
|
319
|
|
320 static int non_ascii_p;
|
|
321
|
|
322 static int
|
|
323 getc_iso2022 (FILE *file)
|
|
324 {
|
|
325 /* #### Kludge -- Parse ISO2022 sequences (more or less) */
|
|
326 static enum iso2022_state state;
|
|
327 static int prevc;
|
|
328 register int c;
|
|
329 c = getc (file);
|
|
330 switch (state)
|
|
331 {
|
|
332 case ISO_NOTHING:
|
|
333 if (c == 27)
|
|
334 state = ISO_ESC;
|
|
335 break;
|
|
336
|
|
337 case ISO_ESC:
|
|
338 if (c == '$')
|
|
339 state = ISO_DOLLAR;
|
|
340 else if (c >= '(' && c <= '/')
|
|
341 state = ISO_FINAL_IS_NEXT;
|
|
342 else
|
|
343 state = ISO_NOTHING;
|
|
344 break;
|
|
345
|
|
346 case ISO_DOLLAR:
|
|
347 if (c >= '(' && c <= '/')
|
|
348 state = ISO_DOLLAR_AND_FINAL_IS_NEXT;
|
|
349 else if (c >= '@' && c <= 'B') /* ESC $ @ etc */
|
|
350 {
|
|
351 non_ascii_p = 1;
|
|
352 state = ISO_NOTHING;
|
|
353 }
|
|
354 else
|
|
355 state = ISO_NOTHING;
|
|
356 break;
|
|
357
|
|
358 case ISO_FINAL_IS_NEXT:
|
|
359 if (prevc == '(' && c == 'B') /* ESC ( B, invoke ASCII */
|
|
360 non_ascii_p = 0;
|
|
361 else if (prevc == '(' || prevc == ',') /* ESC ( x or ESC , x */
|
|
362 non_ascii_p = 1;
|
|
363 state = ISO_NOTHING;
|
|
364 break;
|
|
365
|
|
366 case ISO_DOLLAR_AND_FINAL_IS_NEXT:
|
|
367 if (prevc == '(' || prevc == ',') /* ESC $ ( x or ESC $ , x */
|
|
368 non_ascii_p = 1;
|
|
369 state = ISO_NOTHING;
|
|
370 break;
|
|
371 }
|
|
372
|
|
373 prevc = c;
|
|
374 return c;
|
|
375 }
|
|
376
|
428
|
377
|
1111
|
378 char globalbuf[128];
|
428
|
379
|
|
380 /* Skip a C string from INFILE,
|
930
|
381 and return the character that follows the closing ".
|
428
|
382 If printflag is positive, output string contents to outfile.
|
|
383 If it is negative, store contents in buf.
|
|
384 Convert escape sequences \n and \t to newline and tab;
|
|
385 discard \ followed by newline. */
|
|
386
|
814
|
387 #define MDGET do { prevc = c; c = getc_iso2022 (infile); } while (0)
|
428
|
388 static int
|
|
389 read_c_string (FILE *infile, int printflag, int c_docstring)
|
|
390 {
|
442
|
391 register int prevc = 0, c = 0;
|
1111
|
392 char *p = globalbuf;
|
930
|
393 int start = -1; /* XEmacs addition */
|
428
|
394
|
442
|
395 MDGET;
|
428
|
396 while (c != EOF)
|
|
397 {
|
814
|
398 while ((c_docstring || c != '"' || non_ascii_p) && c != EOF)
|
428
|
399 {
|
930
|
400 /* XEmacs addition: the first two "if" clauses are new */
|
814
|
401 if (c == '*' && !non_ascii_p)
|
428
|
402 {
|
442
|
403 int cc = getc (infile);
|
|
404 if (cc == '/')
|
428
|
405 {
|
442
|
406 if (prevc != '\n')
|
|
407 {
|
|
408 if (printflag > 0)
|
|
409 {
|
|
410 if (ellcc)
|
|
411 fprintf (outfile, "\\n\\");
|
|
412 putc ('\n', outfile);
|
|
413 }
|
|
414 else if (printflag < 0)
|
|
415 *p++ = '\n';
|
|
416 }
|
|
417 break;
|
428
|
418 }
|
442
|
419 else
|
|
420 ungetc (cc, infile);
|
|
421 }
|
428
|
422
|
442
|
423 if (start == 1)
|
|
424 {
|
|
425 if (printflag > 0)
|
428
|
426 {
|
442
|
427 if (ellcc)
|
|
428 fprintf (outfile, "\\n\\");
|
|
429 putc ('\n', outfile);
|
428
|
430 }
|
442
|
431 else if (printflag < 0)
|
|
432 *p++ = '\n';
|
428
|
433 }
|
930
|
434 /* End XEmacs addition */
|
428
|
435
|
814
|
436 if (c == '\\' && !non_ascii_p)
|
428
|
437 {
|
442
|
438 MDGET;
|
428
|
439 if (c == '\n')
|
|
440 {
|
442
|
441 MDGET;
|
428
|
442 start = 1;
|
|
443 continue;
|
|
444 }
|
|
445 if (!c_docstring && c == 'n')
|
|
446 c = '\n';
|
|
447 if (c == 't')
|
|
448 c = '\t';
|
|
449 }
|
930
|
450
|
|
451 /* XEmacs change: the "if" clause is new; the "else" clause is
|
|
452 mostly the original FSF Emacs code */
|
428
|
453 if (c == '\n')
|
|
454 start = 1;
|
|
455 else
|
|
456 {
|
|
457 start = 0;
|
442
|
458 if (printflag > 0)
|
|
459 {
|
814
|
460 if (ellcc && c == '"' && !non_ascii_p)
|
442
|
461 putc ('\\', outfile);
|
|
462 putc (c, outfile);
|
|
463 }
|
428
|
464 else if (printflag < 0)
|
|
465 *p++ = c;
|
|
466 }
|
442
|
467 MDGET;
|
428
|
468 }
|
930
|
469 /* XEmacs change: look for continuation of string */
|
428
|
470 if (Current_file_type == c_file)
|
|
471 {
|
442
|
472 do
|
|
473 {
|
|
474 MDGET;
|
|
475 }
|
|
476 while (isspace (c));
|
814
|
477 if (c != '"' || non_ascii_p)
|
428
|
478 break;
|
|
479 }
|
|
480 else
|
|
481 {
|
442
|
482 MDGET;
|
814
|
483 if (c != '"' || non_ascii_p)
|
428
|
484 break;
|
|
485 /* If we had a "", concatenate the two strings. */
|
|
486 }
|
442
|
487 MDGET;
|
428
|
488 }
|
930
|
489
|
428
|
490 if (printflag < 0)
|
|
491 *p = 0;
|
930
|
492
|
428
|
493 return c;
|
|
494 }
|
|
495
|
|
496 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
|
|
497 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
|
|
498
|
|
499 static void
|
2286
|
500 write_c_args (FILE *out, const char *UNUSED (func), char *buf,
|
|
501 int minargs, int maxargs)
|
428
|
502 {
|
|
503 register char *p;
|
|
504 int in_ident = 0;
|
|
505 int just_spaced = 0;
|
|
506 #if 0
|
|
507 int need_space = 1;
|
|
508
|
|
509 fprintf (out, "(%s", func);
|
|
510 #else
|
|
511 /* XEmacs - "arguments:" is for parsing the docstring. FSF's help system
|
|
512 doesn't parse the docstring for arguments like we do, so we're also
|
|
513 going to omit the function name to preserve compatibility with elisp
|
|
514 that parses the docstring. Finally, not prefixing the arglist with
|
|
515 anything is asking for trouble because it's not uncommon to have an
|
|
516 unescaped parenthesis at the beginning of a line. --Stig */
|
|
517 fprintf (out, "arguments: (");
|
|
518 #endif
|
|
519
|
930
|
520 if (*buf == '(')
|
|
521 ++buf;
|
428
|
522
|
930
|
523 for (p = buf; *p; p++)
|
428
|
524 {
|
|
525 char c = *p;
|
|
526 int ident_start = 0;
|
|
527
|
2603
|
528 /* XEmacs addition: add support for ANSI prototypes and the UNUSED
|
|
529 macros. Hop over them. "Lisp_Object" is the only C type allowed
|
|
530 in DEFUNs. For the UNUSED macros we need to eat parens, too. */
|
|
531 static char uu [] = "UNUSED";
|
|
532 static char ui [] = "USED_IF_";
|
428
|
533 static char lo[] = "Lisp_Object";
|
2603
|
534
|
|
535 /* aren't these all vulnerable to buffer overrun? I guess that
|
|
536 means that the .c is busted, so we may as well just die ... */
|
|
537 /* skip over "Lisp_Object" */
|
428
|
538 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
|
|
539 (strncmp (p, lo, sizeof (lo) - 1) == 0) &&
|
930
|
540 isspace ((unsigned char) p[sizeof (lo) - 1]))
|
428
|
541 {
|
|
542 p += (sizeof (lo) - 1);
|
438
|
543 while (isspace ((unsigned char) (*p)))
|
428
|
544 p++;
|
|
545 c = *p;
|
|
546 }
|
|
547
|
2603
|
548 /* skip over "UNUSED" invocation */
|
|
549 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
|
|
550 (strncmp (p, uu, sizeof (uu) - 1) == 0))
|
|
551 {
|
|
552 char *here = p;
|
|
553 p += (sizeof (uu) - 1);
|
|
554 while (isspace ((unsigned char) (*p)))
|
|
555 p++;
|
|
556 if (*p == '(')
|
|
557 {
|
|
558 while (isspace ((unsigned char) (*++p)))
|
|
559 ;
|
|
560 c = *p;
|
|
561 }
|
|
562 else
|
|
563 p = here;
|
|
564 }
|
|
565
|
|
566 /* skip over "USED_IF_*" invocation (only if USED failed) */
|
|
567 else if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
|
|
568 (strncmp (p, ui, sizeof (ui) - 1) == 0))
|
|
569 {
|
|
570 char *here = p;
|
|
571 p += (sizeof (ui) - 1);
|
|
572 /* There should be a law against parsing in C:
|
|
573 this allows a broken USED_IF call, skipping to next macro's
|
|
574 parens. *You* can fix that, I don't see how offhand. ;-) */
|
|
575 while (*p && *p++ != '(')
|
|
576 ;
|
|
577 if (*p)
|
|
578 {
|
|
579 while (isspace ((unsigned char) (*p)))
|
|
580 p++;
|
|
581 c = *p;
|
|
582 }
|
|
583 else
|
|
584 p = here;
|
|
585 }
|
|
586
|
428
|
587 /* Notice when we start printing a new identifier. */
|
|
588 if (C_IDENTIFIER_CHAR_P (c) != in_ident)
|
|
589 {
|
|
590 if (!in_ident)
|
|
591 {
|
|
592 in_ident = 1;
|
|
593 ident_start = 1;
|
|
594 #if 0
|
|
595 /* XEmacs - This goes along with the change above. */
|
|
596 if (need_space)
|
|
597 putc (' ', out);
|
|
598 #endif
|
|
599 if (minargs == 0 && maxargs > 0)
|
|
600 fprintf (out, "&optional ");
|
|
601 just_spaced = 1;
|
|
602
|
|
603 minargs--;
|
|
604 maxargs--;
|
|
605 }
|
|
606 else
|
|
607 in_ident = 0;
|
|
608 }
|
|
609
|
|
610 /* Print the C argument list as it would appear in lisp:
|
930
|
611 print underscores as hyphens, and print commas and newlines
|
|
612 as spaces. Collapse adjacent spaces into one. */
|
|
613 if (c == '_')
|
|
614 c = '-';
|
1618
|
615 else if (c == ',' /* || c == '\n' */)
|
930
|
616 c = ' ';
|
1618
|
617 /* XEmacs change: handle \n below for readability */
|
428
|
618
|
930
|
619 #if 0
|
|
620 /* In C code, `default' is a reserved word, so we spell it
|
|
621 `defalt'; unmangle that here. */
|
|
622 if (ident_start
|
|
623 && strncmp (p, "defalt", 6) == 0
|
|
624 && ! (('A' <= p[6] && p[6] <= 'Z')
|
|
625 || ('a' <= p[6] && p[6] <= 'z')
|
|
626 || ('0' <= p[6] && p[6] <= '9')
|
|
627 || p[6] == '_'))
|
|
628 {
|
|
629 fprintf (out, "DEFAULT");
|
|
630 p += 5;
|
|
631 in_ident = 0;
|
|
632 just_spaced = 0;
|
|
633 }
|
|
634 #endif
|
428
|
635 /* If the C argument name ends with `_', change it to ' ',
|
|
636 to allow use of C reserved words or global symbols as Lisp args. */
|
|
637 if (c == '-' && ! C_IDENTIFIER_CHAR_P (p[1]))
|
|
638 {
|
|
639 in_ident = 0;
|
|
640 just_spaced = 0;
|
|
641 }
|
1618
|
642 /* XEmacs change: if the character is carriage return or linefeed,
|
|
643 escape it for the compiler */
|
|
644 else if (c == '\n')
|
|
645 {
|
|
646 putc('\\', out);
|
|
647 putc('\n', out);
|
|
648 }
|
|
649 else if (c == '\r')
|
|
650 {
|
|
651 putc('\\', out);
|
|
652 putc('\r', out);
|
|
653 }
|
930
|
654 else if (c != ' ' || !just_spaced)
|
428
|
655 {
|
|
656 if (c >= 'a' && c <= 'z')
|
|
657 /* Upcase the letter. */
|
|
658 c += 'A' - 'a';
|
|
659 putc (c, out);
|
|
660 }
|
|
661
|
|
662 just_spaced = (c == ' ');
|
|
663 #if 0
|
|
664 need_space = 0;
|
|
665 #endif
|
|
666 }
|
930
|
667 /* XEmacs addition */
|
428
|
668 if (!ellcc)
|
930
|
669 putc ('\n', out);
|
428
|
670 }
|
|
671
|
771
|
672 /* Read through a c file. If a .o or .obj file is named,
|
428
|
673 the corresponding .c file is read instead.
|
|
674 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
|
930
|
675 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED ...
|
|
676 which don't exist anymore! */
|
428
|
677
|
|
678 static int
|
442
|
679 scan_c_file (const char *filename, const char *mode)
|
428
|
680 {
|
|
681 FILE *infile;
|
|
682 register int c;
|
|
683 register int commas;
|
|
684 register int defunflag;
|
|
685 register int defvarperbufferflag = 0;
|
|
686 register int defvarflag;
|
|
687 int minargs, maxargs;
|
|
688 int l = strlen (filename);
|
2421
|
689 char f[QXE_PATH_MAX];
|
428
|
690
|
930
|
691 /* XEmacs change: different method for checking filename extension */
|
2421
|
692 if (l > QXE_PATH_MAX - 1)
|
647
|
693 {
|
428
|
694 #ifdef ENAMETOOLONG
|
647
|
695 errno = ENAMETOOLONG;
|
428
|
696 #else
|
647
|
697 errno = EINVAL;
|
428
|
698 #endif
|
930
|
699 return 0;
|
647
|
700 }
|
428
|
701
|
|
702 strcpy (f, filename);
|
771
|
703 if (l > 4 && !strcmp (f + l - 4, ".obj")) /* MS Windows */
|
|
704 strcpy (f + l - 4, ".c");
|
428
|
705 if (f[l - 1] == 'o')
|
|
706 f[l - 1] = 'c';
|
|
707 infile = fopen (f, mode);
|
|
708
|
|
709 /* No error if non-ex input file */
|
|
710 if (infile == NULL)
|
|
711 {
|
|
712 perror (f);
|
|
713 return 0;
|
|
714 }
|
|
715
|
930
|
716 #if 0
|
|
717 /* Reset extension to be able to detect duplicate files. */
|
|
718 filename[strlen (filename) - 1] = extension;
|
|
719 #endif
|
|
720
|
428
|
721 c = '\n';
|
|
722 while (!feof (infile))
|
|
723 {
|
|
724 if (c != '\n')
|
|
725 {
|
|
726 c = getc (infile);
|
|
727 continue;
|
|
728 }
|
|
729 c = getc (infile);
|
|
730 if (c == ' ')
|
|
731 {
|
|
732 while (c == ' ')
|
|
733 c = getc (infile);
|
|
734 if (c != 'D')
|
|
735 continue;
|
|
736 c = getc (infile);
|
|
737 if (c != 'E')
|
|
738 continue;
|
|
739 c = getc (infile);
|
|
740 if (c != 'F')
|
|
741 continue;
|
|
742 c = getc (infile);
|
|
743 if (c != 'V')
|
|
744 continue;
|
|
745 c = getc (infile);
|
|
746 if (c != 'A')
|
|
747 continue;
|
|
748 c = getc (infile);
|
|
749 if (c != 'R')
|
|
750 continue;
|
|
751 c = getc (infile);
|
|
752 if (c != '_')
|
|
753 continue;
|
|
754
|
|
755 defvarflag = 1;
|
|
756 defunflag = 0;
|
|
757
|
|
758 c = getc (infile);
|
|
759 /* Note that this business doesn't apply under XEmacs.
|
|
760 DEFVAR_BUFFER_LOCAL in XEmacs behaves normally. */
|
|
761 defvarperbufferflag = (c == 'P');
|
|
762
|
|
763 c = getc (infile);
|
|
764 }
|
|
765 else if (c == 'D')
|
|
766 {
|
|
767 c = getc (infile);
|
|
768 if (c != 'E')
|
|
769 continue;
|
|
770 c = getc (infile);
|
|
771 if (c != 'F')
|
|
772 continue;
|
|
773 c = getc (infile);
|
|
774 defunflag = (c == 'U');
|
|
775 defvarflag = 0;
|
930
|
776 c = getc (infile); /* XEmacs addition */
|
428
|
777 }
|
|
778 else continue;
|
|
779
|
|
780 while (c != '(')
|
|
781 {
|
|
782 if (c < 0)
|
|
783 goto eof;
|
|
784 c = getc (infile);
|
|
785 }
|
|
786
|
|
787 c = getc (infile);
|
|
788 if (c != '"')
|
|
789 continue;
|
|
790 c = read_c_string (infile, -1, 0);
|
|
791
|
|
792 if (defunflag)
|
|
793 commas = 4;
|
|
794 else if (defvarperbufferflag)
|
|
795 commas = 2;
|
|
796 else if (defvarflag)
|
|
797 commas = 1;
|
930
|
798 else /* For DEFSIMPLE and DEFPRED ... which now don't exist! */
|
428
|
799 commas = 2;
|
|
800
|
|
801 while (commas)
|
|
802 {
|
|
803 if (c == ',')
|
|
804 {
|
|
805 commas--;
|
|
806 if (defunflag && (commas == 1 || commas == 2))
|
|
807 {
|
|
808 do
|
|
809 c = getc (infile);
|
930
|
810 while (c == ' ' || c == '\n' || c == '\t');
|
428
|
811 if (c < 0)
|
|
812 goto eof;
|
|
813 ungetc (c, infile);
|
|
814 if (commas == 2) /* pick up minargs */
|
|
815 fscanf (infile, "%d", &minargs);
|
930
|
816 else /* pick up maxargs */
|
428
|
817 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
|
|
818 maxargs = -1;
|
|
819 else
|
|
820 fscanf (infile, "%d", &maxargs);
|
|
821 }
|
|
822 }
|
|
823 if (c < 0)
|
|
824 goto eof;
|
|
825 c = getc (infile);
|
|
826 }
|
|
827 while (c == ' ' || c == '\n' || c == '\t')
|
|
828 c = getc (infile);
|
|
829 if (c == '"')
|
|
830 c = read_c_string (infile, 0, 0);
|
930
|
831 /* XEmacs change */
|
428
|
832 if (defunflag | defvarflag)
|
|
833 {
|
|
834 while (c != '/')
|
853
|
835 {
|
|
836 if (c < 0)
|
|
837 goto eof;
|
930
|
838 if (defunflag && c == '(')
|
1111
|
839 fatal ("Missing doc string for DEFUN %s\n", globalbuf);
|
853
|
840 c = getc (infile);
|
|
841 }
|
428
|
842 c = getc (infile);
|
|
843 while (c == '*')
|
|
844 c = getc (infile);
|
|
845 }
|
|
846 else
|
|
847 {
|
|
848 while (c != ',')
|
853
|
849 {
|
|
850 if (c < 0)
|
|
851 goto eof;
|
|
852 c = getc (infile);
|
|
853 }
|
428
|
854 c = getc (infile);
|
|
855 }
|
930
|
856 /* End XEmacs change */
|
428
|
857 while (c == ' ' || c == '\n' || c == '\t')
|
|
858 c = getc (infile);
|
930
|
859 /* XEmacs addition */
|
428
|
860 if (defunflag | defvarflag)
|
|
861 ungetc (c, infile);
|
930
|
862 /* End XEmacs addition */
|
428
|
863
|
|
864 if (defunflag || defvarflag || c == '"')
|
|
865 {
|
930
|
866 /* XEmacs change: the original code is in the "else" clause */
|
814
|
867 if (ellcc)
|
|
868 fprintf (outfile, " CDOC%s(\"%s\", \"\\\n",
|
1111
|
869 defvarflag ? "SYM" : "SUBR", globalbuf);
|
814
|
870 else
|
|
871 {
|
|
872 putc (037, outfile);
|
|
873 putc (defvarflag ? 'V' : 'F', outfile);
|
1111
|
874 fprintf (outfile, "%s\n", globalbuf);
|
814
|
875 }
|
930
|
876 c = read_c_string (infile, 1, defunflag || defvarflag);
|
428
|
877
|
|
878 /* If this is a defun, find the arguments and print them. If
|
|
879 this function takes MANY or UNEVALLED args, then the C source
|
|
880 won't give the names of the arguments, so we shouldn't bother
|
|
881 trying to find them. */
|
|
882 if (defunflag && maxargs != -1)
|
|
883 {
|
|
884 char argbuf[1024], *p = argbuf;
|
2603
|
885 int paren_level = 1;
|
814
|
886 #if 0 /* For old DEFUN's only */
|
428
|
887 while (c != ')')
|
|
888 {
|
|
889 if (c < 0)
|
|
890 goto eof;
|
|
891 c = getc (infile);
|
|
892 }
|
|
893 #endif
|
|
894 /* Skip into arguments. */
|
|
895 while (c != '(')
|
|
896 {
|
|
897 if (c < 0)
|
|
898 goto eof;
|
|
899 c = getc (infile);
|
|
900 }
|
|
901 /* Copy arguments into ARGBUF. */
|
|
902 *p++ = c;
|
|
903 do
|
853
|
904 {
|
|
905 *p++ = c = getc (infile);
|
|
906 if (c < 0)
|
|
907 goto eof;
|
2603
|
908 /* XEmacs change: handle macros with args (eg, UNUSED) */
|
|
909 if (c == ')')
|
|
910 paren_level--;
|
|
911 if (c == '(')
|
|
912 paren_level++;
|
853
|
913 }
|
2603
|
914 while (paren_level > 0);
|
428
|
915 *p = '\0';
|
|
916 /* Output them. */
|
814
|
917 if (ellcc)
|
|
918 fprintf (outfile, "\\n\\\n\\n\\\n");
|
|
919 else
|
|
920 fprintf (outfile, "\n\n");
|
1111
|
921 write_c_args (outfile, globalbuf, argbuf, minargs, maxargs);
|
428
|
922 }
|
814
|
923 if (ellcc)
|
|
924 fprintf (outfile, "\\n\");\n\n");
|
428
|
925 }
|
|
926 }
|
|
927 eof:
|
|
928 fclose (infile);
|
|
929 return 0;
|
|
930 }
|
|
931
|
|
932 /* Read a file of Lisp code, compiled or interpreted.
|
930
|
933 Looks for
|
|
934 (defun NAME ARGS DOCSTRING ...)
|
|
935 (defmacro NAME ARGS DOCSTRING ...)
|
|
936 (defsubst NAME ARGS DOCSTRING ...)
|
|
937 (autoload (quote NAME) FILE DOCSTRING ...)
|
|
938 (defvar NAME VALUE DOCSTRING)
|
|
939 (defconst NAME VALUE DOCSTRING)
|
|
940 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
|
|
941 (fset (quote NAME) #[... DOCSTRING ...])
|
|
942 (defalias (quote NAME) #[... DOCSTRING ...])
|
|
943 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
|
|
944 starting in column zero.
|
|
945 (quote NAME) may appear as 'NAME as well.
|
428
|
946
|
|
947 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
|
|
948 When we find that, we save it for the following defining-form,
|
|
949 and we use that instead of reading a doc string within that defining-form.
|
|
950
|
930
|
951 For defvar, defconst, and fset we skip to the docstring with a kludgy
|
428
|
952 formatting convention: all docstrings must appear on the same line as the
|
930
|
953 initial open-paren (the one in column zero) and must contain a backslash
|
|
954 and a newline immediately after the initial double-quote. No newlines
|
428
|
955 must appear between the beginning of the form and the first double-quote.
|
930
|
956 For defun, defmacro, and autoload, we know how to skip over the
|
|
957 arglist, but the doc string must still have a backslash and newline
|
|
958 immediately after the double quote.
|
|
959 The only source files that must follow this convention are preloaded
|
|
960 uncompiled ones like loaddefs.el and bindings.el; aside
|
428
|
961 from that, it is always the .elc file that we look at, and they are no
|
|
962 problem because byte-compiler output follows this convention.
|
|
963 The NAME and DOCSTRING are output.
|
|
964 NAME is preceded by `F' for a function or `V' for a variable.
|
|
965 An entry is output only if DOCSTRING has \ newline just after the opening "
|
|
966 */
|
|
967
|
|
968 static void
|
|
969 skip_white (FILE *infile)
|
|
970 {
|
|
971 char c = ' ';
|
|
972 while (c == ' ' || c == '\t' || c == '\n')
|
|
973 c = getc (infile);
|
|
974 ungetc (c, infile);
|
|
975 }
|
|
976
|
|
977 static void
|
|
978 read_lisp_symbol (FILE *infile, char *buffer)
|
|
979 {
|
|
980 char c;
|
|
981 char *fillp = buffer;
|
|
982
|
|
983 skip_white (infile);
|
|
984 while (1)
|
|
985 {
|
|
986 c = getc (infile);
|
|
987 if (c == '\\')
|
|
988 /* FSF has *(++fillp), which is wrong. */
|
|
989 *fillp++ = getc (infile);
|
|
990 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')')
|
|
991 {
|
|
992 ungetc (c, infile);
|
|
993 *fillp = 0;
|
|
994 break;
|
|
995 }
|
|
996 else
|
|
997 *fillp++ = c;
|
|
998 }
|
|
999
|
|
1000 if (! buffer[0])
|
|
1001 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
|
814
|
1002
|
428
|
1003 skip_white (infile);
|
|
1004 }
|
|
1005
|
|
1006 static int
|
442
|
1007 scan_lisp_file (const char *filename, const char *mode)
|
428
|
1008 {
|
|
1009 FILE *infile;
|
|
1010 register int c;
|
|
1011 char *saved_string = 0;
|
|
1012
|
|
1013 infile = fopen (filename, mode);
|
|
1014 if (infile == NULL)
|
|
1015 {
|
|
1016 perror (filename);
|
930
|
1017 return 0; /* No error */
|
428
|
1018 }
|
|
1019
|
|
1020 c = '\n';
|
|
1021 while (!feof (infile))
|
|
1022 {
|
|
1023 char buffer[BUFSIZ];
|
|
1024 char type;
|
|
1025
|
930
|
1026 /* If not at end of line, skip till we get to one. */
|
428
|
1027 if (c != '\n')
|
|
1028 {
|
814
|
1029 c = getc_skipping_iso2022 (infile);
|
428
|
1030 continue;
|
|
1031 }
|
930
|
1032 /* Skip the line break. */
|
|
1033 while (c == '\n')
|
|
1034 c = getc_skipping_iso2022 (infile);
|
428
|
1035 /* Detect a dynamic doc string and save it for the next expression. */
|
|
1036 if (c == '#')
|
|
1037 {
|
814
|
1038 c = getc_skipping_iso2022 (infile);
|
428
|
1039 if (c == '@')
|
|
1040 {
|
|
1041 int length = 0;
|
|
1042 int i;
|
|
1043
|
|
1044 /* Read the length. */
|
814
|
1045 while ((c = getc_skipping_iso2022 (infile),
|
428
|
1046 c >= '0' && c <= '9'))
|
|
1047 {
|
|
1048 length *= 10;
|
|
1049 length += c - '0';
|
|
1050 }
|
|
1051
|
|
1052 /* The next character is a space that is counted in the length
|
|
1053 but not part of the doc string.
|
|
1054 We already read it, so just ignore it. */
|
|
1055 length--;
|
|
1056
|
|
1057 /* Read in the contents. */
|
|
1058 if (saved_string != 0)
|
|
1059 free (saved_string);
|
|
1060 saved_string = (char *) xmalloc (length);
|
|
1061 for (i = 0; i < length; i++)
|
|
1062 saved_string[i] = getc (infile);
|
|
1063 /* The last character is a ^_.
|
|
1064 That is needed in the .elc file
|
|
1065 but it is redundant in DOC. So get rid of it here. */
|
|
1066 saved_string[length - 1] = 0;
|
930
|
1067 /* Skip the line break. */
|
|
1068 while (c == '\n')
|
|
1069 c = getc_skipping_iso2022 (infile);
|
|
1070 /* Skip the following line. */
|
428
|
1071 while (c != '\n')
|
930
|
1072 c = getc_skipping_iso2022 (infile);
|
428
|
1073 }
|
|
1074 continue;
|
|
1075 }
|
|
1076
|
|
1077 if (c != '(')
|
|
1078 continue;
|
|
1079
|
|
1080 read_lisp_symbol (infile, buffer);
|
|
1081
|
930
|
1082 if (! strcmp (buffer, "defun")
|
|
1083 || ! strcmp (buffer, "defmacro")
|
|
1084 || ! strcmp (buffer, "defsubst"))
|
428
|
1085 {
|
|
1086 type = 'F';
|
|
1087 read_lisp_symbol (infile, buffer);
|
|
1088
|
|
1089 /* Skip the arguments: either "nil" or a list in parens */
|
|
1090
|
814
|
1091 c = getc_skipping_iso2022 (infile);
|
930
|
1092 if (c == 'n') /* nil */
|
428
|
1093 {
|
814
|
1094 if ((c = getc_skipping_iso2022 (infile)) != 'i' ||
|
|
1095 (c = getc_skipping_iso2022 (infile)) != 'l')
|
428
|
1096 {
|
|
1097 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
|
|
1098 buffer, filename);
|
|
1099 continue;
|
|
1100 }
|
|
1101 }
|
|
1102 else if (c != '(')
|
|
1103 {
|
|
1104 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
|
|
1105 buffer, filename);
|
|
1106 continue;
|
|
1107 }
|
|
1108 else
|
|
1109 while (c != ')')
|
853
|
1110 {
|
|
1111 c = getc_skipping_iso2022 (infile);
|
|
1112 if (c < 0)
|
|
1113 continue;
|
|
1114 }
|
428
|
1115 skip_white (infile);
|
|
1116
|
|
1117 /* If the next three characters aren't `dquote bslash newline'
|
|
1118 then we're not reading a docstring.
|
930
|
1119 */
|
814
|
1120 if ((c = getc_skipping_iso2022 (infile)) != '"' ||
|
|
1121 (c = getc_skipping_iso2022 (infile)) != '\\' ||
|
|
1122 (c = getc_skipping_iso2022 (infile)) != '\n')
|
428
|
1123 {
|
|
1124 #ifdef DEBUG
|
|
1125 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1126 buffer, filename);
|
|
1127 #endif
|
|
1128 continue;
|
|
1129 }
|
|
1130 }
|
|
1131
|
930
|
1132 else if (! strcmp (buffer, "defvar")
|
|
1133 || ! strcmp (buffer, "defconst"))
|
428
|
1134 {
|
|
1135 char c1 = 0, c2 = 0;
|
|
1136 type = 'V';
|
|
1137 read_lisp_symbol (infile, buffer);
|
|
1138
|
|
1139 if (saved_string == 0)
|
|
1140 {
|
|
1141
|
930
|
1142 /* Skip until the end of line; remember two previous chars. */
|
428
|
1143 while (c != '\n' && c >= 0)
|
|
1144 {
|
|
1145 c2 = c1;
|
|
1146 c1 = c;
|
814
|
1147 c = getc_skipping_iso2022 (infile);
|
428
|
1148 }
|
930
|
1149
|
|
1150 /* If two previous characters were " and \,
|
|
1151 this is a doc string. Otherwise, there is none. */
|
|
1152 if (c2 != '"' || c1 != '\\')
|
|
1153 {
|
|
1154 #ifdef DEBUG
|
|
1155 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1156 buffer, filename);
|
|
1157 #endif
|
|
1158 continue;
|
|
1159 }
|
|
1160 }
|
|
1161 }
|
428
|
1162
|
930
|
1163 else if (! strcmp (buffer, "custom-declare-variable"))
|
|
1164 {
|
|
1165 char c1 = 0, c2 = 0;
|
|
1166 type = 'V';
|
|
1167
|
|
1168 c = getc (infile);
|
|
1169 if (c == '\'')
|
|
1170 read_lisp_symbol (infile, buffer);
|
|
1171 else
|
|
1172 {
|
|
1173 if (c != '(')
|
|
1174 {
|
|
1175 fprintf (stderr,
|
|
1176 "## unparsable name in custom-declare-variable in %s\n",
|
|
1177 filename);
|
|
1178 continue;
|
|
1179 }
|
|
1180 read_lisp_symbol (infile, buffer);
|
|
1181 if (strcmp (buffer, "quote"))
|
|
1182 {
|
|
1183 fprintf (stderr,
|
|
1184 "## unparsable name in custom-declare-variable in %s\n",
|
|
1185 filename);
|
|
1186 continue;
|
|
1187 }
|
|
1188 read_lisp_symbol (infile, buffer);
|
|
1189 c = getc (infile);
|
|
1190 if (c != ')')
|
|
1191 {
|
|
1192 fprintf (stderr,
|
|
1193 "## unparsable quoted name in custom-declare-variable in %s\n",
|
|
1194 filename);
|
|
1195 continue;
|
|
1196 }
|
|
1197 }
|
|
1198
|
|
1199 if (saved_string == 0)
|
|
1200 {
|
|
1201 /* Skip to end of line; remember the two previous chars. */
|
|
1202 while (c != '\n' && c >= 0)
|
|
1203 {
|
|
1204 c2 = c1;
|
|
1205 c1 = c;
|
|
1206 c = getc_skipping_iso2022 (infile);
|
|
1207 }
|
|
1208
|
428
|
1209 /* If two previous characters were " and \,
|
|
1210 this is a doc string. Otherwise, there is none. */
|
|
1211 if (c2 != '"' || c1 != '\\')
|
|
1212 {
|
|
1213 #ifdef DEBUG
|
|
1214 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1215 buffer, filename);
|
|
1216 #endif
|
|
1217 continue;
|
|
1218 }
|
|
1219 }
|
|
1220 }
|
|
1221
|
|
1222 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
|
|
1223 {
|
|
1224 char c1 = 0, c2 = 0;
|
|
1225 type = 'F';
|
|
1226
|
814
|
1227 c = getc_skipping_iso2022 (infile);
|
428
|
1228 if (c == '\'')
|
|
1229 read_lisp_symbol (infile, buffer);
|
|
1230 else
|
|
1231 {
|
|
1232 if (c != '(')
|
|
1233 {
|
|
1234 fprintf (stderr, "## unparsable name in fset in %s\n",
|
|
1235 filename);
|
|
1236 continue;
|
|
1237 }
|
|
1238 read_lisp_symbol (infile, buffer);
|
|
1239 if (strcmp (buffer, "quote"))
|
|
1240 {
|
|
1241 fprintf (stderr, "## unparsable name in fset in %s\n",
|
|
1242 filename);
|
|
1243 continue;
|
|
1244 }
|
|
1245 read_lisp_symbol (infile, buffer);
|
814
|
1246 c = getc_skipping_iso2022 (infile);
|
428
|
1247 if (c != ')')
|
|
1248 {
|
|
1249 fprintf (stderr,
|
|
1250 "## unparsable quoted name in fset in %s\n",
|
|
1251 filename);
|
|
1252 continue;
|
|
1253 }
|
|
1254 }
|
|
1255
|
|
1256 if (saved_string == 0)
|
|
1257 {
|
930
|
1258 /* Skip to end of line; remember the two previous chars. */
|
428
|
1259 while (c != '\n' && c >= 0)
|
|
1260 {
|
|
1261 c2 = c1;
|
|
1262 c1 = c;
|
814
|
1263 c = getc_skipping_iso2022 (infile);
|
428
|
1264 }
|
930
|
1265
|
428
|
1266 /* If two previous characters were " and \,
|
|
1267 this is a doc string. Otherwise, there is none. */
|
|
1268 if (c2 != '"' || c1 != '\\')
|
|
1269 {
|
|
1270 #ifdef DEBUG
|
|
1271 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1272 buffer, filename);
|
|
1273 #endif
|
|
1274 continue;
|
|
1275 }
|
|
1276 }
|
|
1277 }
|
|
1278
|
|
1279 else if (! strcmp (buffer, "autoload"))
|
|
1280 {
|
|
1281 type = 'F';
|
814
|
1282 c = getc_skipping_iso2022 (infile);
|
428
|
1283 if (c == '\'')
|
|
1284 read_lisp_symbol (infile, buffer);
|
|
1285 else
|
|
1286 {
|
|
1287 if (c != '(')
|
|
1288 {
|
|
1289 fprintf (stderr, "## unparsable name in autoload in %s\n",
|
|
1290 filename);
|
|
1291 continue;
|
|
1292 }
|
|
1293 read_lisp_symbol (infile, buffer);
|
|
1294 if (strcmp (buffer, "quote"))
|
|
1295 {
|
|
1296 fprintf (stderr, "## unparsable name in autoload in %s\n",
|
|
1297 filename);
|
|
1298 continue;
|
|
1299 }
|
|
1300 read_lisp_symbol (infile, buffer);
|
814
|
1301 c = getc_skipping_iso2022 (infile);
|
428
|
1302 if (c != ')')
|
|
1303 {
|
|
1304 fprintf (stderr,
|
|
1305 "## unparsable quoted name in autoload in %s\n",
|
|
1306 filename);
|
|
1307 continue;
|
|
1308 }
|
|
1309 }
|
|
1310 skip_white (infile);
|
814
|
1311 if ((c = getc_skipping_iso2022 (infile)) != '\"')
|
428
|
1312 {
|
|
1313 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
|
|
1314 buffer, filename);
|
|
1315 continue;
|
|
1316 }
|
|
1317 read_c_string (infile, 0, 0);
|
|
1318 skip_white (infile);
|
|
1319
|
|
1320 if (saved_string == 0)
|
|
1321 {
|
|
1322 /* If the next three characters aren't `dquote bslash newline'
|
|
1323 then we're not reading a docstring. */
|
814
|
1324 if ((c = getc_skipping_iso2022 (infile)) != '"' ||
|
|
1325 (c = getc_skipping_iso2022 (infile)) != '\\' ||
|
|
1326 (c = getc_skipping_iso2022 (infile)) != '\n')
|
428
|
1327 {
|
|
1328 #ifdef DEBUG
|
|
1329 fprintf (stderr, "## non-docstring in %s (%s)\n",
|
|
1330 buffer, filename);
|
|
1331 #endif
|
|
1332 continue;
|
|
1333 }
|
|
1334 }
|
|
1335 }
|
|
1336
|
814
|
1337 #if 0 /* causes crash */
|
930
|
1338 else if (! strcmp (buffer, "if")
|
|
1339 || ! strcmp (buffer, "byte-code"))
|
428
|
1340 ;
|
|
1341 #endif
|
|
1342
|
|
1343 else
|
|
1344 {
|
|
1345 #ifdef DEBUG
|
|
1346 fprintf (stderr, "## unrecognized top-level form, %s (%s)\n",
|
|
1347 buffer, filename);
|
|
1348 #endif
|
|
1349 continue;
|
|
1350 }
|
|
1351
|
|
1352 /* At this point, we should either use the previous
|
|
1353 dynamic doc string in saved_string
|
|
1354 or gobble a doc string from the input file.
|
930
|
1355
|
428
|
1356 In the latter case, the opening quote (and leading
|
|
1357 backslash-newline) have already been read. */
|
930
|
1358
|
814
|
1359 putc ('\n', outfile); /* XEmacs addition */
|
428
|
1360 putc (037, outfile);
|
|
1361 putc (type, outfile);
|
|
1362 fprintf (outfile, "%s\n", buffer);
|
|
1363 if (saved_string)
|
|
1364 {
|
|
1365 fputs (saved_string, outfile);
|
|
1366 /* Don't use one dynamic doc string twice. */
|
|
1367 free (saved_string);
|
|
1368 saved_string = 0;
|
|
1369 }
|
|
1370 else
|
|
1371 read_c_string (infile, 1, 0);
|
|
1372 }
|
|
1373 fclose (infile);
|
|
1374 return 0;
|
|
1375 }
|