home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
netx
/
bm
/
uudecode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-06-11
|
2KB
|
119 lines
/* uudecode.c */
/* decode a printable ascii file created by uuencode into */
/* its original binary file mode. Input is expected from */
/* stdin as uudecode is used via a pipe with mail. */
#include <stdio.h>
FILE *outfile;
int count;
main(argc,argv)
int argc;
char *argv[];
{
int c,i,j,k,l,loop;
char ch1,ch2;
char remotedest[65];
char *begin,*end;
begin = "begin ";
end = "end";
count = 0;
if((argc < 2) || (argc > 2))
errexit("Usage: uudecode file (mail | uudecode file)",NULL);
if((outfile = fopen(argv[1],"w")) == NULL)
errexit("Cannot open",argv[1]);
if(findbeg()){
i = 0;
while((c = get_n_c()) != 0x0a) remotedest[i++] = c;
remotedest[i] = 0x00;
printf(" Remote destination = %s\n",remotedest);
/* fndeol();
*/
loop = 1;
while(loop == 1) {
i = get_n_c() - 0x20;
if( i == 0)
loop = 0;
else {
j = 0;
while(j < i) {
switch( j % 3) {
case 0: ch1 = (get_n_c() - 32) << 2;
ch2 = get_n_c() - 32;
ch1 = ch1 | (ch2 >> 4);
putc(ch1,outfile);
ch1 = (ch2 << 4);
break ;
case 1: ch2 = (get_n_c() - 32);
ch1 = ch1 | (ch2 >>2);
putc(ch1,outfile);
ch1 = (ch2 << 6);
break ;
case 2: ch2 = (get_n_c() - 32);
ch1 = ch1 | ch2;
putc(ch1,outfile);
break ;
}
j++;
}
count+=1;
}
fndeol();
}
}
if(get_n_c() == 'e')
printf("Processing complete, total lines = %d.\n",count);
fndeol();
fclose(outfile);
exit(0);
}
findbeg()
{
char c;
int i,j,loop;
loop = 1;
while(loop) {
c = get_n_c();
if( c != 'b') {
c = fndeol();
}
if(c == 'b') {
if(get_n_c() == 'e')
if(get_n_c() == 'g')
if(get_n_c() == 'i')
if(get_n_c() == 'n')
if(get_n_c() == ' '){
return 1;
}
}
}
}
fndeol()
{
char c;
while(((c = get_n_c()) != 0x0a)) ;
return c;
}
get_n_c()
{
int c;
c = getchar();
if( c == EOF )
if( count == 0)
errexit(" begin not found",NULL);
else
errexit(" Unexpected EOF found",NULL);
return c;
}
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);
}