Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GZIP hack (+ first post)

3 views
Skip to first unread message

OPIRG

unread,
Jun 21, 1993, 12:41:01 AM6/21/93
to
If this works, then I am amazed at how lousy the news system is. Of
course, It took me several weeks to work it out myself, and even then
a hint from a friend was necessary. (Note: he couldn't post himself,
due to unusual news software, but did think of a way...)


ObHack: Well, I can't really claim this post, so:

I ftp'd the gzip executables for MSDOS, and was dissapointed to find
that they only included gzip, not gunzip or zcat. Now, I knew that
the functions of both were available using gzip -d and gzip -dc, so I
set up batch files as follows:

GUNZIP.BAT:
gzip -d %1 %2 %3 %4 %5 %6 %7 %8 %9

ZCAT.BAT:
gzip -cd %1 %2 %3 %4 %5 %6 %7 %8 %9

This worked well until I tried to use zcat in my DOS Man batchfile,
where I discovered that you can't re-direct the output of a batch file
from the command line or another batch file. I still havn't figured
out exactly why, but it probably has to do with the spurious %2 %3
etc. when specifying less than 9 files. To get around both this and
the 9 file limit, I wrote two tiny c programs which pre-pended the -d
and -cd arguments and spawned gzip. zcat.c follows:

--------------8<--------<snip>--------8<--------------
#include<process.h>
#include<malloc.h>

#define prog "gzip"
#define swit "-cd"
#define NULL 0

int main(int argc, char *argv[])
{
char **args;
char switches[]=swit;
char program[]=prog;
int i;

args=(char **)calloc(sizeof(char *), argc+2);
args[0]=program;
args[1]=switches;
for(i=1;i<argc;i++)
{
args[i+1]=argv[i];
}
args[argc+1]=NULL;

return(spawnvp(P_WAIT, prog, args));
}

--------------8<--------<snap>--------8<--------------

(I realize that this may not be the best possible solution, but I was
rather proud that I managed to write a program using pointers to
pointers that actually *compiled*!)

Note the fact that this program can be changed to do somehting similar
for any other program by changing only two #define statements.

Christopher Allen
(wcs...@alfred.carleton.ca)

Michael James Gebis

unread,
Jun 21, 1993, 2:15:48 AM6/21/93
to
wcs...@superior.carleton.ca (OPIRG) writes:

[A lot of stuff about an MS-DOS gzip hack he wrote]

Heck, since we're talking gzip hacks, I've got one:
I was running close to my quota...not so much on space as on number of
files. Anyway, I decided that I needed to implement a sort of
stacker-for-unix, a single file that stores other compressed files
within it.

It works pretty well, too. I thought it would be a hassle, but it
actually might be more convienent at times. This is my set of csh
aliases which compress, uncompress, cat, etc. text files. I realize now
that I didn't need to include the \!* at the end, but I'm too lazy to
delete it.

alias zpls "unzip -l ~/text/text.zip"
alias zpless "unzip -p ~/text/text.zip \!* | less"
alias zpcomp "zip -9m ~/text/text.zip \!*"
alias zprm "zip -d ~/text/text.zip \!*"
alias zpuncomp "unzip ~/text/text.zip \!*"
alias zpdir "unzip -v ~/text/text.zip"
alias zpcat "unzip -p ~/text/text.zip \!*"
alias zpl "unzip -l ~/text/text.zip | colrm 1 27"

You'll notice I've used regular unzip, not gzip. That's because it's
more flexible, at least on my machine. A directory in the user's home
stores a file text.zip, which has all of the files in it. (As you can
probably guess, I had a lot of text files.)

I don't know if this is all that impressive, but it worked well for me.

ObCommodore64HackThatShouldNotHaveWorked: My friend's disk drive was
broken. I popped the thing open (A 1541, for the curious) and discoved
that the band that connected the motor to the central hub was broken.
Well, we REALLY wanted to play Space Taxi RIGHT NOW, and since I was
still in junior high at the time, we couldn't drive to the store for a
replacement. Anyway, we searched his basement, and found the solution.

