home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / netx / bm / uuencode.c < prev    next >
C/C++ Source or Header  |  1987-06-11  |  2KB  |  68 lines

  1. /* uuencode.c */
  2.        /* encode a binary file into a printable ascii file */
  3.        /* suitable to be included and send via MAIL to an- */
  4.        /* other user somewhere in the systems */
  5. #include <stdio.h>
  6.  
  7. FILE *infile;
  8.  
  9. main(argc,argv)
  10. int argc;
  11. char *argv[];
  12. {
  13.     int c,i,j,count,loop;
  14.     char ch1,ch2,iline[45];
  15.     char *remotedest;
  16.  
  17.     count = 0;
  18.     if((argc < 2) || (argc > 3))
  19.         errexit("Usage: uuencode [source] remotedest",NULL);
  20.         if( argc == 3 ){
  21.             if((infile = fopen(argv[1],"r")) == NULL)
  22.                 errexit("Cannot open",argv[1]);
  23.         remotedest = argv[2];
  24.     } else {
  25.         infile = stdin;
  26.         remotedest = argv[1];
  27.     }
  28.  
  29.     printf("begin 001 %s \n",remotedest);
  30.     loop = 1;
  31.     while(loop == 1)  {
  32.         i = 0;
  33.         while((i < 45) && ((c = getc(infile)) != EOF)) {
  34.             iline[ i++ ] = c;
  35.         }
  36.         if( c == EOF) 
  37.             loop = 0;
  38.         putchar(i+0x20);
  39.         for(j = 0 ;j < i; ) {
  40.             ch1 = iline[j++];
  41.             c=((ch1 >> 2) & 0x3f) + 0x20;
  42.             putchar(c);
  43.             ch2 = iline[j++];
  44.             c=(((ch1 & 0x03) << 4) | ((ch2 >> 4 ) & 0x0f))+0x20;
  45.             putchar(c);
  46.             ch1 = iline[j++];
  47.             c=(((ch2 & 0x0f) << 2) | ((ch1 >> 6) & 0x03)) +0x20;
  48.             putchar(c);
  49.             c=(ch1 & 0x3f) + 0x20;
  50.             putchar(c);
  51.         };
  52.          putchar('\n');
  53.         count+=1;
  54.     }
  55.     printf(" \nend\n");
  56.     fclose(infile);
  57.  
  58.     printf("Processing complete, total lines = %d.\n",count);
  59.     exit(0);
  60. }
  61. errexit(s1,s2)        /* print error message and exit */
  62. char *s1,*s2;        /* the error strings          */
  63. {
  64.     printf(s2 == NULL ? "%s\n" : "%s %s\n",s1,s2);
  65.     exit(-1);
  66. }
  67.  
  68.