home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / packer / uuprep10 / uuprep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-15  |  2.3 KB  |  85 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <process.h>
  5.  
  6. void main(int argc, char *argv[])
  7. {
  8.   FILE *Input, *Output;
  9.   char line[256], name[256], ext[4] = ".01", *c;
  10.   int  number = 1;
  11.  
  12.   printf("This is uuprep, Version 1.0, written 1992 by Johannes Martin\n");
  13.   if (argc != 3)
  14.     {
  15.       printf("\nuuprep: wrong number of arguments\n\n");
  16.       printf("uuprep: PREPare files for UUdecoding\n\n");
  17.       printf("Usage: uuprep <input-file> <output-file>\n");
  18.       printf("       \".uue\" will be appended to both filenames\n\n");
  19.       exit(1);
  20.     }
  21.   if (strcmp(argv[1], argv[2]) == 0)
  22.     {
  23.       printf("uuprep: input and output file have same name\n");
  24.       exit(1);
  25.     }
  26.   strcpy(name, argv[1]);
  27.   strcat(name, ".uue");
  28.   if ((Input = fopen(name, "r")) == NULL)
  29.     {
  30.       printf("uuprep: file \"%s\" not found\n", name);
  31.       exit(1);
  32.     }
  33.   while (fgets(line, 256, Input) != NULL)
  34.     {
  35.       if (((c = strstr(line, "part")) != NULL) &&
  36.           (*(c + 6) == '/'))
  37.         {
  38.           ext[1] = *(c + 4);
  39.           ext[2] = *(c + 5);
  40.         }
  41.       else
  42.         if (strncmp(line, "BEGIN--cut here--cut here", 25) == 0)
  43.           {
  44.             strcpy(name, argv[2]);
  45.             strcat(name, ext);
  46.             if ((Output = fopen(name, "w")) == NULL)
  47.               {
  48.                 printf("uuprep: could not create file \"%s\"\n", name);
  49.                 fclose(Input);
  50.                 exit(1);
  51.               }
  52.             while ((fgets(line, 256, Input) != NULL) &&
  53.                    (strncmp(line, "END--cut here--cut here", 23) != 0))
  54.               fputs(line, Output);
  55.             fclose(Output);
  56.           }
  57.     }
  58.   fclose(Input);
  59.   strcpy(name, argv[2]);
  60.   strcat(name, ".uue");
  61.   if ((Output = fopen(name, "w")) == NULL)
  62.     {
  63.       printf("uuprep: could not create file \"%s\"\n", name);
  64.       exit(1);
  65.     }
  66.   while (1)
  67.     {
  68.       ext[1] = number / 10 + '0';
  69.       ext[2] = number % 10 + '0';
  70.       strcpy(name, argv[2]);
  71.       strcat(name, ext);
  72.       if ((Input = fopen(name, "r")) == NULL)
  73.         break;
  74.       while (fgets(line, 256, Input) != NULL)
  75.         fputs(line, Output);
  76.       fclose(Input);
  77.       unlink(name);
  78.       number++;
  79.     }
  80.   fclose(Output);
  81.   strcpy(name, argv[2]);
  82.   strcat(name, ".uue");
  83.   execlp("uudecode", "uudecode", name, NULL);
  84. }
  85.