A blue rubber band. We actually used a blue rubber band to fix his
motor, and it worked. Not only that, but he NEVER bought a
replacement. The BRB lasted through Bard's Tale II, Ultima IV, and
about a hundred other games with no problem.

And now, just sometimes, when I watch MacGyver and see him use a
solution that is so absurd it's stupid, I think back to the BRB and
smile.
--
Mike Gebis m-g...@uiuc.edu
I'm free! I'm free! And freedom tastes of reality.

Doug McLaren

unread,
Jun 21, 1993, 2:51:07 AM6/21/93
to
In article <wcsbeau.740637661@cunews> wcs...@superior.carleton.ca (OPIRG) writes:
>
>I ftp'd the gzip executables for MSDOS, and was dissapointed to find
>that they only included gzip, not gunzip or zcat. Now, I knew that
>the functions of both were available using gzip -d and gzip -dc, so I
>set up batch files as follows:

>This worked well until I tried to use zcat in my DOS Man batchfile,


>where I discovered that you can't re-direct the output of a batch file
>from the command line or another batch file. I still havn't figured
>out exactly why, but it probably has to do with the spurious %2 %3
>etc. when specifying less than 9 files. To get around both this and

1) You're doing things the hard way. I'm fairly certain that if you
just copied gzip.exe to gunzip.exe and zcat.exe, you could use the
commands like in Unix. No C programs, no batch files. The program
gzip (in Unix anyways, and I think the DOS port mirrors this) checks
it's name and works like zcat or gunzip if so named.

Of course, DOS doesn't support symbolic or hard links (I guess you
could make a hard link of sorts, but the FAT wouldn't like it at all
if you ran chkdsk or deleted one of the links I think.)

2) Redirection in batch files. Funny, I don't have a problem with it.
But then again I use 4Dos (and 4OS/2 for that matter) and 4Dos tends
to fix a lot of DOS's shortcomings in things like that. I strongly
reccomend looking at 4Dos and 4OS/2 if you're stuck on working on a
DOS or OS/2 machine. (available from wuarchive.wustl.edu and
ftp-os2.nmsu.edu respectively.)

Of course, given the choice, I'd rather write my scripts in sh or ksh.
And in fact there are ports of ksh to both DOS and OS/2. But I've
never really looked into using them ...

--
----------------------- \ Confucius might have once said:
Doug McLaren, \ Weinberg's Second Law: If builders built buildings
DemoN on IRC \ the way programmers wrote programs, then the first
dou...@ccwf.cc.utexas.edu \ woodpecker that came along would destroy
-------------------------- / civilization.

Warren Toomey

unread,
Jun 21, 1993, 2:22:08 AM6/21/93
to
In article <wcsbeau.740637661@cunews>, wcs...@superior.carleton.ca (OPIRG) writes:
||>
|> I ftp'd the gzip executables for MSDOS, and was dissapointed to find
|> that they only included gzip, not gunzip or zcat.

Gzip uses its argv[0] to decide how to run. Thus, the easiest solution
under MS-DOG is:

> copy gzip.exe gunzip.exe
> copy gzip.exe zcat.exe

I wonder is DOG-7 will have links :-) ???

Warren

Luke Mewburn

unread,
Jun 21, 1993, 4:47:46 AM6/21/93
to
wcs...@superior.carleton.ca (OPIRG) writes:

> ObHack: Well, I can't really claim this post, so:
> I ftp'd the gzip executables for MSDOS, and was dissapointed to find
> that they only included gzip, not gunzip or zcat. Now, I knew that
> the functions of both were available using gzip -d and gzip -dc, so I
> set up batch files as follows:

> [partially workable soln deleted]

just do:


copy gzip.exe gunzip.exe
copy gzip.exe zcat.exe

