home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm14.lzh / multicopy.c < prev    next >
Text File  |  1996-07-24  |  6KB  |  205 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. #include <module.h>
  12. #include <errno.h>
  13.  
  14. int
  15. multicopy(numfiles)
  16. int numfiles;
  17. {
  18.     extern char **nameptr;
  19.     extern short *attrptr;
  20.     int x, confirm, overwrite, ask, s_error;
  21.     char *copycmd, *todir, *malloc();
  22.     mod_exec *modloadp(), *modp;
  23.     
  24.     if ((modp = modloadp("copy",0,NULL)) == NULL) {
  25.         error("Can't load command","COPY",errno);
  26.         return(FAIL);
  27.     }
  28.  
  29.     copycmd = malloc(numfiles*32+256);
  30.     todir = malloc(80);
  31.  
  32.     gotoxy(1,24);
  33.     cleol();
  34.     printf("     %cCopy tagged files to: ",7);
  35.     lineinput(todir,80);
  36.     if(*todir == '\0') {
  37.         free(copycmd);
  38.         free(todir);
  39.         commands();
  40.         munlink(modp);
  41.         return(FAIL);
  42.     }
  43.     if(access(todir,S_IFDIR+S_IWRITE+S_IREAD) != 0) {
  44.         gotoxy(1,24);
  45.         cleol();
  46.         printf("     %c%s is not a directory!",7,todir);
  47.         sleep(1);
  48.         free(copycmd);
  49.         free(todir);
  50.         commands();
  51.         munlink(modp);
  52.         return(FAIL);
  53.     }
  54.     gotoxy(1,24);
  55.     cleol();
  56. #ifdef MM1
  57.     CurOn(1);
  58. #endif
  59.     printf("     %cConfirm each copy y/N ",7);
  60.     do {
  61.         confirm = toupper(getchar());
  62.         flush_kbd();
  63.     } while ((confirm != 'Y') && (confirm != 'N') && (confirm != '\n'));
  64.     if(confirm == '\n') {
  65.         confirm = 'N';
  66.     }
  67.     gotoxy(1,24);
  68.     cleol();
  69.     printf("     %cForce overwrite y/N ",7);
  70.     do {
  71.         overwrite = toupper(getchar());
  72.         flush_kbd();
  73.     } while ((overwrite != 'Y') && (overwrite != 'N') && (overwrite != '\n'));
  74.     if(overwrite == '\n') {
  75.         overwrite = 'N';
  76.     }
  77.     if((confirm == 'N') && (overwrite == 'Y')) {
  78.         strcpy(copycmd,"copy -rw=");
  79.         strcat(copycmd,todir);
  80.         strcat(copycmd," ");
  81.         for(x=1;x<=numfiles;x++) {
  82.             if((attrptr[x]&TAG) == TAG) {
  83.                 attrptr[x]&=0xFF;
  84.                 strcat(copycmd,nameptr[x]);
  85.                 strcat(copycmd,">>>/nil");
  86.                 gotoxy(1,24);
  87.                 cleol();
  88.                 printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  89.                 system(copycmd);
  90.                 *(rindex(copycmd,' ') + 1) = '\0';
  91.             }
  92.         }
  93.         free(copycmd);
  94.         free(todir);
  95.         commands();
  96.         munlink(modp);
  97. #ifdef MM1
  98.         CurOff(1);
  99. #endif
  100.         return(PASS);
  101.     }
  102.     if((confirm == 'Y') && (overwrite == 'Y')) {
  103.         strcpy(copycmd,"copy -rw=");
  104.         strcat(copycmd,todir);
  105.         for(x=1;x<=numfiles;x++) {
  106.             if((attrptr[x]&TAG) == TAG) {
  107.                 attrptr[x]&=0xFF;
  108.                 strcat(copycmd," ");
  109.                 strcat(copycmd,nameptr[x]);
  110.                 strcat(copycmd,">>>/nil");
  111.                 gotoxy(1,24);
  112.                 cleol();
  113.                 printf("     %cCopy %s TO %s? (y/N)",7,nameptr[x],todir);
  114.                 ask = toupper(getchar());
  115.                 flush_kbd();
  116.                 if(ask == 'Y') {
  117.                     gotoxy(1,24);
  118.                     cleol();
  119.                     printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  120.                     system(copycmd);
  121.                 }
  122.                 *(rindex(copycmd,' ')) = '\0';
  123.             }
  124.         }
  125.         free(copycmd);
  126.         free(todir);
  127.         commands();
  128.         munlink(modp);
  129. #ifdef MM1
  130.         CurOff(1);
  131. #endif
  132.         return(PASS);
  133.     }
  134.     if((confirm == 'N') && (overwrite == 'N')) {
  135.         strcpy(copycmd,"copy -w=");
  136.         strcat(copycmd,todir);
  137.         strcat(copycmd," ");
  138.         for(x=1;x<=numfiles;x++) {
  139.             if((attrptr[x]&TAG) == TAG) {
  140.                 attrptr[x]&=0xFF;
  141.                 strcat(copycmd,nameptr[x]);
  142.                 strcat(copycmd,">>>/nil");
  143.                 gotoxy(1,24);
  144.                 cleol();
  145.                 printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  146.                 s_error = system(copycmd);
  147.                 if(s_error == 218) {
  148.                     gotoxy(1,24);
  149.                     cleol();
  150.                     printf("     %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
  151.                     sleep(1);
  152.                 }
  153.                 *(rindex(copycmd,' ') + 1) = '\0';
  154.             }
  155.         }
  156.         free(copycmd);
  157.         free(todir);
  158.         commands();
  159.         munlink(modp);
  160. #ifdef MM1
  161.         CurOff(1);
  162. #endif
  163.         return(PASS);
  164.     }
  165.     if((confirm == 'Y') && (overwrite == 'N')) {
  166.         strcpy(copycmd,"copy -w=");
  167.         strcat(copycmd,todir);
  168.         for(x=1;x<=numfiles;x++) {
  169.             if((attrptr[x]&TAG) == TAG) {
  170.                 attrptr[x]&=0xFF;
  171.                 strcat(copycmd," ");
  172.                 strcat(copycmd,nameptr[x]);
  173.                 strcat(copycmd,">>>/nil");
  174.                 gotoxy(1,24);
  175.                 cleol();
  176.                 printf("     %cCopy %s TO %s? y/N ",7,nameptr[x],todir);
  177.                 ask = toupper(getchar());
  178.                 flush_kbd();
  179.                 if(ask == 'Y') {
  180.                     gotoxy(1,24);
  181.                     cleol();
  182.                     printf("     Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
  183.                     s_error = system(copycmd);
  184.                     if(s_error == 218) {
  185.                         gotoxy(1,24);
  186.                         cleol();
  187.                         printf("     %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
  188.                     }
  189.                 }
  190.                 *(rindex(copycmd,' ')) = '\0';
  191.             }
  192.         }
  193.         free(copycmd);
  194.         free(todir);
  195.         commands();
  196.         munlink(modp);
  197. #ifdef MM1
  198.         CurOff(1);
  199. #endif
  200.         return(PASS);
  201.     }
  202. }
  203.  
  204. /* EOF multicopy.c */
  205.