From: root AT jacob DOT remcomp DOT fr (root) Subject: Re: uudecode? 10 Sep 1997 16:50:33 -0700 Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: Content-Type: text Original-To: john DOT cooper AT digitivity DOT com Original-Cc: gnu-win32 AT cygnus DOT com In-Reply-To: <19970909143204218.AAA362@TENDLE> from "John Cooper" at Sep 9, 97 03:32:05 pm Original-Sender: owner-gnu-win32 AT cygnus DOT com To satisfy popular demand, here is uudecode: ------------------------------------------------------------cut here #include #include #define DEC(c) (((c) - ' ') & 077) static char outname[200]; int ReadDataLine(FILE *f,char *buf) { int c,i; i=0; while ((c=fgetc(f)) != EOF) { if (c == '\n') break; if (c != '\r') { buf[i++] = c; } } buf[i] = 0; return(c == EOF ? 0 : 1); } static char *uudecode (FILE *f) { register int n; register char ch, *p; char buf[2 * BUFSIZ]; FILE *out; do { if (!ReadDataLine(f,buf)) return(NULL); } while (strncmp(buf,"begin",5)); p = buf + 6; while (*p && (*p == ' '|| *p == '0' || *p == '6')) p++; strcpy(outname,p); /* Create output file and set mode. */ out = fopen(outname,"wb"); /* For each input line: */ while (1) { if (!ReadDataLine(f,buf)) break; if (!strncmp(buf,"end\r\n",5)) break; p = buf; /* N is used to avoid writing out all the characters at the end of the file. */ n = DEC (*p); if (n <= 0) break; for (++p; n > 0; p += 4, n -= 3) { if (n >= 3) { ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4; fputc(ch,out); ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2; fputc (ch,out); ch = DEC (p[2]) << 6 | DEC (p[3]); fputc (ch,out); } else { if (n >= 1) { ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4; fputc (ch,out); } if (n >= 2) { ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2; fputc (ch,out); } } } } fclose(out); return outname; } int main(int argc,char *argv[]) { FILE *f; if (argc <= 1) { printf("Usage: %s \n",argv[0]); return(1); } f = fopen(argv[1],"rb"); if (f == NULL) { printf("Impossible to open %s\n",argv[1]); return(1); } uudecode(f); fclose(f); printf("Result decoded into %s\n",outname); return(0); } ----------------------------------------------------------------cut here -- Jacob Navia Logiciels/Informatique 41 rue Maurice Ravel Tel 01 48.23.51.44 93430 Villetaneuse Fax 01 48.23.95.39 France - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".