and let gzip do the rest. (too bad MSDOG doesn't have symlinks huh? :)


ObHack: hmm.. not this post, that's for sure. Well, I can't think of a
short obhack (and I'm too lazy to type 2 pages of code), so I'll just be
a `person who follows up to posts in a.h & doesn't have an ObHack'.

Zak.

Doug Merritt

unread,
Jun 24, 1993, 2:41:38 PM6/24/93
to
In article <wcsbeau.740637661@cunews> wcs...@superior.carleton.ca (OPIRG) writes:
>(I realize that this may not be the best possible solution, but I was
>rather proud that I managed to write a program using pointers to
>pointers that actually *compiled*!)

Rather than flaming, let me simply point out that describing novice level
successes can in no sense be considered to be even a small hack, and
posting such things reflects poorly rather than well...not that the
success isn't commendable, just that thinking that it's a *hack* is
deplorable...so what's the point? Oh well... (If you think this observation
is a flame, you should see...er, never mind. :-)

I also can't resist pointing out that all the talk about finding SMTP
documentation recently is completely irrelevent for anyone with the hacker
mentality. Anyone who's hacked SMTP knows what I mean. A popular joke in the
hacker community: "read the documentation??? Surely you jest..." (Note for
non-hackers: the point of the joke is that it is a point of pride to
be able to figure things out even when no documentation is available
from any source, and this can get to be a silly habit even when documentation
*is* available).

ObSmallHack: last week wrote a fault-tolerant client/server distributed
computation tool, calibrated the pooled CPU resources available on our small
Sparc network as a cumulative 430MIPS (the meaning of "MIPS" was calibrated
precisely too), allowing an estimation that next month's cpu-intensive
calculation will require 7.25 days, plus or minus 0.3 days, when distributed
over our network using this new tool, assuming normal loads.

Naturally this is a small hack because it's been done many times before,
is conceptually simple, and doesn't require much code, either. The main
thing that makes it a hack at all is that the man pages on every call
that needs to be made *suck*, therefore it's a "Can't RTFM". :-)
I was tempted at one point during the day to go buy a book that documented
things better, but the hacker ethic got the better of me...

Oh yeah, one last thing...some weeks/months ago when I dropped in here,
people were arguing that calling yourself a hacker means you aren't one.
This is only true in some cases. In other cases, if people label you a
hacker for enough years, you start taking it for granted. The main reason
this isn't a conceit is that "hacker" is not *that* high a status; it's
more of a club or a community of like-thinking people, and belonging
to a huge club isn't all that prestigious...except when comparing to
people not in the club at all. :-)

I usually don't bother to explain anything about hackerdom, but the
recent noise level in here has reached amazing proportions...Looks like
most of the real hackers have been scared off (bored off, I should say).
Doug
--
Doug Merritt do...@netcom.com
Professional Wild-eyed Visionary Member, Crusaders for a Better Tomorrow

ch...@watson.ibm.com

unread,
Jun 25, 1993, 11:10:38 AM6/25/93
to
> From: do...@netcom.com (Doug Merritt)

> Rather than flaming, let me simply point out that describing novice level

> successes can in no sense be considered to be even a small hack...

Beg to differ; it's entirely possible that if you were to read that
code, you'd smile, or chuckle, or groan, or otherwise emote, and
either think or exclaim "What a hack!" or other words to that effect.
The fact that a novice can do it doesn't mean it doesn't have the
hack-nature; an act can be a hack if it has the right relationship
to the hacker, regardless of what it looks like from the outside.
Of course, I've always been a broad-constructionist... *8)

ObHack: One that sort of failed, but in a interesting way. In my
idyllic student days, I was writing a game-playing program for a
basically-bogus "AI" course. Due to quick-and-lazy coding, the
simplest hack to make it obey the rules of the game was to have
the evaluation function return a very negative value for illegal
moves. Then during testing one day, it *cheated* to avoid losing!
I was puzzled but amused. Examination of the code revealed, of
course, that under some circumstances the evaluation function
returned one very negative value ("you've lost!") for all the
legal moves, and another very negative value ("you've cheated!")
for the illegal ones. But I hadn't been careful enough to make
sure that the "lost" value wasn't quite as negative as the
"cheated" one; I had, that is, inadvertantly taught the program
that it's worse to lose than to cheat. Something to think about
now that I have a daughter...

- -- -
David M. Chess | "La raison a ses coeurs que le coeur
High Integrity Computing Lab | ne connait point."
IBM Watson Research | -- Caspal


Doug Merritt

unread,
Jun 25, 1993, 12:30:21 PM6/25/93
to
In article <2c2b075e....@watson.ibm.com> ch...@watson.ibm.com writes:
>The fact that a novice can do it doesn't mean it doesn't have the
>hack-nature; an act can be a hack if it has the right relationship
>to the hacker, regardless of what it looks like from the outside.

Sure, I agree. That wasn't my point. It was the comment about getting
pointers to pointers to compile that I quoted as being the novice
level success and the thing lacking hackiness, not the person posting,
not the program itself. I still claim that such comments lack hack-nature.

> Then during testing one day, it *cheated* to avoid losing!

Heh...that reminds me of one:

ObHack: 5 or 7 years ago I heard about genetic programming and decided to
play with the idea by breeding a population of programs to play tic-tac-toe.
I used a simulated cpu with machine instructions specialized to deal with
the tic-tac-toe board, set up about 32 programs filled with random bits,
held tournaments, killed off the worst programs and used sexual reproduction
of the remaining (treating the programs as genetic bitstreams) to bring
the population back up to max size.

I was puzzled that after a very short period of time (a few hundred
generations, as I recall) a population arose that always won, every single
game. Although I'd hoped for success, this was too dazzling, so when I
checked on what they were up to...yep, they were cheating.

I had a bug that allowed them to make 3 moves in a row in one turn. Since
they played X 50% of the time and O 50% of the time, they found the strategy
of doing nothing at all as O (another manifestation of the same bug),
and as X, making a beeline for marking off 3 in a row down at the bottom,
same spot every time.

I was amused that I'd evolved something that found a bug in my program before
I did. Caveat deus. :-)

Rich Walker

unread,
Jun 25, 1993, 1:31:16 PM6/25/93
to

Yeah, this makes a wonderful debugging technique; while porting the gnu
super-optimiser to the ARM, I debugged the instruction-execution by
watching it find some _amazing_ flawed code (carry flag set oddly on shift
used as condition for executing next one, usually...)

ObMinorHack: porting unix Angband to non-unix system lacking curses and
curses doc's, then realising I could use the PC angband colour with my
curses hack... works rather well.

--
--- Rich! Walker (gr...@cus.cam.ac.uk)
"In a way, we're a kind of Peace Corps."
- Maj. A. Lincoln German, Training Director of the
Green Beret Special Warfare School, Ft. Bragg, N.C.

Sean Captain Napalm Conner

unread,
Jun 25, 1993, 4:32:23 PM6/25/93
to

Okay, since I've received about 7 replies for the hex dump
program I wrote, I decided to post it to alt.sources (so you should find it
there). The program is hex.c, and indeed, it is 121 lines of C.

ObOtherUnixHexHack:
Since I had a program to generate hex dumps, I thought it might be nice to
have a program to take a hex dump (generated by hex) and produce a binary
file. And lo, I did that also. So, given a dump like:

-----uhello-----
00000000: 01 60 00 01 29 FE 25 C5 00 00 00 00 00 00 00 00 .`..).%.........
00000010: 00 38 00 07 01 0B 02 0A 00 00 00 34 00 00 00 00 .8.........4....
00000020: 00 00 00 00 00 40 00 74 00 40 00 00 00 00 00 00 .....@.t.@......
00000030: 10 00 10 00 00 00 00 74 00 00 00 00 00 00 00 00 .......t........
00000040: 00 00 00 00 00 00 00 00 10 00 80 00 2E 74 65 78 .............tex
00000050: 74 00 00 00 00 40 00 74 00 40 00 74 00 00 00 34 t....@.t.@.t...4
00000060: 00 00 00 74 00 00 00 00 00 00 00 00 00 00 00 00 ...t............
00000070: 00 00 00 20 3C 05 00 40 24 04 00 01 24 A5 00 9C ... <..@$...$...
00000080: 24 06 00 0C 24 02 03 EC 00 00 00 0C 00 00 00 00 $...$...........
00000090: 24 02 03 E9 00 00 00 0C 00 00 00 00 68 65 6C 6C $...........hell
000000A0: 6F 20 77 6F 72 6C 64 0A o world.

(which is the hex dump of a program called uhello) it will produce the
binary file (oh, the file does need to exist before hand though - oops).

At least this is useful if you want to change a few bytes in the program
somewhere and don't have an editor capable of handing binary data.

ObYetAnotherUnixHack:
The above program (uhello), a 168 byte (yes, that's byte) executable
(binary, non shell) Unix program to print 'hello world\n' on a RISC based
system. And it's not SPARC either 8-)

ObPostingHack:
Posting today on our newsserver, which is
a) constantly running out of disk space (only 200M drive )-8
b) and wrong permissions on the control files 8-(

-spc (Remember, alt.sources - hex.c - look for it 8-)


Sean Captain Napalm Conner

unread,
Jun 25, 1993, 4:26:17 PM6/25/93
to

Sean Captain Napalm Conner

unread,
Jun 25, 1993, 4:24:07 PM6/25/93
to

Bill Vermillion

unread,
Jun 27, 1993, 3:02:26 PM6/27/93
to

In article <1993Jun25.2...@cybernet.cse.fau.edu> con...@cse.fau.edu (Sean "Captain Napalm" Conner) writes:
>
> Okay, since I've received about 7 replies for the hex dump
>program I wrote, I decided to post it to alt.sources (so you should find it
>there). The program is hex.c, and indeed, it is 121 lines of C.

Don't we really have enough of these hex dump programs.

> Since I had a program to generate hex dumps, I thought it might be nice to
>have a program to take a hex dump (generated by hex) and produce a binary
>file. And lo, I did that also. So, given a dump like:

Those have been around since the early days of CPM. Why invent the
wheel again. Just because the wheel has whitewalls it's still just a
wheel.

And you liked your message so much you posted it twice? :-)

