Re: zmore for bzip2?

2003-08-31 Thread Mikko Työläjärvi
On Sun, 31 Aug 2003 [EMAIL PROTECTED] wrote:

 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

As a somewhat ugly hack, you could read a few bytes, match against
known magic numbers and then prepend those bytes to the stream before
feeding to the decompressor, for the cost of an extra cat process:

   magic=$(dd bs=1 count=3 2/dev/null)
   case $magic in
   BZh) DECOMPRESSOR=bunzip2;;
   *)   DECOMPRESSOR=gzip -cdfq;;
   esac
   (echo -n $magic; exec cat) | $DECOMPRESSOR | eval ${PAGER-more}

Note that gzip will handle compressed data and gzipped data as
well as plain text.

 $.02,
 /Mikko




 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.
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: zmore for bzip2?

2003-08-30 Thread David Kelly
On Wed, Aug 27, 2003 at 11:37:47PM -0500, ES top-posted:
 For your bzip2 files, would the following command suffice?
 
 bzcat filename | less

[...]

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.

I've changed my /etc/newsyslog.conf from J to Z simply so that I could
zmore the files rather than pipe the file or dress up an alias named
bmore or similar.

-- 
David Kelly N4HHE, [EMAIL PROTECTED]
=
The human mind ordinarily operates at only ten percent of its
capacity -- the rest is overhead for the operating system.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: zmore for bzip2?

2003-08-30 Thread Chuck Swiger
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.

Compression formats are similar to graphic image formats in the PBMPLUS sense.

--
-Chuck
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: zmore for bzip2?

2003-08-30 Thread pbdlists
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.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: zmore for bzip2?

2003-08-29 Thread ES
For your bzip2 files, would the following command suffice?

bzcat filename | less

This would be similar to handling a gzipped file with:

zcat filename | less

...which is essentially what zmore does...

-bsdterm


On Wed, Aug 27, 2003 at 11:00:42AM -0500, David Kelly wrote:
 /etc/newsyslog.conf uses J in FreeBSD-5.1 to specify bzip2 format for 
 compression. zmore(1) doesn't know bzip format, is someone working on 
 it?
 
 -- 
 David Kelly N4HHE, [EMAIL PROTECTED]
 =
 The human mind ordinarily operates at only ten percent of its
 capacity -- the rest is overhead for the operating system.
 
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]
---end quoted text---
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: zmore for bzip2?

2003-08-28 Thread Lowell Gilbert
David Kelly [EMAIL PROTECTED] writes:

 /etc/newsyslog.conf uses J in FreeBSD-5.1 to specify bzip2 format for 
 compression. zmore(1) doesn't know bzip format, is someone working on 
 it?

I doubt it; seems kind of trivial to have a separate program to
implement 'bzcat | more`...
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]