#! perl eval "exec perl -S $0 $*" if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; # process any FOO=bar switches #! awk -f $[ = 1; # set array base to 1 $FALSE = 0; $TRUE = !$FALSE; $NOFIN =TRUE; if (!$NOFIN) { for ($i = 1; $i < ($#ARGV+1); $i++) { if ($ARGV[$i] =~ /^-/) { if ($ARGV[$i] =~ /\//) { $NOFIN = $TRUE; $ARGV[$i] =~ s/\///g; } if ($ARGV[$i] =~ /[fh]/) { $fin = $fin . ' ' . $ARGV[$i] . " \"" . $ARGV[$i + 1] . "\""; $ARGV[$i++] = ''; } else { $fin = $fin . ' ' . $ARGV[$i]; } $ARGV[$i] = ''; } } } $note_in = $FALSE; $nnum = 1; $fin = 'xtr -e'; line: while (<>) { chop; # strip record separator next if(($_ =~/^\.ig/) .. ($_ =~/^\.\./)); # fin 互換コマンド .ig 〜 .. if (/^\./) { &getdcmd($_); if ($dcmd eq 'nt{') { $note_in = $TRUE; &xprint(sprintf('(注%2d)', $nnum, $FALSE)); $note{$nnum} = ''; next line; } elsif ($dcmd eq '}') { $note_in = $FALSE; $note{$nnum} =~ s/^\n//; ++$nnum; next line; } elsif ($dcmd eq 'nt') { &xprint(sprintf('(注%2d)', $nnum, $FALSE)); $note{$nnum++} = &Getline1(); next line; } elsif ($dcmd eq 'pn') { &flushnote('(注%2d)', *note, $nnum); $nnum = 1; next line; } } if ($note_in) { $note{$nnum} = $note{$nnum} . "\n" . $_; $s = "\t", $note{$nnum} =~ s/$s//g; next line; } &xprint($_, $TRUE); #$Header: RCS/notes.awk 1.6 92/02/12 04:08:32 Kouzuka Exp $ } &flushnote($npform, *note, $nnum); sub flushnote { local($form, *note, $n, $i) = @_; if ($n < 2) { return; } # &xprint("[note]\n", $TRUE); &xprint("\n【注】\n", $TRUE); &xprint('.i5', $TRUE); for ($i = 1; $i < $n; $i++) { $note{$i} =~ s/^\n/.br\n/; if ($note{$i} =~ /^$/) { $note{$i} = '.br'; } elsif ($note{$i} !~ /^\./) { # $note{$i} = "\\" . $note{$i}; $note{$i} = " " . $note{$i}; } &xprint('.$1 i-5', $TRUE); &xprint(sprintf('注%2d', $i, $TRUE)); &xprint($note{$i}, $TRUE); } &xprint('.i0', $TRUE); } sub xprint { local($line, $nl_flag) = @_; if ($NOFIN) { printf (($line . ($nl_flag ? "\n" : ''))); } else { &Pick('|', $fin) && (printf $fh ($line . ($nl_flag ? "\n" : ''))); } } sub getdcmd { local($line) = @_; $line =~ s/^\.[ \t]*//; $line =~ /^[^ \t]+/ && ($RLENGTH = length($&), $RSTART = length($`)+1); $dcmd = substr($line, 1, $RLENGTH); $darg = substr($line, $RLENGTH + 1, 999999); $darg =~ s/^[ \t]*//; } sub Getline1 { local($_); if ($getline_ok = (($_ = <>) ne '')) { chop; # strip record separator } $_; } sub Pick { local($mode,$name,$pipe) = @_; $fh = $name; open($name,$mode.$name.$pipe) unless $opened{$name}++; }