[comp.sys.amiga] SHAR format for binary files

kms@ecsvax.UUCP (Ken Steele) (05/09/89)

I also experienced initial frustration when dealing with the
X's in the binary shar files.  But this was more a problem of a
novice AND that my Ultrix machine lacks an 'unshar.'

But the task turns out to not be that difficult.  Just delete all
lines that do not begin with an X and then do:
	sed 's/^X//' <saved.filename >filename.zu?.whatever

And if you forget the command, it is right at the top of the shar file 
just before the important stuff begins (about the 28th line or so)

PS.  Don't forget the lines at the bottom of the file starting with
     SHAR_EOF

-- 
Ken Steele   Dept. of Psychology    kms@ecsvax.[bitnet | UUCP]
             Mars Hill College
             Mars Hill, NC 28754   

kms@ecsvax.UUCP (Ken Steele) (05/10/89)

Thanks to all the people that replied to my posting with
instructions on the conventional and easy way to unshar the
binary postings:
		sh <filename

I could give a reasonable account of why I did not know this but 
could do it with 'sed.' However I'm sure there are better
postings to be read on ahead...

-- 
Ken Steele   Dept. of Psychology    kms@ecsvax.[bitnet | UUCP]
             Mars Hill College
             Mars Hill, NC 28754       "I survived using VI"

sparks@corpane.UUCP (John Sparks) (05/10/89)

In article <6960@ecsvax.UUCP> kms@ecsvax.UUCP (Ken Steele) writes:
>
>I also experienced initial frustration when dealing with the
>X's in the binary shar files.  But this was more a problem of a
>novice AND that my Ultrix machine lacks an 'unshar.'

There is no 'unshar' program on unix (or ultrix). The entire file is just
a shell script (read batch file in MSDOS language). You just execute it by:

$ sh script.name
[or:]
$ . script.name

This causes the shell to process it as tho you had typed the file from the 
keyboard. Kinda like running a file thru 'execute' on the Amiga.

>
>But the task turns out to not be that difficult.  Just delete all
>lines that do not begin with an X and then do:
>    sed 's/^X//' <saved.filename >filename.zu?.whatever

Basically you are just playing the part of the shell script processor here.
Better to just do like I suggested above.

Also, when you get finished with unsharing the shar file, if it was from 
comp.binaries.amiga you will be left with a uuencoded file. uuencode is a
program that converts binary files into ascii so you can send it thru usenet.
You need to convert it back to binary by using uudecode. And most of these
encoded files are zoo files also. so after uudecoding, you need to unzoo it.

If it was from comp.sources.amiga it will be ok after just unsharing (it was
text to begin with). 

Here is an example of how I would download a binary file 
(my comments are in []).

[lets say I grabbed a program called 'wanderer' and saved it as a file called
wanderer.shar]

     [on unix:]

     $ sh wanderer.shar  [unsharing. now I have a file called wanderer.zuu]
     $ uudecode wanderer.zuu  [uudecoding. now have file called wanderer.zoo]
     [download to my amiga]
     CLI> zoo x wanderer.zoo

That's it. sounds complex but it's not. Bob is using the easiest method and
the most consistent one that I can think of. Zoo keeps the files small,
uuencode makes it ascii so you can send it thru usenet, and shar packs multiple
text files together and keeps mailers from screwing around with the source
files and uuencoded zoo files. 

uuencode and uudecode are available for the Amiga, but it would be nice to
have a program that unshared a .shar file on the Amiga side. Then you could
do everything on the Amiga. Is there such a beastie?

-- 
John Sparks   |  {rutgers|uunet}!ukma!corpane!sparks | D.I.S.K. 24hrs 1200bps
[not for RHF] |          sparks@corpane.UUCP         | 502/968-5401 thru -5406 
If you've seen one nuclear war, you've seen them all.

page%swap@Sun.COM (Bob Page) (05/12/89)

sparks@corpane.UUCP (John Sparks) wrote:
>There is no 'unshar' program on unix (or ultrix).

Actually there are a couple of them.  They simply take a file, toss
the junk before the #!/bin/sh header, and feed the rest to 'sh'.  Much
easier than editing those pesky headers by hand.

>That's it. sounds complex but it's not.

