Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # do not check in the change in the preceding line, was #!/usr/env perl
- open(ENT,"$ARGV[0]") or die("$ARGV[0] : $!");
- shift @ARGV;
- while (@ARGV) {
- $t{$ARGV[0]}=$ARGV[1]; # was $p
- shift @ARGV;
- shift @ARGV;
- }
- while (<ENT>) {
- if (/<!ENTITY [^%]/) {
- ($n,$q)=/ENTITY *([^ ]*) *([^ ])/;
- ($v)=/ENTITY *[^ ]* *$q([^$q]*)/;
- # behave as XML -- first defn wins
- unless (defined $t{$n}) {
- # while ($v=~s/\%([^;]*);/!!/) {
- # $e=$1;
- # if (defined $p{$e}) {
- # $v=~s/!!/$p{$e}/;
- # } else {
- # print STDERR "udpe: $e\n";
- # exit(1);
- # }
- # }
- $t{$n}=$v;
- }
- }
- }
- while (<>) {
- $some=0;
- while (s/\&([^;]*);/!!/) {
- $e=$1;
- if (defined $t{$e}) {
- s/!!/$t{$e}/;
- } else {
- $some=1;
- s/!!/!_$e;/;
- };
- };
- if ($some) {
- s/!_/\&/g;
- }
- if (/\$Id/) {
- s/\$//g;
- };
- print;
- }
Add Comment
Please, Sign In to add comment