1 Received: from CU-ARPA.CS.CORNELL.EDU by loki.cs.cornell.edu (5.61/I-1.91f)
2 id AA25874; Wed, 18 Jul 90 12:02:22 -0400
3 Message-Id: <9007181320.AA24810@cu-arpa.cs.cornell.edu>
4 Received: from CORNELLC.CIT.CORNELL.EDU by cu-arpa.cs.cornell.edu (5.61+2/1.91d)
5 id AA24810; Wed, 18 Jul 90 09:20:21 -0400
6 Received: from CORNELLC by CORNELLC.cit.cornell.edu (IBM VM SMTP R1.2.1MX) with BSMTP id 6769; Wed, 18 Jul 90 09:18:46 EDT
7 Received: from CAS.BITNET (MAILER) by CORNELLC (Mailer R2.05X) with BSMTP id
8 5378; Wed, 18 Jul 90 09:18:38 EDT
9 From: swl26%CAS.BITNET@CORNELLC.cit.cornell.edu
10 Date: Wed, 18 Jul 1990 09:16 EDT
11 Subject: Re(2): diffs for mvs port of flex-2.3
12 In-Reply-To: Your message of Tue, 17 Jul 90 17:42:3
13 To: vern@cs.cornell.edu
15 Sorry about the trailing blank problem. It's farily common with data sent
16 through bitnet paths, but ever the optimist ...
18 >I think there should be an 'M' at the beginning of the second line.
20 This isn't a problem. I believe that the first byte of the line indicates
21 it's length (in some manner).
23 Rather than re-send the data, how about a uudecode that compensates for
24 the trailing blank problem? I manually mangled the uuencoded file and ran
25 the following decode, and it seemed to work.
28 # This is a shell archive. Remove anything before this line, then feed it
29 # into a shell via "sh file" or similar. To overwrite existing files,
31 # The tool that generated this appeared in the comp.sources.unix newsgroup;
32 # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
33 # If this archive is complete, you will see the following message at the end:
34 # "End of shell archive."
35 # Contents: uudecode.c
36 # Wrapped by swl26@swl26aws on Wed Jul 18 08:59:24 1990
37 PATH=/bin:/usr/bin:/usr/ucb ; export PATH
38 if test -f 'uudecode.c' -a "${1}" != "-c" ; then
39 echo shar: Will not clobber existing file \"'uudecode.c'\"
41 echo shar: Extracting \"'uudecode.c'\" \(6418 characters\)
42 sed "s/^X//" >'uudecode.c' <<'END_OF_FILE'
44 Xstatic char sccsid[] = "@(#)uudecode.c 5.3-1 (Berkeley) 9/1/87";
47 X/* Written by Mark Horton */
48 X/* Modified by ajr (Alan J Rosenthatl,flaps@utcsri.UUCP) to use checksums */
49 X/* Modified by fnf (Fred Fish,well!fnf) to use Keith Pyle's suggestion for
51 X/* Modified by bcn (Bryce Nesbitt,ucbvax!cogsci!bryce) to fix a misleading
52 X error message on the Amiga port, to fix a bug that prevented decoding
53 X certain files, to work even if trailing spaces have been removed from a
54 X file, to check the filesize (if present), to add some error checking, to
55 X loop for multiple decodes from a single file, and to handle common
56 X BITNET mangling. Also kludged around a missing string function in Aztec
62 X * Decode a file encoded with uuencode. WIll extract multiple encoded
63 X * modules from a single file. Can deal with most mangled files, including
71 X#define AMIGA_LATTICE /* Set for Amiga Lattice C */
78 X#include <sys/types.h>
79 X#include <sys/stat.h>
83 X#define DEC(c) (((c) - ' ') & 077) /* single character decode */
89 Xint through_loop=0; /* Dejavu indicator */
90 Xint mode; /* file's mode (from header) */
91 Xlong filesize; /* theoretical file size (from header) */
96 Xextern int Enable_Abort;
100 X /* A filename can be specified to be uudecoded, or nothing can
101 X be specified, and the input will come from STDIN */
110 X if ((in = fopen(argv[1], "r")) == NULL)
112 X fprintf(stderr, "ERROR: can't find %s\n", argv[1]);
113 X fprintf(stderr, "USAGE: uudecode [infile]\n");
119 X fprintf(stderr, "USAGE: uudecode [infile]\n");
124 X /* Loop through file, searching for headers. Decode anything with a
125 X header, complain if there where no headers. */
129 X /* search file for header line */
132 X if (fgets(buf, sizeof buf, in) == NULL)
136 X fprintf(stderr, "ERROR: no `begin' line!\n");
144 X if (strncmp(buf, "begin ", 6) == 0)
147 X sscanf(buf, "begin %o %s", &mode, dest);
150 X /* handle ~user/file format */
151 X if (dest[0] == '~')
154 X struct passwd *getpwnam();
156 X struct passwd *user;
159 X sl = index(dest, '/');
162 X fprintf(stderr, "Illegal ~user\n");
166 X user = getpwnam(dest+1);
169 X fprintf(stderr, "No such user as %s\n", dest);
172 X strcpy(dnbuf, user->pw_dir);
173 X strcat(dnbuf, "/");
175 X strcpy(dest, dnbuf);
179 X /* create output file */
180 X if ((out = fopen(dest, "w")) == NULL)
182 X fprintf(stderr, "ERROR: can't open output file %s\n", dest);
189 X decode(in, out, dest);
191 X if (fgets(buf, sizeof buf, in) == NULL || strncmp(buf,"end",3))
192 X { /* don't be overly picky about newline ^ */
193 X fprintf(stderr, "ERROR: no `end' line\n");
197 X if (!(fgets(buf,sizeof buf,in) == NULL || strncmp(buf,"size ",3)))
199 X sscanf(buf, "size %ld", &filesize);
200 X if (ftell(out) != filesize)
202 X fprintf(stderr, "ERROR: file should have been %ld bytes long but was
211 X * Copy from in to out, decoding as you go.
212 X * If a return or newline is encountered too early in a line, it is
213 X * assumed that means that some editor has truncated trailing spaces.
215 Xdecode(in, out, dest)
230 X for (line = 1; ; line++) /* for each input line */
232 X if (fgets(buf, sizeof buf, in) == NULL)
234 X fprintf(stderr, "ERROR: input ended unexpectedly!\n");
238 X /* Pad end of lines in case some editor truncated trailing
241 X for (n=0;n<79;n++) /* search for first \r, \n or \000 */
243 X if (buf[n]=='\176') /* If BITNET made a twiddle, */
244 X buf[n]='\136'; /* we make a caret */
245 X if (buf[n]=='\r'||buf[n]=='\n'||buf[n]=='\000')
248 X for (;n<79;n++) /* when found, fill rest of line with space */
252 X buf[79]=0; /* terminate new string */
257 X break; /* 0 bytes on a line?? Must be the last line */
261 X /* FOUR input characters go into each THREE output charcters */
265 X j = DEC(bp[0]) << 2 | DEC(bp[1]) >> 4; putc(j, out); checksum += j;
266 X j = DEC(bp[1]) << 4 | DEC(bp[2]) >> 2; putc(j, out); checksum += j;
267 X j = DEC(bp[2]) << 6 | DEC(bp[3]); putc(j, out); checksum += j;
268 X checksum = checksum % SUMSIZE;
273 X j = DEC(bp[0]) << 2 | DEC(bp[1]) >> 4;
277 X j = DEC(bp[1]) << 4 | DEC(bp[2]) >> 2;
281 X j = DEC(bp[2]) << 6 | DEC(bp[3]);
285 X checksum = checksum % SUMSIZE;
290 X /* Error checking under UNIX??? You must be kidding... */
291 X /* Check if an error occured while writing to that last line */
294 X fprintf(stderr, "ERROR: error writing to %s\n",dest);
299 X /* The line has been decoded; now check that sum */
301 X nosum |= !isspace(*bp);
302 X if (nosum) /* Is there a checksum at all?? */
304 X if (checksum != DEC(*bp)) /* Does that checksum match? */
306 X fprintf(stderr, "ERROR: checksum mismatch decoding %s, line %d.\
314 X * Return the ptr in sp at which the character c appears;
319 Xregister char *sp, c;
334 echo shar: NEWLINE appended to \"'uudecode.c'\"
335 if test 6419 -ne `wc -c <'uudecode.c'`; then
336 echo shar: \"'uudecode.c'\" unpacked with wrong size!
338 # end of 'uudecode.c'
340 echo shar: End of shell archive.