In fact, I can make it easier for you (under UNIX).  Here, eat this,
courtesy of Fred Walter:

#!/bin/sh
# shar: SHell ARchive
# Run the following text through 'sh' to create:
#	newsbreak.c
# This is archive 1 of a 1-part kit.
# This archive created: Thu May 11 20:31:16 1989
echo "extracting newsbreak.c"
sed 's/^X//' << \SHAR_EOF > newsbreak.c
X/*
X * newsbreak.c (version 1.02)
X *
X * by G. R. Walter (Fred) December 30, 1988
X *
X * Description:
X *     Takes a series of files which are shar files (strips any
X *     garbage at the start of the shar file) that have been posted to
X *     comp.{sources|binaries}.amiga and feeds them through sh.
X *     After they have been fed through sh the original files are
X *     deleted. Then any uuencoded files are uudecoded, after which
X *     the uuencoded files are also deleted.
X *
X * NOTES:
X *     1) This program assumes that all necessary shar files are in the
X *        current directory. It attempts to not delete stuff if it can't
X *        handle it (like when not all the parts of a multi-part uuencoded
X *        file are available).
X *     2) When there are multiple parts to a uuencoded file, a maximum
X *        of 29 parts are currently handled.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <sys/types.h>
X#include <sys/dir.h>
X
Xmain()
X{
X    DIR            *dirp;
X    struct direct  *dp;
X
X    void            unshar();
X    void            uudecode();
X
X    /* unshar everything */
X    dirp = opendir(".");
X    for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
X	unshar(dp->d_name);
X    closedir(dirp);
X
X    /* uudecode everything */
X    dirp = opendir(".");
X    for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
X	uudecode(dp->d_name);
X    closedir(dirp);
X
X    exit(0);
X}
X
Xvoid
Xunshar(name)
X    char           *name;
X{
X    FILE           *fin;
X    FILE           *fout;
X    char            buf[200];
X
X    fin = fopen(name, "r");
X    if (fin == NULL)		/* file doesn't exist !? */
X	return;
X
X    for (;;) {
X	if (fgets(buf, 200, fin) == NULL) {	/* not a shar file !? */
X	    fclose(fin);
X	    return;
X	}
X	if ((strncmp(buf, "#!/bin/sh", 9) == 0)
X	 || (strncmp(buf, "#! /bin/sh", 10) == 0))
X	    break;
X    }
X
X    fout = fopen(".unshar.temp.file", "w");
X    while (fgets(buf, 200, fin) != NULL)
X	fprintf(fout, "%s", buf);
X    fclose(fout);
X    fclose(fin);
X
X    if (system("sh .unshar.temp.file >> .unshar.output") == 0)
X        unlink(name);
X
X    unlink(".unshar.temp.file");
X}
X
Xvoid
Xuudecode(name)
X    char           *name;
X{
X    FILE           *file;
X    char            buf[200];
X    char            name_buf[200];
X    char           *ptr;
X
X    /* check if the file still exists */
X    file = fopen(name, "r");
X    if (file == NULL)
X	return;
X    fclose(file);
X
X    /* if the file ends in ".uue" or ".uu" or ".zuu" just uudecode it */
X    ptr = name + strlen(name) - 1;
X    if ((*ptr == 'e') && (*(ptr - 1) == 'u')) {
X	ptr -= 2;
X	if ((*ptr == 'u') && (*(ptr - 1) == '.')) {
X	    sprintf(buf, "uudecode %s", name);
X	    if (system(buf) == 0)
X	        unlink(name);
X	}
X	return;
X    }
X    if ((*ptr == 'u') && (*(ptr - 1) == 'u')) {
X	ptr -= 2;
X	if ((*ptr == '.') || ((*ptr == 'z') && (*(ptr - 1) == '.'))) {
X	    sprintf(buf, "uudecode %s", name);
X	    if (system(buf) == 0)
X	        unlink(name);
X	}
X	return;
X    }
X
X    /* handle ".zu#" where # is a number */
X    while (isdigit(*ptr))
X	ptr--;
X
X    if ((*ptr == 'u') && ((*(ptr - 1) == 'z') && (*(ptr - 2) == '.'))) {
X	*(ptr + 1) = NULL;
X
X	/* check out how many parts there are */
X	sprintf(name_buf, "%s10", name);
X        file = fopen(name_buf, "r");
X        if (file == NULL) {
X	    sprintf(buf, "cat %s? | uudecode", name);
X        } else {
X            fclose(file);
X	    sprintf(name_buf, "%s20", name);
X            file = fopen(name_buf, "r");
X            if (file == NULL) {
X	        sprintf(buf, "cat %s? %s1? | uudecode", name, name);
X	    } else {
X                fclose(file);
X	        sprintf(name_buf, "%s30", name);
X                file = fopen(name_buf, "r");
X                if (file == NULL) {
X	            sprintf(buf, "cat %s? %s1? %s2? | uudecode",
X			    name, name, name);
X		} else {
X		    fclose(file);
X		}
X	    }
X	}
X
X	if (system(buf) == 0) {
X	    sprintf(buf, "rm %s*", name);
X	    system(buf);
X	}
X    }
X}
SHAR_EOF
echo "End of archive 1 (of 1)"
# if you want to concatenate archives, remove anything after this line
exit

