1#!/usr/local/bin/tcsh
2#
3# plain2html:	plain text to HTML file
4#		by k-chinen@is.aist-nara.ac.jp , 1994
5#
6# NOTE:
7# 	* This script will be running under csh or tcsh.
8# 	* Handle with care for directory, because this script make
9#	  a lot of temporary file and output file.
10#
11
12
13#
14# require:
15#
16#    program:
17#	csh or tcsh
18#	plain2 ( have -html option verison )
19#	awk
20#	groff ( gtbl, gpic )
21#	latex or jlatex
22#	dvi2ps
23#	convert ( convertable PS to Any-format version )
24#	pnmcrop ( included PBMPLUS )
25#	ghostscript ( called by convert when convert PS format )
26#
27#    script:
28#	pt2htcol.awk ( included this packeage )
29#
30#
31# input:
32#	$1 (plain text file name.  e.g., README.j)
33#
34# output:
35#	$1:r.html  (e.g., README.html)
36#
37# temporary file:
38#	_src, _cut.sh , _out.html , pt2empty.sty, _tmp.pnm
39#	TBL*.p TBL*.ps TBL*.src TBL*.tex TBL*.dvi TBL*.pnm
40#	PIC*.p PIC*.ps PIC*.src PIC*.tex PIC*.dvi PIC*.pnm
41#
42
43
44#
45# Default values
46#
47set tex=1
48set roff=0
49set lib=/usr/local/lib/plain2
50
51
52#
53# Check args.
54#
55if ( $#argv > 0 ) then
56	switch ($1)
57	case -tex:
58		set tex=1
59		set roff=0
60		shift
61		breaksw
62	case -roff:
63		set tex=0
64		set roff=1
65		shift
66		breaksw
67	default:
68		breaksw
69	endsw
70endif
71
72if ( $#argv > 0 ) then
73	set target=$1
74else
75	cat << END_USAGE
76plain2html: plain text to HTML file
77	by k-chinen@is.aist-nara.ac.jp NAIST , 1994
78
79usage: plain2html [option] input-filename
80
81option:		-tex	TeX mode (use latex, dvi2ps) [defauts]
82		-roff	roff mode (use groff)
83
84END_USAGE
85	exit
86endif
87
88
89
90#
91# Start
92#	convert document's main body.
93#	collect table/picture location and cut these.
94#
95
96echo "Copy Target $target ."
97cp $target _src
98
99echo "Process document main body"
100plain2 -html -jis -here _src > _out.html
101
102echo "Collect Table/Picutre"
103awk -f $lib/pt2htcol.awk _out.html > _cut.sh
104
105
106
107#
108# Convert parts(table/picture) via LaTeX
109#	If you don't have jlatex substitute to "latex".
110#	( jlatex is Japanese LaTeX )
111#
112if ( $tex ) then
113cat << END_STYLEFILE > pt2empty.sty
114\\thispagestyle{empty}
115\\pagestyle{empty}
116END_STYLEFILE
117cat << END_TEX_CUT >> _cut.sh
118foreach i ( TBL*.p PIC*.p ) 
119	echo "Part \$i process"
120        plain2 -tex -jis -tstyle=pt2empty \$i > \$i:r.tex
121        jlatex \$i:r.tex
122        dvi2ps \$i:r.dvi > \$i:r.ps
123	convert -density 144x144 \$i:r.ps \$i:r.pnm
124	pnmcrop -white \$i:r.pnm > _tmp.pnm
125	convert _tmp.pnm \$i:r.gif
126	rm -f \$i:r.ps \$i:r.dvi \$i:r.aux \$i:r.log \$i:r.tex \$i:r.p \$i:r.pnm
127end
128END_TEX_CUT
129endif
130
131#
132# Convert parts(table/picture) via GROFF
133#	If you don't have gorff substitute to ROFF-like program.
134#
135if ( $roff ) then
136cat << END_ROFF_CUT >> _cut.sh
137foreach i ( TBL*.p PIC*.p ) 
138	echo "Part \$i process"
139	plain2 -roff -euc  \$i > \$i:r.src
140	groff -me -t -p \$i:r.src > \$i:r.ps
141	convert -density 144x144 \$i:r.ps \$i:r.pnm
142	pnmcrop -white \$i:r.pnm > _tmp.pnm
143	convert _tmp.pnm \$i:r.gif
144	rm -f \$i:r.ps \$i:r.src \$i:r.p \$i:r.pnm
145end
146END_ROFF_CUT
147endif
148
149#
150# Run parts conversion script
151#
152echo "Cut Table/Picture"
153$shell _cut.sh
154
155rm -f $target:r.html
156mv _out.html $target:r.html
157rm -f _cut.sh pt2empty.sty _src _tmp.pnm
158
159echo "Complete"
160