doc.sh.in 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. do_view_action() {
  20. filetype=$1
  21. case "${filetype}" in
  22. ps)
  23. ps2ascii "${MC_EXT_FILENAME}"
  24. ;;
  25. pdf)
  26. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
  27. ;;
  28. odt)
  29. if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  30. staroffice_console "${MC_EXT_FILENAME}" "view"
  31. else
  32. odt2txt "${MC_EXT_FILENAME}"
  33. fi
  34. ;;
  35. msdoc)
  36. which wvHtml >/dev/null 2>&1 &&
  37. {
  38. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  39. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
  40. elinks -dump "$tmp/page.html"
  41. rm -rf "$tmp"
  42. } || \
  43. antiword -t "${MC_EXT_FILENAME}" || \
  44. catdoc -w "${MC_EXT_FILENAME}" || \
  45. word2x -f text "${MC_EXT_FILENAME}" - || \
  46. strings "${MC_EXT_FILENAME}"
  47. ;;
  48. msxls)
  49. which xlHtml >/dev/null 2>&1 && {
  50. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  51. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  52. elinks -dump "$tmp/page.html"
  53. rm -rf "$tmp"
  54. } || \
  55. xls2csv "${MC_EXT_FILENAME}" || \
  56. strings "${MC_EXT_FILENAME}"
  57. ;;
  58. dvi)
  59. dvi2tty "${MC_EXT_FILENAME}"
  60. ;;
  61. djvu)
  62. djvused -e print-pure-txt "${MC_EXT_FILENAME}"
  63. ;;
  64. *)
  65. ;;
  66. esac
  67. }
  68. do_open_action() {
  69. filetype=$1
  70. case "${filetype}" in
  71. ps)
  72. if [ -n "$DISPLAY" ]; then
  73. (gv "${MC_EXT_FILENAME}" &)
  74. else
  75. ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
  76. fi
  77. ;;
  78. pdf)
  79. if [ -n "$DISPLAY" ]; then
  80. (xpdf "${MC_EXT_FILENAME}" &)
  81. else
  82. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
  83. fi
  84. #(acroread "${MC_EXT_FILENAME}" &)
  85. #(ghostview "${MC_EXT_FILENAME}" &)
  86. ;;
  87. ooffice)
  88. if [ -n "$DISPLAY" ]; then
  89. (ooffice "${MC_EXT_FILENAME}" &)
  90. else
  91. if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  92. staroffice_console "${MC_EXT_FILENAME}"
  93. else
  94. odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
  95. fi
  96. fi
  97. ;;
  98. abw)
  99. (abiword "${MC_EXT_FILENAME}" &)
  100. ;;
  101. msdoc)
  102. if [ -n "$DISPLAY" ]; then
  103. (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  104. else
  105. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  106. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
  107. elinks "$tmp/page.html"
  108. rm -rf "$tmp"
  109. fi
  110. ;;
  111. msxls)
  112. if [ -n "$DISPLAY" ]; then
  113. (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  114. else
  115. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  116. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  117. elinks "$tmp/page.html"
  118. rm -rf "$tmp"
  119. fi
  120. ;;
  121. msppt)
  122. if [ -n "$DISPLAY" ]; then
  123. (ooffice %f >/dev/null 2>&1 &)
  124. else
  125. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  126. ppthtml %f > "$tmp/page.html"
  127. elinks "$tmp/page.html"
  128. rm -rf "$tmp"
  129. fi
  130. ;;
  131. framemaker)
  132. fmclient -f "${MC_EXT_FILENAME}"
  133. ;;
  134. dvi)
  135. if [ -n "$DISPLAY" ]; then
  136. (xdvi "${MC_EXT_FILENAME}" &)
  137. else
  138. dvisvga "${MC_EXT_FILENAME}" || \
  139. dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
  140. fi
  141. ;;
  142. djvu)
  143. djview "${MC_EXT_FILENAME}" &
  144. ;;
  145. *)
  146. ;;
  147. esac
  148. }
  149. case "${action}" in
  150. view)
  151. do_view_action "${filetype}"
  152. ;;
  153. open)
  154. xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
  155. do_open_action "${filetype}"
  156. ;;
  157. *)
  158. ;;
  159. esac