xzmore 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. # Copyright (C) 2001, 2002, 2007 Free Software Foundation
  3. # Copyright (C) 1992, 1993 Jean-loup Gailly
  4. # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #SET_PATH - This line is a placeholder to ease patching this script.
  14. # Instead of unsetting XZ_OPT, just make sure that xz will use file format
  15. # autodetection. This way memory usage limit and thread limit can be
  16. # specified via XZ_OPT.
  17. xz='xz --format=auto'
  18. version='xzmore (XZ Utils) 5.4.2'
  19. usage="Usage: ${0##*/} [OPTION]... [FILE]...
  20. Like 'more', but operate on the uncompressed contents of xz compressed FILEs.
  21. Report bugs to <xz@tukaani.org>."
  22. case $1 in
  23. --help) printf '%s\n' "$usage" || exit 2; exit;;
  24. --version) printf '%s\n' "$version" || exit 2; exit;;
  25. esac
  26. oldtty=`stty -g 2>/dev/null`
  27. if stty -cbreak 2>/dev/null; then
  28. cb='cbreak'; ncb='-cbreak'
  29. else
  30. # 'stty min 1' resets eof to ^a on both SunOS and SysV!
  31. cb='min 1 -icanon'; ncb='icanon eof ^d'
  32. fi
  33. if test $? -eq 0 && test -n "$oldtty"; then
  34. trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
  35. else
  36. trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
  37. fi
  38. if test $# = 0; then
  39. if test -t 0; then
  40. printf '%s\n' "$usage"; exit 1
  41. else
  42. $xz -cdfqQ | eval "${PAGER:-more}"
  43. fi
  44. else
  45. FIRST=1
  46. for FILE; do
  47. < "$FILE" || continue
  48. if test $FIRST -eq 0; then
  49. printf "%s--More--(Next file: %s)" "" "$FILE"
  50. stty $cb -echo 2>/dev/null
  51. ANS=`dd bs=1 count=1 2>/dev/null`
  52. stty $ncb echo 2>/dev/null
  53. echo " "
  54. case "$ANS" in
  55. [eq]) exit;;
  56. esac
  57. fi
  58. if test "$ANS" != 's'; then
  59. printf '%s\n' "------> $FILE <------"
  60. $xz -cdfqQ -- "$FILE" | eval "${PAGER:-more}"
  61. fi
  62. if test -t 1; then
  63. FIRST=0
  64. fi
  65. done
  66. fi