Path: utzoo!attcan!uunet!seismo!sundc!pitstop!texsun!sun-barr!rutgers!apple!oliveb!sun!swap!page From: page%swap@Sun.COM (Bob Page) Newsgroups: comp.sys.amiga Subject: Re: SHAR format for binary files Message-ID: <104429@sun.Eng.Sun.COM> Date: 12 May 89 03:48:12 GMT References: <6960@ecsvax.UUCP> <614@corpane.UUCP> Sender: news@sun.Eng.Sun.COM Reply-To: page@sun.UUCP (Bob Page) Organization: Sun Microsystems, Mountain View Lines: 203 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 X#include X#include X#include 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