doc.sh.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of file
  4. action=$1
  5. filetype=$2
  6. STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
  7. staroffice_console() {
  8. filename=$1;shift
  9. is_view=$1; shift
  10. if [ -n "${is_view}" ]; then
  11. is_view='-dump'
  12. fi
  13. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  14. cd $tmp
  15. soffice2html.pl "${filename}"
  16. elinks ${is_view} content.html
  17. rm -rf "$tmp"
  18. }
  19. get_ooffice_executable() {
  20. which loffice >/dev/null 2>&1 && \
  21. echo "loffice" || \
  22. echo "ooffice"
  23. }
  24. do_view_action() {
  25. filetype=$1
  26. case "${filetype}" in
  27. ps)
  28. ps2ascii "${MC_EXT_FILENAME}"
  29. ;;
  30. pdf)
  31. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
  32. ;;
  33. odt)
  34. if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  35. staroffice_console "${MC_EXT_FILENAME}" "view"
  36. else
  37. odt2txt "${MC_EXT_FILENAME}"
  38. fi
  39. ;;
  40. msdoc)
  41. which wvHtml >/dev/null 2>&1 &&
  42. {
  43. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  44. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
  45. elinks -dump "$tmp/page.html"
  46. rm -rf "$tmp"
  47. } || \
  48. antiword -t "${MC_EXT_FILENAME}" || \
  49. catdoc -w "${MC_EXT_FILENAME}" || \
  50. word2x -f text "${MC_EXT_FILENAME}" - || \
  51. strings "${MC_EXT_FILENAME}"
  52. ;;
  53. msxls)
  54. which xlHtml >/dev/null 2>&1 && {
  55. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  56. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  57. elinks -dump "$tmp/page.html"
  58. rm -rf "$tmp"
  59. } || \
  60. xls2csv "${MC_EXT_FILENAME}" || \
  61. strings "${MC_EXT_FILENAME}"
  62. ;;
  63. dvi)
  64. which dvi2tty >/dev/null 2>&1 && \
  65. dvi2tty "${MC_EXT_FILENAME}" || \
  66. catdvi "${MC_EXT_FILENAME}"
  67. ;;
  68. djvu)
  69. djvused -e print-pure-txt "${MC_EXT_FILENAME}"
  70. ;;
  71. epub)
  72. einfo -v "${MC_EXT_FILENAME}"
  73. ;;
  74. *)
  75. ;;
  76. esac
  77. }
  78. do_open_action() {
  79. 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}
  86. fi
  87. ;;
  88. pdf)
  89. if [ ! -n "$DISPLAY" ]; then
  90. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
  91. elif see > /dev/null 2>&1; then
  92. (see "${MC_EXT_FILENAME}" &)
  93. else
  94. (xpdf "${MC_EXT_FILENAME}" &)
  95. fi
  96. #(acroread "${MC_EXT_FILENAME}" &)
  97. #(ghostview "${MC_EXT_FILENAME}" &)
  98. ;;
  99. ooffice)
  100. if [ -n "$DISPLAY" ]; then
  101. OOFFICE=`get_ooffice_executable`
  102. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  103. else
  104. if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  105. staroffice_console "${MC_EXT_FILENAME}"
  106. else
  107. odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
  108. fi
  109. fi
  110. ;;
  111. abw)
  112. (abiword "${MC_EXT_FILENAME}" &)
  113. ;;
  114. gnumeric)
  115. (gnumeric "${MC_EXT_FILENAME}" &)
  116. ;;
  117. msdoc)
  118. if [ -n "$DISPLAY" ]; then
  119. (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  120. else
  121. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  122. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
  123. elinks "$tmp/page.html"
  124. rm -rf "$tmp"
  125. fi
  126. ;;
  127. msxls)
  128. if [ -n "$DISPLAY" ]; then
  129. (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  130. else
  131. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  132. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  133. elinks "$tmp/page.html"
  134. rm -rf "$tmp"
  135. fi
  136. ;;
  137. msppt)
  138. if [ -n "$DISPLAY" ]; then
  139. OOFFICE=`get_ooffice_executable`
  140. (${OOFFICE} %f >/dev/null 2>&1 &)
  141. else
  142. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  143. ppthtml %f > "$tmp/page.html"
  144. elinks "$tmp/page.html"
  145. rm -rf "$tmp"
  146. fi
  147. ;;
  148. framemaker)
  149. fmclient -f "${MC_EXT_FILENAME}"
  150. ;;
  151. dvi)
  152. if [ -n "$DISPLAY" ]; then
  153. (xdvi "${MC_EXT_FILENAME}" &)
  154. else
  155. dvisvga "${MC_EXT_FILENAME}" || \
  156. dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
  157. fi
  158. ;;
  159. djvu)
  160. djview "${MC_EXT_FILENAME}" &
  161. ;;
  162. comic)
  163. cbrpager "${MC_EXT_FILENAME}" &
  164. ;;
  165. epub)
  166. lucidor "${MC_EXT_FILENAME}" >/dev/null &
  167. ;;
  168. *)
  169. ;;
  170. esac
  171. }
  172. case "${action}" in
  173. view)
  174. do_view_action "${filetype}"
  175. ;;
  176. open)
  177. xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
  178. do_open_action "${filetype}"
  179. ;;
  180. *)
  181. ;;
  182. esac