comparison lib-src/make-docfile.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children b39c14581166
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
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
49 #include <unistd.h> 50 #include <unistd.h>
51 #endif
50 #include <string.h> 52 #include <string.h>
51 #include <ctype.h> 53 #include <ctype.h>
52 #endif 54 #endif
53 55
54 #if defined(MSDOS) || defined(__CYGWIN32__) 56 #ifdef CYGWIN
55 #include <fcntl.h> 57 #include <fcntl.h>
56 #endif /* MSDOS */ 58 #endif
57 #ifdef WINDOWSNT 59 #ifdef WIN32_NATIVE
58 #include <direct.h> 60 #include <direct.h>
59 #include <fcntl.h> 61 #include <fcntl.h>
60 #include <io.h> 62 #include <io.h>
61 #include <stdlib.h> 63 #include <stdlib.h>
62 #endif /* WINDOWSNT */ 64 #endif /* WIN32_NATIVE */
63 65
66 #ifndef WIN32_NATIVE
64 #include <sys/param.h> 67 #include <sys/param.h>
65 68 #endif /* not WIN32_NATIVE */
66 #if defined(DOS_NT) || defined(__CYGWIN32__) 69
70 #if defined(WIN32_NATIVE) || defined(CYGWIN)
67 #define READ_TEXT "rt" 71 #define READ_TEXT "rt"
68 #define READ_BINARY "rb" 72 #define READ_BINARY "rb"
69 #define WRITE_BINARY "wb" 73 #define WRITE_BINARY "wb"
70 #define APPEND_BINARY "ab" 74 #define APPEND_BINARY "ab"
71 #else /* not DOS_NT */ 75 #else /* not WIN32_NATIVE */
72 #define READ_TEXT "r" 76 #define READ_TEXT "r"
73 #define READ_BINARY "r" 77 #define READ_BINARY "r"
74 #define WRITE_BINARY "w" 78 #define WRITE_BINARY "w"
75 #define APPEND_BINARY "a" 79 #define APPEND_BINARY "a"
76 #endif /* not DOS_NT */ 80 #endif /* not WIN32_NATIVE */
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
83 81
84 /* Stdio stream for output to the DOC file. */ 82 /* Stdio stream for output to the DOC file. */
85 static FILE *outfile; 83 static FILE *outfile;
86 84
87 enum 85 enum
89 el_file, 87 el_file,
90 elc_file, 88 elc_file,
91 c_file 89 c_file
92 } Current_file_type; 90 } Current_file_type;
93 91
94 static int scan_file (CONST char *filename); 92 static int scan_file (const char *filename);
95 static int read_c_string (FILE *, int, int); 93 static int read_c_string (FILE *, int, int);
96 static void write_c_args (FILE *out, CONST char *func, char *buf, int minargs, 94 static void write_c_args (FILE *out, const char *func, char *buf, int minargs,
97 int maxargs); 95 int maxargs);
98 static int scan_c_file (CONST char *filename, CONST char *mode); 96 static int scan_c_file (const char *filename, const char *mode);
99 static void skip_white (FILE *); 97 static void skip_white (FILE *);
100 static void read_lisp_symbol (FILE *, char *); 98 static void read_lisp_symbol (FILE *, char *);
101 static int scan_lisp_file (CONST char *filename, CONST char *mode); 99 static int scan_lisp_file (const char *filename, const char *mode);
102 100
103 #define C_IDENTIFIER_CHAR_P(c) \ 101 #define C_IDENTIFIER_CHAR_P(c) \
104 (('A' <= c && c <= 'Z') || \ 102 (('A' <= c && c <= 'Z') || \
105 ('a' <= c && c <= 'z') || \ 103 ('a' <= c && c <= 'z') || \
106 ('0' <= c && c <= '9') || \ 104 ('0' <= c && c <= '9') || \
113 int ellcc = 0; 111 int ellcc = 0;
114 112
115 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 113 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
116 114
117 static void 115 static void
118 error (CONST char *s1, CONST char *s2) 116 error (const char *s1, const char *s2)
119 { 117 {
120 fprintf (stderr, "%s: ", progname); 118 fprintf (stderr, "%s: ", progname);
121 fprintf (stderr, s1, s2); 119 fprintf (stderr, s1, s2);
122 fprintf (stderr, "\n"); 120 fprintf (stderr, "\n");
123 } 121 }
124 122
125 /* Print error message and exit. */ 123 /* Print error message and exit. */
126 124
127 static void 125 static void
128 fatal (CONST char *s1, CONST char *s2) 126 fatal (const char *s1, const char *s2)
129 { 127 {
130 error (s1, s2); 128 error (s1, s2);
131 exit (1); 129 exit (1);
132 } 130 }
133 131
189 progname = argv[0]; 187 progname = argv[0];
190 188
191 outfile = stdout; 189 outfile = stdout;
192 190
193 /* Don't put CRs in the DOC file. */ 191 /* Don't put CRs in the DOC file. */
194 #ifdef MSDOS 192 #ifdef WIN32_NATIVE
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
204 _fmode = O_BINARY; 193 _fmode = O_BINARY;
205 _setmode (fileno (stdout), O_BINARY); 194 _setmode (fileno (stdout), O_BINARY);
206 #endif /* WINDOWSNT */ 195 #endif /* WIN32_NATIVE */
207 196
208 /* If first two args are -o FILE, output to FILE. */ 197 /* If first two args are -o FILE, output to FILE. */
209 i = 1; 198 i = 1;
210 if (argc > i + 1 && !strcmp (argv[i], "-o")) 199 if (argc > i + 1 && !strcmp (argv[i], "-o"))
211 { 200 {
272 261
273 /* Read file FILENAME and output its doc strings to outfile. */ 262 /* Read file FILENAME and output its doc strings to outfile. */
274 /* Return 1 if file is not found, 0 if it is found. */ 263 /* Return 1 if file is not found, 0 if it is found. */
275 264
276 static int 265 static int
277 scan_file (CONST char *filename) 266 scan_file (const char *filename)
278 { 267 {
279 int len = strlen (filename); 268 int len = strlen (filename);
280 if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc")) 269 if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc"))
281 { 270 {
282 Current_file_type = elc_file; 271 Current_file_type = elc_file;
301 If printflag is positive, output string contents to outfile. 290 If printflag is positive, output string contents to outfile.
302 If it is negative, store contents in buf. 291 If it is negative, store contents in buf.
303 Convert escape sequences \n and \t to newline and tab; 292 Convert escape sequences \n and \t to newline and tab;
304 discard \ followed by newline. */ 293 discard \ followed by newline. */
305 294
295 #define MDGET do { prevc = c; c = getc (infile); } while (0)
306 static int 296 static int
307 read_c_string (FILE *infile, int printflag, int c_docstring) 297 read_c_string (FILE *infile, int printflag, int c_docstring)
308 { 298 {
309 register int c; 299 register int prevc = 0, c = 0;
310 char *p = buf; 300 char *p = buf;
311 int start = -1; 301 int start = -1;
312 302
313 c = getc (infile); 303 MDGET;
314 while (c != EOF) 304 while (c != EOF)
315 { 305 {
316 while ((c_docstring || c != '"') && c != EOF) 306 while ((c_docstring || c != '"') && c != EOF)
317 { 307 {
318 if (start) 308 if (c == '*')
319 { 309 {
320 if (c == '*') 310 int cc = getc (infile);
321 { 311 if (cc == '/')
322 int cc = getc (infile); 312 {
323 if (cc == '/') 313 if (prevc != '\n')
324 break; 314 {
325 else 315 if (printflag > 0)
326 ungetc (cc, infile); 316 {
327 } 317 if (ellcc)
328 318 fprintf (outfile, "\\n\\");
329 if (start != -1) 319 putc ('\n', outfile);
330 { 320 }
331 if (printflag > 0) 321 else if (printflag < 0)
332 { 322 *p++ = '\n';
333 if (ellcc) 323 }
334 fprintf (outfile, "\\n\\"); 324 break;
335 putc ('\n', outfile); 325 }
336 } 326 else
337 else if (printflag < 0) 327 ungetc (cc, infile);
338 *p++ = '\n'; 328 }
339 } 329
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 c = getc (infile); 344 MDGET;
345 if (c == '\n') 345 if (c == '\n')
346 { 346 {
347 c = getc (infile); 347 MDGET;
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 if (ellcc && c == '"') 362 {
363 putc ('\\', outfile); 363 if (ellcc && c == '"')
364 putc (c, outfile); 364 putc ('\\', outfile);
365 } 365 putc (c, outfile);
366 }
366 else if (printflag < 0) 367 else if (printflag < 0)
367 *p++ = c; 368 *p++ = c;
368 } 369 }
369 c = getc (infile); 370 MDGET;
370 } 371 }
371 /* look for continuation of string */ 372 /* look for continuation of string */
372 if (Current_file_type == c_file) 373 if (Current_file_type == c_file)
373 { 374 {
374 while (isspace (c = getc (infile))) 375 do
375 ; 376 {
377 MDGET;
378 }
379 while (isspace (c));
376 if (c != '"') 380 if (c != '"')
377 break; 381 break;
378 } 382 }
379 else 383 else
380 { 384 {
381 c = getc (infile); 385 MDGET;
382 if (c != '"') 386 if (c != '"')
383 break; 387 break;
384 /* If we had a "", concatenate the two strings. */ 388 /* If we had a "", concatenate the two strings. */
385 } 389 }
386 c = getc (infile); 390 MDGET;
387 } 391 }
388 392
389 if (printflag < 0) 393 if (printflag < 0)
390 *p = 0; 394 *p = 0;
391 395
394 398
395 /* Write to file OUT the argument names of function FUNC, whose text is in BUF. 399 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
396 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ 400 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
397 401
398 static void 402 static void
399 write_c_args (FILE *out, CONST char *func, char *buff, int minargs, 403 write_c_args (FILE *out, const char *func, char *buff, int minargs,
400 int maxargs) 404 int maxargs)
401 { 405 {
402 register char *p; 406 register char *p;
403 int in_ident = 0; 407 int in_ident = 0;
404 int just_spaced = 0; 408 int just_spaced = 0;
494 the corresponding .c file is read instead. 498 the corresponding .c file is read instead.
495 Looks for DEFUN constructs such as are defined in ../src/lisp.h. 499 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
496 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ 500 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
497 501
498 static int 502 static int
499 scan_c_file (CONST char *filename, CONST char *mode) 503 scan_c_file (const char *filename, const char *mode)
500 { 504 {
501 FILE *infile; 505 FILE *infile;
502 register int c; 506 register int c;
503 register int commas; 507 register int commas;
504 register int defunflag; 508 register int defunflag;
785 789
786 skip_white (infile); 790 skip_white (infile);
787 } 791 }
788 792
789 static int 793 static int
790 scan_lisp_file (CONST char *filename, CONST char *mode) 794 scan_lisp_file (const char *filename, const char *mode)
791 { 795 {
792 FILE *infile; 796 FILE *infile;
793 register int c; 797 register int c;
794 char *saved_string = 0; 798 char *saved_string = 0;
795 799