3 # $Header: s2p,v 2.0 88/06/05 00:15:55 root Exp $
6 # Revision 2.0 88/06/05 00:15:55 root
7 # Baseline version 2.0.
16 while ($ARGV[0] =~ '^-') {
32 die "I don't recognize this switch: $_\n";
36 open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
39 if (!$assumen && !$assumep) {
41 'while ($ARGV[0] =~ /^-/) {
48 die "I don\'t recognize this switch: $_\\n";
59 $printit++ unless $nflag;
69 $label = do make_label($_);
74 if ($lastlinewaslabel++) {$_ .= "\t;";}
81 $lastlinewaslabel = '';
93 delim: while (s:^([^(|)\\/]*)([(|)\\/])::) {
99 $delim = '' if index("(|)",$ch) >= 0;
102 elsif ($delim ne '/') {
103 $delim = '\\' . $delim;
119 delim: while (s:^([^(|)\\/]*)([(|)\\/])::) {
122 if ($delim eq '\\') {
125 $delim = '' if index("(|)",$ch) >= 0;
128 elsif ($delim ne '/') {
129 $delim = '\\' . $delim;
138 do Die("Invalid second address at line $.\n");
140 $addr1 .= " .. $addr2";
142 # a { to keep vi happy
150 $else = "$r else $l\n";
155 if (s/^{//) { # a } to keep vi happy
162 if ($addr2 || $addr1) {
163 $space = substr(' ',0,$shiftwidth);
167 $_ = do transmogrify();
171 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
172 $_ !~ / if / && $_ !~ / unless /) {
174 $_ = substr($_,$shiftwidth,1000);
177 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
183 @lines = split(/\n/,$_);
184 while ($#lines >= 0) {
186 unless (s/^ *<<--//) {
187 print body substr("\t\t\t\t\t\t\t\t\t\t\t\t",0,$indent / 8),
188 substr(' ',0,$indent % 8);
202 if ($appendseen || $tseen || !$assumen) {
203 $printit++ if $dseen || (!$assumen && !$assumep);
211 if ($printit) { print;} else { $printit++ unless $nflag; }
223 if ($atext) { print $atext; $atext = \'\'; }
232 open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
233 print head "#define PRINTIT\n" if ($printit);
234 print head "#define APPENDSEEN\n" if ($appendseen);
235 print head "#define TSEEN\n" if ($tseen);
236 print head "#define DSEEN\n" if ($dseen);
237 print head "#define ASSUMEN\n" if ($assumen);
238 print head "#define ASSUMEP\n" if ($assumep);
239 if ($opens) {print head "$opens\n";}
240 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
246 print "#!/bin/perl\n\n";
247 open(body,"cc -E /tmp/sperl2$$.c |") ||
248 do Die("Can't reopen temp file");
257 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
260 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
263 sub make_filehandle {
267 if (/^([a-z])([a-z]*)$/) {
270 $first =~ y/a-z/A-Z/;
274 $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
281 $label =~ s/[^a-zA-Z0-9]/_/g;
282 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
283 $label = substr($label,0,8);
284 if ($label =~ /^([a-z])([a-z]*)$/) {
287 $first =~ y/a-z/A-Z/;
288 $label = $first . $rest;
312 if ($printit) { print;} else { $printit++ unless $nflag; }
320 <<--#ifdef APPENDSEEN
321 if ($atext) {print $atext; $atext = \'\';}
332 $command = $space . '$atext .=' . "\n<<--'";
337 unless (s|\\$||) { $lastline = 1;}
339 s/^([ \t]*\n)/<><>$1/;
344 $_ = $command . "';";
349 if (/^c/) { $change = 1; }
350 $addr1 = '$iter = (' . $addr1 . ')';
351 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
356 unless (s/\\$//) { $lastline = 1;}
358 s/^([ \t]*\n)/<><>$1/;
363 $_ = $command . "';}";
369 $space\$printit = '';
377 $delim = substr($_,1,1);
380 for ($i = 2; $i < $len; $i++) {
381 $c = substr($_,$i,1);
388 $_ = substr($_,0,--$len);
390 elsif (!$repl && index("(|)",substr($_,$i,1)) >= 0) {
393 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
396 elsif ($c eq $delim) {
404 elsif (!$repl && index("(|)",$c) >= 0) {
405 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
410 do Die("Malformed substitution at line $.\n") unless $end;
411 $pat = substr($_, 0, $repl + 1);
412 $repl = substr($_, $repl + 1, $end - $repl - 1);
413 $end = substr($_, $end + 1, 1000);
417 $repl =~ s/[\\]([0-9])/$dol$1/g;
418 $subst = "$pat$repl$delim";
421 if ($end =~ s/^g//) { $subst .= 'g'; next; }
422 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
423 if ($end =~ s/^w[ \t]*//) {
424 $fh = do make_filehandle($end);
425 $cmd .= " && (print $fh \$_)";
429 do Die("Unrecognized substitution command ($end) at line $.\n");
431 $_ = $subst . $cmd . ';';
442 $fh = do make_filehandle($_);
443 $_ = "print $fh \$_;";
451 $_ = "\$atext .= `cat $file 2>/dev/null`;";
457 'if (/(^[^\n]*\n)/) {
486 $_ = '$hold .= $_ ? $_ : "\n";';
496 $_ = '$_ .= $hold ? $hold : "\n";';
501 $_ = '($_, $hold) = ($hold, $_);';
512 $lab = do make_label($_);
513 if ($lab eq $toplabel) {
522 $_ = 'next line if $tflag;';
529 $lab = do make_label($_);
530 if ($lab eq $toplabel) {
531 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
533 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
540 $_ = 'print "$.\n";';
554 s/(\n)(.)/$1$space$2/g;