mcedit: make backward search interruptible.
[midnight-commander.git] / misc / ext.d / doc.sh.in
blobc8e83cfee4d5e46f74641868b5b540bbb693a792
1 #!/bin/sh
3 # $1 - action
4 # $2 - type of file
6 action=$1
7 filetype=$2
9 [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
11 STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
13 staroffice_console() {
14 filename=$1;shift
15 is_view=$1; shift
16 if [ -n "${is_view}" ]; then
17 is_view='-dump'
20 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
21 cd $tmp
22 soffice2html.pl "${filename}"
23 elinks ${is_view} content.html
24 rm -rf "$tmp"
27 get_ooffice_executable() {
28 which loffice >/dev/null 2>&1 && \
29 echo "loffice" || \
30 echo "ooffice"
33 do_view_action() {
34 filetype=$1
36 case "${filetype}" in
37 ps)
38 ps2ascii "${MC_EXT_FILENAME}"
40 pdf)
41 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
43 odt)
44 if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
45 staroffice_console "${MC_EXT_FILENAME}" "view"
46 else
47 odt2txt "${MC_EXT_FILENAME}"
50 msdoc)
51 which wvHtml >/dev/null 2>&1 &&
53 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
54 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
55 elinks -dump "$tmp/page.html"
56 rm -rf "$tmp"
57 } || \
58 antiword -t "${MC_EXT_FILENAME}" || \
59 catdoc -w "${MC_EXT_FILENAME}" || \
60 word2x -f text "${MC_EXT_FILENAME}" - || \
61 strings "${MC_EXT_FILENAME}"
63 msxls)
64 which xlHtml >/dev/null 2>&1 && {
65 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
66 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
67 elinks -dump "$tmp/page.html"
68 rm -rf "$tmp"
69 } || \
70 xls2csv "${MC_EXT_FILENAME}" || \
71 strings "${MC_EXT_FILENAME}"
73 dvi)
74 which dvi2tty >/dev/null 2>&1 && \
75 dvi2tty "${MC_EXT_FILENAME}" || \
76 catdvi "${MC_EXT_FILENAME}"
78 djvu)
79 djvused -e print-pure-txt "${MC_EXT_FILENAME}"
81 epub)
82 einfo -v "${MC_EXT_FILENAME}"
86 esac
89 do_open_action() {
90 filetype=$1
92 case "${filetype}" in
93 ps)
94 if [ -n "$DISPLAY" ]; then
95 (gv "${MC_EXT_FILENAME}" &)
96 else
97 ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
100 pdf)
101 if [ ! -n "$DISPLAY" ]; then
102 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
103 elif see > /dev/null 2>&1; then
104 (see "${MC_EXT_FILENAME}" &)
105 else
106 (xpdf "${MC_EXT_FILENAME}" &)
108 #(acroread "${MC_EXT_FILENAME}" &)
109 #(ghostview "${MC_EXT_FILENAME}" &)
111 ooffice)
112 if [ -n "$DISPLAY" ]; then
113 OOFFICE=`get_ooffice_executable`
114 (${OOFFICE} "${MC_EXT_FILENAME}" &)
115 else
116 if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
117 staroffice_console "${MC_EXT_FILENAME}"
118 else
119 odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
123 abw)
124 (abiword "${MC_EXT_FILENAME}" &)
126 gnumeric)
127 (gnumeric "${MC_EXT_FILENAME}" &)
129 msdoc)
130 if [ -n "$DISPLAY" ]; then
131 (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
132 else
133 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
134 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
135 elinks "$tmp/page.html"
136 rm -rf "$tmp"
139 msxls)
140 if [ -n "$DISPLAY" ]; then
141 (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
142 else
143 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
144 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
145 elinks "$tmp/page.html"
146 rm -rf "$tmp"
149 msppt)
150 if [ -n "$DISPLAY" ]; then
151 OOFFICE=`get_ooffice_executable`
152 (${OOFFICE} "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
153 else
154 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
155 ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
156 elinks "$tmp/page.html"
157 rm -rf "$tmp"
160 framemaker)
161 fmclient -f "${MC_EXT_FILENAME}"
163 dvi)
164 if [ -n "$DISPLAY" ]; then
165 (xdvi "${MC_EXT_FILENAME}" &)
166 else
167 dvisvga "${MC_EXT_FILENAME}" || \
168 dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
171 djvu)
172 djview "${MC_EXT_FILENAME}" &
174 comic)
175 cbrpager "${MC_EXT_FILENAME}" &
177 epub)
178 lucidor "${MC_EXT_FILENAME}" >/dev/null &
182 esac
185 case "${action}" in
186 view)
187 do_view_action "${filetype}"
189 open)
190 ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
191 do_open_action "${filetype}"
195 esac