File: translate-docformat

package info (click to toggle)
translate-docformat 0.6-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 44 kB
  • ctags: 1
  • sloc: sh: 191; makefile: 43
file content (226 lines) | stat: -rwxr-xr-x 5,534 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash

#Translates doc format
#Copyright 2001 Junichi Uekawa
#distributed under GPL version 2.
#started 2001 Sep 16 by Junichi Uekawa <dancer@debian.org>
#$Id: translate-docformat,v 1.8 2002/05/20 06:50:19 dancer Exp $
# Depends: sgmltools-lite linuxdoc-tools debiandoc-sgml w3m|lynx tetex-bin
#          texinfo texi2html docbook-dsssl jadetex 


#targets are
#  txt = text
#  html = html file
#  mhtml = multiple html files
#  texinfo = texinfo file.
#  info = info file.
#  ps = ps file
#  pdf = pdf file
#  tex = latex2e
#  rtf = rich text format

function unsupportedformaterror () {
    echo Unsupported file format has been specified. "[$1]" >&2
    exit 1;
}

SOURCE="$1"
FORMAT="$2"
test -z "$LATEX" && LATEX="latex"
SOURCEDIR=$(dirname "$SOURCE")

if [ -z "$FORMAT" ]; then
    cat <<EOF
translate-docformat is a wrapper script to translate documentation formats from
 one to another.

Usage:
  translate-docformat source-document.name format

The formats supported are :
  txt html ps dvi pdf

Not all of them is really supported.
This program tries to build the transformed documentation on
the source directory.

EOF
fi ;

