home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
netx
/
bm
/
uuencode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-06-11
|
2KB
|
68 lines
/* uuencode.c */
/* encode a binary file into a printable ascii file */
/* suitable to be included and send via MAIL to an- */
/* other user somewhere in the systems */
#include <stdio.h>
FILE *infile;
main(argc,argv)
int argc;
char *argv[];
{
int c,i,j,count,loop;
char ch1,ch2,iline[45];
char *remotedest;
count = 0;
if((argc < 2) || (argc > 3))
errexit("Usage: uuencode [source] remotedest",NULL);
if( argc == 3 ){
if((infile = fopen(argv[1],"r")) == NULL)
errexit("Cannot open",argv[1]);
remotedest = argv[2];
} else {
infile = stdin;
remotedest = argv[1];
}
printf("begin 001 %s \n",remotedest);
loop = 1;
while(loop == 1) {
i = 0;
while((i < 45) && ((c = getc(infile)) != EOF)) {
iline[ i++ ] = c;
}
if( c == EOF)
loop = 0;
putchar(i+0x20);
for(j = 0 ;j < i; ) {
ch1 = iline[j++];
c=((ch1 >> 2) & 0x3f) + 0x20;
putchar(c);
ch2 = iline[j++];
c=(((ch1 & 0x03) << 4) | ((ch2 >> 4 ) & 0x0f))+0x20;
putchar(c);
ch1 = iline[j++];
c=(((ch2 & 0x0f) << 2) | ((ch1 >> 6) & 0x03)) +0x20;
putchar(c);
c=(ch1 & 0x3f) + 0x20;
putchar(c);
};
putchar('\n');
count+=1;
}
printf(" \nend\n");
fclose(infile);
printf("Processing complete, total lines = %d.\n",count);
exit(0);
}
errexit(s1,s2) /* print error message and exit */
char *s1,*s2; /* the error strings */
{
printf(s2 == NULL ? "%s\n" : "%s %s\n",s1,s2);
exit(-1);
}