Changeset 2bf04b in git for old_modgen
- Timestamp:
- Nov 12, 2015, 2:39:46 PM (8 years ago)
- Branches:
- (u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
- Children:
- 6da2d6765f8866f8426131bf3a097a5c051e956e
- Parents:
- 412c61b77c65fd4adca8f6576d7f1a597459552e
- Location:
- old_modgen/modgen
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
old_modgen/modgen/getopt.c
r412c61 r2bf04b 4 4 before changing it! 5 5 Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 6 6 Free Software Foundation, Inc. 7 7 This file is part of the GNU C Library. 8 8 … … 66 66 /* This needs to come after some library #include 67 67 to get __GNU_LIBRARY__ defined. */ 68 #ifdef 68 #ifdef __GNU_LIBRARY__ 69 69 /* Don't include stdlib.h for non-GNU C libraries because some of them 70 70 contain conflicting prototypes for getopt. */ 71 71 # include <stdlib.h> 72 72 # include <unistd.h> 73 #endif 73 #endif /* GNU C library. */ 74 74 75 75 #ifdef VMS … … 85 85 # include <libintl.h> 86 86 # ifndef _ 87 # define _(msgid) 87 # define _(msgid) gettext (msgid) 88 88 # endif 89 89 # else 90 # define _(msgid) 90 # define _(msgid) (msgid) 91 91 # endif 92 92 #endif … … 195 195 196 196 197 #ifdef 197 #ifdef __GNU_LIBRARY__ 198 198 /* We want to avoid inclusion of string.h with non-GNU libraries 199 199 because there are many ways it can cause trouble. … … 201 201 in GCC. */ 202 202 # include <string.h> 203 # define my_index 203 # define my_index strchr 204 204 #else 205 205 … … 225 225 { 226 226 if (*str == chr) 227 227 return (char *) str; 228 228 str++; 229 229 } … … 275 275 # ifdef USE_NONOPTION_FLAGS 276 276 # define SWAP_FLAGS(ch1, ch2) \ 277 if (nonoption_flags_len > 0) 278 { 279 char __tmp = __getopt_nonoption_flags[ch1]; 280 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; 281 __getopt_nonoption_flags[ch2] = __tmp; 277 if (nonoption_flags_len > 0) \ 278 { \ 279 char __tmp = __getopt_nonoption_flags[ch1]; \ 280 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ 281 __getopt_nonoption_flags[ch2] = __tmp; \ 282 282 } 283 283 # else 284 284 # define SWAP_FLAGS(ch1, ch2) 285 285 # endif 286 #else 286 #else /* !_LIBC */ 287 287 # define SWAP_FLAGS(ch1, ch2) 288 #endif 288 #endif /* _LIBC */ 289 289 290 290 /* Exchange two adjacent subsequences of ARGV. … … 322 322 { 323 323 /* We must extend the array. The user plays games with us and 324 324 presents new arguments. */ 325 325 char *new_str = malloc (top + 1); 326 326 if (new_str == NULL) 327 327 nonoption_flags_len = nonoption_flags_max_len = 0; 328 328 else 329 330 331 332 333 334 335 329 { 330 memset (__mempcpy (new_str, __getopt_nonoption_flags, 331 nonoption_flags_max_len), 332 '\0', top + 1 - nonoption_flags_max_len); 333 nonoption_flags_max_len = top + 1; 334 __getopt_nonoption_flags = new_str; 335 } 336 336 } 337 337 #endif … … 340 340 { 341 341 if (top - middle > middle - bottom) 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 342 { 343 /* Bottom segment is the short one. */ 344 int len = middle - bottom; 345 register int i; 346 347 /* Swap it with the top part of the top segment. */ 348 for (i = 0; i < len; i++) 349 { 350 tem = argv[bottom + i]; 351 argv[bottom + i] = argv[top - (middle - bottom) + i]; 352 argv[top - (middle - bottom) + i] = tem; 353 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 354 } 355 /* Exclude the moved bottom segment from further swapping. */ 356 top -= len; 357 } 358 358 else 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 359 { 360 /* Top segment is the short one. */ 361 int len = top - middle; 362 register int i; 363 364 /* Swap it with the bottom part of the bottom segment. */ 365 for (i = 0; i < len; i++) 366 { 367 tem = argv[bottom + i]; 368 argv[bottom + i] = argv[middle + i]; 369 argv[middle + i] = tem; 370 SWAP_FLAGS (bottom + i, middle + i); 371 } 372 /* Exclude the moved top segment from further swapping. */ 373 bottom += len; 374 } 375 375 } 376 376 … … 424 424 { 425 425 if (nonoption_flags_max_len == 0) 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 426 { 427 if (__getopt_nonoption_flags == NULL 428 || __getopt_nonoption_flags[0] == '\0') 429 nonoption_flags_max_len = -1; 430 else 431 { 432 const char *orig_str = __getopt_nonoption_flags; 433 int len = nonoption_flags_max_len = strlen (orig_str); 434 if (nonoption_flags_max_len < argc) 435 nonoption_flags_max_len = argc; 436 __getopt_nonoption_flags = 437 (char *) malloc (nonoption_flags_max_len); 438 if (__getopt_nonoption_flags == NULL) 439 nonoption_flags_max_len = -1; 440 else 441 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), 442 '\0', nonoption_flags_max_len - len); 443 } 444 } 445 445 nonoption_flags_len = nonoption_flags_max_len; 446 446 } … … 530 530 { 531 531 if (optind == 0) 532 optind = 1;/* Don't scan ARGV[0], the program name. */532 optind = 1; /* Don't scan ARGV[0], the program name. */ 533 533 optstring = _getopt_initialize (argc, argv, optstring); 534 534 __getopt_initialized = 1; … … 540 540 is only used when the used in the GNU libc. */ 541 541 #if defined _LIBC && defined USE_NONOPTION_FLAGS 542 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' 543 || (optind < nonoption_flags_len\544 542 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ 543 || (optind < nonoption_flags_len \ 544 && __getopt_nonoption_flags[optind] == '1')) 545 545 #else 546 546 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') … … 552 552 553 553 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 554 554 moved back by the user (who may also have changed the arguments). */ 555 555 if (last_nonopt > optind) 556 556 last_nonopt = optind; 557 557 if (first_nonopt > optind) 558 558 first_nonopt = optind; 559 559 560 560 if (ordering == PERMUTE) 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 561 { 562 /* If we have just processed some options following some non-options, 563 exchange them so that the options come first. */ 564 565 if (first_nonopt != last_nonopt && last_nonopt != optind) 566 exchange ((char **) argv); 567 else if (last_nonopt != optind) 568 first_nonopt = optind; 569 570 /* Skip any additional non-options 571 and extend the range of non-options previously skipped. */ 572 573 while (optind < argc && NONOPTION_P) 574 optind++; 575 last_nonopt = optind; 576 } 577 577 578 578 /* The special ARGV-element `--' means premature end of options. 579 580 581 579 Skip it like a null option, 580 then exchange with previous non-options as if it were an option, 581 then skip everything else like a non-option. */ 582 582 583 583 if (optind != argc && !strcmp (argv[optind], "--")) 584 585 586 587 588 589 590 591 592 593 594 584 { 585 optind++; 586 587 if (first_nonopt != last_nonopt && last_nonopt != optind) 588 exchange ((char **) argv); 589 else if (first_nonopt == last_nonopt) 590 first_nonopt = optind; 591 last_nonopt = argc; 592 593 optind = argc; 594 } 595 595 596 596 /* If we have done all the ARGV-elements, stop the scan 597 597 and back over any non-options that we skipped and permuted. */ 598 598 599 599 if (optind == argc) 600 601 602 603 604 605 606 600 { 601 /* Set the next-arg-index to point at the non-options 602 that we previously skipped, so the caller will digest them. */ 603 if (first_nonopt != last_nonopt) 604 optind = first_nonopt; 605 return -1; 606 } 607 607 608 608 /* If we have come to a non-option and did not permute it, 609 609 either stop the scan or describe it to the caller and pass it by. */ 610 610 611 611 if (NONOPTION_P) 612 613 614 615 616 617 612 { 613 if (ordering == REQUIRE_ORDER) 614 return -1; 615 optarg = argv[optind++]; 616 return 1; 617 } 618 618 619 619 /* We have found another option-ARGV-element. 620 620 Skip the initial punctuation. */ 621 621 622 622 nextchar = (argv[optind] + 1 623 623 + (longopts != NULL && argv[optind][1] == '-')); 624 624 } 625 625 … … 641 641 if (longopts != NULL 642 642 && (argv[optind][1] == '-' 643 643 || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) 644 644 { 645 645 char *nameend; … … 652 652 653 653 for (nameend = nextchar; *nameend && *nameend != '='; nameend++) 654 654 /* Do nothing. */ ; 655 655 656 656 /* Test all long options for either exact match 657 657 or abbreviated matches. */ 658 658 for (p = longopts, option_index = 0; p->name; p++, option_index++) 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 659 if (!strncmp (p->name, nextchar, nameend - nextchar)) 660 { 661 if ((unsigned int) (nameend - nextchar) 662 == (unsigned int) strlen (p->name)) 663 { 664 /* Exact match found. */ 665 pfound = p; 666 indfound = option_index; 667 exact = 1; 668 break; 669 } 670 else if (pfound == NULL) 671 { 672 /* First nonexact match found. */ 673 pfound = p; 674 indfound = option_index; 675 } 676 else if (long_only 677 || pfound->has_arg != p->has_arg 678 || pfound->flag != p->flag 679 || pfound->val != p->val) 680 /* Second or later nonexact match found. */ 681 ambig = 1; 682 } 683 683 684 684 if (ambig && !exact) 685 686 687 688 689 690 691 692 693 685 { 686 if (print_errors) 687 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 688 argv[0], argv[optind]); 689 nextchar += strlen (nextchar); 690 optind++; 691 optopt = 0; 692 return '?'; 693 } 694 694 695 695 if (pfound != NULL) 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 696 { 697 option_index = indfound; 698 optind++; 699 if (*nameend) 700 { 701 /* Don't test has_arg with >, because some C compilers don't 702 allow it to be used on enums. */ 703 if (pfound->has_arg) 704 optarg = nameend + 1; 705 else 706 { 707 if (print_errors) 708 { 709 if (argv[optind - 1][1] == '-') 710 /* --option */ 711 fprintf (stderr, 712 _("%s: option `--%s' doesn't allow an argument\n"), 713 argv[0], pfound->name); 714 else 715 /* +option or -option */ 716 fprintf (stderr, 717 _("%s: option `%c%s' doesn't allow an argument\n"), 718 argv[0], argv[optind - 1][0], pfound->name); 719 } 720 721 nextchar += strlen (nextchar); 722 723 optopt = pfound->val; 724 return '?'; 725 } 726 } 727 else if (pfound->has_arg == 1) 728 { 729 if (optind < argc) 730 optarg = argv[optind++]; 731 else 732 { 733 if (print_errors) 734 fprintf (stderr, 735 _("%s: option `%s' requires an argument\n"), 736 argv[0], argv[optind - 1]); 737 nextchar += strlen (nextchar); 738 optopt = pfound->val; 739 return optstring[0] == ':' ? ':' : '?'; 740 } 741 } 742 nextchar += strlen (nextchar); 743 if (longind != NULL) 744 *longind = option_index; 745 if (pfound->flag) 746 { 747 *(pfound->flag) = pfound->val; 748 return 0; 749 } 750 return pfound->val; 751 } 752 752 753 753 /* Can't find it as a long option. If this is not getopt_long_only, 754 755 756 754 or the option starts with '--' or is not a valid short 755 option, then it's an error. 756 Otherwise interpret it as a short option. */ 757 757 if (!long_only || argv[optind][1] == '-' 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 758 || my_index (optstring, *nextchar) == NULL) 759 { 760 if (print_errors) 761 { 762 if (argv[optind][1] == '-') 763 /* --option */ 764 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 765 argv[0], nextchar); 766 else 767 /* +option or -option */ 768 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 769 argv[0], argv[optind][0], nextchar); 770 } 771 nextchar = (char *) ""; 772 optind++; 773 optopt = 0; 774 return '?'; 775 } 776 776 } 777 777 … … 788 788 if (temp == NULL || c == ':') 789 789 { 790 791 792 793 794 795 796 797 798 799 800 801 790 if (print_errors) 791 { 792 if (posixly_correct) 793 /* 1003.2 specifies the format of this message. */ 794 fprintf (stderr, _("%s: illegal option -- %c\n"), 795 argv[0], c); 796 else 797 fprintf (stderr, _("%s: invalid option -- %c\n"), 798 argv[0], c); 799 } 800 optopt = c; 801 return '?'; 802 802 } 803 803 /* Convenience. Treat POSIX -W foo same as long option --foo */ 804 804 if (temp[0] == 'W' && temp[1] == ';') 805 805 { 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 806 char *nameend; 807 const struct option *p; 808 const struct option *pfound = NULL; 809 int exact = 0; 810 int ambig = 0; 811 int indfound = 0; 812 int option_index; 813 814 /* This is an option that requires an argument. */ 815 if (*nextchar != '\0') 816 { 817 optarg = nextchar; 818 /* If we end this ARGV-element by taking the rest as an arg, 819 we must advance to the next element now. */ 820 optind++; 821 } 822 else if (optind == argc) 823 { 824 if (print_errors) 825 { 826 /* 1003.2 specifies the format of this message. */ 827 fprintf (stderr, _("%s: option requires an argument -- %c\n"), 828 argv[0], c); 829 } 830 optopt = c; 831 if (optstring[0] == ':') 832 c = ':'; 833 else 834 c = '?'; 835 return c; 836 } 837 else 838 /* We already incremented `optind' once; 839 increment it again when taking next ARGV-elt as argument. */ 840 optarg = argv[optind++]; 841 842 /* optarg is now the argument, see if it's in the 843 table of longopts. */ 844 845 for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) 846 /* Do nothing. */ ; 847 848 /* Test all long options for either exact match 849 or abbreviated matches. */ 850 for (p = longopts, option_index = 0; p->name; p++, option_index++) 851 if (!strncmp (p->name, nextchar, nameend - nextchar)) 852 { 853 if ((unsigned int) (nameend - nextchar) == strlen (p->name)) 854 { 855 /* Exact match found. */ 856 pfound = p; 857 indfound = option_index; 858 exact = 1; 859 break; 860 } 861 else if (pfound == NULL) 862 { 863 /* First nonexact match found. */ 864 pfound = p; 865 indfound = option_index; 866 } 867 else 868 /* Second or later nonexact match found. */ 869 ambig = 1; 870 } 871 if (ambig && !exact) 872 { 873 if (print_errors) 874 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 875 argv[0], argv[optind]); 876 nextchar += strlen (nextchar); 877 optind++; 878 return '?'; 879 } 880 if (pfound != NULL) 881 { 882 option_index = indfound; 883 if (*nameend) 884 { 885 /* Don't test has_arg with >, because some C compilers don't 886 allow it to be used on enums. */ 887 if (pfound->has_arg) 888 optarg = nameend + 1; 889 else 890 { 891 if (print_errors) 892 fprintf (stderr, _("\ 893 893 %s: option `-W %s' doesn't allow an argument\n"), 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 return 'W';/* Let the application handle it. */894 argv[0], pfound->name); 895 896 nextchar += strlen (nextchar); 897 return '?'; 898 } 899 } 900 else if (pfound->has_arg == 1) 901 { 902 if (optind < argc) 903 optarg = argv[optind++]; 904 else 905 { 906 if (print_errors) 907 fprintf (stderr, 908 _("%s: option `%s' requires an argument\n"), 909 argv[0], argv[optind - 1]); 910 nextchar += strlen (nextchar); 911 return optstring[0] == ':' ? ':' : '?'; 912 } 913 } 914 nextchar += strlen (nextchar); 915 if (longind != NULL) 916 *longind = option_index; 917 if (pfound->flag) 918 { 919 *(pfound->flag) = pfound->val; 920 return 0; 921 } 922 return pfound->val; 923 } 924 nextchar = NULL; 925 return 'W'; /* Let the application handle it. */ 926 926 } 927 927 if (temp[1] == ':') 928 928 { 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 929 if (temp[2] == ':') 930 { 931 /* This is an option that accepts an argument optionally. */ 932 if (*nextchar != '\0') 933 { 934 optarg = nextchar; 935 optind++; 936 } 937 else 938 optarg = NULL; 939 nextchar = NULL; 940 } 941 else 942 { 943 /* This is an option that requires an argument. */ 944 if (*nextchar != '\0') 945 { 946 optarg = nextchar; 947 /* If we end this ARGV-element by taking the rest as an arg, 948 we must advance to the next element now. */ 949 optind++; 950 } 951 else if (optind == argc) 952 { 953 if (print_errors) 954 { 955 /* 1003.2 specifies the format of this message. */ 956 fprintf (stderr, 957 _("%s: option requires an argument -- %c\n"), 958 argv[0], c); 959 } 960 optopt = c; 961 if (optstring[0] == ':') 962 c = ':'; 963 else 964 c = '?'; 965 } 966 else 967 /* We already incremented `optind' once; 968 increment it again when taking next ARGV-elt as argument. */ 969 optarg = argv[optind++]; 970 nextchar = NULL; 971 } 972 972 } 973 973 return c; … … 982 982 { 983 983 return _getopt_internal (argc, argv, optstring, 984 985 986 984 (const struct option *) 0, 985 (int *) 0, 986 0); 987 987 } 988 988 989 #endif 989 #endif /* Not ELIDE_CODE. */ 990 990 991 991 … … 1009 1009 c = getopt (argc, argv, "abc:d:0123456789"); 1010 1010 if (c == -1) 1011 1011 break; 1012 1012 1013 1013 switch (c) 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1014 { 1015 case '0': 1016 case '1': 1017 case '2': 1018 case '3': 1019 case '4': 1020 case '5': 1021 case '6': 1022 case '7': 1023 case '8': 1024 case '9': 1025 if (digit_optind != 0 && digit_optind != this_option_optind) 1026 printf ("digits occur in two different argv-elements.\n"); 1027 digit_optind = this_option_optind; 1028 printf ("option %c\n", c); 1029 break; 1030 1031 case 'a': 1032 printf ("option a\n"); 1033 break; 1034 1035 case 'b': 1036 printf ("option b\n"); 1037 break; 1038 1039 case 'c': 1040 printf ("option c with value `%s'\n", optarg); 1041 break; 1042 1043 case '?': 1044 break; 1045 1046 default: 1047 printf ("?? getopt returned character code 0%o ??\n", c); 1048 } 1049 1049 } 1050 1050 … … 1053 1053 printf ("non-option ARGV-elements: "); 1054 1054 while (optind < argc) 1055 1055 printf ("%s ", argv[optind++]); 1056 1056 printf ("\n"); 1057 1057 } -
old_modgen/modgen/main.cc
r412c61 r2bf04b 117 117 break; 118 118 default: 119 120 119 printf("\t-%c (--%s) %s\n", long_options[i].val, 120 long_options[i].name, "<argument>"); 121 121 } 122 122 } else … … 147 147 case 'v' : trace=1; break; 148 148 case 'm' : do_create_makefile = 0; break; 149 150 149 case 'i' : inst_dir=optarg; break; 150 case 's' : do_create_srcdir = 0; break; 151 151 152 152 case '?' : usage(argv[0]); -
old_modgen/modgen/mod_grammar.y
r412c61 r2bf04b 141 141 fprintf(module_def.fmtfp, "%s", $1); 142 142 fprintf(module_def.fmtfp, "#line %d \"%s\"\n", 143 143 yylineno, module_def.filename); 144 144 free($1); 145 145 write_mod_init(&module_def, module_def.fmtfp); 146 146 initdone = 1; 147 147 }; 148 148 … … 154 154 sect1end: 155 155 codeline2 SECTEND 156 {157 memset(&procedure_decl, 0, sizeof(procdef));158 if(debug>2)printf("End of section 1 (new=%d)\n", sectnum);159 }160 | SECTEND161 156 { 162 157 memset(&procedure_decl, 0, sizeof(procdef)); 163 158 if(debug>2)printf("End of section 1 (new=%d)\n", sectnum); 164 159 } 160 | SECTEND 161 { 162 memset(&procedure_decl, 0, sizeof(procdef)); 163 if(debug>2)printf("End of section 1 (new=%d)\n", sectnum); 164 } 165 165 ; 166 166 167 167 codeline2: CODEPART 168 168 { 169 170 171 172 } 173 174 169 if(initdone == 0) { 170 write_mod_init(&module_def, module_def.fmtfp); 171 initdone = 1; 172 } 173 fprintf(module_def.fmtfp, "#line %d \"%s\"\n", 174 yylineno, module_def.filename); 175 175 fprintf(module_def.fmtfp, "%s", $1); 176 176 } … … 195 195 if(vt==VAR_VERSION) 196 196 make_version($3.string, &module_def); 197 198 197 if(vt==VAR_MODULE) 198 make_module_name($3.string, &module_def); 199 199 } 200 200 else { … … 349 349 if(debug>2)printf("SG-PROCDEF:\n"); 350 350 write_singular_end(&module_def, &procedure_decl, yylineno); 351 352 351 setup_proc(&module_def, &procedure_decl); 352 write_helpfile_help(&module_def, &procedure_decl); 353 353 } 354 354 | procdeclsg proccode procdeclexample … … 358 358 write_singular_end(&module_def, &procedure_decl, yylineno); 359 359 setup_proc(&module_def, &procedure_decl); 360 360 write_helpfile_help(&module_def, &procedure_decl); 361 361 } 362 362 ; … … 403 403 { 404 404 if(debug>2)printf("PROCDEF:\n"); 405 405 write_helpfile_help(&module_def, &procedure_decl); 406 406 } 407 407 | procdecl proccode procdeclexample 408 408 { 409 409 if(debug>2)printf("PROCDEF mit example:\n"); 410 410 write_helpfile_help(&module_def, &procedure_decl); 411 411 fflush(module_def.fmtfp); 412 412 } … … 717 717 { 718 718 fprintf(module_def.modfp, "#line %d \"%s\"\n", 719 719 yylineno, module_def.filename); 720 720 fprintf(module_def.modfp, "%s", $1); 721 721 } 722 722 | codeline CODEPART 723 723 { 724 724 fprintf(module_def.modfp, "%s", $2); 725 725 } 726 726 ; -
old_modgen/modgen/my_getopt.h
r412c61 r2bf04b 35 35 #endif 36 36 37 #ifdef 37 #ifdef __cplusplus 38 38 extern "C" { 39 39 #endif … … 77 77 78 78 The field `has_arg' is: 79 no_argument 80 required_argument 81 optional_argument 79 no_argument (or 0) if the option does not take an argument, 80 required_argument (or 1) if the option requires an argument, 81 optional_argument (or 2) if the option takes an optional argument. 82 82 83 83 If the field `flag' is not NULL, it points to a variable that is set … … 108 108 /* Names for the values of the `has_arg' field of `struct option'. */ 109 109 110 # define no_argument 111 # define required_argument 112 # define optional_argument 113 #endif 110 # define no_argument 0 111 # define required_argument 1 112 # define optional_argument 2 113 #endif /* need getopt */ 114 114 115 115 … … 149 149 # ifndef __need_getopt 150 150 extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 151 151 const struct option *__longopts, int *__longind); 152 152 extern int getopt_long_only (int __argc, char *const *__argv, 153 154 153 const char *__shortopts, 154 const struct option *__longopts, int *__longind); 155 155 156 156 /* Internal only. Users should not call this directly. */ 157 157 extern int _getopt_internal (int __argc, char *const *__argv, 158 159 160 158 const char *__shortopts, 159 const struct option *__longopts, int *__longind, 160 int __long_only); 161 161 # endif 162 162 #else /* not __STDC__ */ … … 170 170 #endif /* __STDC__ */ 171 171 172 #ifdef 172 #ifdef __cplusplus 173 173 } 174 174 #endif -
old_modgen/modgen/scanner.l
r412c61 r2bf04b 153 153 <COMMENT,COMMENTB,STRING,INITIAL><<EOF>> { 154 154 printf( "EOF encountered inside an action\n"); 155 155 printf("ERRRRROOOOORRR\n"); 156 156 } 157 157 … … 224 224 ^"/*" push_state(YYSTATE, COMMENT, "COMMENT"); yymore(); 225 225 "//".*{NL} ++yylineno; ACTION_ECHO; 226 227 228 229 226 {BOOL} { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i); 227 else { 228 if(strcasecmp(yytext, "yes")==0) lvalp->i = 1; 229 else lvalp->i = 0; 230 230 } 231 231 return BOOLTOK; } 232 233 234 235 236 237 238 239 240 241 242 243 244 232 ^"%{".*{NL} { 233 yylineno++; 234 push_state(YYSTATE, CODEBLOCK, "CODEBLOCK"); 235 fprintf(module_def.fmtfp, "#line %d \"%s\"\n", 236 yylineno, module_def.filename); 237 } 238 ^"%modinitial".*{NL} { 239 yylineno++; 240 push_state(YYSTATE, MODINITIAL, "MODINITIAL"); 241 fprintf(module_def.fmtfp, "#line %d \"%s\"\n", 242 yylineno, module_def.filename); 243 } 244 {WS} /* discard */ 245 245 {NL} { yylineno++; } 246 246 … … 254 254 } 255 255 256 257 256 ^{NAME} { 257 lvalp->name = strdup(yytext); 258 258 return NAME; 259 259 } 260 261 260 {FILENAME} { 261 lvalp->name = strdup(yytext); 262 262 return FILENAME; 263 263 } 264 264 } 265 265 266 266 <CODEBLOCK>{ … … 269 269 270 270 yylineno++; 271 272 273 274 275 276 277 278 279 271 pop_state(); 272 s = t = lvalp->name = dupyytext(); 273 while (*yytext) 274 { 275 if (*yytext == '\\') yytext++; 276 *s++ = *yytext++; 277 } 278 if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0'; 279 return MCCODETOK; 280 280 } 281 281 {NL} { yylineno++; yymore(); } … … 284 284 <MODINITIAL>{ 285 285 ^"%endinitial".*{NL} { 286 287 286 yylineno++; 287 pop_state(); 288 288 } 289 289 .*{NL} { yylineno++; 290 291 290 lvalp->name = yytext; 291 return CODEPART; } 292 292 } 293 293 <STRING>{ … … 299 299 char * s, *t; 300 300 pop_state(); 301 301 if(do_return) { 302 302 s = t = lvalp->sv.string = dupyytext(); 303 303 while (*yytext) … … 306 306 *s++ = *yytext++; 307 307 } 308 309 310 308 *s++ = *yytext++; 309 do_return = 0; 310 return MSTRINGTOK; 311 311 } else { 312 312 do_return = 0; 313 313 yymore(); 314 314 } 315 316 315 } 316 } 317 317 318 318 <COMMENT>{ … … 321 321 {NL} { yylineno++; yymore(); } 322 322 . { yymore(); } 323 323 } 324 324 325 325 <SECT2>{ … … 333 333 brace2 = 0; /* ( */ 334 334 brace3 = 0; /* [ */ 335 336 335 push_state(YYSTATE, PROCDECL, "PROCDECL"); 336 return PROCDECLTOK; 337 337 } 338 338 example { 339 339 #if DEBUG > 1 340 340 printf(">>>EXAMPLE\n"); 341 341 #endif 342 342 brace1 = 0; /* { */ 343 343 brace2 = 0; /* ( */ 344 344 brace3 = 0; /* [ */ 345 346 347 } 348 345 push_state(YYSTATE, EXAMPLE, "EXAMPLE"); 346 return EXAMPLETOK; 347 } 348 static { return STATICTOK; } 349 349 . { printf("SG(%d) <<<'%s' ", yylineno, yytext); } 350 350 } … … 358 358 example { 359 359 #if DEBUG > 1 360 360 printf(">>>EXAMPLE\n"); 361 361 #endif 362 362 brace1 = 0; /* { */ 363 363 brace2 = 0; /* ( */ 364 364 brace3 = 0; /* [ */ 365 366 367 } 368 369 370 365 push_state(YYSTATE, EXAMPLE, "EXAMPLE"); 366 return EXAMPLETOK; 367 } 368 static { return STATICTOK; } 369 {NAME} { 370 int i,tok; 371 371 #if DEBUG > 1 372 373 #endif 374 372 printf("(%d) VAR: %s\n", yylineno, yytext); 373 #endif 374 i = IsCmd(yytext, tok); 375 375 #if DEBUG > 1 376 377 378 #endif 379 380 381 382 383 384 385 386 387 388 389 390 376 printf("Res=%d, %d => %s\n", i, tok, 377 i ? "VARTYPETOK" : "NAME"); 378 #endif 379 if(i) { 380 lvalp->tp.name = strdup(yytext); 381 lvalp->tp.typ = tok; 382 push_state(YYSTATE, PROCDECL, "PROCDECL"); 383 return VARTYPETOK; 384 } 385 else { 386 //do_return++; 387 lvalp->name = strdup(yytext); 388 push_state(YYSTATE, PROCDECL, "PROCDECL"); 389 return NAME; 390 } 391 391 } 392 392 . { printf("PR(%d) <<<'%s' ", yylineno, yytext); } … … 397 397 {WS} /* ignore */ 398 398 "{" { brace1++; 399 400 401 399 switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2"); 400 return '{'; 401 } 402 402 . { printf("ERROR <<<'%s' ", yytext); } 403 403 } … … 406 406 {NL} { yylineno++; } 407 407 .*(\n?) { lvalp->name = yytext; 408 408 return CODEPART; } 409 409 410 410 <<EOF>> { sectnum = 0; 411 412 413 411 iseof=1; 412 lvalp->name = yytext; 413 return SECT4END; 414 414 /* yyterminate(); */ 415 415 } … … 418 418 <PROCDECL>{ 419 419 "{" { brace1++; 420 421 422 420 switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2"); 421 return '{'; 422 } 423 423 "/*" push_state(YYSTATE, COMMENT, "COMMENT");yymore(); 424 424 "//".*{NL} ++yylineno; ACTION_ECHO; 425 425 "\"" { do_return++; 426 426 lvalp->sv.lineno = yylineno; 427 427 push_state(YYSTATE, STRING, "string"); 428 428 } 429 430 431 432 429 {BOOL} { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i); 430 else { 431 if(strcasecmp(yytext, "yes")==0) lvalp->i = 1; 432 else lvalp->i = 0; 433 433 } 434 434 return BOOLTOK; } 435 436 437 435 {NUMBER} { sscanf(yytext, "%d", &lvalp->i); return NUMTOK; } 436 {NAME} { 437 int i,tok; 438 438 #if DEBUG > 1 439 440 #endif 441 439 printf("(%d) VAR: %s\n", yylineno, yytext); 440 #endif 441 i = IsCmd(yytext, tok); 442 442 #if DEBUG > 1 443 444 445 #endif 446 447 448 449 450 451 452 453 454 455 443 printf("Res=%d, %d => %s\n", i, tok, 444 i ? "VARTYPETOK" : "NAME"); 445 #endif 446 if(i) { 447 lvalp->tp.name = strdup(yytext); 448 lvalp->tp.typ = tok; 449 return VARTYPETOK; 450 } 451 else { 452 //do_return++; 453 lvalp->name = strdup(yytext); 454 return NAME; 455 } 456 456 } 457 457 {NL} { yylineno++; } 458 459 460 461 462 463 458 "(" { return '('; } 459 ")" { return ')'; } 460 "," { return ','; } 461 "#" { return '#'; } 462 "=" { return '='; } 463 ";" { return ';'; } 464 464 . { } 465 465 … … 471 471 lvalp->name = yytext; 472 472 return CMTPART; 473 473 yymore(); 474 474 } 475 475 "*" yymore(); 476 476 {NL} { yylineno++; yymore(); } 477 477 . { yymore(); } 478 478 } 479 479 480 480 <CODEBLOCK2>{ … … 482 482 "//".*{NL} { yylineno++; lvalp->name = yytext; return CODEPART; } 483 483 "\"" { 484 484 lvalp->sv.lineno = yylineno; 485 485 push_state(YYSTATE, STRING, "string"); yymore();} 486 486 "{" { brace1++; yymore();} … … 489 489 char * s, *t; 490 490 491 491 pop_state(); 492 492 #if 0 493 494 495 496 497 498 499 493 s = t = lvalp->name = dupyytext(); 494 while (*yytext) 495 { 496 if (*yytext == '\\') yytext++; 497 *s++ = *yytext++; 498 } 499 if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0'; 500 500 #else 501 501 lvalp->name = yytext; … … 504 504 printf("2 BRACE DOWN=%d\n", brace1); 505 505 #endif 506 506 return MCODETOK; 507 507 } else { 508 508 yymore(); 509 509 } 510 510 } 511 511 {NL} { yylineno++; lvalp->name = yytext; return CODEPART; } 512 512 "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK"); 513 513 procedure_decl.flags.start_of_code = 1; 514 514 return '%'; } … … 520 520 <PROCCMDBLOCK>{ 521 521 {col} { pop_state(); return ';'; } 522 523 524 522 "(" { return '('; } 523 ")" { return ')'; } 524 "," { return ','; } 525 525 {WS} /* ignore */ 526 526 {NAME} { lvalp->name = strdup(yytext); return NAME; }
Note: See TracChangeset
for help on using the changeset viewer.