case "$SOURCE" in
    *.sgml)
	# an heuristics to decide if it is a debiandoc or docbook.
	if grep "//OASIS//DTD DocBook" "$SOURCE" > /dev/null ; then
	    # docbook
	    case "$FORMAT" in
		txt)
		    sgmltools -b txt "$SOURCE"
		    ;;
		html)
		    sgmltools -b onehtml "$SOURCE"
		    ;;
		ps)
		    sgmltools -b ps "$SOURCE"
		    ;;
		dvi)
		    sgmltools -b dvi "$SOURCE"
		    ;;
		rtf)
		    sgmltools -b rtf "$SOURCE"
		    ;;
		*)
		    unsupportedformaterror "unhandled doc translation from docbook"
		    ;;
	    esac
	elif grep '<!doctype linuxdoc system' "$SOURCE" > /dev/null ; then
	    # linuxdoc
	    case "$FORMAT" in
		txt)
		    linuxdoc --backend=txt "$SOURCE"
		    ;;
		rtf)
		    linuxdoc --backend=rtf "$SOURCE"
		    ;;
		lyx)
		    linuxdoc --backend=lyx "$SOURCE"
		    ;;
		info)
		    linuxdoc --backend=info "$SOURCE"
		    ;;
		tex)
		    linuxdoc --backend=latex2e "$SOURCE"
		    ;;
		*)
		    unsupportedformaterror "unhandled doc translation from linuxdoc"
	    esac
	elif grep -i '<!doctype debiandoc system' "$SOURCE" > /dev/null || grep "//DebianDoc//DTD DebianDoc//EN" "$SOURCE" > /dev/null ; then
	    # debiandoc
	    case "$FORMAT" in
		txt)
		    debiandoc2text -- "$SOURCE"
		    ;;
		texinfo)
		    debiandoc2texinfo -- "$SOURCE"
		    ;;
		info)
		    debiandoc2info -- "$SOURCE"
		    ;;
		pdf)
		    debiandoc2latexpdf -- "$SOURCE"
		    ;;
		ps)
		    debiandoc2latexps  -- "$SOURCE"
		    ;;
		*)
		    unsupportedformaterror "Unhandled doc translation from debiandoc"
		    ;;
	    esac
	else
	    unsupportedformaterror "Not a known DTD, file a bug with your doc-header"
	fi
	;;
    *.tex)
	case "$FORMAT" in
	    dvi)
		# tip from The Debian SGML/XML HOWTO, originally from aph, I think.
		PRIOR=$(tempfile)
		PPRIOR=$(tempfile)
		cp -pf "$PRIOR" "$PPRIOR"
		cp -pf "$SOURCEDIR"/$(basename "$SOURCE".tex).aux "$PRIOR"
		RECURSION=1
		"$LATEX" "$SOURCE"
		while ! cmp "$SOURCEDIR"/$(basename "$SOURCE".tex).aux "$PRIOR" && \
		    cmp "$SOURCEDIR"/$(basename "$SOURCE".tex).aux "$PPRIOR" && \
		    test $RECURSION < 5 ; do
		  "$LATEX" "$SOURCE";
		  RECURSION=$(($RECURSION + 1))
		done
		rm -f "$PRIOR" "$PPRIOR"
		;;
	    ps)
		"$0" "$SOURCE" dvi
		"$0" "$SOURCEDIR"/$(basename "$SOURCE" .tex).dvi ps
		;;
	    pdf)
		"$0" "$SOURCE" dvi
		"$0" "$SOURCEDIR"/$(basename "$SOURCE" .tex).dvi ps
		;;
	    *)
		unsupportedformaterror "Not supported translation $FORMAT for latex"
		;;
	esac
	;;
    *.dvi)
	case "$FORMAT" in
	    ps)
		dvips "$SOURCE" -o "$SOURCEDIR"/$(basename "$SOURCE" .tex).ps
		;;
	    *)
		unsupportedformaterror "Not supported translation $FORMAT for dvi"
		;;
	esac
	;;
    *.texi)
	case "$FORMAT" in
	    dvi)
		texi2dvi "$SOURCE"
		;;
	    html)
		texi2html "$SOURCE"
		;;
	    txt)
		makeinfo  --no-headers -o  "$SOURCEDIR"/$(basename "$SOURCE" .texi).txt "$SOURCE"
		;;
	    *)
		unsupportedformaterror "Not supported translation $FORMAT for texi"
		;;
	esac
	;;
    *.xml)
	# XML file. -- assume DocBk XML
	case "$FORMAT" in
	    html)
		jade -t sgml  -V nochunks -d /usr/lib/sgml/stylesheet/dsssl/docbook/nwalsh/html/docbook.dsl \
		    /usr/lib/sgml/declaration/xml.dcl "$SOURCE" > "$SOURCEDIR"/$(basename "$SOURCE" .xml).html
		;;
	    txt)
		"$0" "$SOURCE" html
		"$0" "$SOURCEDIR"/$(basename "$SOURCE" .xml).html txt
		;;
	    jadetex)
		jade -t tex  -V tex-backend -d /usr/lib/sgml/stylesheet/dsssl/docbook/nwalsh/print/docbook.dsl \
		    /usr/lib/sgml/declaration/xml.dcl "$SOURCE" > "$SOURCEDIR"/$(basename "$SOURCE" .xml).html
		;;
	    ps)
		"$0" "$SOURCE" jadetex
		LATEX="jadetex" translate-docformat "$0" "$SOURCEDIR"/$(basename "$SOURCE" .xml).tex ps
		;;
	    *)
		unsupportedformaterror "Not supported format $FORMAT for xml"
		;;
	esac
	;;
    *.html)
	case "$FORMAT" in
	    txt)
		if [ -x /usr/bin/w3m ]; then 
		    w3m -dump -T text/html "$SOURCE" > "$SOURCEDIR"/$(basename "$SOURCE" .html).txt
		elif [ -x /usr/bin/w3mmee ]; then
		    w3mmee -dump -T text/html "$SOURCE" > "$SOURCEDIR"/$(basename "$SOURCE" .html).txt
		elif [ -x /usr/bin/lynx ]; then
		    lynx -dump -T text/html "$SOURCE" > "$SOURCEDIR"/$(basename "$SOURCE" .html).txt
		else
		    unsupportedformaterror "w3m nor lynx is available"
		    exit 1
		fi		
		;;
	    *)
		unsupportedformaterror "Not supported format $FORMAT for html"
		;;
	esac
	;;
    *)
	unsupportedformaterror "Unknown source doc format"
	;;
esac