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 -s ../config.sh . || \
11 ln ../../config.sh . || \
12 ln ../../../config.sh . || \
13 (echo "Can't find config.sh."; exit 1)
18 echo "Extracting s2p (with variable substitutions)"
19 : This section of the file will have variable substitutions done on it.
20 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
21 : Protect any dollar signs and backticks that you do not want interpreted
22 : by putting a backslash in front. You may delete these comments.
23 $spitshell >s2p <<!GROK!THIS!
29 : In the following dollars and backticks do not need the extra backslash.
30 $spitshell >>s2p <<'!NO!SUBS!'
32 # $Header: s2p.SH,v 3.0.1.7 91/01/11 18:36:44 lwall Locked $
35 # Revision 3.0.1.7 91/01/11 18:36:44 lwall
36 # patch42: x2p/s2p.SH blew up on /afs misfeature
38 # Revision 3.0.1.6 90/10/20 02:21:43 lwall
39 # patch37: changed some ". config.sh" to ". ./config.sh"
41 # Revision 3.0.1.5 90/10/16 11:32:40 lwall
42 # patch29: s2p modernized
44 # Revision 3.0.1.4 90/08/09 05:50:43 lwall
45 # patch19: s2p didn't translate \n right
47 # Revision 3.0.1.3 90/03/01 10:31:21 lwall
48 # patch9: s2p didn't handle \< and \>
50 # Revision 3.0.1.2 89/11/17 15:51:27 lwall
51 # patch5: in s2p, line labels without a subsequent statement were done wrong
52 # patch5: s2p left residue in /tmp
54 # Revision 3.0.1.1 89/11/11 05:08:25 lwall
55 # patch2: in s2p, + within patterns needed backslashing
56 # patch2: s2p was printing out some debugging info to the output file
58 # Revision 3.0 89/10/18 15:35:02 lwall
61 # Revision 2.0.1.1 88/07/11 23:26:23 root
62 # patch2: s2p didn't put a proper prologue on output script
64 # Revision 2.0 88/06/05 00:15:55 root
65 # Baseline version 2.0.
73 while ($ARGV[0] =~ /^-/) {
89 die "I don't recognize this switch: $_\n";
93 open(BODY,">/tmp/sperl$$") ||
94 &Die("Can't open temp file: $!\n");
97 if (!$assumen && !$assumep) {
99 while ($ARGV[0] =~ /^-/) {
106 die "I don't recognize this switch: $_\\n";
118 $printit++ unless $nflag;
126 # Wipe out surrounding whitespace.
130 # Perhaps it's a label/comment.
134 $label = &make_label($_);
139 if ($lastlinewaslabel++) {
141 print BODY &tab, ";\n";
150 $lastlinewaslabel = '';
153 # Look for one or two address clauses
164 $addr1 = &fetchpat('/');
172 $addr2 = &fetchpat('/');
174 &Die("Invalid second address at line $.\n");
176 $addr1 .= " .. $addr2";
179 # Now we check for metacommands {, }, and ! and worry
183 # a { to keep vi happy
190 $else = "$r else $l\n";
195 if (s/^{//) { # a } to keep vi happy
202 if ($addr2 || $addr1) {
203 $space = ' ' x $shiftwidth;
207 $_ = &transmogrify();
210 # See if we can optimize to modifier form.
213 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
214 $_ !~ / if / && $_ !~ / unless /) {
216 $_ = substr($_,$shiftwidth,1000);
218 $_ = "$if ($addr1) $l\n$change$_$rmaybe";
224 @lines = split(/\n/,$_);
226 unless (s/^ *<<--//) {
239 if ($lastlinewaslabel++) {
241 print BODY &tab, ";\n";
246 if ($appendseen || $tseen || !$assumen) {
247 $printit++ if $dseen || (!$assumen && !$assumep);
259 { $printit++ unless $nflag; }
271 if ($atext) { print $atext; $atext = ''; }
280 open(HEAD,">/tmp/sperl2$$.c")
281 || &Die("Can't open temp file 2: $!\n");
282 print HEAD "#define PRINTIT\n" if ($printit);
283 print HEAD "#define APPENDSEEN\n" if ($appendseen);
284 print HEAD "#define TSEEN\n" if ($tseen);
285 print HEAD "#define DSEEN\n" if ($dseen);
286 print HEAD "#define ASSUMEN\n" if ($assumen);
287 print HEAD "#define ASSUMEP\n" if ($assumep);
288 if ($opens) {print HEAD "$opens\n";}
289 open(BODY,"/tmp/sperl$$")
290 || &Die("Can't reopen temp file: $!\n");
298 eval 'exec $bin/perl -S \$0 \$*'
299 if \$running_under_some_shell;
302 open(BODY,"cc -E /tmp/sperl2$$.c |") ||
303 &Die("Can't reopen temp file: $!\n");
317 unlink "sperl$$", "sperl2$$", "sperl2$$.c";
324 "\t" x ($indent / 8) . ' ' x ($indent % 8);
326 sub make_filehandle {
331 substr($_,0,1) =~ y/a-z/A-Z/ if /^[a-z]/;
334 open($_,'>$fname') || die "Can't create $fname";
342 $label =~ s/[^a-zA-Z0-9]/_/g;
343 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
344 $label = substr($label,0,8);
346 # Could be a reserved word, so capitalize it.
347 substr($label,0,1) =~ y/a-z/A-Z/
348 if $label =~ /^[a-z]/;
376 { $printit++ unless $nflag; }
384 <<--#ifdef APPENDSEEN
385 if ($atext) {print $atext; $atext = '';}
397 $command = $space . '$atext .=' . "\n<<--'";
402 unless (s|\\$||) { $lastline = 1;}
404 s/^([ \t]*\n)/<><>$1/;
409 $_ = $command . "';";
414 if (/^c/) { $change = 1; }
415 $addr1 = '$iter = (' . $addr1 . ')';
416 $command = $space . 'if ($iter == 1) { print'
422 unless (s/\\$//) { $lastline = 1;}
424 s/^([ \t]*\n)/<><>$1/;
429 $_ = $command . "';}";
435 $space\$printit = '';
444 $delim = substr($_,1,1);
448 for ($i = 2; $i < $len; $i++) {
449 $c = substr($_,$i,1);
452 substr($_, $i, 0) = '\\';
471 $_ = substr($_,0,--$len);
473 elsif (substr($_,$i,1) =~ /^[n]$/) {
477 substr($_,$i,1) =~ /^[(){}\w]$/) {
480 substr($_, $i, 1) = '';
483 substr($_,$i,1) =~ /^[<>]$/) {
484 substr($_,$i,1) = 'b';
487 elsif ($c eq '[' && !$repl) {
488 $i++ if substr($_,$i,1) eq '^';
489 $i++ if substr($_,$i,1) eq ']';
495 elsif (!$repl && index("()+",$c) >= 0) {
496 substr($_, $i, 0) = '\\';
501 &Die("Malformed substitution at line $.\n")
503 $pat = substr($_, 0, $repl + 1);
504 $repl = substr($_, $repl+1, $end-$repl-1);
505 $end = substr($_, $end + 1, 1000);
509 $repl =~ s/[\\]([0-9])/$dol$1/g;
510 $subst = "$pat$repl$delim";
513 if ($end =~ s/^g//) {
517 if ($end =~ s/^p//) {
518 $cmd .= ' && (print)';
521 if ($end =~ s/^w[ \t]*//) {
522 $fh = &make_filehandle($end);
523 $cmd .= " && (print $fh \$_)";
527 &Die("Unrecognized substitution command".
528 "($end) at line $.\n");
532 $subst && \$tflag++$cmd;
547 $fh = &make_filehandle($_);
548 $_ = "print $fh \$_;";
556 $_ = "\$atext .= `cat $file 2>/dev/null`;";
561 $_ = 'print $1 if /(^.*\n)/;';
590 $_ = '$hold .= $_ ? $_ : "\n";';
600 $_ = '$_ .= $hold ? $hold : "\n";';
605 $_ = '($_, $hold) = ($hold, $_);';
616 $lab = &make_label($_);
617 if ($lab eq $toplabel) {
626 $_ = 'next LINE if $tflag;';
633 $lab = &make_label($_);
634 $_ = q/if ($tflag) {$tflag = ''; /;
635 if ($lab eq $toplabel) {
645 $_ = 'print "$.\n";';
660 s/(\n)(.)/$1$space$2/g;
669 local($addr) = $outer;
671 local($prefix,$delim,$ch);
673 # Process pattern one potential delimiter at a time.
675 DELIM: while (s#^([^\]+(|)[\\/]*)([]+(|)[\\/])##) {
678 if ($delim eq '\\') {
681 $delim = '' if $ch =~ /^[(){}A-Za-mo-z]$/;
682 $ch = 'b' if $ch =~ /^[<>]$/;
685 elsif ($delim eq '[') {
687 s/^\^// && ($delim .= '^');
688 s/^]// && ($delim .= ']');
690 elsif ($delim eq ']') {
693 elsif ($inbracket || $delim ne $outer) {
694 $delim = '\\' . $delim;
698 if ($delim eq $outer && !$inbracket) {