home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- subject: v11i097: latest uudec.cc for the world
- From: GORMAN_B@uk.ac.LANCSP.P1 (Barry Gorman )
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 11, Issue 97
- Submitted-by: GORMAN_B@uk.ac.LANCSP.P1 (Barry Gorman )
- Archive-name: uudec/part01
-
- Some little time ago, I asked a good friend on a unix site to send me a copy
- of a uudecoder program. I was sent the version by scott@max (see below).
- Needless to say I had a fiddle with it, and I append the result of this.
- I would claim that the transformed program is more "structured" (what is this?)
- and certainly shorter. I have used my personal layout rules (indent=4*{'s)
- which will no doubt be controversial. Please feel free to use, distribute etc.
-
- Please do not attempt to reply via the uucp gateway @ uk.ac.ukc; but earn-relay
- and nsfnet-relay are ok. Alternatively send via jjsc@uk.ac.rl.inf for forwarding
-
- Barry
- .....
- ----------------------------------- cut here -----------------------------------
- #! /bin/sh
- # This file was wrapped with "dummyshar". "sh" this file to extract.
- # Contents: uudec.c
- echo extracting 'uudec.c'
- if test -f 'uudec.c' -a -z "$1"; then echo Not overwriting 'uudec.c'; else
- sed 's/^X//' << \EOF > 'uudec.c'
- X/********** From: scott@max.u.washington.edu - 20 Feb 90 21:13:03 GMT *********/
- X/* For the those may not have access to a UUDECODER, you may not
- X * be able to take benefit of like UX-Maze file exchange
- X * which require the files to be uuencoded.
- X * If that is the case may be just may be the following posts
- X * will be of help. This post contains the source code in
- X * C of a UUDECODER tested on msc 3.0 and PCDOS 3.1.
- X * Perhaps if you have access to an IBM/CLONE you could do
- X * the file uudecoding on the IBM before the final transfer
- X * to the C64 or C128.
- X * Or perhaps if you are knowledgeable with programing you
- X * could convert this program for the C64 or perhaps to another
- X * popular language like Pascal or Fortran that is supported
- X * by your system.
- X
- X/* source code reduced in size whilst maintaining the exact operation
- X * of the original program: GORMAN_B@UK.AC.LANCSP.P1 March 19th 1990.
- X * Probably favours machines capable of 32 bit working; but should
- X * work on others. The "register unsigned long word" variable is used
- X * for some long (16 place) shifts. This may or may not be faster than
- X * the use of division, depending on you processor design. I have left
- X * it in this form as I feel it is in the spirit of C and illustrates
- X * my technique. (bring back 24 bit machines with cyclic shifts!)
- X
- X/* usage for this file is as follows:
- X * uudecode <input file name (with extension)>
- X * file is placed in the file name contained on the
- X * first line of the uuencoded file ...
- X *
- X * The program expects this to look like begin XXX <FN>
- X * where XXX are the Unix(tm) file permissions
- X * and <fn> is the Unix file name. If this name is
- X * too long for DOS, edit it to fit. It has been
- X * tested with msc v3.0 and PC-DOS 3.1. the companion
- X * file is uuencode.c ...
- X
- X/*************************** single character decode **************************/
- X
- X#define DEC(c) (((c) - ' ') & 077)
- X#include <stdio.h>
- X
- X/************************************ MAIN ************************************/
- Xmain (argc,argv) int argc; char *argv[]; /* expects one (or no) argument */
- X/******************************************************************************/
- X
- X {FILE *in, *out; char buf[80];
- X
- X switch(argc) /* sort out number of arguments supplied */
- X
- X {default: fprintf(stderr,"Usage: uudec [file]n"); exit(2); /* 2+ args */
- X
- X case 1: in=stdin; break; /* take source from stdin */
- X
- X case 2: if(!(in=fopen(argv[1],"r"))) {perror(argv[1]); exit(1);}}
- X
- X/***** now that the source has been identified, scan for the "begin" line *****/
- X
- X do if(!(fgets(buf,sizeof buf,in))) /* read input line by line */
- X
- X {fprintf(stderr, "No "begin" linen"); exit(3);} /* complain if end */
- X
- X while(strncmp(buf,"begin ",6)); /* until the "begin" line is found */
- X
- X/* the begin line must be followed by three (octal) digits and the file name **/
- X
- X {char dest[32]; int mode; /* these variables are needed transiently */
- X
- X sscanf(buf,"begin %o %s",&mode,dest); /* extract mode and file name */
- X
- X if(!(out=fopen(dest,"w"))) {perror(dest); exit(4);}} /* open outfile? */
- X
- X/** having opened the file and read the "begin" line, decode it line by line **/
- X
- X {char *p; int n; /* line pointer and character count */
- X
- X while((p=fgets(buf,sizeof buf,in)) ? (n=DEC(buf[0])) /* read line */
- X
- X : (fprintf(stderr,"Short filen"), exit(10))) /* end of file */
- X
- X {register unsigned long word; int k; /* local workspace */
- X
- X do {k=4; do word=word<<6|DEC(*++p); while(--k); /* decode 4 to 3 */
- X
- X k=3; do {putc(word>>16,out); word<<=8;} while(--n && --k);}}
- X
- X while(n);}} /* keep going until all decoding done */
- X
- X/* the decode should now be complete, we have read the zero length byte count */
- X
- X if(!(fgets(buf,sizeof buf,in)) || strncmp(buf,"end",3)) /* check for end */
- X
- X {fprintf(stderr,"No "end" linen"); exit(5);}} /* complain if none */
- X
- X/******************************** end of uudec ********************************/
- EOF
- chars=`wc -c < 'uudec.c'`
- if test $chars != 4181; then echo 'uudec.c' is $chars characters, should be 4181 characters!; fi
- fi
- exit 0
-
-
- ---
- ===============================================================================
- John Cullen || JANET : jjsc@uk.ac.rl.inf
- System Support Group || ARPA : jjsc%inf.rl.ac.uk@nsfnet-relay.ac.uk
- Informatics Department || BITNET: jjsc@ukacrl (I think!)
- Rutherford Appleton Laboratory || UUCP : {...!mcvax}!ukc!rlinf!jjsc
- Chilton, Didcot, Oxon. OX11 0QX || VOICE : +44 (0)235 821900 ext 6555
- ===============================================================================
- Your fortune cookie says:
- Birth: The first and direst of all disasters.
-
-