Tweak sources for --with-x/--without-x option.
[midnight-commander.git] / misc / ext.d / doc.sh.in
blob79fc381a806a2e121aa844dbf0a79015ea882614
1 #!/bin/sh
3 # $1 - action
4 # $2 - type of file
6 action=$1
7 filetype=$2
10 STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
12 staroffice_console() {
13 filename=$1;shift
14 is_view=$1; shift
15 if [ -n "${is_view}" ]; then
16 is_view='-dump'
19 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
20 cd $tmp
21 soffice2html.pl "${filename}"
22 elinks ${is_view} content.html
23 rm -rf "$tmp"
26 get_ooffice_executable() {
27 which loffice >/dev/null 2>&1 && \
28 echo "loffice" || \
29 echo "ooffice"
32 do_view_action() {
33 filetype=$1
35 case "${filetype}" in
36 ps)
37 ps2ascii "${MC_EXT_FILENAME}"
39 pdf)
40 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
42 odt)
43 if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
44 staroffice_console "${MC_EXT_FILENAME}" "view"
45 else
46 odt2txt "${MC_EXT_FILENAME}"
49 msdoc)
50 which wvHtml >/dev/null 2>&1 &&
52 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
53 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
54 elinks -dump "$tmp/page.html"
55 rm -rf "$tmp"
56 } || \
57 antiword -t "${MC_EXT_FILENAME}" || \
58 catdoc -w "${MC_EXT_FILENAME}" || \
59 word2x -f text "${MC_EXT_FILENAME}" - || \
60 strings "${MC_EXT_FILENAME}"
62 msxls)
63 which xlHtml >/dev/null 2>&1 && {
64 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
65 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
66 elinks -dump "$tmp/page.html"
67 rm -rf "$tmp"
68 } || \
69 xls2csv "${MC_EXT_FILENAME}" || \
70 strings "${MC_EXT_FILENAME}"
72 dvi)
73 which dvi2tty >/dev/null 2>&1 && \
74 dvi2tty "${MC_EXT_FILENAME}" || \
75 catdvi "${MC_EXT_FILENAME}"
77 djvu)
78 djvused -e print-pure-txt "${MC_EXT_FILENAME}"
80 epub)
81 einfo -v "${MC_EXT_FILENAME}"
85 esac
88 do_open_action() {
89 filetype=$1
91 case "${filetype}" in
92 ps)
93 if [ -n "$DISPLAY" ]; then
94 (gv "${MC_EXT_FILENAME}" &)
95 else
96 ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
99 pdf)
100 if [ ! -n "$DISPLAY" ]; then
101 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
102 elif see > /dev/null 2>&1; then
103 (see "${MC_EXT_FILENAME}" &)
104 else
105 (xpdf "${MC_EXT_FILENAME}" &)
107 #(acroread "${MC_EXT_FILENAME}" &)
108 #(ghostview "${MC_EXT_FILENAME}" &)
110 ooffice)
111 if [ -n "$DISPLAY" ]; then
112 OOFFICE=`get_ooffice_executable`
113 (${OOFFICE} "${MC_EXT_FILENAME}" &)
114 else
115 if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
116 staroffice_console "${MC_EXT_FILENAME}"
117 else
118 odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
122 abw)
123 (abiword "${MC_EXT_FILENAME}" &)
125 gnumeric)
126 (gnumeric "${MC_EXT_FILENAME}" &)
128 msdoc)
129 if [ -n "$DISPLAY" ]; then
130 (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
131 else
132 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
133 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
134 elinks "$tmp/page.html"
135 rm -rf "$tmp"
138 msxls)
139 if [ -n "$DISPLAY" ]; then
140 (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
141 else
142 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
143 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
144 elinks "$tmp/page.html"
145 rm -rf "$tmp"
148 msppt)
149 if [ -n "$DISPLAY" ]; then
150 OOFFICE=`get_ooffice_executable`
151 (${OOFFICE} %f >/dev/null 2>&1 &)
152 else
153 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
154 ppthtml %f > "$tmp/page.html"
155 elinks "$tmp/page.html"
156 rm -rf "$tmp"
159 framemaker)
160 fmclient -f "${MC_EXT_FILENAME}"
162 dvi)
163 if [ -n "$DISPLAY" ]; then
164 (xdvi "${MC_EXT_FILENAME}" &)
165 else
166 dvisvga "${MC_EXT_FILENAME}" || \
167 dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
170 djvu)
171 djview "${MC_EXT_FILENAME}" &
173 comic)
174 cbrpager "${MC_EXT_FILENAME}" &
176 epub)
177 lucidor "${MC_EXT_FILENAME}" >/dev/null &
181 esac
184 case "${action}" in
185 view)
186 do_view_action "${filetype}"
188 open)
189 xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
190 do_open_action "${filetype}"
194 esac