Merge branch '2103_mcext_enhancement'
[midnight-commander.git] / misc / ext.d / doc.sh.in
blobd598753320902abdd9e2b707077950d7ead0f427
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 do_view_action() {
27 filetype=$1
29 case "${filetype}" in
30 ps)
31 ps2ascii "${MC_EXT_FILENAME}"
33 pdf)
34 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
36 odt)
37 if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
38 staroffice_console "${MC_EXT_FILENAME}" "view"
39 else
40 odt2txt "${MC_EXT_FILENAME}"
43 msdoc)
44 which wvHtml >/dev/null 2>&1 &&
46 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
47 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
48 elinks -dump "$tmp/page.html"
49 rm -rf "$tmp"
50 } || \
51 antiword -t "${MC_EXT_FILENAME}" || \
52 catdoc -w "${MC_EXT_FILENAME}" || \
53 word2x -f text "${MC_EXT_FILENAME}" - || \
54 strings "${MC_EXT_FILENAME}"
56 msxls)
57 which xlHtml >/dev/null 2>&1 && {
58 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
59 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
60 elinks -dump "$tmp/page.html"
61 rm -rf "$tmp"
62 } || \
63 xls2csv "${MC_EXT_FILENAME}" || \
64 strings "${MC_EXT_FILENAME}"
66 dvi)
67 dvi2tty "${MC_EXT_FILENAME}"
69 djvu)
70 djvused -e print-pure-txt "${MC_EXT_FILENAME}"
74 esac
77 do_open_action() {
78 filetype=$1
80 case "${filetype}" in
81 ps)
82 if [ -n "$DISPLAY" ]; then
83 (gv "${MC_EXT_FILENAME}" &)
84 else
85 ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
88 pdf)
89 if [ -n "$DISPLAY" ]; then
90 (xpdf "${MC_EXT_FILENAME}" &)
91 else
92 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
94 #(acroread "${MC_EXT_FILENAME}" &)
95 #(ghostview "${MC_EXT_FILENAME}" &)
97 ooffice)
98 if [ -n "$DISPLAY" ]; then
99 (ooffice "${MC_EXT_FILENAME}" &)
100 else
101 if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
102 staroffice_console "${MC_EXT_FILENAME}"
103 else
104 odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
108 abw)
109 (abiword "${MC_EXT_FILENAME}" &)
111 msdoc)
112 if [ -n "$DISPLAY" ]; then
113 (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
114 else
115 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
116 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
117 elinks "$tmp/page.html"
118 rm -rf "$tmp"
121 msxls)
122 if [ -n "$DISPLAY" ]; then
123 (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
124 else
125 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
126 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
127 elinks "$tmp/page.html"
128 rm -rf "$tmp"
131 msppt)
132 if [ -n "$DISPLAY" ]; then
133 (ooffice %f >/dev/null 2>&1 &)
134 else
135 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
136 ppthtml %f > "$tmp/page.html"
137 elinks "$tmp/page.html"
138 rm -rf "$tmp"
141 framemaker)
142 fmclient -f "${MC_EXT_FILENAME}"
144 dvi)
145 if [ -n "$DISPLAY" ]; then
146 (xdvi "${MC_EXT_FILENAME}" &)
147 else
148 dvisvga "${MC_EXT_FILENAME}" || \
149 dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
152 djvu)
153 djview "${MC_EXT_FILENAME}" &
157 esac
160 case "${action}" in
161 view)
162 do_view_action "${filetype}"
164 open)
165 xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
166 do_open_action "${filetype}"
170 esac