home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / csh4.zip / CHMOD.C < prev    next >
C/C++ Source or Header  |  1985-09-03  |  2KB  |  120 lines

  1. #include <stdio.h>
  2. #include <stat.h>
  3. #ifdef MAIN
  4. main
  5. #else
  6. ch_mod
  7. #endif
  8. (argc,argv)
  9.     char *argv[];
  10. {
  11.     int or_mask,and_mask,file_stat;
  12.     struct { int ax,bx,cx,dx,si,di,ds,es; } regs;
  13.     extern int _dsval;
  14.     char *current;
  15.     regs.ds = _dsval;
  16.     if (argc==1)
  17.     {
  18.         fprintf(stderr,"Usage : chmod +|-[ahw] file [file ...]\n");
  19.     }
  20.     /* set attributes to default */
  21.     or_mask = 0; and_mask = 0xFFFF;
  22.     while(--argc)
  23.     {
  24.         current = *(++argv);
  25.         switch (*current)
  26.         {
  27.         case '-':
  28.             while (*++current)
  29.             {
  30.                 switch(*current)
  31.                 {
  32.                 case 'w':
  33.                 case 'W':
  34.                     or_mask |= ST_RDONLY;
  35.                     break;
  36.                 case 'h':
  37.                 case 'H':
  38.                     and_mask &= (ST_HIDDEN ^ 0xFFFF);
  39.                     break;
  40.                 case 'r':
  41.                 case 'R':
  42.                     or_mask |= ST_HIDDEN;
  43.                     break;
  44.                 case 'a':
  45.                 case 'A':
  46.                     and_mask &= (ST_ARCHIV ^ 0xFFFF);
  47.                     break;
  48.                 case 's':
  49.                 case 'S':
  50.                     and_mask &= (ST_SYSTEM ^ 0xFFFF);
  51.                     break;
  52.                 default:
  53.                     write(2,"invalid attribute\r\n",19);
  54.                 return -1;
  55.                 }
  56.             }
  57.             break;
  58.         case '+':
  59.             while(*++current)
  60.             {
  61.                 switch(*current)
  62.                 {
  63.                 case 'w':
  64.                 case 'W':
  65.                     and_mask &= (ST_RDONLY ^ 0xFFFF);
  66.                     break;
  67.                 case 'h':
  68.                 case 'H':
  69.                     or_mask |= ST_HIDDEN;
  70.                     break;
  71.                 case 's':
  72.                 case 'S':
  73.                     or_mask |= ST_SYSTEM;
  74.                     break;
  75.                 case 'r':
  76.                 case 'R':
  77.                     and_mask &= (ST_HIDDEN ^ 0xFFFF);
  78.                     break;
  79.                 case 'a':
  80.                 case 'A':
  81.                     or_mask |= ST_ARCHIV;
  82.                     break;
  83.                 default:
  84.                     write(2,"invalid attribute\r\n",19);
  85.                     return -1;
  86.  
  87.                 }
  88.             }
  89.             break;
  90.         default:
  91.             /* get current attribute */
  92.             regs.ax = 0x4300;
  93.             regs.dx = (int)current;
  94.             regs.ds = _dsval;
  95.             sysint(0x21,®s,®s);
  96.             file_stat = regs.cx;
  97.             fprintf(stderr,"current attribute for %s = %x\n",
  98.                 current,file_stat);
  99.             /* set new attribute */
  100.             file_stat |= or_mask;
  101.             file_stat &= and_mask;
  102.             regs.ax = 0x4301;
  103.             regs.dx = (int)current;
  104.             regs.cx = file_stat;
  105.             regs.ds = _dsval;
  106.             sysint(0x21,®s,®s);
  107.             /* get attribute to see if it changed */
  108.             regs.ax = 0x4300;
  109.             regs.dx = (int)current;
  110.             regs.ds = _dsval;
  111.             sysint(0x21,®s,®s);
  112.             file_stat = regs.cx;
  113.             fprintf(stderr,"new attribute for %s = %x\n",
  114.                 current,file_stat);
  115.             break;
  116.         }
  117.     }
  118. }
  119.  
  120.