home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm.lzh / multicopy.c < prev    next >
Text File  |  1995-04-07  |  5KB  |  176 lines

  1. /* multicopy.c function for DISKMASTER.C      */
  2. /* copyright (c) 1995 by Bob Devries          */
  3. /* email: bdevries@gil.ipswichcity.qld.gov.au */
  4.  
  5. /* copies all tagged files to a destination directory */
  6.  
  7. #include "diskmaster.h"
  8. #include <stdio.h>
  9. #include <modes.h>
  10. #include <strings.h>
  11.  
  12. int
  13. multicopy(numfiles)
  14. int numfiles;
  15. {
  16.     extern char **nameptr;
  17.     extern short *attrptr;
  18.     int x, confirm, overwrite, ask, error;
  19.     char *copycmd, *todir, *malloc();
  20.  
  21.     copycmd = malloc(numfiles*32+256);
  22.     todir = malloc(80);
  23.  
  24.     gotoxy(1,24);
  25.     cleol();
  26.     printf("     %cCopy tagged files to: ",7);
  27.     lineinput(todir,80);
  28.     if(*todir == '\0') {
  29.         free(copycmd);
  30.         free(todir);
  31.         commands();
  32.         return(FAIL);
  33.     }
  34.     if(access(todir,S_IFDIR+S_IWRITE+S_IREAD) != 0) {
  35.         gotoxy(1,24);
  36.         cleol();
  37.         printf("     %c%s is not a directory!",7,todir);
  38.         sleep(1);
  39.         free(copycmd);
  40.         free(todir);
  41.         commands();
  42.         return(FAIL);
  43.     }
  44.     gotoxy(1,24);
  45.     cleol();
  46.     printf("     %cConfirm each copy y/N ",7);
  47.     do {
  48.         confirm = toupper(getchar());
  49.         flush_kbd();
  50.     } while ((confirm != 'Y') && (confirm != 'N') && (confirm != '\n'));
  51.     if(confirm == '\n') {
  52.         confirm = 'N';
  53.     }
  54.     gotoxy(1,24);
  55.     cleol();
  56.     printf("     %cForce overwrite y/N ",7);
  57.     do {
  58.         overwrite = toupper(getchar());
  59.         flush_kbd();
  60.     } while ((overwrite != 'Y') && (overwrite != 'N') && (overwrite != '\n'));
  61.     if(overwrite == '\n') {
  62.         overwrite = 'N';
  63.     }
  64.     if((confirm == 'N') && (overwrite == 'Y')) {
  65.         strcpy(copycmd,"copy -rw=");
  66.         strcat(copycmd,todir);
  67.         strcat(copycmd," ");
  68.         for(x=1;x<=numfiles;x++) {
  69.             if((attrptr[x]&TAG) == TAG) {
  70.                 attrptr[x]&=0xFF;
  71.                 strcat(copycmd,nameptr[x]);
  72.                 strcat(copycmd,">>>/nil");
  73.                 gotoxy(1,24);
  74.                 cleol();
  75.                 printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  76.                 system(copycmd);
  77.                 *(rindex(copycmd,' ') + 1) = '\0';
  78.             }
  79.         }
  80.         free(copycmd);
  81.         free(todir);
  82.         commands();
  83.         return(PASS);
  84.     }
  85.     if((confirm == 'Y') && (overwrite == 'Y')) {
  86.         strcpy(copycmd,"copy -rw=");
  87.         strcat(copycmd,todir);
  88.         for(x=1;x<=numfiles;x++) {
  89.             if((attrptr[x]&TAG) == TAG) {
  90.                 attrptr[x]&=0xFF;
  91.                 strcat(copycmd," ");
  92.                 strcat(copycmd,nameptr[x]);
  93.                 strcat(copycmd,">>>/nil");
  94.                 gotoxy(1,24);
  95.                 cleol();
  96.                 printf("     %cCopy %s TO %s? (y/N)",7,nameptr[x],todir);
  97.                 ask = toupper(getchar());
  98.                 flush_kbd();
  99.                 if(ask == 'Y') {
  100.                     gotoxy(1,24);
  101.                     cleol();
  102.                     printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  103.                     system(copycmd);
  104.                 }
  105.                 *(rindex(copycmd,' ')) = '\0';
  106.             }
  107.         }
  108.         free(copycmd);
  109.         free(todir);
  110.         commands();
  111.         return(PASS);
  112.     }
  113.     if((confirm == 'N') && (overwrite == 'N')) {
  114.         strcpy(copycmd,"copy -w=");
  115.         strcat(copycmd,todir);
  116.         strcat(copycmd," ");
  117.         for(x=1;x<=numfiles;x++) {
  118.             if((attrptr[x]&TAG) == TAG) {
  119.                 attrptr[x]&=0xFF;
  120.                 strcat(copycmd,nameptr[x]);
  121.                 strcat(copycmd,">>>/nil");
  122.                 gotoxy(1,24);
  123.                 cleol();
  124.                 printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  125.                 error = system(copycmd);
  126.                 if(error == 218) {
  127.                     gotoxy(1,24);
  128.                     cleol();
  129.                     printf("     %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
  130.                     sleep(1);
  131.                 }
  132.                 *(rindex(copycmd,' ') + 1) = '\0';
  133.             }
  134.         }
  135.         free(copycmd);
  136.         free(todir);
  137.         commands();
  138.         return(PASS);
  139.     }
  140.     if((confirm == 'Y') && (overwrite == 'N')) {
  141.         strcpy(copycmd,"copy -w=");
  142.         strcat(copycmd,todir);
  143.         for(x=1;x<=numfiles;x++) {
  144.             if((attrptr[x]&TAG) == TAG) {
  145.                 attrptr[x]&=0xFF;
  146.                 strcat(copycmd," ");
  147.                 strcat(copycmd,nameptr[x]);
  148.                 strcat(copycmd,">>>/nil");
  149.                 gotoxy(1,24);
  150.                 cleol();
  151.                 printf("     %cCopy %s TO %s? y/N ",7,nameptr[x],todir);
  152.                 ask = toupper(getchar());
  153.                 flush_kbd();
  154.                 if(ask == 'Y') {
  155.                     gotoxy(1,24);
  156.                     cleol();
  157.                     printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  158.                     error = system(copycmd);
  159.                     if(error == 218) {
  160.                         gotoxy(1,24);
  161.                         cleol();
  162.                         printf("     %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
  163.                     }
  164.                 }
  165.                 *(rindex(copycmd,' ')) = '\0';
  166.             }
  167.         }
  168.         free(copycmd);
  169.         free(todir);
  170.         commands();
  171.         return(PASS);
  172.     }
  173. }
  174.  
  175. /* EOF multicopy.c */
  176.