comparison lib-src/make-docfile.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
38 Added 19.15/20.1: `-i site-packages' allow installer to dump extra packages 38 Added 19.15/20.1: `-i site-packages' allow installer to dump extra packages
39 without modifying Makefiles, etc. 39 without modifying Makefiles, etc.
40 */ 40 */
41 41
42 #define NO_SHORTNAMES /* Tell config not to load remap.h */ 42 #define NO_SHORTNAMES /* Tell config not to load remap.h */
43 #include <config.h> 43 #include <../src/config.h>
44 44
45 #include <stdio.h> 45 #include <stdio.h>
46 #include <errno.h> 46 #include <errno.h>
47 #if __STDC__ || defined(STDC_HEADERS) 47 #if __STDC__ || defined(STDC_HEADERS)
48 #include <stdlib.h> 48 #include <stdlib.h>
49 #ifdef HAVE_UNISTD_H
50 #include <unistd.h> 49 #include <unistd.h>
51 #endif
52 #include <string.h> 50 #include <string.h>
53 #include <ctype.h> 51 #include <ctype.h>
54 #endif 52 #endif
55 53
56 #ifdef CYGWIN 54 #if defined(MSDOS) || defined(__CYGWIN32__)
57 #include <fcntl.h> 55 #include <fcntl.h>
58 #endif 56 #endif /* MSDOS */
59 #ifdef WIN32_NATIVE 57 #ifdef WINDOWSNT
60 #include <direct.h> 58 #include <direct.h>
61 #include <fcntl.h> 59 #include <fcntl.h>
62 #include <io.h> 60 #include <io.h>
63 #include <stdlib.h> 61 #include <stdlib.h>
64 #endif /* WIN32_NATIVE */ 62 #endif /* WINDOWSNT */
65 63
66 #ifndef WIN32_NATIVE
67 #include <sys/param.h> 64 #include <sys/param.h>
68 #endif /* not WIN32_NATIVE */ 65
69 66 #if defined(DOS_NT) || defined(__CYGWIN32__)
70 #if defined(WIN32_NATIVE) || defined(CYGWIN)
71 #define READ_TEXT "rt" 67 #define READ_TEXT "rt"
72 #define READ_BINARY "rb" 68 #define READ_BINARY "rb"
73 #define WRITE_BINARY "wb" 69 #define WRITE_BINARY "wb"
74 #define APPEND_BINARY "ab" 70 #define APPEND_BINARY "ab"
75 #else /* not WIN32_NATIVE */ 71 #else /* not DOS_NT */
76 #define READ_TEXT "r" 72 #define READ_TEXT "r"
77 #define READ_BINARY "r" 73 #define READ_BINARY "r"
78 #define WRITE_BINARY "w" 74 #define WRITE_BINARY "w"
79 #define APPEND_BINARY "a" 75 #define APPEND_BINARY "a"
80 #endif /* not WIN32_NATIVE */ 76 #endif /* not DOS_NT */
77
78 #ifdef MSDOS
79 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
80 file where that function is defined. */
81 #undef chdir
82 #endif
81 83
82 /* Stdio stream for output to the DOC file. */ 84 /* Stdio stream for output to the DOC file. */
83 static FILE *outfile; 85 static FILE *outfile;
84 86
85 enum 87 enum
87 el_file, 89 el_file,
88 elc_file, 90 elc_file,
89 c_file 91 c_file
90 } Current_file_type; 92 } Current_file_type;
91 93
92 static int scan_file (const char *filename); 94 static int scan_file (CONST char *filename);
93 static int read_c_string (FILE *, int, int); 95 static int read_c_string (FILE *, int, int);
94 static void write_c_args (FILE *out, const char *func, char *buf, int minargs, 96 static void write_c_args (FILE *out, CONST char *func, char *buf, int minargs,
95 int maxargs); 97 int maxargs);
96 static int scan_c_file (const char *filename, const char *mode); 98 static int scan_c_file (CONST char *filename, CONST char *mode);
97 static void skip_white (FILE *); 99 static void skip_white (FILE *);
98 static void read_lisp_symbol (FILE *, char *); 100 static void read_lisp_symbol (FILE *, char *);
99 static int scan_lisp_file (const char *filename, const char *mode); 101 static int scan_lisp_file (CONST char *filename, CONST char *mode);
100 102
101 #define C_IDENTIFIER_CHAR_P(c) \ 103 #define C_IDENTIFIER_CHAR_P(c) \
102 (('A' <= c && c <= 'Z') || \ 104 (('A' <= c && c <= 'Z') || \
103 ('a' <= c && c <= 'z') || \ 105 ('a' <= c && c <= 'z') || \
104 ('0' <= c && c <= '9') || \ 106 ('0' <= c && c <= '9') || \
111 int ellcc = 0; 113 int ellcc = 0;
112 114
113 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 115 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
114 116
115 static void 117 static void
116 error (const char *s1, const char *s2) 118 error (CONST char *s1, CONST char *s2)
117 { 119 {
118 fprintf (stderr, "%s: ", progname); 120 fprintf (stderr, "%s: ", progname);
119 fprintf (stderr, s1, s2); 121 fprintf (stderr, s1, s2);
120 fprintf (stderr, "\n"); 122 fprintf (stderr, "\n");
121 } 123 }
122 124
123 /* Print error message and exit. */ 125 /* Print error message and exit. */
124 126
125 static void 127 static void
126 fatal (const char *s1, const char *s2) 128 fatal (CONST char *s1, CONST char *s2)
127 { 129 {
128 error (s1, s2); 130 error (s1, s2);
129 exit (1); 131 exit (1);
130 } 132 }
131 133
187 progname = argv[0]; 189 progname = argv[0];
188 190
189 outfile = stdout; 191 outfile = stdout;
190 192
191 /* Don't put CRs in the DOC file. */ 193 /* Don't put CRs in the DOC file. */
192 #ifdef WIN32_NATIVE 194 #ifdef MSDOS
195 _fmode = O_BINARY;
196 #if 0 /* Suspicion is that this causes hanging.
197 So instead we require people to use -o on MSDOS. */
198 (stdout)->_flag &= ~_IOTEXT;
199 _setmode (fileno (stdout), O_BINARY);
200 #endif
201 outfile = 0;
202 #endif /* MSDOS */
203 #ifdef WINDOWSNT
193 _fmode = O_BINARY; 204 _fmode = O_BINARY;
194 _setmode (fileno (stdout), O_BINARY); 205 _setmode (fileno (stdout), O_BINARY);
195 #endif /* WIN32_NATIVE */ 206 #endif /* WINDOWSNT */
196 207
197 /* If first two args are -o FILE, output to FILE. */ 208 /* If first two args are -o FILE, output to FILE. */
198 i = 1; 209 i = 1;
199 if (argc > i + 1 && !strcmp (argv[i], "-o")) 210 if (argc > i + 1 && !strcmp (argv[i], "-o"))
200 { 211 {
261 272
262 /* Read file FILENAME and output its doc strings to outfile. */ 273 /* Read file FILENAME and output its doc strings to outfile. */
263 /* Return 1 if file is not found, 0 if it is found. */ 274 /* Return 1 if file is not found, 0 if it is found. */
264 275
265 static int 276 static int
266 scan_file (const char *filename) 277 scan_file (CONST char *filename)
267 { 278 {
268 int len = strlen (filename); 279 int len = strlen (filename);
269 if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc")) 280 if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc"))
270 { 281 {
271 Current_file_type = elc_file; 282 Current_file_type = elc_file;
290 If printflag is positive, output string contents to outfile. 301 If printflag is positive, output string contents to outfile.
291 If it is negative, store contents in buf. 302 If it is negative, store contents in buf.
292 Convert escape sequences \n and \t to newline and tab; 303 Convert escape sequences \n and \t to newline and tab;
293 discard \ followed by newline. */ 304 discard \ followed by newline. */
294 305
295 #define MDGET do { prevc = c; c = getc (infile); } while (0)
296 static int 306 static int
297 read_c_string (FILE *infile, int printflag, int c_docstring) 307 read_c_string (FILE *infile, int printflag, int c_docstring)
298 { 308 {
299 register int prevc = 0, c = 0; 309 register int c;
300 char *p = buf; 310 char *p = buf;
301 int start = -1; 311 int start = -1;
302 312
303 MDGET; 313 c = getc (infile);
304 while (c != EOF) 314 while (c != EOF)
305 { 315 {
306 while ((c_docstring || c != '"') && c != EOF) 316 while ((c_docstring || c != '"') && c != EOF)
307 { 317 {
308 if (c == '*') 318 if (start)
309 { 319 {
310 int cc = getc (infile); 320 if (c == '*')
311 if (cc == '/') 321 {
312 { 322 int cc = getc (infile);
313 if (prevc != '\n') 323 if (cc == '/')
314 { 324 break;
315 if (printflag > 0) 325 else
316 { 326 ungetc (cc, infile);
317 if (ellcc) 327 }
318 fprintf (outfile, "\\n\\"); 328
319 putc ('\n', outfile); 329 if (start != -1)
320 } 330 {
321 else if (printflag < 0) 331 if (printflag > 0)
322 *p++ = '\n'; 332 {
323 } 333 if (ellcc)
324 break; 334 fprintf (outfile, "\\n\\");
325 } 335 putc ('\n', outfile);
326 else 336 }
327 ungetc (cc, infile); 337 else if (printflag < 0)
328 } 338 *p++ = '\n';
329 339 }
330 if (start == 1)
331 {
332 if (printflag > 0)
333 {
334 if (ellcc)
335 fprintf (outfile, "\\n\\");
336 putc ('\n', outfile);
337 }
338 else if (printflag < 0)
339 *p++ = '\n';
340 } 340 }
341 341
342 if (c == '\\') 342 if (c == '\\')
343 { 343 {
344 MDGET; 344 c = getc (infile);
345 if (c == '\n') 345 if (c == '\n')
346 { 346 {
347 MDGET; 347 c = getc (infile);
348 start = 1; 348 start = 1;
349 continue; 349 continue;
350 } 350 }
351 if (!c_docstring && c == 'n') 351 if (!c_docstring && c == 'n')
352 c = '\n'; 352 c = '\n';
356 if (c == '\n') 356 if (c == '\n')
357 start = 1; 357 start = 1;
358 else 358 else
359 { 359 {
360 start = 0; 360 start = 0;
361 if (printflag > 0) 361 if (printflag > 0) {
362 { 362 if (ellcc && c == '"')
363 if (ellcc && c == '"') 363 putc ('\\', outfile);
364 putc ('\\', outfile); 364 putc (c, outfile);
365 putc (c, outfile); 365 }
366 }
367 else if (printflag < 0) 366 else if (printflag < 0)
368 *p++ = c; 367 *p++ = c;
369 } 368 }
370 MDGET; 369 c = getc (infile);
371 } 370 }
372 /* look for continuation of string */ 371 /* look for continuation of string */
373 if (Current_file_type == c_file) 372 if (Current_file_type == c_file)
374 { 373 {
375 do 374 while (isspace (c = getc (infile)))
376 { 375 ;
377 MDGET;
378 }
379 while (isspace (c));
380 if (c != '"') 376 if (c != '"')
381 break; 377 break;
382 } 378 }
383 else 379 else
384 { 380 {
385 MDGET; 381 c = getc (infile);
386 if (c != '"') 382 if (c != '"')
387 break; 383 break;
388 /* If we had a "", concatenate the two strings. */ 384 /* If we had a "", concatenate the two strings. */
389 } 385 }
390 MDGET; 386 c = getc (infile);
391 } 387 }
392 388
393 if (printflag < 0) 389 if (printflag < 0)
394 *p = 0; 390 *p = 0;
395 391
398 394
399 /* Write to file OUT the argument names of function FUNC, whose text is in BUF. 395 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
400 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ 396 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
401 397
402 static void 398 static void
403 write_c_args (FILE *out, const char *func, char *buff, int minargs, 399 write_c_args (FILE *out, CONST char *func, char *buff, int minargs,
404 int maxargs) 400 int maxargs)
405 { 401 {
406 register char *p; 402 register char *p;
407 int in_ident = 0; 403 int in_ident = 0;
408 int just_spaced = 0; 404 int just_spaced = 0;
431 /* Add support for ANSI prototypes. Hop over 427 /* Add support for ANSI prototypes. Hop over
432 "Lisp_Object" string (the only C type allowed in DEFUNs) */ 428 "Lisp_Object" string (the only C type allowed in DEFUNs) */
433 static char lo[] = "Lisp_Object"; 429 static char lo[] = "Lisp_Object";
434 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident && 430 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
435 (strncmp (p, lo, sizeof (lo) - 1) == 0) && 431 (strncmp (p, lo, sizeof (lo) - 1) == 0) &&
436 isspace((unsigned char) (* (p + sizeof (lo) - 1)))) 432 isspace(*(p + sizeof (lo) - 1)))
437 { 433 {
438 p += (sizeof (lo) - 1); 434 p += (sizeof (lo) - 1);
439 while (isspace ((unsigned char) (*p))) 435 while (isspace (*p))
440 p++; 436 p++;
441 c = *p; 437 c = *p;
442 } 438 }
443 439
444 /* Notice when we start printing a new identifier. */ 440 /* Notice when we start printing a new identifier. */
498 the corresponding .c file is read instead. 494 the corresponding .c file is read instead.
499 Looks for DEFUN constructs such as are defined in ../src/lisp.h. 495 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
500 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ 496 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
501 497
502 static int 498 static int
503 scan_c_file (const char *filename, const char *mode) 499 scan_c_file (CONST char *filename, CONST char *mode)
504 { 500 {
505 FILE *infile; 501 FILE *infile;
506 register int c; 502 register int c;
507 register int commas; 503 register int commas;
508 register int defunflag; 504 register int defunflag;
789 785
790 skip_white (infile); 786 skip_white (infile);
791 } 787 }
792 788
793 static int 789 static int
794 scan_lisp_file (const char *filename, const char *mode) 790 scan_lisp_file (CONST char *filename, CONST char *mode)
795 { 791 {
796 FILE *infile; 792 FILE *infile;
797 register int c; 793 register int c;
798 char *saved_string = 0; 794 char *saved_string = 0;
799 795
917 { 913 {
918 914
919 /* Skip until the first newline; remember the two previous chars. */ 915 /* Skip until the first newline; remember the two previous chars. */
920 while (c != '\n' && c >= 0) 916 while (c != '\n' && c >= 0)
921 { 917 {
922 /* #### Kludge -- Ignore any ESC x x ISO2022 sequences */ 918 /* ### Kludge -- Ignore any ESC x x ISO2022 sequences */
923 if (c == 27) 919 if (c == 27)
924 { 920 {
925 getc (infile); 921 getc (infile);
926 getc (infile); 922 getc (infile);
927 goto nextchar; 923 goto nextchar;