handle tri graphs in h2ph.PL -> h2ph*
Peter Prymmer [Thu, 14 Jun 2001 16:25:33 +0000 (09:25 -0700)]
Message-ID: <Pine.OSF.4.10.10106141608080.110974-100000@aspara.forte.com>

p4raw-id: //depot/perl@10605

t/lib/h2ph.h
t/lib/h2ph.pht
t/lib/h2ph.t
utils/h2ph.PL

index 128ec5f..9fd535d 100644 (file)
@@ -82,4 +82,20 @@ typedef struct a_struct {
 typedef enum _days_of_week { sun, mon, tue, wed, thu, fri, sat, Sun=0, Mon,
                             Tue, Wed, Thu, Fri, Sat } days_of_week;
 
+/* 
+ * Some moderate flexing of tri-graph pre substitution.
+ */
+??=ifndef _SOMETHING_TRIGRAPHIC
+??=define _SOMETHING_TRIGRAPHIC
+??= define SOMETHING_ELSE_TRIGRAPHIC_0 "??!"          /* | ??!|  || */
+ ??=define SOMETHING_ELSE_TRIGRAPHIC_1 "??'"          /* | ??'|  ^| */
+??= define SOMETHING_ELSE_TRIGRAPHIC_2 "??("          /* | ??(|  [| */
+ ??= define SOMETHING_ELSE_TRIGRAPHIC_3 "??)"         /* | ??)|  ]| */
+??=define SOMETHING_ELSE_TRIGRAPHIC_4  "??-0"         /* | ??-|  ~| */
+       ??= define SOMETHING_ELSE_TRIGRAPHIC_5 "??/ " /* | ??/|  \| */
+??= define SOMETHING_ELSE_TRIGRAPHIC_6 "??<"          /* | ??<|  {| */
+??=define SOMETHING_ELSE_TRIGRAPHIC_7  "??="          /* | ??=|  #| */
+??= define SOMETHING_ELSE_TRIGRAPHIC_8 "??>"          /* | ??>|  }| */
+       ??=endif
+
 #endif /* _H2PH_H_ */
index e8868dc..07b9470 100644 (file)
@@ -67,5 +67,17 @@ unless(defined(&_H2PH_H_)) {
     eval("sub Thu () { 4; }") unless defined(&Thu);
     eval("sub Fri () { 5; }") unless defined(&Fri);
     eval("sub Sat () { 6; }") unless defined(&Sat);
+    unless(defined(&_SOMETHING_TRIGRAPHIC)) {
+       eval 'sub _SOMETHING_TRIGRAPHIC () {1;}' unless defined(&_SOMETHING_TRIGRAPHIC);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_0 () {"|";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_0);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_1 () {"^";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_1);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_2 () {"[";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_2);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_3 () {"]";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_3);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_4 () {"~0";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_4);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_5 () {"\\ ";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_5);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_6 () {"{";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_6);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_7 () {"#";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_7);
+       eval 'sub SOMETHING_ELSE_TRIGRAPHIC_8 () {"}";}' unless defined(&SOMETHING_ELSE_TRIGRAPHIC_8);
+    }
 }
 1;
index 15dc2b5..7b339b3 100755 (executable)
@@ -8,6 +8,13 @@ BEGIN {
     @INC = '../lib';
 }
 
+my $extracted_program = '../utils/h2ph'; # unix, nt, ...
+if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2ph.com'; }
+if (!(-e $extracted_program)) {
+    print "1..0 # Skip: $extracted_program was not built\n";
+    exit 0;
+}
+
 print "1..2\n";
 
 # quickly compare two text files
@@ -17,19 +24,14 @@ sub txt_compare {
     $A cmp $B;
 }
 
-unless(-e '../utils/h2ph') {
-    print("ok 1\nok 2\n");
-    # i'll probably get in trouble for this :)
-} else {
-    # does it run?
-    $ok = system("./perl -I../lib ../utils/h2ph -d. -Q lib/h2ph.h");
-    print(($ok == 0 ? "" : "not "), "ok 1\n");
+# does it run?
+$ok = system("$^X \"-I../lib\" $extracted_program -d. \"-Q\" lib/h2ph.h");
+print(($ok == 0 ? "" : "not "), "ok 1\n");
     
-    # does it work? well, does it do what we expect? :-)
-    $ok = txt_compare("lib/h2ph.ph", "lib/h2ph.pht");
-    print(($ok == 0 ? "" : "not "), "ok 2\n");
+# does it work? well, does it do what we expect? :-)
+$ok = txt_compare("lib/h2ph.ph", "lib/h2ph.pht");
+print(($ok == 0 ? "" : "not "), "ok 2\n");
     
-    # cleanup - should this be in an END block?
-    unlink("lib/h2ph.ph");
-    unlink("_h2ph_pre.ph");
-}
+# cleanup - should this be in an END block?
+unlink("lib/h2ph.ph");
+unlink("_h2ph_pre.ph");
index d852fc2..f647831 100644 (file)
@@ -401,6 +401,7 @@ sub expr {
 sub next_line
 {
     my ($in, $out);
+    my $pre_sub_tri_graphs = 1;
 
     READ: while (not eof IN) {
         $in  .= <IN>;
@@ -408,6 +409,19 @@ sub next_line
         next unless length $in;
 
         while (length $in) {
+            if ($pre_sub_tri_graphs) {
+                # Preprocess all tri-graphs 
+                # including things stuck in quoted string constants.
+                $in =~ s/\?\?=/#/g;                         # | ??=|  #|
+                $in =~ s/\?\?\!/|/g;                        # | ??!|  ||
+                $in =~ s/\?\?'/^/g;                         # | ??'|  ^|
+                $in =~ s/\?\?\(/[/g;                        # | ??(|  [|
+                $in =~ s/\?\?\)/]/g;                        # | ??)|  ]|
+                $in =~ s/\?\?\-/~/g;                        # | ??-|  ~|
+                $in =~ s/\?\?\//\\/g;                       # | ??/|  \|
+                $in =~ s/\?\?</{/g;                         # | ??<|  {|
+                $in =~ s/\?\?>/}/g;                         # | ??>|  }|
+            }
             if ($in =~ s/\\$//) {                           # \-newline
                 $out    .= ' ';
                 next READ;