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