home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / uucopy.zip / uucopy.c next >
C/C++ Source or Header  |  1995-02-26  |  1KB  |  57 lines

  1. #include <process.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <io.h>
  5. int main(int argc, char *argv[])
  6. {
  7.  FILE *fp;
  8.  char string[1024];
  9.  if (argc != 2) {
  10.   printf("UUCOPY V0.01\n\nSYNTAX: UUCOPY filename\n");
  11.   return 0;
  12.  }
  13.  if ((fp=fopen(argv[1],"rt")) == NULL) {
  14.   fprintf(stderr,"Cannot open input file %s\n",argv[1]);
  15.   return 1;
  16.  }
  17.  while(fscanf(fp,"%[^\n]\n",&string) != EOF) {
  18.   switch (string[0]) {
  19.    case '#':
  20.     printf("Copying and truncating file %s\n",string+1);
  21.     if (spawnlp(P_WAIT,"xcopy.exe","xcopy.exe",string+1,NULL) != 0) {
  22.      fprintf(stderr,"Unable to copy file %s\n",string+1);
  23.      return 1;
  24.     }
  25.     if (_truncate(string+1,0) != 0) {
  26.      fprintf(stderr,"Unable to truncate file %s\n",string+1);
  27.      return 1;
  28.     }
  29.    break;
  30.    case '^':
  31.     printf("Copying and deleting file %s\n",string+1);
  32.     if (spawnlp(P_WAIT,"xcopy.exe","xcopy.exe",string+1,NULL) != 0) {
  33.      fprintf(stderr,"Unable to copy file %s\n",string+1);
  34.      return 1;
  35.     }
  36.     if (unlink(string+1) != 0){
  37.      fprintf(stderr,"Unable to delete file %s\n",string+1);
  38.      return 1;
  39.     }
  40.    break;
  41.    default :
  42.     printf("Copying file %s\n",string);
  43.     if (spawnlp(P_WAIT,"xcopy.exe","xcopy.exe",string+1,NULL) != 0) {
  44.      fprintf(stderr,"Unable to copy file %s\n",string+1);
  45.      return 1;
  46.     }
  47.    }
  48.  } 
  49.  fclose(fp);
  50.  if (unlink(argv[1]) != 0){
  51.   fprintf(stderr,"Unable to delete file %s\n",argv[1]);
  52.   return 1;
  53.  }
  54.  return 0;
  55. }
  56.  
  57.