From owner-freebsd-questions@FreeBSD.ORG Sat Aug 30 15:51:16 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3114116A4BF for ; Sat, 30 Aug 2003 15:51:16 -0700 (PDT) Received: from mail.pinboard.com (mail.pinboard.com [194.209.195.7]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3A7F14400E for ; Sat, 30 Aug 2003 15:50:39 -0700 (PDT) (envelope-from kurt@pinboard.com) Received: (from uucp@localhost)AAA18936 for FreeBSD-Questions@freebsd.org; Sun, 31 Aug 2003 00:50:36 +0200 (CEST) (envelope-from kurt@pinboard.com (kurt@pinboard.com)) (client-IP ) Received: (from kurt@localhost)AAA95445; Sun, 31 Aug 2003 00:32:06 +0200 (CEST) (envelope-from kurt (kurt)) (client-IP ) Date: Sun, 31 Aug 2003 00:32:05 +0200 From: pbdlists@pinboard.com To: FreeBSD-Questions@freebsd.org Message-ID: <20030831003205.A94657@pinboard.com> Mail-Followup-To: pbdlists@pinboard.com, FreeBSD-Questions@freebsd.org References: <200308271100.42049.dkelly@HiWAAY.net> <20030828043747.GA1206@terminator.client.attbi.com> <20030829235939.GE42454@grumpy.dyndns.org> <3F50CF19.5030200@mac.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3F50CF19.5030200@mac.com>; from cswiger@mac.com on Sat, Aug 30, 2003 at 12:21:45PM -0400 Subject: Re: zmore for bzip2? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Aug 2003 22:51:16 -0000 Adapting zmore for the case where you specify the files to display on the command line is not problem at all: > diff kk zmore 5,14d4 < get_decompressor () < { < case `file ${1--} | sed "s/[^:]*: *\([^ ]*\).*/\1/"` in < "compress"*) DECOMPRESSOR="uncompress -c";; < "gzip"*) DECOMPRESSOR="gzip -cdfq";; < "bzip2"*) DECOMPRESSOR="bunzip2 -cdq";; < *) DECOMPRESSOR="cat";; < esac < } < 56,57c46 < get_decompressor ${FILE} < ${DECOMPRESSOR} "$FILE" | eval ${PAGER-more} --- > gzip -cdfq "$FILE" | eval ${PAGER-more} But when zmore is used as a pipe or with input redirection, things become more complicated. gzip -cdfq | eval ${PAGER-more} In order to detect the type of data passed on STDIN, the get_decompressor function or any other means of detection would consume STDIN. STDIN, however must be passed to the decompressor after the type of data has been detected. I don't have an idea hot to 'duplicate' STDIN, so it could be consumed twice. Sure, writing it to a temporary file would be a workaround: 38,53c28 < FILE="/tmp/.zmore.${$}" < touch ${FILE} 2>/dev/null < if [ "${?}" -ne "0" ]; then < echo "can't create temporary file" < exit 1 < fi < chmod 0600 ${FILE} < cat >${FILE} < if [ "${?}" -ne "0" ]; then < echo "can't create temporary file" < rm -f ${FILE} < exit 1 < fi < get_decompressor ${FILE} < cat ${FILE} | ${DECOMPRESSOR} | eval ${PAGER-more} < rm -f ${FILE} --- > gzip -cdfq | eval ${PAGER-more} But I don't like that. I myself sometimes work with compressed files larger than anything I would be happy to write to /tmp or somewhere else (even though those cases usually rather use zcat and its cousinds than zmore...) Kurt On Sat, Aug 30, 2003 at 12:21:45PM -0400, Chuck Swiger wrote: > David Kelly wrote: > [ ... ] > > Yes, of course. But zmore is smart enough to figure out what to do with > > several compression techniques, or even to handle non-compressed files > > very trivially and without hassle. > > 'zmore' is a simple shell script which calls "gzcat | ${PAGER-more}". One > solution to your problem, or at least a solution, would be to change zmore to > look for a trailing bz/bz2 or invoke bzcat instead. Another would be to change > the sources of gzip to recognize the bzip2 magic files bytes, extending the > detection of gzip versus classic LZH used by compress.