Re: A fix for the F3 /var/log bug... / POSIX and '##'



On Sun, 1 Jun 2003 12:10, Oswald Buddenhagen wrote:

one thing to consider is, whether all 'file's in the wild support -z
or a configure check and optionally manual on-the-fly decompression
would have to be done instead.

Dismaying thought.  Going through the checklist:  Linux is OK.

HP-UX?  Here's a 'file' man page from "HP-UX Release 11.00: October
1997", with no '-z' switch:

	http://www.calpoly.edu/cgi-bin/man-cgi?file+1

Might have changed in six years though...

SunOS?  AIX?

> The logic would go like:
>
> 1) let x = `file foo`
> 2) is foo compressed?  Goto 4.

what would these be good for?

Nothing, it was a typo.  I meant 2) is "foo UNcompressed?  Goto 4."

The idea was to save a '-z' call, on the guess that not using '-z'
many times would be worth calling 'file' twice if necessary....

> 3) let x = `file -z foo`
> 4) return x

...but now I think that guess was wrong. I had thought that 'file -z' took much longer with big files, but after running some tests, it seems not to be the case.

---

Recap: /var/log files don't view right using F3 in 'mc'. This can be gotten around using various filters. The two attempts considered here so far (one using the POSIX shell's '##', and the other using 'file -z') may not work "out of the box" on all of mc's current platforms.

Are there more portable substitutes? The POSIX shell '##' can be replaced with a less efficient 'grep' pipe. Before:

View=%view{ascii,nroff} d=%d ; d=${d##/var/log*} ; if [ -z "$d" ] ; then gzip -dc %f ; else gzip -dc %f | nroff -c -Tlatin1 -mandoc ; fi

After:

View=%view{ascii,nroff} if echo %d | grep --quiet /var/log ; then gzip -dc %f ; else gzip -dc %f | nroff -c -Tlatin1 -mandoc ; fi

(If not all "grep"s have the '--quiet' switch, then 'grep /var/log > /dev/null' would work...)

How to most efficiently replace 'file -z' is less obvious. Uncompressing a big file just to get its type could cause long waits if resources are low. Man pages don't tend to be too big, perhaps only checking the file types of archives smaller than a given size is better?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]