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 89/10/18 15:35:02 lwall Locked $
34 # Revision 3.0 89/10/18 15:35:02 lwall
37 # Revision 2.0.1.1 88/07/11 23:26:23 root
38 # patch2: s2p didn't put a proper prologue on output script
40 # Revision 2.0 88/06/05 00:15:55 root
41 # Baseline version 2.0.
50 while ($ARGV[0] =~ '^-') {
66 die "I don't recognize this switch: $_\n";
70 open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
73 if (!$assumen && !$assumep) {
75 'while ($ARGV[0] =~ /^-/) {
82 die "I don\'t recognize this switch: $_\\n";
93 $printit++ unless $nflag;
103 $label = do make_label($_);
108 if ($lastlinewaslabel++) {$_ .= "\t;";}
115 $lastlinewaslabel = '';
126 $addr1 = do fetchpat('/');
134 $addr2 = do fetchpat('/');
136 do Die("Invalid second address at line $.\n");
138 $addr1 .= " .. $addr2";
140 # a { to keep vi happy
148 $else = "$r else $l\n";
153 if (s/^{//) { # a } to keep vi happy
160 if ($addr2 || $addr1) {
161 $space = ' ' x $shiftwidth;
165 $_ = do transmogrify();
169 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
170 $_ !~ / if / && $_ !~ / unless /) {
172 $_ = substr($_,$shiftwidth,1000);
175 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
181 @lines = split(/\n/,$_);
182 while ($#lines >= 0) {
184 unless (s/^ *<<--//) {
185 print body "\t" x ($indent / 8), ' ' x ($indent % 8);
199 if ($appendseen || $tseen || !$assumen) {
200 $printit++ if $dseen || (!$assumen && !$assumep);
208 if ($printit) { print;} else { $printit++ unless $nflag; }
220 if ($atext) { print $atext; $atext = \'\'; }
229 open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
230 print head "#define PRINTIT\n" if ($printit);
231 print head "#define APPENDSEEN\n" if ($appendseen);
232 print head "#define TSEEN\n" if ($tseen);
233 print head "#define DSEEN\n" if ($dseen);
234 print head "#define ASSUMEN\n" if ($assumen);
235 print head "#define ASSUMEP\n" if ($assumep);
236 if ($opens) {print head "$opens\n";}
237 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
244 eval \"exec $bin/perl -S \$0 \$*\"
245 if \$running_under_some_shell;
248 open(body,"cc -E /tmp/sperl2$$.c |") ||
249 do Die("Can't reopen temp file");
258 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
261 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
264 sub make_filehandle {
268 if (/^([a-z])([a-z]*)$/) {
271 $first =~ y/a-z/A-Z/;
275 $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
282 $label =~ s/[^a-zA-Z0-9]/_/g;
283 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
284 $label = substr($label,0,8);
285 if ($label =~ /^([a-z])([a-z]*)$/) { # could be reserved word
288 $first =~ y/a-z/A-Z/; # so capitalize it
289 $label = $first . $rest;
313 if ($printit) { print;} else { $printit++ unless $nflag; }
321 <<--#ifdef APPENDSEEN
322 if ($atext) {print $atext; $atext = \'\';}
333 $command = $space . '$atext .=' . "\n<<--'";
338 unless (s|\\$||) { $lastline = 1;}
340 s/^([ \t]*\n)/<><>$1/;
345 $_ = $command . "';";
350 if (/^c/) { $change = 1; }
351 $addr1 = '$iter = (' . $addr1 . ')';
352 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
357 unless (s/\\$//) { $lastline = 1;}
359 s/^([ \t]*\n)/<><>$1/;
364 $_ = $command . "';}";
370 $space\$printit = '';
378 $delim = substr($_,1,1);
382 for ($i = 2; $i < $len; $i++) {
383 $c = substr($_,$i,1);
386 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
405 $_ = substr($_,0,--$len);
407 elsif (!$repl && substr($_,$i,1) =~ /^[(){}\w]$/) {
410 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
413 elsif ($c eq '[' && !$repl) {
414 $i++ if substr($_,$i,1) eq '^';
415 $i++ if substr($_,$i,1) eq ']';
421 elsif (!$repl && index("()",$c) >= 0) {
422 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
427 do Die("Malformed substitution at line $.\n") unless $end;
428 $pat = substr($_, 0, $repl + 1);
429 $repl = substr($_, $repl + 1, $end - $repl - 1);
430 $end = substr($_, $end + 1, 1000);
434 $repl =~ s/[\\]([0-9])/$dol$1/g;
435 $subst = "$pat$repl$delim";
438 if ($end =~ s/^g//) { $subst .= 'g'; next; }
439 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
440 if ($end =~ s/^w[ \t]*//) {
441 $fh = do make_filehandle($end);
442 $cmd .= " && (print $fh \$_)";
446 do Die("Unrecognized substitution command ($end) at line $.\n");
450 $subst && \$tflag++$cmd;
464 $fh = do make_filehandle($_);
465 $_ = "print $fh \$_;";
473 $_ = "\$atext .= `cat $file 2>/dev/null`;";
478 $_ = 'print $1 if /(^.*\n)/;';
505 $_ = '$hold .= $_ ? $_ : "\n";';
515 $_ = '$_ .= $hold ? $hold : "\n";';
520 $_ = '($_, $hold) = ($hold, $_);';
531 $lab = do make_label($_);
532 if ($lab eq $toplabel) {
541 $_ = 'next line if $tflag;';
548 $lab = do make_label($_);
549 if ($lab eq $toplabel) {
550 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
552 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
559 $_ = 'print "$.\n";';
573 s/(\n)(.)/$1$space$2/g;
582 local($addr) = $outer;
584 local($prefix,$delim,$ch);
586 delim: while (s:^([^\](|)[\\/]*)([](|)[\\/])::) {
589 print "$prefix\t$delim\t$_\n";
590 if ($delim eq '\\') {
593 $delim = '' if $ch =~ /^[(){}\w]$/;
596 elsif ($delim eq '[') {
598 s/^\^// && ($delim .= '^');
599 s/^]// && ($delim .= ']');
600 print "$prefix\t$delim\t$_\n";
602 elsif ($delim eq ']') {
605 elsif ($inbracket || $delim ne $outer) {
607 $delim = '\\' . $delim;
611 if ($delim eq $outer && !$inbracket) {