ผู้
% sgmlcheck foo.sgml
ใน
ผู้
% sgml2txt -c latin foo.sgml
ถ้าfoo.txt
ในไดเ
ผู้
% sgml2html foo.sgml
ถ้าfoo.html
และ foo-1.html, foo-2.html, ...
ในไดเ-c latin
, เอก&LATIN_CHAR_NAME;
ให้cttex
มา
#!/usr/bin/perl
################################################################
# sgmlthtml:
# Run sgml2html and convert latin symbols to Thai characters.
# This program will change, for example, เ to "\340".
#
# by Poonlap Veeratanabutr <poon-v@fedu.uec.ac.jp>
# $Id: sgmlthtml,v 1.1 1998/09/28 06:51:52 poon-v Exp poon-v $
################################################################
sub error {
print STDERR "usage: $0 [-c] file.sgml\n";
print STDERR " -c , use cttex to fill <WBR>\n";
exit;
}
# command line processing.
if( $#ARGV == -1 ){
&error;
} elsif ( $#ARGV == 0 && $ARGV[0] ne "-c"){
$file = $ARGV[0];
$cut = 0;
} elsif ( $#ARGV == 1 ){
if( $ARGV[0] eq "-c"){
$cut = 1;
$file = $ARGV[1];
} elsif( $ARGV[1] eq "-c"){
$cut = 1;
$file = $ARGV[0];
} else {
&error;
}
} else {
&error;
}
# run sgml2html
if( system( "sgml2html $file" ) != 0 ){
exit;
}
# lookup table for what to change and not to change
%lookuptbl = (quot, "quot",amp,"amp","lt","lt","gt","gt",copy,"\251",reg,"\256",
micro,"\265",Agrave,"\300",Aacute,"\301",Acirc,"\302",Atilde,"\303",
Auml,"\304",Aring,"\305",AElig,"\306",Ccedil,"\307",Egrave,"\310",
Eacute,"\311",Ecirc,"\312",Euml,"\313",Igrave,"\314",Iacute,"\315",
Icirc,"\316",Iduml,"\317",ETH,"\320",eth,"\320",Ntilde,"\321",
Ograve,"\322",Oacute,"\323",Ocirc,"\324",Otilde,"\325",Ouml,"\326",
Oslash,"\330",Ugrave,"\331",Uacute,"\332",THORN,"THORN�",Thorn,"Thron",
szlig,"\337",agrave,"\340",aacute,"\341",acirc,"\342",atilde,"\343",
auml,"\344",aring,"\345",aelig,"\346",ccedil,"\347",egrave,"\350",
eacute,"\351",ecirc,"\352",euml,"\353",igrave,"\354",iacute,"\355",
icirc,"\356",iuml,"\357",eth,"\360",ntilde,"\361",ograve,"\362",
oacute,"\363",ocirc,"\364",otilde,"\365",ouml,"\366",oslash,"\370",
ugrave,"\371",uacute,"\372",ucirc,"\373",uuml,"uuml",yacute,"yacute",
yuml,"yuml");
# separate directory and file name from the given file name
if( $file =~ /(.*)[\/](.+)$/ ){
$dir = $1;
$file = $2;
}
$file =~ s/(.+)\.sgml/$1/; # get rootname
if( length( $dir ) == 0 ){
opendir( DIR, ".");
} else {
opendir( DIR, "$dir" );
}
@html = grep {/$file.*\.html$/} readdir( DIR ); # get all related html files
closedir( DIR );
foreach $html_file (@html) {
print "Processing file $html_file\n";
open( INPUT, "$html_file");
open( OUTPUT,">$html_file.tmp" );
while( <INPUT> ){
$line = $_;
$beg = index( $line, "&");
$end = index( $line, ";");
while( $beg >= 0 && $end > $beg ){
$target = substr( $line, $beg+1, $end-$beg-1);
$thai = $lookuptbl{ $target };
if( $target eq $thai ){
$line = sprintf( "%s%s%s", substr( $line, 0, $beg), '&' . $thai . ';',
substr( $line, $end+1 ));
} else {
$line = sprintf( "%s%s%s", substr( $line, 0, $beg), $thai,
substr( $line, $end+1 ));
}
$beg = index( $line, "&", $beg+1);
$end = index( $line, ";", $beg);
}
print OUTPUT "$line";
}
close( INPUT );
close( OUTPUT );
if( $cut == 1 ){
system( "cttex 0 < $html_file.tmp > $html_file" );
system( "rm -f $html_file.tmp" );
} else {
rename( "$html_file.tmp", "$html_file");
}
}
# EOF
ผู้sgmlthtml
แทน sgml2html
สำหรับ
% sgmlthtml foo.sgml -c
จากsgmlthtml
จะsgml2html
ซึ่งsgmlthtml
จะ&LATIN_CHAR_NAME;
ให้sgml2html
จะcttex
มาfoo.sgml
)
ให้cttex
อยู่cttex
ตัด-c
ดัง
% sgmlthtml foo.sgml
ผู้
ผู้.tex
) ที่
% sgml2latex --output=tex foo.sgml
จากsgml2latex
จะfoo.tex
ในไดเcttex
และ latex
ต่อ
ผู้foo.tex
\usepackage[latin1]{inputenc}
\usepackage{t1enc}
\usepackage{babel}
และ
\usepackage{thai}
จากcttex
และ latex
ตาม
% cttex < foo.tex > foo_ok.tex
% latex foo_ok.tex
จะsgmltlatex
ทำ
#!/usr/bin/perl
###############################################################################
# sgmltlatex:
# Processing SGML or LaTeX file for Thai language.
#
#
# by Poonlap Veeratanabutr <poon-v@fedu.uec.ac.jp>
# $Id: sgmltools.sgml,v 1.1 1998/09/28 11:26:44 poon-v Exp poon-v $
###############################################################################
sub error {
print STDERR "$0 - Processing SGML or LaTeX file for Thai language.\n";
print STDERR "usage: $0 [-[t|d|p] sgml_file] [-l latex_file] \n";
print STDERR " -t , create latex_file file from sgml_file\n";
print STDERR " -d , create dvi file from sgml_file and leave latex_file\n";
print STDERR " -p , create Postscript file and leave latex_file\n";
print STDERR " -l , run latex on latex_file\n";
exit( -1 );
}
# command line processing
if( $#ARGV != 1 ){
&error;
} elsif ( $ARGV[0] eq "-l" ){
$option = "l";
} elsif ( $ARGV[0] eq "-t" ){
$option = "t";
} elsif ( $ARGV[0] eq "-d" ){
$option = "d";
} elsif ( $ARGV[0] eq "-p" ){
$option = "p";
} else {
&error;
}
$file = $ARGV[1];
$tempfile = "$file" . ".tmp";
if( $option ne "l" ){
if( system( "sgml2latex --output=tex $file" ) != 0 ){
exit( -1 );
}
# separate directory and file name from the given file name
if( $file =~ /(.*)[\/](.+)$/ ){
$dir = $1;
$file = $2;
}
if( $file =~ m/(.+)\.sgml$/ ){
$rootname = "$1";
} else {
$rootname = $file;
}
$file = $rootname . ".tex";
print "Processing file $file\n";
open( INPUT, "$file" );
open( OUTPUT, ">" . "$tempfile" );
$preamble = 1;
while( <INPUT> ){
if( $preamble == 1 ){
if( /^\\begin\s*{\s*document\s*}\s*$/ ){
print OUTPUT "\\usepackage{thai}\n";
$preamble = 0;
break;
}
s/^\\usepackage.*{\s*inputenc.*}\n//;
s/^\\usepackage.*{\s*babel.*}\n//;
s/^\\usepackage.*{\s*t1enc.*}\n//;
print OUTPUT;
} else {
print OUTPUT;
}
}
close( INPUT );
close( OUTPUT );
} else {
unless( $file =~ m/(.+)\.tex$/ ){
print STDERR "$0 needs .tex file\n";
&error;
}
rename( "$file", "$tempfile" );
}
if( $option eq "t" ){
rename( "$tempfile", "$file" );
exit( 0 );
} else {
system( "cttex < $tempfile > $file" );
system( "latex $file" );
rename( "$tempfile", "$file" );
}
if( $option eq "p" ){
$psfile = "$rootname" . ".ps";
$dvifile = "$rootname" . ".dvi";
system( "dvips -o $psfile $dvifile" );
}
exit( 0 );
#EOF
ผู้sgmltlatex
แทน sgml2latex
สำหรับ.dvi
,
% sgmltlatex -d foo.sgml
หากfoo.dvi
ในไดเ
% sgmltlatex -p foo.sgml
หรือ.tex
) ให้
% sgmltlatex -t foo.sgml
ในd
" หรือ "p
" หรือ "t
"
จะ.tex
) ด้วย. ผู้foo.tex
แล้ว