--
Bill Vermillion - bi...@bilver.uucp OR bi...@bilver.oau.org

Sean Captain Napalm Conner

unread,
Jun 27, 1993, 4:56:58 PM6/27/93
to
In article <1993Jun27....@bilver.uucp> bi...@bilver.uucp (Bill Vermillion) writes:
>
>In article <1993Jun25.2...@cybernet.cse.fau.edu> con...@cse.fau.edu (Sean "Captain Napalm" Conner) writes:
>>
>> Okay, since I've received about 7 replies for the hex dump
>>program I wrote, I decided to post it to alt.sources (so you should find it
>>there). The program is hex.c, and indeed, it is 121 lines of C.
>
>Don't we really have enough of these hex dump programs.
>
I don't know. od on Unix (horrible program), debug under DOS (horrible OS),
and type under AmigaDOS (the best of the lot IMHO). I needed to do some hex
dumps, and (since I was new to Unix at the time) didn't know about od. The
time could have spent trying to find a hex dump program was (probably) greater
than the time it took to write the program in the first place.

Plus it works EXACTLY like I want it to 8-)

>> Since I had a program to generate hex dumps, I thought it might be nice to
>>have a program to take a hex dump (generated by hex) and produce a binary
>>file. And lo, I did that also. So, given a dump like:
>
>Those have been around since the early days of CPM. Why invent the
>wheel again. Just because the wheel has whitewalls it's still just a
>wheel.
>

