From: Hans Mulder Date: Mon, 29 Dec 1997 19:38:18 +0000 (-0500) Subject: Make s2p not use cpp: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1aa91729dac49eab17c672e09121db869388a50a;p=p5sagit%2Fp5-mst-13.2.git Make s2p not use cpp: Subject: [PATCH for 5.004_56] s2p shouldn't use cpp p4raw-id: //depot/perl@408 --- diff --git a/x2p/s2p.PL b/x2p/s2p.PL index 73f6787..fa0d567 100644 --- a/x2p/s2p.PL +++ b/x2p/s2p.PL @@ -135,7 +135,7 @@ while ($ARGV[0] =~ /^-/) { } unless ($debug) { - open(BODY,">/tmp/sperl$$") || + open(BODY,"+>/tmp/sperl$$") || &Die("Can't open temp file: $!\n"); } @@ -343,26 +343,7 @@ print BODY &q(<<'EOT'); EOT } -close BODY; - unless ($debug) { - open(HEAD,">/tmp/sperl2$$.c") - || &Die("Can't open temp file 2: $!\n"); - print HEAD "#define PRINTIT\n" if $printit; - print HEAD "#define APPENDSEEN\n" if $appendseen; - print HEAD "#define TSEEN\n" if $tseen; - print HEAD "#define DSEEN\n" if $dseen; - print HEAD "#define ASSUMEN\n" if $assumen; - print HEAD "#define ASSUMEP\n" if $assumep; - print HEAD "#define TOPLABEL\n" if $toplabel; - print HEAD "#define SAWNEXT\n" if $sawnext; - if ($opens) {print HEAD "$opens\n";} - open(BODY,"/tmp/sperl$$") - || &Die("Can't reopen temp file: $!\n"); - while () { - print HEAD $_; - } - close HEAD; print &q(<<"EOT"); : $startperl @@ -370,11 +351,13 @@ unless ($debug) { : if \$running_under_some_shell; : EOT - open(BODY,"cc -E /tmp/sperl2$$.c |") || - &Die("Can't reopen temp file: $!\n"); + print"$opens\n" if $opens; + seek(BODY, 0, 0) || die "Can't rewind temp file: $!\n"; while () { - /^# [0-9]/ && next; /^[ \t]*$/ && next; + /^#ifdef (\w+)/ && ((${lc $1} || &skip), next); + /^#else/ && (&skip, next); + /^#endif/ && next; s/^<><>//; print; } @@ -384,8 +367,7 @@ EOT exit; sub Cleanup { - chdir "/tmp"; - unlink "sperl$$", "sperl2$$", "sperl2$$.c"; + unlink "/tmp/sperl$$"; } sub Die { &Cleanup; @@ -603,7 +585,6 @@ EOT $repl = substr($_, $repl+1, $end-$repl-1); $end = substr($_, $end + 1, 1000); &simplify($pat); - $dol = '$'; $subst = "$pat$repl$delim"; $cmd = ''; while ($end) { @@ -846,6 +827,17 @@ sub simplify { $_[0] =~ s/([\w\s!@#%^&-=,:;'"])\1\*/$1+/g; } +sub skip { + local($level) = 0; + + while() { + /^#ifdef/ && $level++; + /^#else/ && !$level && return; + /^#endif/ && !$level-- && return; + } + + die "Unterminated `#ifdef' conditional\n"; +} !NO!SUBS! close OUT or die "Can't close $file: $!";