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