>Zoo keeps the files small, uuencode makes it ascii so you can send it

uuencode also makes it big again.  It looks very good that I might
switch to btoa5.3 (or later) soon.  Not only does it produce smaller
ASCII files to ship around (and store, and download, etc) but version
5.3 will do some fancy things to make life much easier for everybody,
like automatically deal with split files.

[Note I have not said I'm going to switch, only that it looks good
that I will sometime soon.  Of course it won't be until atob 5.3
runs under AmigaDOS, UNIX and VMS; it seems I have enough enemies
reading the binaries/sources groups.]

>it would be nice to have a program that unshared a .shar file on the
>Amiga side. [...] Is there such a beastie?

More than one such package has been posted to Usenet.  The one that was
posted last week (unshar, comp.sources.amiga, v89i116) will also deal
with sed scripts and subdirectories.  I urge everyone to check it out.

..bob

kms@ecsvax.UUCP (Ken Steele) (05/12/89)

In article <614@corpane.UUCP>, sparks@corpane.UUCP (John Sparks) writes:
> In article <6960@ecsvax.UUCP> kms@ecsvax.UUCP (Ken Steele) writes:
> >
And then John gives a nice and clear tutorial on using 'sh' 
to unshar files.  Thanks John.  And thanks to others who sent
similar replies for which my mailed thanks bounced.

Then he goes on to query...
> uuencode and uudecode are available for the Amiga, but it would be nice to
> have a program that unshared a .shar file on the Amiga side. Then you could
> do everything on the Amiga. Is there such a beastie?
> 
Yes there is.  It is on Fish #28, and is called 'shar.'  It has
a command line '-u' switch to unshar.  That is one of many reasons
I was in search of a mythical 'unshar' mainframe program.
> -- 
> John Sparks   |  {rutgers|uunet}!ukma!corpane!sparks | D.I.S.K. 24hrs 1200bps
> [not for RHF] |          sparks@corpane.UUCP         | 502/968-5401 thru -5406 
> If you've seen one nuclear war, you've seen them all.


-- 
Ken Steele   Dept. of Psychology    kms@ecsvax.[bitnet | UUCP]
             Mars Hill College
             Mars Hill, NC 28754       

kelso@mimsy.UUCP (Stephen Kelley) (05/12/89)

W/ all the weenies flaming, just thot I'd add another voice to the
"thank for a job well done" club.

-- 
Real:	Stephen Kelley, Welch Med. Lib., Johns Hopkins Univ.
Internet: stevek@welch.jhu.edu

new@udel.EDU (Darren New) (05/16/89)

In article <614@corpane.UUCP> sparks@corpane.UUCP (John Sparks) writes:
>uuencode and uudecode are available for the Amiga, but it would be nice to
>have a program that unshared a .shar file on the Amiga side. Then you could
>do everything on the Amiga. Is there such a beastie?

Yes there is. It even scans for the #! line and stops at the
exit command so that several .shar files can be put into one
amiga file and then torn apart. I'm quite busy right now,
but I can upload it and mail it to anyone not desparate.
Who did this one?  -- Darren