home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2UTIL.ZIP / NO.C < prev    next >
Text File  |  1990-05-21  |  4KB  |  154 lines

  1. #define INCL_SUB    1
  2. #define INCL_ERRORS
  3. #define HIDE        0x0002
  4. #define UNHIDE      0xFFFD
  5.  
  6. #include <os2.h>
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11.  
  12. typedef struct filenm {
  13.                        char flname[13];
  14.                        struct filenm *next;
  15.                } FILENODE, *FILEPTR;
  16.  
  17. FILEPTR hptr, ptr;
  18. char path[80];
  19.  
  20. int hide(char *mask);
  21. int unhide(void);
  22. int check(int num);
  23. FILEPTR file_alloc(void);
  24.  
  25. int main(int argc, char* *argv);
  26.  
  27. main(argc, argv)
  28. int argc;
  29. char *argv[];
  30. {
  31.      char cmdln[256];
  32.      int i;
  33.  
  34.      check(argc);
  35.  
  36.      if ( !hide(argv[1]) ) {
  37.  
  38.          strcpy(cmdln, argv[2]);
  39.          for (i = 3; i < argc; i++) {
  40.              strcat(cmdln, " ");
  41.              strcat(cmdln, argv[i]);
  42.          }
  43.  
  44.          if ( system(cmdln) )
  45.             switch (errno) {
  46.                    case E2BIG:
  47.                         printf("NO: Out of environment space");
  48.                         break;
  49.                    case ENOENT:
  50.                         printf("NO: COMMAND problem");
  51.                         break;
  52.                    case ENOEXEC:
  53.                         printf("NO: Needs OS/2");
  54.                         break;
  55.                    case ENOMEM:
  56.                         printf("NO: Allocation problem");
  57.             }
  58.      }
  59.  
  60.      unhide();
  61.      return(0);
  62. }
  63.  
  64. hide(mask)
  65. char *mask;
  66. {
  67.     HDIR hdir            = 0xFFFF;
  68.     USHORT usSearchCount = 1, mode;
  69.     FILEFINDBUF findbuf;
  70.     char flname[80], *lstsl, *colon;
  71.     int retcode;
  72.  
  73.     lstsl = strrchr(mask, '\\');
  74.     colon = strchr(mask, ':');
  75.     if (lstsl == NULL)
  76.        if (colon == NULL)
  77.           strcpy(path, "");
  78.        else
  79.           strncpy(path, mask, colon-mask+1);
  80.     else {
  81.        strncpy(path, mask, lstsl-mask+1);
  82.        path[lstsl-mask+2] = NULL;
  83.     }
  84.  
  85.     if (!(retcode = DosFindFirst(mask, &hdir, 0x00, &findbuf,
  86.         sizeof(findbuf), &usSearchCount, 0L)))
  87.         do {
  88.                strcpy(flname, path);
  89.                strcat(flname, findbuf.achName);
  90.                DosQFileMode(flname, &mode, 0L);
  91.                DosSetFileMode(flname, mode | HIDE, 0L);
  92.  
  93.                if (hptr == NULL) {
  94.                   if ( (hptr      = file_alloc()) == NULL ) {
  95.                      printf("NO: Too many files to hide");
  96.                      return(1);
  97.                   }
  98.                   ptr             = hptr;
  99.                }
  100.                else {
  101.                   if ( (ptr->next = file_alloc()) == NULL ) {
  102.                      printf("NO: Too many files to hide");
  103.                      return(1);
  104.                   }
  105.                   ptr             = ptr->next;
  106.                }
  107.                strcpy(ptr->flname, findbuf.achName);
  108.                ptr -> next = NULL;
  109.         }
  110.         while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
  111.         else
  112.             if (retcode == ERROR_PATH_NOT_FOUND) {
  113.                printf("NO: Incorrect File Spec: %s", mask);
  114.                return(2);
  115.             }
  116.  
  117.     return(0);
  118. }
  119.  
  120. unhide()
  121. {
  122.     USHORT mode;
  123.     char flname[80];
  124.  
  125.     ptr = hptr;
  126.     while (ptr !=NULL) {
  127.                strcpy(flname, path);
  128.                strcat(flname, ptr->flname);
  129.                DosQFileMode(flname, &mode, 0L);
  130.                DosSetFileMode(flname, mode & 0xFFFD, 0L);
  131.  
  132.                ptr = ptr->next;
  133.     }
  134.  
  135.     return(0);
  136. }
  137.  
  138. check(num)
  139. int num;
  140. {
  141.     switch (num) {
  142.            case 1: case 2:
  143.                 printf("Syntax: NO filespec command [parameters]");
  144.                 exit(num);
  145.     }
  146.     return(num);
  147. }
  148.  
  149. FILEPTR file_alloc()
  150. {
  151.    void *malloc();
  152.    return((FILEPTR) malloc(sizeof(FILENODE)));
  153. }
  154.