離開 emacs。 把它原來的 jka-compr.elc 放到安全的地方以防有臭蟲時備用?!? 用新的 jka-compr.elc來代替它?!? 好好玩吧! --- jka-compr.el Sat Jul 26 17:02:39 1997 +++ jka-compr.el.new Thu Feb 5 17:44:35 1998 @@ -44,7 +44,7 @@ ;; The variable, jka-compr-compression-info-list can be used to ;; customize jka-compr to work with other compression programs. ;; The default value of this variable allows jka-compr to work with -;; Unix compress and gzip. +;; Unix compress and gzip. David Fetter added bzip2 support :) ;; ;; If you are concerned about the stderr output of gzip and other ;; compression/decompression programs showing up in your buffers, you @@ -121,7 +121,9 @@
;;; I have this defined so that .Z files are assumed to be in unix -;;; compress format; and .gz files, in gzip format. +;;; compress format; and .gz files, in gzip format, and .bz2 files, +;;; in the snappy new bzip2 format from http://www.muraroa.demon.co.uk. +;;; Keep up the good work, people! (defcustom jka-compr-compression-info-list ;;[regexp ;; compr-message compr-prog compr-args @@ -131,6 +133,10 @@ "compressing" "compress" ("-c") "uncompressing" "uncompress" ("-c") nil t] + ["http://.bz2//'" + "bzip2ing" "bzip2" ("") + "bunzip2ing" "bzip2" ("-d") + nil t] ["http://.tgz//'" "zipping" "gzip" ("-c" "-q") "unzipping" "gzip" ("-c" "-q" "-d")
;; Automatic (un)compression on loading/saving files (gzip(1) and similar) ;; We start it in the off state, so that bzip2(1) support can be added. ;; Code thrown together by Ulrik Dickow for ~/.emacs with Emacs 19.34. ;; Should work with many older and newer Emacsen too. No warranty though. ;; (if (fboundp 'auto-compression-mode) ; Emacs 19.30+ (auto-compression-mode 0) (require 'jka-compr) (toggle-auto-compression 0)) ;; Now add bzip2 support and turn auto compression back on. (add-to-list 'jka-compr-compression-info-list ["http://.bz2//(~//|//.~[0-9]+~//)?//'" "zipping" "bzip2" () "unzipping" "bzip2" ("-d") nil t]) (toggle-auto-compression 1 t)
# bgrep -- a wrapper around a grep program that decompresses files as needed PATH="/usr/bin:$PATH"; export PATH
prog=`echo $0 | sed 's|.*/||'` case "$prog" in *egrep) grep=${EGREP-egrep} ;; *fgrep) grep=${FGREP-fgrep} ;; *) grep=${GREP-grep} ;; esac pat="" while test $# -ne 0; do case "$1" in -e | -f) opt="$opt $1"; shift; pat="$1" if test "$grep" = grep; then # grep is buggy with -e on SVR4 grep=egrep fi;; -*) opt="$opt $1";; *) if test -z "$pat"; then pat="$1" else break; fi;; esac shift done
if test -z "$pat"; then echo "grep through bzip2 files" echo "usage: $prog [grep_options] pattern [files]" exit 1 fi
list=0 silent=0 op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'` case "$op" in *l*) list=1 esac case "$op" in *h*) silent=1 esac
if test $# -eq 0; then bzip2 -cd | $grep $opt "$pat" exit $? fi
res=0 for i do if test $list -eq 1; then bzip2 -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i r=$? elif test $# -eq 1 -o $silent -eq 1; then bzip2 -cd "$i" | $grep $opt "$pat" r=$? else bzip2 -cd "$i" | $grep $opt "$pat" | sed "s|^|${i}:|" r=$? fi test "$r" -ne 0 && res="$r" done exit $res
10. 使用 bzip2 來再壓縮其他的壓縮格式 下面的 perl 程式會把以下列的壓縮格式檔 (.tar.gz, .tgz. .tar.Z, 和 .Z for this iteration) 重新打包成最佳的壓縮值。這 perl 原始程式都有全方位的好文件來說明它做什麼以及它如何辦到的?!?
#!/usr/bin/perl -w
####################################################### # # # This program takes compressed and gzipped programs # # in the current directory and turns them into bzip2 # # format. It handles the .tgz extension in a # # reasonable way, producing a .tar.bz2 file. # # # ####################################################### $counter = 0; $saved_bytes = 0; $totals_file = '/tmp/machine_bzip2_total'; $machine_bzip2_total = 0;
while(<*[Zz]>) { next if /^bzip2-0.1pl2.tar.gz$/; push @files, $_; } $total = scalar(@files);
foreach (@files) { if (/tgz$/) { ($new=$_) =~ s/tgz$/tar.bz2/; } else { ($new=$_) =~ s//.g?z$/.bz2/i; } $orig_size = (stat $_)[7]; ++$counter; print "Repacking $_ ($counter/$total).../n"; if ((system "gzip -cd $_ |bzip2 >$new") == 0) { $new_size = (stat $new)[7]; $factor = int(100*$new_size/$orig_size+.5); $saved_bytes += $orig_size-$new_size; print "$new is about $factor% of the size of $_. :",($factor<100)?')':'(',"/n"; unlink $_; } else { print "Arrgghh! Something happened to $_: $!/n"; } } print "You've ", ($saved_bytes>=0)?"saved":"lost", " $saved_bytes bytes of storage space :", ($saved_bytes>=0)?")":"(", "/n";
unless (-e '/tmp/machine_bzip2_total') { system ('echo "0" >/tmp/machine_bzip2_total'); system ('chmod', '0666', '/tmp/machine_bzip2_total'); }
chomp($machine_bzip2_total = `cat $totals_file`); open TOTAL, ">$totals_file" or die "Can't open system-wide total: $!"; $machine_bzip2_total += $saved_bytes; print TOTAL $machine_bzip2_total; close TOTAL;
print "That's a machine-wide total of ",`cat $totals_file`," bytes saved./n";
譯注:這份 HOWTO 文件的中文版可在臺灣 Linux 使用者組織下的中文 Linux 文件計畫 http://www.linux.org.tw/CLDP/ 或是"Linux for Taiwan 臺灣人的 Linux " http://members.xoom.com/linux4tw/ 下取得。