wok annotate xz/stuff/lzma @ rev 21896

updated seamonkey (2.46 -> 2.49.5)
author Hans-G?nter Theisgen
date Thu Oct 03 17:09:38 2019 +0100 (2019-10-03)
parents 90ab20b44e0f
children
rev   line source
pascal@4863 1 #!/bin/sh
pascal@4863 2 #
pascal@4863 3 # Wrapper to accept lzma_alone or lzma_utils arguments
pascal@4863 4 #
pascal@4863 5
pascal@4863 6 usage()
pascal@4863 7 {
gokhlayeh@8114 8 status=$?
pascal@4863 9 cat 1>&2 <<EOT
pascal@4863 10 Usage: LZMA <e|d> inputFile outputFile [<switches>...]
pascal@4863 11 e: encode file
pascal@4863 12 d: decode file
pascal@4863 13 <Switches>
pascal@4863 14 -a{N}: set compression mode - [0, 2], default: 1 (max)
pascal@4863 15 -d{N}: set dictionary - [12,30], default: 23 (8MB)
pascal@4863 16 -fb{N}: set number of fast bytes - [2, 273], default: 64
pascal@4863 17 -mc{N}: set number of cycles for match finder
pascal@4863 18 -lc{N}: set number of literal context bits - [0, 3], default: 3
pascal@4863 19 -lp{N}: set number of literal pos bits - [0, 4], default: 0
pascal@4863 20 -pb{N}: set number of pos bits - [0, 4], default: 2
pascal@4863 21 -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc3, hc4], default: bt4
pascal@4863 22 -eos: write End Of Stream marker
pascal@4863 23 -si: read data from stdin
pascal@4863 24 -so: write data to stdout
pascal@4863 25 EOT
gokhlayeh@8114 26 if [ "$1" = error ]; then
gokhlayeh@8114 27 echo -e "\nError"
gokhlayeh@8114 28 exit $status
gokhlayeh@8114 29 else
gokhlayeh@8114 30 exit 0
gokhlayeh@8114 31 fi
pascal@4863 32 }
pascal@4863 33
pascal@4863 34 # Get lzma_alone arg
pascal@4863 35 getarg()
pascal@4863 36 {
pascal@4863 37 case "$1" in
pascal@4863 38 -a0) mode="lzma1=mode=fast";;
pascal@4863 39 -a1) mode="lzma1=mode=normal";;
pascal@4863 40 -a2) mode="lzma2=mode=normal";;
pascal@4863 41 -d*) extra="$extra,dict=$((2 ** ${1#-d}))";;
pascal@4863 42 -fb*) extra="$extra,fb=${1#-fb}";;
pascal@4863 43 -mc*) extra="$extra,depth=${1#-mc}";;
pascal@4863 44 -lc*) extra="$extra,lc=${1#-lc}";;
pascal@4863 45 -lp*) extra="$extra,lp=${1#-lp}";;
pascal@4863 46 -pb*) extra="$extra,pb=${1#-pb}";;
pascal@4863 47 -mf*) extra="$extra,mf=${1#-mf}";;
pascal@4863 48 -eos|-mt*) ;;
pascal@4863 49 -si) output="> ${input#< }"; input="";;
pascal@4863 50 -so) output="";;
pascal@4863 51 *) return 1;;
pascal@4863 52 esac
pascal@4863 53 return 0
pascal@4863 54 }
pascal@4863 55
pascal@4863 56 lzma_utils()
pascal@4863 57 {
pascal@4863 58 args="--format=lzma"
pascal@4863 59 files=""
pascal@4863 60 suffix=lzma
pascal@4863 61 while [ -n "$1" ]; do
pascal@4863 62 case "$1" in
pascal@4863 63 -e) args="$args -z";;
pascal@4863 64 -d|-k|-[0-9]) args="$args $1";;
pascal@4863 65 --fast) args="$args -1";;
pascal@4863 66 --best) args="$args -9";;
pascal@4863 67 -c|--stdout|--to-stdout) args="$args -c";;
pascal@4863 68 -S) suffix=${2#.}; shift;;
pascal@4863 69 -*);;
pascal@4863 70 *) files="$files $1";;
pascal@4863 71 esac
pascal@4863 72 shift
pascal@4863 73 done
pascal@4863 74 for i in $files; do
gokhlayeh@8114 75 xz $args $i || usage error
pascal@20892 76 [ "lzma" = "$suffix" ] || mv ${i%.*}.lzma ${i%.*}.$suffix
pascal@4863 77 done
pascal@4863 78 exit
pascal@4863 79 }
pascal@4863 80
pascal@9343 81 fix_size()
pascal@9343 82 {
pascal@9343 83 n=$1
pascal@9343 84 for i in $(seq 1 8); do
pascal@9343 85 printf '\\\\x%02X' $(($n & 255))
pascal@9343 86 n=$(($n >> 8))
pascal@9343 87 done | xargs echo -en | dd of=$2 conv=notrunc bs=1 seek=5 2> /dev/null
pascal@9343 88 }
pascal@9343 89
pascal@7616 90 case "$0" in
pascal@7616 91 *unlzma) lzma_utils -d $@ ;;
pascal@7616 92 *lzcat) lzma_utils -c -d $@ ;;
pascal@7616 93 esac
pascal@7616 94
gokhlayeh@8114 95 # First look if help is needed.
gokhlayeh@8114 96 case "$1" in
pascal@9342 97 --version|-V|--help|-h|-\?|'') usage;;
pascal@9343 98 --size) size=$(od -t d8 -j5 -N8 < $2 | awk '{ print $2; exit }')
pascal@9342 99 if [ $size -eq -1 ]; then
pascal@9342 100 size=$(unlzma -c $2 | wc -c)
pascal@9343 101 fix_size $size $2
pascal@9342 102 fi
pascal@9342 103 echo $size
pascal@9342 104 exit ;;
gokhlayeh@8114 105 esac
gokhlayeh@8114 106
pascal@4863 107 # lzma_utils or lzma_alone ?
pascal@4863 108 [ -n "$3" ] || lzma_utils $@
pascal@4863 109 case "$1" in
pascal@4863 110 d) args="-d";;
pascal@4863 111 e) args="-z";;
pascal@4863 112 *) lzma_utils $@;;
pascal@4863 113 esac
pascal@4863 114
pascal@4863 115 # it's lzma_alone
pascal@4863 116 # get filenames
pascal@4863 117 input="< $2"
pascal@4863 118 output="> $2"
pascal@4863 119 shift
pascal@4863 120 if ! getarg "$1"; then
pascal@4863 121 output="> $2"
pascal@4863 122 getarg "$2"
pascal@4863 123 shift
pascal@4863 124 fi
pascal@4863 125
pascal@4863 126 # get arguments
pascal@4863 127 extra=""
pascal@4863 128 mode="lzma1=mode=normal"
pascal@4863 129 while [ -n "$2" ]; do
gokhlayeh@8114 130 getarg "$2" || usage error
pascal@4863 131 shift
pascal@4863 132 done
pascal@4863 133
pascal@4863 134 # fake lzma_alone (-eos -mt1)
gokhlayeh@8114 135 eval xz $args --format=lzma --$mode$extra --stdout $input $output || usage error
pascal@9343 136 [ -n "$input" -a -n "$output" ] &&
pascal@9343 137 fix_size $(stat -c "%s" ${input#< }) ${output#> }
gokhlayeh@8114 138 exit 0