Guest User

Untitled

a guest
Jul 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # do not check in the change in the preceding line, was #!/usr/env perl
  3. open(ENT,"$ARGV[0]") or die("$ARGV[0] : $!");
  4. shift @ARGV;
  5. while (@ARGV) {
  6. $t{$ARGV[0]}=$ARGV[1]; # was $p
  7. shift @ARGV;
  8. shift @ARGV;
  9. }
  10. while (<ENT>) {
  11. if (/<!ENTITY [^%]/) {
  12. ($n,$q)=/ENTITY *([^ ]*) *([^ ])/;
  13. ($v)=/ENTITY *[^ ]* *$q([^$q]*)/;
  14. # behave as XML -- first defn wins
  15. unless (defined $t{$n}) {
  16. # while ($v=~s/\%([^;]*);/!!/) {
  17. # $e=$1;
  18. # if (defined $p{$e}) {
  19. # $v=~s/!!/$p{$e}/;
  20. # } else {
  21. # print STDERR "udpe: $e\n";
  22. # exit(1);
  23. # }
  24. # }
  25. $t{$n}=$v;
  26. }
  27. }
  28. }
  29. while (<>) {
  30. $some=0;
  31. while (s/\&([^;]*);/!!/) {
  32. $e=$1;
  33. if (defined $t{$e}) {
  34. s/!!/$t{$e}/;
  35. } else {
  36. $some=1;
  37. s/!!/!_$e;/;
  38. };
  39. };
  40. if ($some) {
  41. s/!_/\&/g;
  42. }
  43. if (/\$Id/) {
  44. s/\$//g;
  45. };
  46. print;
  47. }
Add Comment
Please, Sign In to add comment