Path: utzoo!utgpu!watmath!watcgl!grwalter From: grwalter@watcgl.waterloo.edu (Fred Walter) Newsgroups: comp.sys.amiga Subject: Re: Comp.binaries- multiple files Keywords: How to piece together Message-ID: <7512@watcgl.waterloo.edu> Date: 3 Jan 89 05:49:26 GMT References: <263@lakesys.UUCP> Reply-To: grwalter@watcgl.waterloo.edu (Fred Walter) Organization: U. of Waterloo, Ontario Lines: 162 In article <263@lakesys.UUCP> mikes@lakesys.UUCP (Mike Shawaluk) writes: >Then, assuming I have all of the pieces, I >can type "cat rgb1.zu? | uudecode", which will take the pieces rgb1.zu1 >through rgb1.zu9 (or however high up it got), concatenate them together, and >uudecode the .zuu file into a .zoo file. If there are more than 9 pieces, as >there were for the recent rgb demo, you might have to modify your cat command >slightly, such as "cat rgb1.zu? rgb1.zu1? | uudecode". In the program I just posted a couple of days ago that tries to automate putting together binaries/source postings I didn't take the above into account. Here is an updated version. fred ---cut-here--------------------------hey-that-tickles!!!!---------- /* * newsbreak.c (version 1.02) * * by G. R. Walter (Fred) December 30, 1988 * * Description: * Takes a series of files which are shar files (strips any * garbage at the start of the shar file) that have been posted to * comp.{sources|binaries}.amiga and feeds them through sh. * After they have been fed through sh the original files are * deleted. Then any uuencoded files are uudecoded, after which * the uuencoded files are also deleted. * * NOTES: * 1) This program assumes that all necessary shar files are in the * current directory. It attempts to not delete stuff if it can't * handle it (like when not all the parts of a multi-part uuencoded * file are available). * 2) When there are multiple parts to a uuencoded file, a maximum * of 29 parts are currently handled. */ #include #include #include #include main() { DIR *dirp; struct direct *dp; void unshar(); void uudecode(); /* unshar everything */ dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) unshar(dp->d_name); closedir(dirp); /* uudecode everything */ dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) uudecode(dp->d_name); closedir(dirp); exit(0); } void unshar(name) char *name; { FILE *fin; FILE *fout; char buf[200]; fin = fopen(name, "r"); if (fin == NULL) /* file doesn't exist !? */ return; for (;;) { if (fgets(buf, 200, fin) == NULL) { /* not a shar file !? */ fclose(fin); return; } if (strncmp(buf, "#!/bin/sh", 9) == 0) break; } fout = fopen(".unshar.temp.file", "w"); while (fgets(buf, 200, fin) != NULL) fprintf(fout, "%s", buf); fclose(fout); fclose(fin); if (system("sh .unshar.temp.file >> .unshar.output") == 0) unlink(name); unlink(".unshar.temp.file"); } void uudecode(name) char *name; { FILE *file; char buf[200]; char name_buf[200]; char *ptr; /* check if the file still exists */ file = fopen(name, "r"); if (file == NULL) return; fclose(file); /* if the file ends in ".uu" or ".zuu" just uudecode it */ ptr = name + strlen(name) - 1; if ((*ptr == 'u') && (*(ptr - 1) == 'u')) { ptr -= 2; if ((*ptr == '.') || ((*ptr == 'z') && (*(ptr - 1) == '.'))) { sprintf(buf, "uudecode %s", name); if (system(buf) == 0) unlink(name); return; } } /* handle ".zu#" where # is a number */ while (isdigit(*ptr)) ptr--; if ((*ptr == 'u') && ((*(ptr - 1) == 'z') && (*(ptr - 2) == '.'))) { *(ptr + 1) = NULL; /* check out how many parts there are */ sprintf(name_buf, "%s10", name); file = fopen(name_buf, "r"); if (file == NULL) { sprintf(buf, "cat %s? | uudecode", name); } else { fclose(file); sprintf(name_buf, "%s20", name); file = fopen(name_buf, "r"); if (file == NULL) { sprintf(buf, "cat %s? %s1? | uudecode", name, name); } else { fclose(file); sprintf(name_buf, "%s30", name); file = fopen(name_buf, "r"); if (file == NULL) { sprintf(buf, "cat %s? %s1? %s2? | uudecode", name, name, name); } else { fclose(file); } } } if (system(buf) == 0) { sprintf(buf, "rm %s*", name); system(buf); } } }