Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-picayune.mit.edu!athena.mit.edu!acook From: acook@athena.mit.edu (Andrew R Cook) Newsgroups: comp.sources.wanted Subject: Re: Joiner for uuencoded file parts Message-ID: <1991May29.180054.393@athena.mit.edu> Date: 29 May 91 18:00:54 GMT Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 103 I got a bunch of responses asking for this code, so in the interest of sanity, here it is: (code is pretty simple, please ignore if you have something better, and no flames please): ********************************************************************************* /* This is a rather simple way to clean up cat'ed uue files. It assumes standard uue format: begin ... Mdata(61 or 62 chars).. end. A better way would be to test the number of chars in the line and see if the first char is the correct one for the number of bytes represented. This is explained in the formats section of any standard unix manual. Places where errors will occur: 1) if data lines do not begin with 'M'. 2) if any other line beginning with 'M' (not data) also has 61 or 62 chars in it. This one is unavoidable in any case. If you find other bugs, or make major improvements, I would appreciate it if you would let me know. I wrote this code to be helpful, so the more useful it becomes, the better. Written by: Andrew Cook acook@athena.mit.edu andy@ivana.mit.edu typical usage: clean uuefile | uudecode where uuefile is the cat'ed together uuencoded parts. Distribute freely, use freely as long as this authorship notice remains intact. */ #include #include #define INTERVAL 100 main(argc, argv) int argc; char **argv; { int i, cnt=0, num=0, bflag=0, eflag=0; FILE *in; char buf[300], bufa[300], bufb[300], ff[100]; if(argc != 2) { fprintf(stderr, "Usage: clean file\n"); exit(0); } if((in = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Error: can't open \"%s\"\n", argv[1]); exit(0); } fprintf(stderr, "Cleaning catted uue file \"%s\" ", argv[1]); while(fgets(buf, 295, in) != NULL) { buf[strlen(buf)-1] = '\0'; if(buf[0] == 'b') { /* begin */ if(buf[1]=='e' && buf[2]=='g' && buf[3]=='i' && buf[4]=='n') { bflag = 1; if(puts(buf) == EOF) { fprintf(stderr, "error on puts.\n"); exit(0); } } } else if(buf[0] == 'M' && bflag == 1 && (strlen(buf) == 61 || strlen(buf) == 62)) { /*uue stuff*/ if(puts(buf) == EOF) { fprintf(stderr, "error on puts.\n"); exit(0); } cnt++; num++; if(cnt == INTERVAL) { fprintf(stderr, "."); fflush(stderr); cnt = 0; } } else if(strcmp(buf, "end") == 0) { /* end */ if(puts(bufb) == EOF) { fprintf(stderr, "error on puts.\n"); exit(0); } if(puts(bufa) == EOF) { fprintf(stderr, "error on puts.\n"); exit(0); } if(puts(buf) == EOF) { fprintf(stderr, "error on puts.\n"); exit(0); } fprintf(stdout, "\n\n"); eflag = 1; break; } strcpy(bufb, bufa); strcpy(bufa, buf); } if(bflag != 1) { fprintf(stderr, "Error: never found \"begin\" line.\n"); exit(0) ; } if(eflag != 1) { fprintf(stderr, "Error: never found \"end\" line. num = %d\n", num); exit(0) ; } fclose(in); fprintf(stderr, " done.\nFound %d lines in file.\n", num); }