From: Peter Prymmer Date: Thu, 14 Jun 2001 16:25:33 +0000 (-0700) Subject: handle tri graphs in h2ph.PL -> h2ph* X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b7bcf49446150838af3c7cd1dec335ba45a2fc6b;p=p5sagit%2Fp5-mst-13.2.git handle tri graphs in h2ph.PL -> h2ph* Message-ID: p4raw-id: //depot/perl@10605 --- diff --git a/t/lib/h2ph.h b/t/lib/h2ph.h index 128ec5f..9fd535d 100644 --- a/t/lib/h2ph.h +++ b/t/lib/h2ph.h @@ -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_ */ diff --git a/t/lib/h2ph.pht b/t/lib/h2ph.pht index e8868dc..07b9470 100644 --- a/t/lib/h2ph.pht +++ b/t/lib/h2ph.pht @@ -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; diff --git a/t/lib/h2ph.t b/t/lib/h2ph.t index 15dc2b5..7b339b3 100755 --- a/t/lib/h2ph.t +++ b/t/lib/h2ph.t @@ -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"); diff --git a/utils/h2ph.PL b/utils/h2ph.PL index d852fc2..f647831 100644 --- a/utils/h2ph.PL +++ b/utils/h2ph.PL @@ -401,6 +401,7 @@ sub expr { sub next_line { my ($in, $out); + my $pre_sub_tri_graphs = 1; READ: while (not eof 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; # | ??>| }| + } if ($in =~ s/\\$//) { # \-newline $out .= ' '; next READ;