Because the wheels on CPM are a bit smaller than those used on Unix 8-)
And yes, I do realize that these programs exist, but sometimes I write
programs for fun (or for avoiding real work 8-)

>And you liked your message so much you posted it twice? :-)
>

Sorry about that. I was recently put somewhat in charge of news here at
FAU, and the computer that processes news only has 200M set aside for news,
and the disk is constantly 90% filled (and more likely 98%). I was trying
to clean up space and post at the same time.

Something got screwed up 8-|

ObLastMinuteDrawingClassFinalHack:

When I took drawing here several years ago, our final was to do a self-
portrait (either a full drawing, or a part of our body). Being the lazy
person that I am, I took a photocopy of my hand (just happen to have had
a copy machine in my closet 8-) put it on a lightboard (again, just happen
to have one of those in my closet also from a hack MANY years ago). I then
took a piece of paper which I had covered in graphite (so it was now a dark
gray), put it over the photocopy, and proceeded to trace my hand with an
eraser.

Thirty minutes later, I had a piece of art that got me an A 8-)

ObSomeWhatLameHackToJustifyPostingToThisHereGroup:

The previous hack 8-)

-spc (if (0x2b | ~0x2b) ... now that's a question ... )


Warren Harmon

unread,
Jun 29, 1993, 4:20:51 PM6/29/93
to
In article <1993Jun25.1...@infodev.cam.ac.uk> gr...@cus.cam.ac.uk (Rich Walker) writes:
>In article <dougC96...@netcom.com>, do...@netcom.com (Doug Merritt) writes:
>
>Yeah, this makes a wonderful debugging technique; while porting the gnu
>super-optimiser to the ARM, I debugged the instruction-execution by
>watching it find some _amazing_ flawed code (carry flag set oddly on shift
>used as condition for executing next one, usually...)

A hack and a haiku!

carry flag set oddly
on shift used as condition for
executing next one, usually

Well okay, so it's not a haiku ... but that's okay, this isnt a hack.

-Warren Harmon
wha...@wpi.wpi.edu
Man With No Sig. (oops)

mark lewis

unread,
Jun 28, 1993, 5:56:17 PM6/28/93
to
con...@cse.fau.edu (Sean "Captain Napalm" Conner) writes:
> ObPostingHack:
> Posting today on our newsserver, which is
> a) constantly running out of disk space (only 200M drive )-8

