| 1 | # This script takes the output produced from perly.y by byacc and
|
|---|
| 2 | # the perly.fixer shell script (i.e. the perly.c and perly.h built
|
|---|
| 3 | # for Unix systems) and patches them to produce copies containing
|
|---|
| 4 | # appropriate declarations for VMS handling of global symbols.
|
|---|
| 5 | #
|
|---|
| 6 | # If it finds that the input files are already patches for VMS,
|
|---|
| 7 | # it just copies the input to the output.
|
|---|
| 8 | #
|
|---|
| 9 | # Revised 20-Dec-1996 by Charles Bailey [email protected]
|
|---|
| 10 |
|
|---|
| 11 | $VERSION = '1.11';
|
|---|
| 12 |
|
|---|
| 13 | push(@ARGV,(qw[ perly.c perly.h vms/perly_c.vms vms/perly_h.vms])[@ARGV..4])
|
|---|
| 14 | if @ARGV < 4;
|
|---|
| 15 | ($cinfile,$hinfile,$coutfile,$houtfile) = @ARGV;
|
|---|
| 16 |
|
|---|
| 17 | open C,$cinfile or die "Can't read $cinfile: $!\n";
|
|---|
| 18 | open COUT, ">$coutfile" or die "Can't create $coutfile: $!\n";
|
|---|
| 19 | print COUT <<EOH;
|
|---|
| 20 | /* Postprocessed by vms_yfix.pl $VERSION to add VMS declarations of globals */
|
|---|
| 21 | EOH
|
|---|
| 22 | while (<C>) {
|
|---|
| 23 | # "y.tab.c" is illegal as a VMS filename; DECC 5.2/VAX preprocessor
|
|---|
| 24 | # doesn't like this.
|
|---|
| 25 | if ( s/^#line\s+(\d+)\s+"y.tab.c"/#line $1 "y_tab.c"/ ) { 1; }
|
|---|
| 26 | elsif (/char \*getenv/) {
|
|---|
| 27 | # accomodate old VAXC's macro susbstitution pecularities
|
|---|
| 28 | $_ = "# ifndef getenv\n$_# endif\n";
|
|---|
| 29 | }
|
|---|
| 30 | elsif ( /getenv\("YYDEBUG"\)/ ) {
|
|---|
| 31 | $_ = " {\n register int saved_errno = errno;\n"
|
|---|
| 32 | . "#ifdef VMS\n register int saved_vaxc_errno = vaxc\$errno;\n"
|
|---|
| 33 | . "#else\n register int saved_vaxc_errno = 0;\n#endif\n" . $_;
|
|---|
| 34 | # Reset the "error" status if an optional lookup fails
|
|---|
| 35 | while (not /^\s+\}/) { print COUT; $_ = <C>; }
|
|---|
| 36 | $_ .= " else SETERRNO(saved_errno,saved_vaxc_errno);\n }\n";
|
|---|
| 37 | }
|
|---|
| 38 | else {
|
|---|
| 39 | # add the dEXT tag to definitions of global vars, so we'll insert
|
|---|
| 40 | # a globaldef when perly.c is compiled
|
|---|
| 41 | s/^(short|int|YYSTYPE|char \*)\s*yy/dEXT $1 yy/;
|
|---|
| 42 | }
|
|---|
| 43 | print COUT;
|
|---|
| 44 | }
|
|---|
| 45 | close C;
|
|---|
| 46 | close COUT;
|
|---|
| 47 |
|
|---|
| 48 | open H,$hinfile or die "Can't read $hinfile: $!\n";
|
|---|
| 49 | open HOUT, ">$houtfile" or die "Can't create $houtfile: $!\n";
|
|---|
| 50 | print HOUT <<EOH;
|
|---|
| 51 | /* Postprocessed by vms_yfix.pl $VERSION to add VMS declarations of globals */
|
|---|
| 52 | EOH
|
|---|
| 53 | $hfixed = 0; # keep -w happy
|
|---|
| 54 | while (<H>) {
|
|---|
| 55 | $hfixed = /globalref/ unless $hfixed; # we've already got a fixed copy
|
|---|
| 56 | next if /^extern YYSTYPE yylval/; # we've got a Unix version, and this
|
|---|
| 57 | # is what we want to replace
|
|---|
| 58 | print HOUT;
|
|---|
| 59 | }
|
|---|
| 60 | close H;
|
|---|
| 61 |
|
|---|
| 62 | print HOUT <<'EODECL' unless $hfixed;
|
|---|
| 63 | #ifndef vax11c
|
|---|
| 64 | extern YYSTYPE yylval;
|
|---|
| 65 | #else
|
|---|
| 66 | globalref YYSTYPE yylval;
|
|---|
| 67 | #endif
|
|---|
| 68 | EODECL
|
|---|
| 69 |
|
|---|
| 70 | close HOUT;
|
|---|