wok-stable annotate xz/stuff/lzma @ rev 8751

Removed all/most _pkg= lines in wok. The new tazwok-experimental can SOURCE paths and source are are all extracted to WOK/PACKAGE/PACKAGE-VERSION now with tazwok-experimental.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Feb 20 06:53:59 2011 +0000 (2011-02-20)
parents 79ebfa5003d6
children 885c330a75ba
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@4863 76 [ "lzma" == "$suffix" ] || mv ${i%.*}.lzma ${i%.*}.$suffix
pascal@4863 77 done
pascal@4863 78 exit
pascal@4863 79 }
pascal@4863 80
pascal@7616 81 case "$0" in
pascal@7616 82 *unlzma) lzma_utils -d $@ ;;
pascal@7616 83 *lzcat) lzma_utils -c -d $@ ;;
pascal@7616 84 esac
pascal@7616 85
gokhlayeh@8114 86 # First look if help is needed.
gokhlayeh@8114 87 [ "$1" ] || usage
gokhlayeh@8114 88 case "$1" in
gokhlayeh@8114 89 --version|-V|--help|-h|-\?|'') usage;;
gokhlayeh@8114 90 esac
gokhlayeh@8114 91
pascal@4863 92 # lzma_utils or lzma_alone ?
pascal@4863 93 [ -n "$3" ] || lzma_utils $@
pascal@4863 94 case "$1" in
pascal@4863 95 d) args="-d";;
pascal@4863 96 e) args="-z";;
pascal@4863 97 *) lzma_utils $@;;
pascal@4863 98 esac
pascal@4863 99
pascal@4863 100 # it's lzma_alone
pascal@4863 101 # get filenames
pascal@4863 102 input="< $2"
pascal@4863 103 output="> $2"
pascal@4863 104 shift
pascal@4863 105 if ! getarg "$1"; then
pascal@4863 106 output="> $2"
pascal@4863 107 getarg "$2"
pascal@4863 108 shift
pascal@4863 109 fi
pascal@4863 110
pascal@4863 111 # get arguments
pascal@4863 112 extra=""
pascal@4863 113 mode="lzma1=mode=normal"
pascal@4863 114 while [ -n "$2" ]; do
gokhlayeh@8114 115 getarg "$2" || usage error
pascal@4863 116 shift
pascal@4863 117 done
pascal@4863 118
pascal@4863 119 # fake lzma_alone (-eos -mt1)
gokhlayeh@8114 120 eval xz $args --format=lzma --$mode$extra --stdout $input $output || usage error
pascal@5062 121 if [ -n "$input" -a -n "$output" ]; then
pascal@5062 122 size=$(stat -c "%s" ${input#< })
pascal@5062 123 ascii="00000 "
pascal@5062 124 for i in 1 2 3 4 5 6 7 8; do
pascal@5062 125 ascii="$ascii $(printf "%02x" $((size % 256)) )"
pascal@5062 126 size=$(( $size / 256 ))
pascal@5062 127 done
pascal@5062 128 echo "$ascii | .." | hexdump -R | \
pascal@5062 129 dd of=${output#> } seek=5 bs=1 conv=notrunc 2> /dev/null
pascal@5062 130 fi
gokhlayeh@8114 131 exit 0