summaryrefslogtreecommitdiffstats
path: root/misc/ext.d/doc.sh.in
blob: c296ca270ec44019075dd25ecf35fa6776e8a649 (plain)
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
#!/bin/sh

# $1 - action
# $2 - type of file

action=$1
filetype=$2

[ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"

STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'

staroffice_console() {
    filename=$1;shift
    is_view=$1; shift
    if [ -n "${is_view}" ]; then
        is_view='-dump'
    fi

    tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
    cd $tmp
    soffice2html.pl "${filename}"
    elinks ${is_view} content.html
    rm -rf "$tmp"
}

get_ooffice_executable() {
    if which loffice >/dev/null 2>&1; then
        echo "loffice"
    elif which ooffice >/dev/null 2>&1; then
        echo "ooffice"
    else
        echo -n
    fi
}

do_view_action() {
    filetype=$1

    case "${filetype}" in
    ps)
        ps2ascii "${MC_EXT_FILENAME}"
        ;;
    pdf)
        pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
        ;;
    odt)
        if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
            staroffice_console "${MC_EXT_FILENAME}" "view"
        else
            odt2txt "${MC_EXT_FILENAME}"
        fi
        ;;
    msdoc)
        if which wvHtml >/dev/null 2>&1; then
            tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
            wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
            elinks -dump "$tmp/page.html"
            rm -rf "$tmp"
        elif which antiword >/dev/null 2>&1; then
            antiword -t "${MC_EXT_FILENAME}"
        elif which catdoc >/dev/null 2>&1; then
            catdoc -w "${MC_EXT_FILENAME}"
        elif which word2x >/dev/null 2>&1; then
            word2x -f text "${MC_EXT_FILENAME}" -
        else
            strings "${MC_EXT_FILENAME}"
        fi
        ;;
    msxls)
        if which xlhtml >/dev/null 2>&1; then
            tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
            xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
            elinks -dump "$tmp/page.html"
            rm -rf "$tmp"
        elif which xls2csv >/dev/null 2>&1; then
            xls2csv "${MC_EXT_FILENAME}"
        else
            strings "${MC_EXT_FILENAME}"
        fi
        ;;
    dvi)
        which dvi2tty >/dev/null 2>&1 && \
            dvi2tty "${MC_EXT_FILENAME}" || \
            catdvi "${MC_EXT_FILENAME}"
        ;;
    djvu)
        djvused -e print-pure-txt "${MC_EXT_FILENAME}"
        ;;
    ebook)
        einfo -v "${MC_EXT_FILENAME}"
        ;;
    *)
        ;;
    esac
}

do_open_action() {
    filetype=$1

    case "${filetype}" in
    ps)
        if [ -n "$DISPLAY" ]; then
            (gv "${MC_EXT_FILENAME}" &)
        else
            ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
        fi
        ;;
    pdf)
        if [ ! -n "$DISPLAY" ]; then
            pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
        elif see > /dev/null 2>&1; then
            (see "${MC_EXT_FILENAME}" &)
        else
            (xpdf "${MC_EXT_FILENAME}" &)
        fi
        #(acroread "${MC_EXT_FILENAME}" &)
        #(ghostview "${MC_EXT_FILENAME}" &)
        ;;
    ooffice)
        if [ -n "$DISPLAY" ]; then
            OOFFICE=`get_ooffice_executable`
            if [ -n "${OOFFICE}" ]; then
                (${OOFFICE} "${MC_EXT_FILENAME}" &)
            fi
        else
            if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
                staroffice_console "${MC_EXT_FILENAME}"
            else
                odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
            fi
        fi
        ;;
    abw)
        (abiword "${MC_EXT_FILENAME}" &)
        ;;
    gnumeric)
        (gnumeric "${MC_EXT_FILENAME}" &)
        ;;
    msdoc)
        if [ -n "$DISPLAY" ]; then
            OOFFICE=`get_ooffice_executable`
            if [ -n "${OOFFICE}" ]; then
                (${OOFFICE} "${MC_EXT_FILENAME}" &)
            else
                (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
            fi
        else
            tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
            wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
            elinks "$tmp/page.html"
            rm -rf "$tmp"
        fi
        ;;
    msxls)
        if [ -n "$DISPLAY" ]; then
            OOFFICE=`get_ooffice_executable`
            if [ -n "${OOFFICE}" ]; then
                (${OOFFICE} "${MC_EXT_FILENAME}" &)
            else
                (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
            fi
        else
            tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
            xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
            elinks "$tmp/page.html"
            rm -rf "$tmp"
        fi
        ;;
    msppt)
        if [ -n "$DISPLAY" ]; then
            OOFFICE=`get_ooffice_executable`
            if [ -n "${OOFFICE}" ]; then
                (${OOFFICE} "${MC_EXT_FILENAME}" &)
            fi
        else
            tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
            ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
            elinks "$tmp/page.html"
            rm -rf "$tmp"
        fi
        ;;
    framemaker)
        fmclient -f "${MC_EXT_FILENAME}"
        ;;
    dvi)
        if [ -n "$DISPLAY" ]; then
            (xdvi "${MC_EXT_FILENAME}" &)
        else
            dvisvga "${MC_EXT_FILENAME}" || \
                dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
        fi
        ;;
    djvu)
        djview "${MC_EXT_FILENAME}" &
        ;;
    comic)
        cbrpager "${MC_EXT_FILENAME}" &
        ;;
    ebook)
        lucidor "${MC_EXT_FILENAME}" >/dev/null &
        ;;
    *)
        ;;
    esac
}

case "${action}" in
view)
    do_view_action "${filetype}"
    ;;
open)
    ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
        do_open_action "${filetype}"
    ;;
*)
    ;;
esac