home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm.lzh / multiattr.c < prev    next >
Text File  |  1995-10-26  |  2KB  |  108 lines

  1. /* multiattr.c function for DISKMASTER.C      */
  2. /* copyright (c) 1995 by Bob Devries          */
  3. /* email: bdevries@gil.ipswichcity.qld.gov.au */
  4.  
  5. /* changes the attributes of multiple files in current directory */
  6.  
  7. #include "diskmaster.h"
  8. #include <strings.h>
  9. #include <stdio.h>
  10.  
  11. int
  12. multiattr(numfiles)
  13. int numfiles;
  14. {
  15.     extern char **nameptr;
  16.     extern short *attrptr;
  17.     char *attrcmd;
  18.     char *newattr, oldattr[8], *malloc();
  19.     char *getattr();
  20.     int confirm, ask, success, x;
  21.     
  22.     attrcmd = malloc(numfiles*32+256);
  23.     newattr = malloc(80);
  24.     strcpy(oldattr,"dsewrewr");
  25.     
  26.     gotoxy(1,24);
  27.     cleol();
  28.     printf("     %cChange attributes of tagged files to: ",7);
  29.     success = lineinput(newattr,80);
  30.     if((success == FAIL) || (*newattr == '\0')) {
  31.         free(attrcmd);
  32.         free(newattr);
  33.         commands();
  34.         return(FAIL);
  35.     }
  36.     if(index(newattr,'d') != NULL) {
  37.         gotoxy(1,24);
  38.         cleol();
  39.         printf("     %cCan't change the directory attribute!",7);
  40.         free(attrcmd);
  41.         free(newattr);
  42.         sleep(1);
  43.         commands();
  44.         return(FAIL);
  45.     }
  46.     gotoxy(1,24);
  47.     cleol();
  48.     printf("     %cConfirm each attribute change? y/N ",7);
  49.     do {
  50.         confirm = toupper(getchar());
  51.         flush_kbd();
  52.     } while ((confirm != 'Y') && (confirm != 'N') && (confirm != '\n'));
  53.     if(confirm == '\n') {
  54.         confirm = 'N';
  55.     }
  56.     strcpy(attrcmd,"attr ");
  57.     strcat(attrcmd,newattr);
  58.     strcat(attrcmd," ");
  59.     if(confirm == 'N') {
  60.         for(x=1; x<=numfiles;x++) {
  61.             if((attrptr[x]&TAG) == TAG) {
  62.                 strcat(attrcmd,nameptr[x]);
  63.                 strcat(attrcmd," ");
  64.                 attrptr[x]&=0xFF;
  65.             }
  66.         }
  67.         strcat(attrcmd,">>>/nil");
  68.         gotoxy(1,24);
  69.         cleol();
  70.         printf("     Working...");
  71.         system(attrcmd);
  72.         free(attrcmd);
  73.         free(newattr);
  74.         commands();
  75.         return(PASS);
  76.     }
  77.     for(x=1;x<=numfiles;x++) {
  78.         if((attrptr[x]&TAG) == TAG) {
  79.             attrptr[x]&=0xFF;
  80.             gotoxy(1,24);
  81.             cleol();
  82.             printf("     %cChange attributes of %s from %s to %s? y/N ",7,nameptr[x],getattr(oldattr,attrptr[x]&0xFF),newattr);
  83.             do {
  84.                 ask = toupper(getchar());
  85.                 flush_kbd();
  86.             } while((ask != 'Y') && (ask != 'N') && (ask != '\n'));
  87.             if (ask == '\n') {
  88.                 ask = 'N';
  89.             }
  90.             if (ask == 'Y') {
  91.                 strcat(attrcmd,nameptr[x]);
  92.                 strcat(attrcmd,">>>/nil");
  93.                 gotoxy(1,24);
  94.                 cleol();
  95.                 printf("     Changing attributes on %s to %s...",nameptr[x],newattr);
  96.                 system(attrcmd);
  97.                 *(rindex(attrcmd,' ') + 1) = '\0';
  98.             }
  99.         }
  100.     }
  101.     free(attrcmd);
  102.     free(newattr);
  103.     commands();
  104.     return(PASS);
  105. }
  106.  
  107. /* EOF multiattr.c */
  108.