i'll say... i just got three postings of this self same article -=B-)

ObDivorceHack: give her everything she wants during the divorce. then
have her come begging back again about 10 years later. not only that, but
she's threatening to send the boy to live with me full time if i don't
take her back. right! after 10 years, the anger has mellowed (somewhat)
but the pain is still intense. let her rot! i want my son -=B-)

)\/(ark

<-----------------------------------v------------------------------->
UUCP ~!wolves!cssnet!wplace!mlewis | Ashes to ashes... = o
Bike = o o = | Dust to dust... _/-_
Collider = _ /-_ _-\ _ = | Steel gets wet... = _>(_)
Project! ....(_)>(_) (_)<(_)..... | And turns to Rust.... (_)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

David Gilbert

unread,
Jun 26, 1993, 5:07:26 AM6/26/93
to
>>>>> On Mon, 21 Jun 1993 06:15:48 GMT, mjg5...@uxa.cso.uiuc.edu (Michael James Gebis) said:


Michael> ObCommodore64HackThatShouldNotHaveWorked: My friend's disk
Michael> drive was broken. I popped the thing open (A 1541, for the
Michael> curious) and discoved that the band that connected the motor
Michael> to the central hub was broken. Well, we REALLY wanted to
Michael> play Space Taxi RIGHT NOW, and since I was still in junior
Michael> high at the time, we couldn't drive to the store for a
Michael> replacement. Anyway, we searched his basement, and found the
Michael> solution.

Michael> A blue rubber band. We actually used a blue rubber band to
Michael> fix his motor, and it worked. Not only that, but he NEVER
Michael> bought a replacement. The BRB lasted through Bard's Tale II,
Michael> Ultima IV, and about a hundred other games with no problem.

This is even more amazing when you consider that the motor in
question (if I read the post right) is the stepper motor (which is on
top, and connected in this fashon). Gawsh think of the tolerances
that the 1541 must of had (but it only stored 170K).

ObHack: I remember that I kept a VCR alive for a very long time after
it should have been by tying a string around one of the little wheels.
whenever you wanted to switch direction, you had to pull the string in
that direction (even worked with the case on). You see, after much
angst, I figured that there was this wheel that was too worn. It
didn't quite engage ('twas a friction affair). By installing the
string, I could give it some help.

Needless to say, until I got my new VCR, I always bought
tape-protection. It was a good value when there's a 25% chance of
botching the tape ;).

Dave.
--
----------------------------------------------------------------------------
|David Gilbert, University Of Guelph, Ontario | Two things can only be |
|Preferred : dgil...@jaywon.pci.on.ca | equal if and only if they |
|Possible : dgil...@snowhite.cis.uoguelph.ca| are precisely opposite. |
---------------------------------------------------------GLO----------------

0 new messages