Commit | Line | Data |
4633a7c4 |
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 | # |
bd3fa61c |
9 | # Revised 20-Dec-1996 by Charles Bailey bailey@newman.upenn.edu |
c07a80fd |
10 | |
71be2cbc |
11 | $VERSION = '1.11'; |
4633a7c4 |
12 | |
71be2cbc |
13 | push(@ARGV,(qw[ perly.c perly.h vms/perly_c.vms vms/perly_h.vms])[@ARGV..4]) |
14 | if @ARGV < 4; |
4633a7c4 |
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"; |
c07a80fd |
19 | print COUT <<EOH; |
20 | /* Postprocessed by vms_yfix.pl $VERSION to add VMS declarations of globals */ |
21 | EOH |
4633a7c4 |
22 | while (<C>) { |
c07a80fd |
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; } |
9607fc9c |
26 | elsif (/char \*getenv/) { |
27 | # accomodate old VAXC's macro susbstitution pecularities |
28 | $_ = "# ifndef getenv\n$_# endif\n"; |
29 | } |
61bb5906 |
30 | elsif ( /getenv\("YYDEBUG"\)/ ) { |
2ac72d6e |
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" . $_; |
61bb5906 |
34 | # Reset the "error" status if an optional lookup fails |
35 | while (not /^\s+\}/) { print COUT; $_ = <C>; } |
2ac72d6e |
36 | $_ .= " else SETERRNO(saved_errno,saved_vaxc_errno);\n }\n"; |
61bb5906 |
37 | } |
c07a80fd |
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/; |
4633a7c4 |
42 | } |
4633a7c4 |
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"; |
c07a80fd |
50 | print HOUT <<EOH; |
51 | /* Postprocessed by vms_yfix.pl $VERSION to add VMS declarations of globals */ |
52 | EOH |
4633a7c4 |
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; |