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.1 89/11/11 05:08:25 lwall Locked $
34 # Revision 3.0.1.1 89/11/11 05:08:25 lwall
35 # patch2: in s2p, + within patterns needed backslashing
36 # patch2: s2p was printing out some debugging info to the output file
38 # Revision 3.0 89/10/18 15:35:02 lwall
41 # Revision 2.0.1.1 88/07/11 23:26:23 root
42 # patch2: s2p didn't put a proper prologue on output script
44 # Revision 2.0 88/06/05 00:15:55 root
45 # Baseline version 2.0.
54 while ($ARGV[0] =~ '^-') {
70 die "I don't recognize this switch: $_\n";
74 open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
77 if (!$assumen && !$assumep) {
79 'while ($ARGV[0] =~ /^-/) {
86 die "I don\'t recognize this switch: $_\\n";
97 $printit++ unless $nflag;
107 $label = do make_label($_);
112 if ($lastlinewaslabel++) {$_ .= "\t;";}
119 $lastlinewaslabel = '';
130 $addr1 = do fetchpat('/');
138 $addr2 = do fetchpat('/');
140 do Die("Invalid second address at line $.\n");
142 $addr1 .= " .. $addr2";
144 # a { to keep vi happy
152 $else = "$r else $l\n";
157 if (s/^{//) { # a } to keep vi happy
164 if ($addr2 || $addr1) {
165 $space = ' ' x $shiftwidth;
169 $_ = do transmogrify();
173 if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
174 $_ !~ / if / && $_ !~ / unless /) {
176 $_ = substr($_,$shiftwidth,1000);
179 $_ = "$if ($addr1) $l\n$change$command$rmaybe";
185 @lines = split(/\n/,$_);
186 while ($#lines >= 0) {
188 unless (s/^ *<<--//) {
189 print body "\t" x ($indent / 8), ' ' x ($indent % 8);
203 if ($appendseen || $tseen || !$assumen) {
204 $printit++ if $dseen || (!$assumen && !$assumep);
212 if ($printit) { print;} else { $printit++ unless $nflag; }
224 if ($atext) { print $atext; $atext = \'\'; }
233 open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
234 print head "#define PRINTIT\n" if ($printit);
235 print head "#define APPENDSEEN\n" if ($appendseen);
236 print head "#define TSEEN\n" if ($tseen);
237 print head "#define DSEEN\n" if ($dseen);
238 print head "#define ASSUMEN\n" if ($assumen);
239 print head "#define ASSUMEP\n" if ($assumep);
240 if ($opens) {print head "$opens\n";}
241 open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
248 eval \"exec $bin/perl -S \$0 \$*\"
249 if \$running_under_some_shell;
252 open(body,"cc -E /tmp/sperl2$$.c |") ||
253 do Die("Can't reopen temp file");
262 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
265 unlink "/tmp/sperl$$", "/tmp/sperl2$$";
268 sub make_filehandle {
272 if (/^([a-z])([a-z]*)$/) {
275 $first =~ y/a-z/A-Z/;
279 $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
286 $label =~ s/[^a-zA-Z0-9]/_/g;
287 if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
288 $label = substr($label,0,8);
289 if ($label =~ /^([a-z])([a-z]*)$/) { # could be reserved word
292 $first =~ y/a-z/A-Z/; # so capitalize it
293 $label = $first . $rest;
317 if ($printit) { print;} else { $printit++ unless $nflag; }
325 <<--#ifdef APPENDSEEN
326 if ($atext) {print $atext; $atext = \'\';}
337 $command = $space . '$atext .=' . "\n<<--'";
342 unless (s|\\$||) { $lastline = 1;}
344 s/^([ \t]*\n)/<><>$1/;
349 $_ = $command . "';";
354 if (/^c/) { $change = 1; }
355 $addr1 = '$iter = (' . $addr1 . ')';
356 $command = $space . 'if ($iter == 1) { print' . "\n<<--'";
361 unless (s/\\$//) { $lastline = 1;}
363 s/^([ \t]*\n)/<><>$1/;
368 $_ = $command . "';}";
374 $space\$printit = '';
382 $delim = substr($_,1,1);
386 for ($i = 2; $i < $len; $i++) {
387 $c = substr($_,$i,1);
390 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
409 $_ = substr($_,0,--$len);
411 elsif (!$repl && substr($_,$i,1) =~ /^[(){}\w]$/) {
414 $_ = substr($_,0,$i) . substr($_,$i+1,10000);
417 elsif ($c eq '[' && !$repl) {
418 $i++ if substr($_,$i,1) eq '^';
419 $i++ if substr($_,$i,1) eq ']';
425 elsif (!$repl && index("()+",$c) >= 0) {
426 $_ = substr($_,0,$i) . '\\' . substr($_,$i,10000);
431 do Die("Malformed substitution at line $.\n") unless $end;
432 $pat = substr($_, 0, $repl + 1);
433 $repl = substr($_, $repl + 1, $end - $repl - 1);
434 $end = substr($_, $end + 1, 1000);
438 $repl =~ s/[\\]([0-9])/$dol$1/g;
439 $subst = "$pat$repl$delim";
442 if ($end =~ s/^g//) { $subst .= 'g'; next; }
443 if ($end =~ s/^p//) { $cmd .= ' && (print)'; next; }
444 if ($end =~ s/^w[ \t]*//) {
445 $fh = do make_filehandle($end);
446 $cmd .= " && (print $fh \$_)";
450 do Die("Unrecognized substitution command ($end) at line $.\n");
454 $subst && \$tflag++$cmd;
468 $fh = do make_filehandle($_);
469 $_ = "print $fh \$_;";
477 $_ = "\$atext .= `cat $file 2>/dev/null`;";
482 $_ = 'print $1 if /(^.*\n)/;';
509 $_ = '$hold .= $_ ? $_ : "\n";';
519 $_ = '$_ .= $hold ? $hold : "\n";';
524 $_ = '($_, $hold) = ($hold, $_);';
535 $lab = do make_label($_);
536 if ($lab eq $toplabel) {
545 $_ = 'next line if $tflag;';
552 $lab = do make_label($_);
553 if ($lab eq $toplabel) {
554 $_ = 'if ($tflag) {$tflag = \'\'; redo line;}';
556 $_ = "if (\$tflag) {\$tflag = ''; goto $lab;}";
563 $_ = 'print "$.\n";';
577 s/(\n)(.)/$1$space$2/g;
586 local($addr) = $outer;
588 local($prefix,$delim,$ch);
590 delim: while (s:^([^\]+(|)[\\/]*)([]+(|)[\\/])::) {
593 if ($delim eq '\\') {
596 $delim = '' if $ch =~ /^[(){}\w]$/;
599 elsif ($delim eq '[') {
601 s/^\^// && ($delim .= '^');
602 s/^]// && ($delim .= ']');
604 elsif ($delim eq ']') {
607 elsif ($inbracket || $delim ne $outer) {
608 $delim = '\\' . $delim;
612 if ($delim eq $outer && !$inbracket) {