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.3 90/03/01 10:31:21 lwall Locked $
34 # Revision 3.0.1.3 90/03/01 10:31:21 lwall
35 # patch9: s2p didn't handle \< and \>
37 # Revision 3.0.1.2 89/11/17 15:51:27 lwall
38 # patch5: in s2p, line labels without a subsequent statement were done wrong
39 # patch5: s2p left residue in /tmp
41 # Revision 3.0.1.1 89/11/11 05:08:25 lwall
42 # patch2: in s2p, + within patterns needed backslashing
43 # patch2: s2p was printing out some debugging info to the output file
45 # Revision 3.0 89/10/18 15:35:02 lwall
48 # Revision 2.0.1.1 88/07/11 23:26:23 root
49 # patch2: s2p didn't put a proper prologue on output script
51 # Revision 2.0 88/06/05 00:15:55 root
52 # Baseline version 2.0.
61 while ($ARGV[0] =~ '^-') {
77 die "I don't recognize this switch: $_\n";
81 open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
84 if (!$assumen && !$assumep) {
86 'while ($ARGV[0] =~ /^-/) {
93 die "I don\'t recognize this switch: $_\\n";
104 $printit++ unless $nflag;
114 $label = do make_label($_);
119 if ($lastlinewaslabel++) {
121 print body "\t" x ($indent / 8), ' ' x ($indent % 8), ";\n";
130 $lastlinewaslabel = '';
141 $addr1 = do fetchpat('/');
149 $addr2 = do fetchpat('/');
151 do Die("Invalid second address at line $.\n");
153 $addr1 .= " .. $addr2";
155 # a { to keep vi happy
163 $else = "$r else $l\n";
168 if (s/^{//) { # a } to keep vi happy
175 if ($addr2 || $addr1) {
176 $space = ' ' x $shiftwidth;
180 $_ = do transmogrify();
184 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
185 $_ !~ / if / && $_ !~ / unless /) {
187 $_ = substr($_,$shiftwidth,1000);
190 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
196 @lines = split(/\n/,$_);
197 while ($#lines >= 0) {
199 unless (s/^ *<<--//) {
200 print body "\t" x ($indent / 8), ' ' x ($indent % 8);
212 if ($lastlinewaslabel++) {
214 print body "\t" x ($indent / 8), ' ' x ($indent % 8), ";\n";
219 if ($appendseen || $tseen || !$assumen) {
220 $printit++ if $dseen || (!$assumen && !$assumep);
228 if ($printit) { print;} else { $printit++ unless $nflag; }
240 if ($atext) { print $atext; $atext = \'\'; }
249 open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
250 print head "#define PRINTIT\n" if ($printit);
251 print head "#define APPENDSEEN\n" if ($appendseen);
252 print head "#define TSEEN\n" if ($tseen);
253 print head "#define DSEEN\n" if ($dseen);
254 print head "#define ASSUMEN\n" if ($assumen);
255 print head "#define ASSUMEP\n" if ($assumep);
256 if ($opens) {print head "$opens\n";}
257 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
264 eval \"exec $bin/perl -S \$0 \$*\"
265 if \$running_under_some_shell;
268 open(body,"cc -E /tmp/sperl2$$.c |") ||
269 do Die("Can't reopen temp file");
278 unlink "/tmp/sperl$$", "/tmp/sperl2$$", "/tmp/sperl2$$.c";
281 unlink "/tmp/sperl$$", "/tmp/sperl2$$", "/tmp/sperl2$$.c";
284 sub make_filehandle {
288 if (/^([a-z])([a-z]*)$/) {
291 $first =~ y/a-z/A-Z/;
295 $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
302 $label =~ s/[^a-zA-Z0-9]/_/g;
303 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
304 $label = substr($label,0,8);
305 if ($label =~ /^([a-z])([a-z]*)$/) { # could be reserved word
308 $first =~ y/a-z/A-Z/; # so capitalize it
309 $label = $first . $rest;
333 if ($printit) { print;} else { $printit++ unless $nflag; }
341 <<--#ifdef APPENDSEEN
342 if ($atext) {print $atext; $atext = \'\';}
353 $command = $space . '$atext .=' . "\n<<--'";
358 unless (s|\\$||) { $lastline = 1;}
360 s/^([ \t]*\n)/<><>$1/;
365 $_ = $command . "';";
370 if (/^c/) { $change = 1; }
371 $addr1 = '$iter = (' . $addr1 . ')';
372 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
377 unless (s/\\$//) { $lastline = 1;}
379 s/^([ \t]*\n)/<><>$1/;
384 $_ = $command . "';}";
390 $space\$printit = '';
398 $delim = substr($_,1,1);
402 for ($i = 2; $i < $len; $i++) {
403 $c = substr($_,$i,1);
406 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
425 $_ = substr($_,0,--$len);
427 elsif (!$repl && substr($_,$i,1) =~ /^[(){}\w]$/) {
430 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
432 elsif (!$repl && substr($_,$i,1) =~ /^[<>]$/) {
433 substr($_,$i,1) = 'b';
436 elsif ($c eq '[' && !$repl) {
437 $i++ if substr($_,$i,1) eq '^';
438 $i++ if substr($_,$i,1) eq ']';
444 elsif (!$repl && index("()+",$c) >= 0) {
445 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
450 do Die("Malformed substitution at line $.\n") unless $end;
451 $pat = substr($_, 0, $repl + 1);
452 $repl = substr($_, $repl + 1, $end - $repl - 1);
453 $end = substr($_, $end + 1, 1000);
457 $repl =~ s/[\\]([0-9])/$dol$1/g;
458 $subst = "$pat$repl$delim";
461 if ($end =~ s/^g//) { $subst .= 'g'; next; }
462 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
463 if ($end =~ s/^w[ \t]*//) {
464 $fh = do make_filehandle($end);
465 $cmd .= " && (print $fh \$_)";
469 do Die("Unrecognized substitution command ($end) at line $.\n");
473 $subst && \$tflag++$cmd;
487 $fh = do make_filehandle($_);
488 $_ = "print $fh \$_;";
496 $_ = "\$atext .= `cat $file 2>/dev/null`;";
501 $_ = 'print $1 if /(^.*\n)/;';
528 $_ = '$hold .= $_ ? $_ : "\n";';
538 $_ = '$_ .= $hold ? $hold : "\n";';
543 $_ = '($_, $hold) = ($hold, $_);';
554 $lab = do make_label($_);
555 if ($lab eq $toplabel) {
564 $_ = 'next line if $tflag;';
571 $lab = do make_label($_);
572 if ($lab eq $toplabel) {
573 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
575 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
582 $_ = 'print "$.\n";';
596 s/(\n)(.)/$1$space$2/g;
605 local($addr) = $outer;
607 local($prefix,$delim,$ch);
609 delim: while (s:^([^\]+(|)[\\/]*)([]+(|)[\\/])::) {
612 if ($delim eq '\\') {
615 $delim = '' if $ch =~ /^[(){}\w]$/;
616 $ch = 'b' if $ch =~ /^[<>]$/;
619 elsif ($delim eq '[') {
621 s/^\^// && ($delim .= '^');
622 s/^]// && ($delim .= ']');
624 elsif ($delim eq ']') {
627 elsif ($inbracket || $delim ne $outer) {
628 $delim = '\\' . $delim;
632 if ($delim eq $outer && !$inbracket) {