wok-next rev 4863
xz: add wrapper...
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Feb 03 22:37:34 2010 +0100 (2010-02-03) |
parents | b462c462655c |
children | b7ad907547b5 |
files | xz/stuff/lzma |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xz/stuff/lzma Wed Feb 03 22:37:34 2010 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# Wrapper to accept lzma_alone or lzma_utils arguments 1.7 +# 1.8 + 1.9 +usage() 1.10 +{ 1.11 + cat 1>&2 <<EOT 1.12 +Usage: LZMA <e|d> inputFile outputFile [<switches>...] 1.13 + e: encode file 1.14 + d: decode file 1.15 +<Switches> 1.16 + -a{N}: set compression mode - [0, 2], default: 1 (max) 1.17 + -d{N}: set dictionary - [12,30], default: 23 (8MB) 1.18 + -fb{N}: set number of fast bytes - [2, 273], default: 64 1.19 + -mc{N}: set number of cycles for match finder 1.20 + -lc{N}: set number of literal context bits - [0, 3], default: 3 1.21 + -lp{N}: set number of literal pos bits - [0, 4], default: 0 1.22 + -pb{N}: set number of pos bits - [0, 4], default: 2 1.23 + -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc3, hc4], default: bt4 1.24 + -eos: write End Of Stream marker 1.25 + -si: read data from stdin 1.26 + -so: write data to stdout 1.27 +EOT 1.28 + exit 1 1.29 +} 1.30 + 1.31 +# Get lzma_alone arg 1.32 +getarg() 1.33 +{ 1.34 + case "$1" in 1.35 + -a0) mode="lzma1=mode=fast";; 1.36 + -a1) mode="lzma1=mode=normal";; 1.37 + -a2) mode="lzma2=mode=normal";; 1.38 + -d*) extra="$extra,dict=$((2 ** ${1#-d}))";; 1.39 + -fb*) extra="$extra,fb=${1#-fb}";; 1.40 + -mc*) extra="$extra,depth=${1#-mc}";; 1.41 + -lc*) extra="$extra,lc=${1#-lc}";; 1.42 + -lp*) extra="$extra,lp=${1#-lp}";; 1.43 + -pb*) extra="$extra,pb=${1#-pb}";; 1.44 + -mf*) extra="$extra,mf=${1#-mf}";; 1.45 + -eos|-mt*) ;; 1.46 + -si) output="> ${input#< }"; input="";; 1.47 + -so) output="";; 1.48 + *) return 1;; 1.49 + esac 1.50 + return 0 1.51 +} 1.52 + 1.53 +lzma_utils() 1.54 +{ 1.55 + args="--format=lzma" 1.56 + files="" 1.57 + suffix=lzma 1.58 + while [ -n "$1" ]; do 1.59 + case "$1" in 1.60 + -e) args="$args -z";; 1.61 + -d|-k|-[0-9]) args="$args $1";; 1.62 + --fast) args="$args -1";; 1.63 + --best) args="$args -9";; 1.64 + -c|--stdout|--to-stdout) args="$args -c";; 1.65 + -S) suffix=${2#.}; shift;; 1.66 + -*);; 1.67 + *) files="$files $1";; 1.68 + esac 1.69 + shift 1.70 + done 1.71 + for i in $files; do 1.72 + xz $args $i || break 1.73 + [ "lzma" == "$suffix" ] || mv ${i%.*}.lzma ${i%.*}.$suffix 1.74 + done 1.75 + exit 1.76 +} 1.77 + 1.78 +# lzma_utils or lzma_alone ? 1.79 +[ -n "$3" ] || lzma_utils $@ 1.80 +case "$1" in 1.81 +d) args="-d";; 1.82 +e) args="-z";; 1.83 +--help|-h|-\?|'') usage;; 1.84 +*) lzma_utils $@;; 1.85 +esac 1.86 + 1.87 +# it's lzma_alone 1.88 +# get filenames 1.89 +input="< $2" 1.90 +output="> $2" 1.91 +shift 1.92 +if ! getarg "$1"; then 1.93 + output="> $2" 1.94 + getarg "$2" 1.95 + shift 1.96 +fi 1.97 + 1.98 +# get arguments 1.99 +extra="" 1.100 +mode="lzma1=mode=normal" 1.101 +while [ -n "$2" ]; do 1.102 + getarg "$2" || usage 1.103 + shift 1.104 +done 1.105 + 1.106 +# fake lzma_alone (-eos -mt1) 1.107 +eval exec xz $args --format=lzma --$mode$extra --stdout $input $output