Newsgroups: fj.comp.texhax
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!news.u-tokyo.ac.jp!newssinet!euclides.josai.ac.jp!yamasaki
From: yamasaki@euclides.josai.ac.jp (Masayuki Yamasaki)
Subject: Re: src2lines-tex^^;)
Message-ID: <D79BLv.9CM@euclides.josai.ac.jp>
Lines: 172
Sender: yamasaki@euclides.josai.ac.jp (Masayuki Yamasaki)
Organization: Josai University
X-Newsreader: mnews [version 1.17] 1994-01/27(Thu)
References: <AZUKI.95Apr17231711@mira.is.uec.ac.jp>
Distribution: fj
Date: Wed, 19 Apr 1995 00:49:06 GMT
Xref: galaxy.trc.rwcp.or.jp fj.comp.texhax:6148
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.comp.texhax&nb=6148&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

src2tex $B3+H/6(NO<T$N;3:j!w>k@>?t3X$G$9!#(B
$B2<$KIU$1$?$h$&$J(BPerl$B%9%/%j%W%H$O!"$I$&$G$7$g$&!#(B

>    1$BKg$N%Z!<%8$K=PNO$9$k9T?t$r%Q%i%a!<%?$G;XDj$G$-$k(B
>    $B9TF,$K9THV9f$rIU2C$9$k(B

$B$K$O$J$s$H$+BP1~$7$F$$$^$9!##A#4$G$O#7#09TDxEY0u:~$G$-$^$9!#(B
$BD9$$9T$N@^$jJV$7$,$G$-$J$$$N$G!"#2%+%i%`$J$I$K$OJQ99$,$`$:$+$7$$$G$9!#(B
$B$"$:$-$5$s$K%a!<%k$G$*Aw$j$7$?$b$N$N%P%0$r8:$i$7$?$N$G!"Ej9F$7$F$_$^$9!#(B
$B;HMQ$9$k(B TeX $B%W%m%0%i%`L>$dBh#19TL\$r<+J,$N4D6-$K$"$o$;$F$+$i!"$*;H$$2<$5$$!#(B

$B;3:j!!@5G7(B
yamasaki@euclides.josai.ac.jp
myamasa@tansei.cc.u-tokyo.ac.jp
------------------ cut here -----------------
#!/usr/bin/jperl
# s2d     by Masayuki Yamasaki      April 19, 1995
# 
# s2d filename.ext $B$G(B filename.ext $B$+$i(B filename.tex $B$r:n$j!"(B
# $B$5$i$K(B tex $B$r8F$S=P$7(B filename.dvi $B%U%!%$%k$r:n$j$^$9!#(B
# 
# tex $B$K$+$1$k$H$-!"(Bs2d.st $B$H$$$&%U%!%$%k$,%+%l%s%H!&%G%#%l%/%H%j$K$"(B
# $B$l$P!"$^$:$=$N%U%!%$%k$r(B \input $B$7$^$9!#(B\magnification, \hsize, \vsize
# $B$J$I$O$3$N%U%!%$%k$NCf$G@_Dj$G$-$^$9!#(B
# s2d $B$G$O$H$j$"$($:!"K\J8$O$9$Y$F(B \tt$B!J%?%$%W%i%$%?!<!&%?%$%W!K$r;HMQ$7$F(B
# $B$$$^$9!#(B
# 
# $B%*%W%7%g%s!'(B
#  o -$B<+A3?t(B  $B#1%Z!<%8$N9T?t$N;XDj!J%G%U%)!<%k%H$O(B52$B!K(B
#  o -y       non-default$B!J1_%^!<%/!K$N(B \ $B$r;HMQ(B
#
# $BCm0U!'(B
#  o jtex $B$r$*;H$$$N>l9g$O(B $tex = 'jtex' $B$H$7$F$/$@$5$$!#(B
#  o $B%U%!%$%k$N3HD%;R$,(B .tex $B$N$H$-$O0z?t$r$b$&$R$H$D$D$1$F$/$@$5$$!#$=$l(B
#    $B$,:n$i$l$k(B tex $B%U%!%$%k$NL>A0$K$J$j$^$9!#$/$l$0$l$bF1$8L>A0$r;XDj$7$J(B
#    $B$$$h$&$K$7$F$/$@$5$$!#(B
#  o $BB?$9$.$k0z?t$OL5;k$5$l$^$9!#(B
#  o DOS $B$G$O(B exexe $B$J$I$N%9%/%j%W%H<B9T4D6-$r@0$($F$*$/$HJXMx$G$9!#(B
#  o jperl version 4.036 + 1.4 $B$G$NF0:n$r3NG'$7$F$$$^$9!#!!8E$$(B jperl $B$G$N(B
#    $B8mF0:n$b3NG'$7$F$$$^$9(B(^^;;;
#
$tex = 'tex';               # TeX program name 
$tabsize = 8;               # TAB width
$num_lines = 52;            # default number of lines per page
$stylefile = 's2d.st';      # stylefile name
@bsl = ('\\char92 ', 'Y\\llap='); # default of backslash and an alternative
$ibsl = 0;  # index for backslash; choosing \char92 as the deault
#$ibsl = 0;  # index for backslash; choosing 'yen' mark as the deault

# remove extension from filename
sub rmext
{   
    local($fname) = @_;
    local($name) = ($fname =~ m/^([^.]+)/ );
    return($name);
}

# TAB --> spaces  ( use the variable $tabsize )
sub expand_tab {
    local($string) = @_;
    local($num);
    local($spaces);
    while ( $string =~ /^([^\t]*)\t/ ) {
        $num = $tabsize - (length($1) % $tabsize);
        $spaces = ' ' x $num;
        $string =~ s/^([^\t]*)\t/$1$spaces/;
    }
    return $string;
}

# string -> tt   (presumes that there are no TABs)
sub strtott
{
    local($string) = @_;
    $string =~ s/~/\t/g;             # save ~ as \t
    $string =~ s/ /~/g;              # space
    $string =~ s/\\/$bsl[$ibsl]/g;   # \
    $string =~ s/#/\\char35 /g;      # #
    $string =~ s/\$/\\char36 /g;     # $
    $string =~ s/%/\\char37 /g;      # %
    $string =~ s/&/\\char38 /g;      # &
    $string =~ s/\^/\\char94 /g;     # ^
    $string =~ s/_/\\char95 /g;      # _
    $string =~ s/{/\\char123 /g;     # {
    $string =~ s/}/\\char125 /g;     # }
    $string =~ s/\t/\\char126 /g;    # restore ~
    $string =  "\\tt{}". $string;
    return($string);
}

# Usage:
sub usage {
    die "Usage: s2d [options] filename
       s2d [options] texfile newtexfile
Options: -n: number of lines per page (>>1),  default=52
         -y: use 'yen' instead of 'backslash'\n";
}

# getting options
while (1) {
    ($op = shift) || &usage;
    ($op =~ /^-y$/) && do {
        $ibsl = 1 - $ibsl;
        next;
    };
    ($op =~ /^-(.*)$/ ) && do {
        ($1 <= 0) && &usage;
        ($1 >  0) && ($num_lines = $1);
        next;
    };
    unshift(@ARGV, $op);
    last;
}

# getting filename(s)
$srcfile = shift;
if ($srcfile =~ /\.[Tt][Ee][Xx]$/) {
    ($texfile = shift) || &usage;
} else {
    $texfile = &rmext($srcfile) . ".tex";
}

print STDERR "TAB size = $tabsize\n";
print STDERR "$srcfile --> $texfile\n";

open (SRC, $srcfile) || die "Can't open $srcfile: $!\n";
open (TEX, ">$texfile") || die "Can't open $texfile: $!\n";

print TEX("\\footline={\\rm\\hfill $srcfile\\qquad page \\folio}\n\n");

# instruction to input the stylefile (when there is one)
print TEX("\\newread\\MyStyle
\\openin\\MyStyle=$stylefile
\\ifeof\\MyStyle
  \\closein\\MyStyle
\\else
  \\input $stylefile
  \\closein\\MyStyle
\\fi\n\n");

$k = 0;
while (<SRC>) {
    $_ = &expand_tab($_);
    print TEX "\\vbox to \\vsize{\n" if ( $k % $num_lines == 0);
    $k++;
    print TEX "\\hbox{\\tt ";
    printf(TEX "%04d: ", $k);
    print TEX &strtott($_);
    print TEX "}\n";
    if ($k % $num_lines != 0 ) {
        print TEX "\\vss\n";
    } else {
        print TEX "}\n\\vfill\\eject\n";
    }
}

$j = $k % $num_lines;
if ($j != 0) {
    while ($j < $num_lines) {
        print TEX "\\hbox{ }\n\\vss\n";
        $j++;
    }
    print TEX "\\hbox{ }}\n";
}

print TEX "\\bye\n";
close TEX;
close SRC;

print STDERR "$tex $texfile\n";
exec "$tex $texfile";
------------------ cut here -----------------
