comparison src/variables.cc @ 2487:8c6e9535cbda

[project @ 1996-11-08 15:58:52 by jwe]
author jwe
date Fri, 08 Nov 1996 15:58:53 +0000
parents b8c53143581b
children 06595bc7f2d0
comparison
equal deleted inserted replaced
2486:830038ee04aa 2487:8c6e9535cbda
450 } 450 }
451 451
452 // Eat whitespace and comments from FFILE, returning the text of the 452 // Eat whitespace and comments from FFILE, returning the text of the
453 // comments read if it doesn't look like a copyright notice. If 453 // comments read if it doesn't look like a copyright notice. If
454 // IN_PARTS, consider each block of comments separately; otherwise, 454 // IN_PARTS, consider each block of comments separately; otherwise,
455 // grab them all at once. 455 // grab them all at once. If UPDATE_POS is TRUE, line and column
456 // number information is updated.
456 457
457 // XXX FIXME XXX -- grab_help_text() in lex.l duplicates some of this 458 // XXX FIXME XXX -- grab_help_text() in lex.l duplicates some of this
458 // code! 459 // code!
459 460
460 static string 461 static string
461 gobble_leading_white_space (FILE *ffile, bool in_parts) 462 gobble_leading_white_space (FILE *ffile, bool in_parts, bool update_pos)
462 { 463 {
463 string help_txt; 464 string help_txt;
464 465
465 bool first_comments_seen = false; 466 bool first_comments_seen = false;
466 bool begin_comment = false; 467 bool begin_comment = false;
468 bool in_comment = false; 469 bool in_comment = false;
469 int c; 470 int c;
470 471
471 while ((c = getc (ffile)) != EOF) 472 while ((c = getc (ffile)) != EOF)
472 { 473 {
473 current_input_column++; 474 if (update_pos)
475 current_input_column++;
474 476
475 if (begin_comment) 477 if (begin_comment)
476 { 478 {
477 if (c == '%' || c == '#') 479 if (c == '%' || c == '#')
478 continue; 480 continue;
488 help_txt += (char) c; 490 help_txt += (char) c;
489 } 491 }
490 492
491 if (c == '\n') 493 if (c == '\n')
492 { 494 {
493 input_line_number++; 495 if (update_pos)
494 current_input_column = 0; 496 {
497 input_line_number++;
498 current_input_column = 0;
499 }
495 in_comment = false; 500 in_comment = false;
496 501
497 if (in_parts) 502 if (in_parts)
498 { 503 {
499 if ((c = getc (ffile)) != EOF) 504 if ((c = getc (ffile)) != EOF)
500 { 505 {
501 current_input_column--; 506 if (update_pos)
507 current_input_column--;
502 ungetc (c, ffile); 508 ungetc (c, ffile);
503 if (c == '\n') 509 if (c == '\n')
504 break; 510 break;
505 } 511 }
506 else 512 else
519 break; 525 break;
520 526
521 case '\n': 527 case '\n':
522 if (first_comments_seen) 528 if (first_comments_seen)
523 have_help_text = true; 529 have_help_text = true;
524 input_line_number++; 530 if (update_pos)
525 current_input_column = 0; 531 {
532 input_line_number++;
533 current_input_column = 0;
534 }
526 continue; 535 continue;
527 536
528 case '%': 537 case '%':
529 case '#': 538 case '#':
530 begin_comment = true; 539 begin_comment = true;
531 in_comment = true; 540 in_comment = true;
532 break; 541 break;
533 542
534 default: 543 default:
535 current_input_column--; 544 if (update_pos)
545 current_input_column--;
536 ungetc (c, ffile); 546 ungetc (c, ffile);
537 goto done; 547 goto done;
538 } 548 }
539 } 549 }
540 } 550 }
545 { 555 {
546 if (looks_like_octave_copyright (help_txt)) 556 if (looks_like_octave_copyright (help_txt))
547 help_txt.resize (0); 557 help_txt.resize (0);
548 558
549 if (in_parts && help_txt.empty ()) 559 if (in_parts && help_txt.empty ())
550 help_txt = gobble_leading_white_space (ffile, in_parts); 560 help_txt = gobble_leading_white_space (ffile, in_parts, update_pos);
551 } 561 }
552 562
553 return help_txt; 563 return help_txt;
554 } 564 }
555 565
558 { 568 {
559 int status = 0; 569 int status = 0;
560 570
561 long pos = ftell (ffile); 571 long pos = ftell (ffile);
562 572
563 gobble_leading_white_space (ffile, false); 573 gobble_leading_white_space (ffile, false, false);
564 574
565 char buf [10]; 575 char buf [10];
566 fgets (buf, 10, ffile); 576 fgets (buf, 10, ffile);
567 int len = strlen (buf); 577 int len = strlen (buf);
568 if (len > 8 && strncmp (buf, "function", 8) == 0 578 if (len > 8 && strncmp (buf, "function", 8) == 0
640 650
641 unwind_protect_ptr (curr_sym_tab); 651 unwind_protect_ptr (curr_sym_tab);
642 652
643 reset_parser (); 653 reset_parser ();
644 654
645 help_buf = gobble_leading_white_space (ffile, true); 655 help_buf = gobble_leading_white_space (ffile, true, true);
646 656
647 // XXX FIXME XXX -- this should not be necessary. 657 // XXX FIXME XXX -- this should not be necessary.
648 gobble_leading_white_space (ffile, false); 658 gobble_leading_white_space (ffile, false, true);
649 659
650 int status = yyparse (); 660 int status = yyparse ();
651 661
652 if (status != 0) 662 if (status != 0)
653 { 663 {
775 { 785 {
776 FILE *fptr = fopen (path.c_str (), "r"); 786 FILE *fptr = fopen (path.c_str (), "r");
777 787
778 if (fptr) 788 if (fptr)
779 { 789 {
780 retval = gobble_leading_white_space (fptr, true); 790 retval = gobble_leading_white_space (fptr, true, true);
781 fclose (fptr); 791 fclose (fptr);
782 } 792 }
783 } 793 }
784 794
785 return retval; 795 return retval;