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 {
|
pascal@4863
|
8 cat 1>&2 <<EOT
|
pascal@4863
|
9 Usage: LZMA <e|d> inputFile outputFile [<switches>...]
|
pascal@4863
|
10 e: encode file
|
pascal@4863
|
11 d: decode file
|
pascal@4863
|
12 <Switches>
|
pascal@4863
|
13 -a{N}: set compression mode - [0, 2], default: 1 (max)
|
pascal@4863
|
14 -d{N}: set dictionary - [12,30], default: 23 (8MB)
|
pascal@4863
|
15 -fb{N}: set number of fast bytes - [2, 273], default: 64
|
pascal@4863
|
16 -mc{N}: set number of cycles for match finder
|
pascal@4863
|
17 -lc{N}: set number of literal context bits - [0, 3], default: 3
|
pascal@4863
|
18 -lp{N}: set number of literal pos bits - [0, 4], default: 0
|
pascal@4863
|
19 -pb{N}: set number of pos bits - [0, 4], default: 2
|
pascal@4863
|
20 -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc3, hc4], default: bt4
|
pascal@4863
|
21 -eos: write End Of Stream marker
|
pascal@4863
|
22 -si: read data from stdin
|
pascal@4863
|
23 -so: write data to stdout
|
pascal@4863
|
24 EOT
|
pascal@4863
|
25 exit 1
|
pascal@4863
|
26 }
|
pascal@4863
|
27
|
pascal@4863
|
28 # Get lzma_alone arg
|
pascal@4863
|
29 getarg()
|
pascal@4863
|
30 {
|
pascal@4863
|
31 case "$1" in
|
pascal@4863
|
32 -a0) mode="lzma1=mode=fast";;
|
pascal@4863
|
33 -a1) mode="lzma1=mode=normal";;
|
pascal@4863
|
34 -a2) mode="lzma2=mode=normal";;
|
pascal@4863
|
35 -d*) extra="$extra,dict=$((2 ** ${1#-d}))";;
|
pascal@4863
|
36 -fb*) extra="$extra,fb=${1#-fb}";;
|
pascal@4863
|
37 -mc*) extra="$extra,depth=${1#-mc}";;
|
pascal@4863
|
38 -lc*) extra="$extra,lc=${1#-lc}";;
|
pascal@4863
|
39 -lp*) extra="$extra,lp=${1#-lp}";;
|
pascal@4863
|
40 -pb*) extra="$extra,pb=${1#-pb}";;
|
pascal@4863
|
41 -mf*) extra="$extra,mf=${1#-mf}";;
|
pascal@4863
|
42 -eos|-mt*) ;;
|
pascal@4863
|
43 -si) output="> ${input#< }"; input="";;
|
pascal@4863
|
44 -so) output="";;
|
pascal@4863
|
45 *) return 1;;
|
pascal@4863
|
46 esac
|
pascal@4863
|
47 return 0
|
pascal@4863
|
48 }
|
pascal@4863
|
49
|
pascal@4863
|
50 lzma_utils()
|
pascal@4863
|
51 {
|
pascal@4863
|
52 args="--format=lzma"
|
pascal@4863
|
53 files=""
|
pascal@4863
|
54 suffix=lzma
|
pascal@4863
|
55 while [ -n "$1" ]; do
|
pascal@4863
|
56 case "$1" in
|
pascal@4863
|
57 -e) args="$args -z";;
|
pascal@4863
|
58 -d|-k|-[0-9]) args="$args $1";;
|
pascal@4863
|
59 --fast) args="$args -1";;
|
pascal@4863
|
60 --best) args="$args -9";;
|
pascal@4863
|
61 -c|--stdout|--to-stdout) args="$args -c";;
|
pascal@4863
|
62 -S) suffix=${2#.}; shift;;
|
pascal@4863
|
63 -*);;
|
pascal@4863
|
64 *) files="$files $1";;
|
pascal@4863
|
65 esac
|
pascal@4863
|
66 shift
|
pascal@4863
|
67 done
|
pascal@4863
|
68 for i in $files; do
|
pascal@4863
|
69 xz $args $i || break
|
pascal@4863
|
70 [ "lzma" == "$suffix" ] || mv ${i%.*}.lzma ${i%.*}.$suffix
|
pascal@4863
|
71 done
|
pascal@4863
|
72 exit
|
pascal@4863
|
73 }
|
pascal@4863
|
74
|
pascal@4863
|
75 # lzma_utils or lzma_alone ?
|
pascal@4863
|
76 [ -n "$3" ] || lzma_utils $@
|
pascal@4863
|
77 case "$1" in
|
pascal@4863
|
78 d) args="-d";;
|
pascal@4863
|
79 e) args="-z";;
|
pascal@4863
|
80 --help|-h|-\?|'') usage;;
|
pascal@4863
|
81 *) lzma_utils $@;;
|
pascal@4863
|
82 esac
|
pascal@4863
|
83
|
pascal@4863
|
84 # it's lzma_alone
|
pascal@4863
|
85 # get filenames
|
pascal@4863
|
86 input="< $2"
|
pascal@4863
|
87 output="> $2"
|
pascal@4863
|
88 shift
|
pascal@4863
|
89 if ! getarg "$1"; then
|
pascal@4863
|
90 output="> $2"
|
pascal@4863
|
91 getarg "$2"
|
pascal@4863
|
92 shift
|
pascal@4863
|
93 fi
|
pascal@4863
|
94
|
pascal@4863
|
95 # get arguments
|
pascal@4863
|
96 extra=""
|
pascal@4863
|
97 mode="lzma1=mode=normal"
|
pascal@4863
|
98 while [ -n "$2" ]; do
|
pascal@4863
|
99 getarg "$2" || usage
|
pascal@4863
|
100 shift
|
pascal@4863
|
101 done
|
pascal@4863
|
102
|
pascal@4863
|
103 # fake lzma_alone (-eos -mt1)
|
pascal@4863
|
104 eval exec xz $args --format=lzma --$mode$extra --stdout $input $output
|