Unified · Split
| @@ -613,23 +613,32 @@ void sym_pop(SymStack *st, Sym *b) · 612 unmodified lines | ||
| 613 | 613 | st->top = b; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | +/* no need to put that inline */ | |
| 617 | +int handle_eof(void) | |
| 618 | +{ | |
| 619 | + if (include_stack_ptr == include_stack) | |
| 620 | + return -1; | |
| 621 | + /* pop include stack */ | |
| 622 | + fclose(file); | |
| 623 | + free(filename); | |
| 624 | + include_stack_ptr--; | |
| 625 | + file = include_stack_ptr->file; | |
| 626 | + filename = include_stack_ptr->filename; | |
| 627 | + line_num = include_stack_ptr->line_num; | |
| 628 | + return 0; | |
| 629 | +} | |
| 630 | + | |
| 616 | 631 | /* read next char from current input file */ |
| 617 | −void inp(void) | |
| 632 | +static inline void inp(void) | |
| 618 | 633 | { |
| 619 | 634 | redo: |
| 620 | 635 | /* faster than fgetc */ |
| 621 | 636 | ch1 = getc_unlocked(file); |
| 622 | 637 | if (ch1 == -1) { |
| 623 | − if (include_stack_ptr == include_stack) | |
| 638 | + if (handle_eof() < 0) | |
| 624 | 639 | return; |
| 625 | − /* pop include stack */ | |
| 626 | − fclose(file); | |
| 627 | − free(filename); | |
| 628 | − include_stack_ptr--; | |
| 629 | − file = include_stack_ptr->file; | |
| 630 | − filename = include_stack_ptr->filename; | |
| 631 | − line_num = include_stack_ptr->line_num; | |
| 632 | − goto redo; | |
| 640 | + else | |
| 641 | + goto redo; | |
| 633 | 642 | } |
| 634 | 643 | if (ch1 == '\n') |
| 635 | 644 | line_num++; |
| @@ -637,9 +646,9 @@ void inp(void) · 1 unmodified line | ||
| 637 | 646 | } |
| 638 | 647 | |
| 639 | 648 | /* input with '\\n' handling */ |
| 640 | −void minp() | |
| 649 | +static inline void minp(void) | |
| 641 | 650 | { |
| 642 | − redo: | |
| 651 | + redo: | |
| 643 | 652 | ch = ch1; |
| 644 | 653 | inp(); |
| 645 | 654 | if (ch == '\\' && ch1 == '\n') { |
| @@ -649,8 +658,9 @@ void minp() · 3 unmodified lines | ||
| 649 | 658 | //printf("ch=%c 0x%x\n", ch, ch); |
| 650 | 659 | } |
| 651 | 660 | |
| 661 | + | |
| 652 | 662 | /* same as minp, but also skip comments */ |
| 653 | −void cinp() | |
| 663 | +void cinp(void) | |
| 654 | 664 | { |
| 655 | 665 | int c; |
| 656 | 666 | |
| @@ -669,11 +679,11 @@ void cinp() · 12 unmodified lines | ||
| 669 | 679 | while (ch1 != -1) { |
| 670 | 680 | c = ch1; |
| 671 | 681 | inp(); |
| 672 | − if (c == '*' && ch1 == '/') { | |
| 673 | − inp(); | |
| 674 | − ch = ' '; /* return space */ | |
| 675 | − break; | |
| 676 | − } | |
| 682 | + if (c == '*' && ch1 == '/') { | |
| 683 | + inp(); | |
| 684 | + ch = ' '; /* return space */ | |
| 685 | + break; | |
| 686 | + } | |
| 677 | 687 | } |
| 678 | 688 | } else { |
| 679 | 689 | ch = '/'; |
| @@ -683,7 +693,7 @@ void cinp() · 3 unmodified lines | ||
| 683 | 693 | } |
| 684 | 694 | } |
| 685 | 695 | |
| 686 | −void skip_spaces() | |
| 696 | +void skip_spaces(void) | |
| 687 | 697 | { |
| 688 | 698 | while (ch == ' ' || ch == '\t') |
| 689 | 699 | cinp(); |