1 : This forces SH files to create target in same directory as SH file.
2 : This is so that make depend always knows where to find SH derivatives.
4 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
8 if test ! -f config.sh; then
10 ln ../../config.sh . || \
11 ln ../../../config.sh . || \
12 (echo "Can't find config.sh."; exit 1)
17 echo "Extracting s2p (with variable substitutions)"
18 : This section of the file will have variable substitutions done on it.
19 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
20 : Protect any dollar signs and backticks that you do not want interpreted
21 : by putting a backslash in front. You may delete these comments.
22 $spitshell >s2p <<!GROK!THIS!
28 : In the following dollars and backticks do not need the extra backslash.
29 $spitshell >>s2p <<'!NO!SUBS!'
31 # $Header: s2p.SH,v 3.0.1.2 89/11/17 15:51:27 lwall Locked $
34 # Revision 3.0.1.2 89/11/17 15:51:27 lwall
35 # patch5: in s2p, line labels without a subsequent statement were done wrong
36 # patch5: s2p left residue in /tmp
38 # Revision 3.0.1.1 89/11/11 05:08:25 lwall
39 # patch2: in s2p, + within patterns needed backslashing
40 # patch2: s2p was printing out some debugging info to the output file
42 # Revision 3.0 89/10/18 15:35:02 lwall
45 # Revision 2.0.1.1 88/07/11 23:26:23 root
46 # patch2: s2p didn't put a proper prologue on output script
48 # Revision 2.0 88/06/05 00:15:55 root
49 # Baseline version 2.0.
58 while ($ARGV[0] =~ '^-') {
74 die "I don't recognize this switch: $_\n";
78 open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
81 if (!$assumen && !$assumep) {
83 'while ($ARGV[0] =~ /^-/) {
90 die "I don\'t recognize this switch: $_\\n";
101 $printit++ unless $nflag;
111 $label = do make_label($_);
116 if ($lastlinewaslabel++) {
118 print body "\t" x ($indent / 8), ' ' x ($indent % 8), ";\n";
127 $lastlinewaslabel = '';
138 $addr1 = do fetchpat('/');
146 $addr2 = do fetchpat('/');
148 do Die("Invalid second address at line $.\n");
150 $addr1 .= " .. $addr2";
152 # a { to keep vi happy
160 $else = "$r else $l\n";
165 if (s/^{//) { # a } to keep vi happy
172 if ($addr2 || $addr1) {
173 $space = ' ' x $shiftwidth;
177 $_ = do transmogrify();
181 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
182 $_ !~ / if / && $_ !~ / unless /) {
184 $_ = substr($_,$shiftwidth,1000);
187 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
193 @lines = split(/\n/,$_);
194 while ($#lines >= 0) {
196 unless (s/^ *<<--//) {
197 print body "\t" x ($indent / 8), ' ' x ($indent % 8);
209 if ($lastlinewaslabel++) {
211 print body "\t" x ($indent / 8), ' ' x ($indent % 8), ";\n";
216 if ($appendseen || $tseen || !$assumen) {
217 $printit++ if $dseen || (!$assumen && !$assumep);
225 if ($printit) { print;} else { $printit++ unless $nflag; }
237 if ($atext) { print $atext; $atext = \'\'; }
246 open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
247 print head "#define PRINTIT\n" if ($printit);
248 print head "#define APPENDSEEN\n" if ($appendseen);
249 print head "#define TSEEN\n" if ($tseen);
250 print head "#define DSEEN\n" if ($dseen);
251 print head "#define ASSUMEN\n" if ($assumen);
252 print head "#define ASSUMEP\n" if ($assumep);
253 if ($opens) {print head "$opens\n";}
254 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
261 eval \"exec $bin/perl -S \$0 \$*\"
262 if \$running_under_some_shell;
265 open(body,"cc -E /tmp/sperl2$$.c |") ||
266 do Die("Can't reopen temp file");
275 unlink "/tmp/sperl$$", "/tmp/sperl2$$", "/tmp/sperl2$$.c";
278 unlink "/tmp/sperl$$", "/tmp/sperl2$$", "/tmp/sperl2$$.c";
281 sub make_filehandle {
285 if (/^([a-z])([a-z]*)$/) {
288 $first =~ y/a-z/A-Z/;
292 $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
299 $label =~ s/[^a-zA-Z0-9]/_/g;
300 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
301 $label = substr($label,0,8);
302 if ($label =~ /^([a-z])([a-z]*)$/) { # could be reserved word
305 $first =~ y/a-z/A-Z/; # so capitalize it
306 $label = $first . $rest;
330 if ($printit) { print;} else { $printit++ unless $nflag; }
338 <<--#ifdef APPENDSEEN
339 if ($atext) {print $atext; $atext = \'\';}
350 $command = $space . '$atext .=' . "\n<<--'";
355 unless (s|\\$||) { $lastline = 1;}
357 s/^([ \t]*\n)/<><>$1/;
362 $_ = $command . "';";
367 if (/^c/) { $change = 1; }
368 $addr1 = '$iter = (' . $addr1 . ')';
369 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
374 unless (s/\\$//) { $lastline = 1;}
376 s/^([ \t]*\n)/<><>$1/;
381 $_ = $command . "';}";
387 $space\$printit = '';
395 $delim = substr($_,1,1);
399 for ($i = 2; $i < $len; $i++) {
400 $c = substr($_,$i,1);
403 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
422 $_ = substr($_,0,--$len);
424 elsif (!$repl && substr($_,$i,1) =~ /^[(){}\w]$/) {
427 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
430 elsif ($c eq '[' && !$repl) {
431 $i++ if substr($_,$i,1) eq '^';
432 $i++ if substr($_,$i,1) eq ']';
438 elsif (!$repl && index("()+",$c) >= 0) {
439 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
444 do Die("Malformed substitution at line $.\n") unless $end;
445 $pat = substr($_, 0, $repl + 1);
446 $repl = substr($_, $repl + 1, $end - $repl - 1);
447 $end = substr($_, $end + 1, 1000);
451 $repl =~ s/[\\]([0-9])/$dol$1/g;
452 $subst = "$pat$repl$delim";
455 if ($end =~ s/^g//) { $subst .= 'g'; next; }
456 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
457 if ($end =~ s/^w[ \t]*//) {
458 $fh = do make_filehandle($end);
459 $cmd .= " && (print $fh \$_)";
463 do Die("Unrecognized substitution command ($end) at line $.\n");
467 $subst && \$tflag++$cmd;
481 $fh = do make_filehandle($_);
482 $_ = "print $fh \$_;";
490 $_ = "\$atext .= `cat $file 2>/dev/null`;";
495 $_ = 'print $1 if /(^.*\n)/;';
522 $_ = '$hold .= $_ ? $_ : "\n";';
532 $_ = '$_ .= $hold ? $hold : "\n";';
537 $_ = '($_, $hold) = ($hold, $_);';
548 $lab = do make_label($_);
549 if ($lab eq $toplabel) {
558 $_ = 'next line if $tflag;';
565 $lab = do make_label($_);
566 if ($lab eq $toplabel) {
567 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
569 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
576 $_ = 'print "$.\n";';
590 s/(\n)(.)/$1$space$2/g;
599 local($addr) = $outer;
601 local($prefix,$delim,$ch);
603 delim: while (s:^([^\]+(|)[\\/]*)([]+(|)[\\/])::) {
606 if ($delim eq '\\') {
609 $delim = '' if $ch =~ /^[(){}\w]$/;
612 elsif ($delim eq '[') {
614 s/^\^// && ($delim .= '^');
615 s/^]// && ($delim .= ']');
617 elsif ($delim eq ']') {
620 elsif ($inbracket || $delim ne $outer) {
621 $delim = '\\' . $delim;
625 if ($delim eq $outer && !$inbracket) {