comparison lib-src/make-docfile.c @ 39897:3e6f2f2a0a62

(read_c_string_or_comment): Renamed from read_c_string. Add parameter COMMENT. Read C-style comments. (scan_c_file): Handle doc strings in C comments.
author Gerd Moellmann <gerd@gnu.org>
date Sat, 13 Oct 2001 20:41:25 +0000
parents 39b2af5f7ee2
children f169b10c8e00
comparison
equal deleted inserted replaced
39896:258ac90a4fed 39897:3e6f2f2a0a62
196 return scan_c_file (filename, READ_TEXT); 196 return scan_c_file (filename, READ_TEXT);
197 } 197 }
198 198
199 char buf[128]; 199 char buf[128];
200 200
201 /* Skip a C string from INFILE, 201 /* Skip a C string or C-style comment from INFILE, and return the
202 and return the character that follows the closing ". 202 character that follows. COMMENT non-zero means skip a comment. If
203 If printflag is positive, output string contents to outfile. 203 PRINTFLAG is positive, output string contents to outfile. If it is
204 If it is negative, store contents in buf. 204 negative, store contents in buf. Convert escape sequences \n and
205 Convert escape sequences \n and \t to newline and tab; 205 \t to newline and tab; discard \ followed by newline. */
206 discard \ followed by newline. */
207 206
208 int 207 int
209 read_c_string (infile, printflag) 208 read_c_string_or_comment (infile, printflag, comment)
210 FILE *infile; 209 FILE *infile;
211 int printflag; 210 int printflag;
212 { 211 {
213 register int c; 212 register int c;
214 char *p = buf; 213 char *p = buf;
215 214
216 c = getc (infile); 215 if (comment)
216 {
217 while ((c = getc (infile)) != EOF
218 && (c == '\n' || c == '\r' || c == '\t' || c == ' '))
219 ;
220 }
221 else
222 c = getc (infile);
223
217 while (c != EOF) 224 while (c != EOF)
218 { 225 {
219 while (c != '"' && c != EOF) 226 while (c != EOF && (comment ? c != '*' : c != '"'))
220 { 227 {
221 if (c == '\\') 228 if (c == '\\')
222 { 229 {
223 c = getc (infile); 230 c = getc (infile);
224 if (c == '\n' || c == '\r') 231 if (c == '\n' || c == '\r')
229 if (c == 'n') 236 if (c == 'n')
230 c = '\n'; 237 c = '\n';
231 if (c == 't') 238 if (c == 't')
232 c = '\t'; 239 c = '\t';
233 } 240 }
241
234 if (printflag > 0) 242 if (printflag > 0)
235 putc (c, outfile); 243 putc (c, outfile);
236 else if (printflag < 0) 244 else if (printflag < 0)
237 *p++ = c; 245 *p++ = c;
238 c = getc (infile); 246 c = getc (infile);
239 } 247 }
248
240 c = getc (infile); 249 c = getc (infile);
241 if (c != '"') 250
242 break; 251 if (comment)
243 /* If we had a "", concatenate the two strings. */ 252 {
244 c = getc (infile); 253 if (c == '/')
245 } 254 {
246 255 c = getc (infile);
256 break;
257 }
258 }
259 else
260 {
261 if (c != '"')
262 break;
263
264 /* If we had a "", concatenate the two strings. */
265 c = getc (infile);
266 }
267 }
268
247 if (printflag < 0) 269 if (printflag < 0)
248 *p = 0; 270 *p = 0;
249 271
250 return c; 272 return c;
251 } 273 }
274
275
252 276
253 /* Write to file OUT the argument names of function FUNC, whose text is in BUF. 277 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
254 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ 278 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
255 279
256 void 280 void
429 if (c < 0) 453 if (c < 0)
430 goto eof; 454 goto eof;
431 c = getc (infile); 455 c = getc (infile);
432 } 456 }
433 457
458 /* Lisp variable or function name. */
434 c = getc (infile); 459 c = getc (infile);
435 if (c != '"') 460 if (c != '"')
436 continue; 461 continue;
437 c = read_c_string (infile, -1); 462 c = read_c_string_or_comment (infile, -1, 0);
463
464 /* DEFVAR_LISP ("name", addr /\* doc *\/)
465 DEFVAR_LISP ("name", addr, doc) */
438 466
439 if (defunflag) 467 if (defunflag)
440 commas = 5; 468 commas = 5;
441 else if (defvarperbufferflag) 469 else if (defvarperbufferflag)
442 commas = 2; 470 commas = 2;
448 while (commas) 476 while (commas)
449 { 477 {
450 if (c == ',') 478 if (c == ',')
451 { 479 {
452 commas--; 480 commas--;
481
453 if (defunflag && (commas == 1 || commas == 2)) 482 if (defunflag && (commas == 1 || commas == 2))
454 { 483 {
455 do 484 do
456 c = getc (infile); 485 c = getc (infile);
457 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 486 while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
465 maxargs = -1; 494 maxargs = -1;
466 else 495 else
467 fscanf (infile, "%d", &maxargs); 496 fscanf (infile, "%d", &maxargs);
468 } 497 }
469 } 498 }
470 if (c < 0) 499
500 if (c == EOF)
471 goto eof; 501 goto eof;
472 c = getc (infile); 502 c = getc (infile);
473 } 503 }
504
474 while (c == ' ' || c == '\n' || c == '\r' || c == '\t') 505 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
475 c = getc (infile); 506 c = getc (infile);
507
476 if (c == '"') 508 if (c == '"')
477 c = read_c_string (infile, 0); 509 c = read_c_string_or_comment (infile, 0, 0);
478 while (c != ',') 510
511 while (c != EOF && c != ',' && c != '/')
479 c = getc (infile); 512 c = getc (infile);
480 c = getc (infile); 513 if (c == ',')
481 while (c == ' ' || c == '\n' || c == '\r' || c == '\t') 514 {
482 c = getc (infile); 515 c = getc (infile);
483 516 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
484 if (c == '"') 517 c = getc (infile);
485 { 518 }
519
520 if (c == '"'
521 || (c == '/'
522 && (c = getc (infile),
523 ungetc (c, infile),
524 c == '*')))
525 {
526 int comment = c != '"';
527
486 putc (037, outfile); 528 putc (037, outfile);
487 putc (defvarflag ? 'V' : 'F', outfile); 529 putc (defvarflag ? 'V' : 'F', outfile);
488 fprintf (outfile, "%s\n", buf); 530 fprintf (outfile, "%s\n", buf);
489 c = read_c_string (infile, 1); 531
532 if (comment)
533 getc (infile); /* Skip past `*' */
534 c = read_c_string_or_comment (infile, 1, comment);
490 535
491 /* If this is a defun, find the arguments and print them. If 536 /* If this is a defun, find the arguments and print them. If
492 this function takes MANY or UNEVALLED args, then the C source 537 this function takes MANY or UNEVALLED args, then the C source
493 won't give the names of the arguments, so we shouldn't bother 538 won't give the names of the arguments, so we shouldn't bother
494 trying to find them. */ 539 trying to find them.
540
541 Old: DEFUN (..., "DOC") (args)
542 New: DEFUN (..., /\* DOC *\/ (args)) */
495 if (defunflag && maxargs != -1) 543 if (defunflag && maxargs != -1)
496 { 544 {
497 char argbuf[1024], *p = argbuf; 545 char argbuf[1024], *p = argbuf;
498 while (c != ')') 546
499 { 547 if (!comment)
500 if (c < 0) 548 while (c != ')')
501 goto eof; 549 {
502 c = getc (infile); 550 if (c < 0)
503 } 551 goto eof;
552 c = getc (infile);
553 }
554
504 /* Skip into arguments. */ 555 /* Skip into arguments. */
505 while (c != '(') 556 while (c != '(')
506 { 557 {
507 if (c < 0) 558 if (c < 0)
508 goto eof; 559 goto eof;
907 { 958 {
908 fprintf (stderr, "## autoload of %s unparsable (%s)\n", 959 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
909 buffer, filename); 960 buffer, filename);
910 continue; 961 continue;
911 } 962 }
912 read_c_string (infile, 0); 963 read_c_string_or_comment (infile, 0, 0);
913 skip_white (infile); 964 skip_white (infile);
914 965
915 if (saved_string == 0) 966 if (saved_string == 0)
916 { 967 {
917 /* If the next three characters aren't `dquote bslash newline' 968 /* If the next three characters aren't `dquote bslash newline'
960 /* Don't use one dynamic doc string twice. */ 1011 /* Don't use one dynamic doc string twice. */
961 free (saved_string); 1012 free (saved_string);
962 saved_string = 0; 1013 saved_string = 0;
963 } 1014 }
964 else 1015 else
965 read_c_string (infile, 1); 1016 read_c_string_or_comment (infile, 1, 0);
966 } 1017 }
967 fclose (infile); 1018 fclose (infile);
968 return 0; 1019 return 0;
969 } 1020 }