8 while ($ARGV[0] =~ '^-') {
24 die "I don't recognize this switch: $_";
28 open(body,">/tmp/sperl$$") || do Die("Can't open temp file.");
31 if (!$assumen && !$assumep) {
33 'while ($ARGV[0] =~ /^-/) {
40 die "I don\'t recognize this switch: $_";
51 $printit++ unless $nflag;
61 $label = do make_label($_);
66 if ($lastlinewaslabel++) {$_ .= "\t;";}
73 $lastlinewaslabel = '';
85 delim: while (s:^([^(|)\\/]*)([(|)\\/])::) {
91 $delim = '' if index("(|)",$ch) >= 0;
94 elsif ($delim ne '/') {
95 $delim = '\\' . $delim;
111 delim: while (s:^([^(|)\\/]*)([(|)\\/])::) {
114 if ($delim eq '\\') {
117 $delim = '' if index("(|)",$ch) >= 0;
120 elsif ($delim ne '/') {
121 $delim = '\\' . $delim;
130 do Die("Invalid second address at line $.: $_");
132 $addr1 .= " .. $addr2";
134 # a { to keep vi happy
141 $else = "$r else $l\n";
146 if (s/^{//) { # a } to keep vi happy
153 if ($addr2 || $addr1) {
154 $space = substr(' ',0,$shiftwidth);
158 $_ = do transmogrify();
162 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
163 $_ !~ / if / && $_ !~ / unless /) {
165 $_ = substr($_,$shiftwidth,1000);
168 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
174 @lines = split(/\n/,$_);
175 while ($#lines >= 0) {
177 unless (s/^ *<<--//) {
178 print body substr("\t\t\t\t\t\t\t\t\t\t\t\t",0,$indent / 8),
179 substr(' ',0,$indent % 8);
193 if ($appendseen || $tseen || !$assumen) {
194 $printit++ if $dseen || (!$assumen && !$assumep);
202 if ($printit) { print;} else { $printit++ unless $nflag; }
214 if ($atext) { print $atext; $atext = \'\'; }
223 open(head,">/tmp/sperl2$$") || do Die("Can't open temp file 2.\n");
224 print head "#define PRINTIT\n" if ($printit);
225 print head "#define APPENDSEEN\n" if ($appendseen);
226 print head "#define TSEEN\n" if ($tseen);
227 print head "#define DSEEN\n" if ($dseen);
228 print head "#define ASSUMEN\n" if ($assumen);
229 print head "#define ASSUMEP\n" if ($assumep);
230 if ($opens) {print head "$opens\n";}
231 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file.");
237 print "#!/bin/perl\n\n";
238 open(body,"cc -E /tmp/sperl2$$ |") ||
239 do Die("Can't reopen temp file.");
248 `/bin/rm -f /tmp/sperl$$ /tmp/sperl2$$`;
251 `/bin/rm -f /tmp/sperl$$ /tmp/sperl2$$`;
254 sub make_filehandle {
258 if (/^([a-z])([a-z]*)$/) {
261 $first =~ y/a-z/A-Z/;
265 $opens .= "open($_,'>$fname') || die \"Can't create $fname.\";\n";
272 $label =~ s/[^a-zA-Z0-9]/_/g;
273 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
274 $label = substr($label,0,8);
275 if ($label =~ /^([a-z])([a-z]*)$/) {
278 $first =~ y/a-z/A-Z/;
279 $label = $first . $rest;
303 if ($printit) { print;} else { $printit++ unless $nflag; }
311 <<--#ifdef APPENDSEEN
312 if ($atext) {print $atext; $atext = \'\';}
323 $command = $space . '$atext .=' . "\n<<--'";
328 unless (s|\\$||) { $lastline = 1;}
330 s/^([ \t]*\n)/<><>$1/;
335 $_ = $command . "';";
340 if (/^c/) { $change = 1; }
341 $addr1 = '$iter = (' . $addr1 . ')';
342 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
347 unless (s/\\$//) { $lastline = 1;}
349 s/^([ \t]*\n)/<><>$1/;
354 $_ = $command . "';}";
360 $space\$printit = '';
368 $delim = substr($_,1,1);
371 for ($i = 2; $i < $len; $i++) {
372 $c = substr($_,$i,1);
379 $_ = substr($_,0,--$len);
381 elsif (!$repl && index("(|)",substr($_,$i,1)) >= 0) {
384 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
387 elsif ($c eq $delim) {
395 elsif (!$repl && index("(|)",$c) >= 0) {
396 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
401 print "repl $repl end $end $_\n";
402 do Die("Malformed substitution at line $.") unless $end;
403 $pat = substr($_, 0, $repl + 1);
404 $repl = substr($_, $repl + 1, $end - $repl - 1);
405 $end = substr($_, $end + 1, 1000);
408 $repl =~ s/[\\]([0-9])/$dol$1/g;
409 $subst = "$pat$repl$delim";
412 if ($end =~ s/^g//) { $subst .= 'g'; next; }
413 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
414 if ($end =~ s/^w[ \t]*//) {
415 $fh = do make_filehandle($end);
416 $cmd .= " && (print $fh \$_)";
420 do Die("Unrecognized substitution command ($end) at line $.");
422 $_ = $subst . $cmd . ';';
433 $fh = do make_filehandle($_);
434 $_ = "print $fh \$_;";
442 $_ = "\$atext .= `cat $file 2>/dev/null`;";
448 'if (/(^[^\n]*\n)/) {
477 $_ = '$hold .= $_ ? $_ : "\n";';
487 $_ = '$_ .= $hold ? $hold : "\n";';
492 $_ = '($_, $hold) = ($hold, $_);';
503 $lab = do make_label($_);
504 if ($lab eq $toplabel) {
513 $_ = 'next line if $tflag;';
520 $lab = do make_label($_);
521 if ($lab eq $toplabel) {
522 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
524 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
531 $_ = 'print "$.\n";';
545 s/(\n)(.)/$1$space$2/g;