home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
OS2UTIL.ZIP
/
NO.C
< prev
next >
Wrap
Text File
|
1990-05-21
|
4KB
|
154 lines
#define INCL_SUB 1
#define INCL_ERRORS
#define HIDE 0x0002
#define UNHIDE 0xFFFD
#include <os2.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct filenm {
char flname[13];
struct filenm *next;
} FILENODE, *FILEPTR;
FILEPTR hptr, ptr;
char path[80];
int hide(char *mask);
int unhide(void);
int check(int num);
FILEPTR file_alloc(void);
int main(int argc, char* *argv);
main(argc, argv)
int argc;
char *argv[];
{
char cmdln[256];
int i;
check(argc);
if ( !hide(argv[1]) ) {
strcpy(cmdln, argv[2]);
for (i = 3; i < argc; i++) {
strcat(cmdln, " ");
strcat(cmdln, argv[i]);
}
if ( system(cmdln) )
switch (errno) {
case E2BIG:
printf("NO: Out of environment space");
break;
case ENOENT:
printf("NO: COMMAND problem");
break;
case ENOEXEC:
printf("NO: Needs OS/2");
break;
case ENOMEM:
printf("NO: Allocation problem");
}
}
unhide();
return(0);
}
hide(mask)
char *mask;
{
HDIR hdir = 0xFFFF;
USHORT usSearchCount = 1, mode;
FILEFINDBUF findbuf;
char flname[80], *lstsl, *colon;
int retcode;
lstsl = strrchr(mask, '\\');
colon = strchr(mask, ':');
if (lstsl == NULL)
if (colon == NULL)
strcpy(path, "");
else
strncpy(path, mask, colon-mask+1);
else {
strncpy(path, mask, lstsl-mask+1);
path[lstsl-mask+2] = NULL;
}
if (!(retcode = DosFindFirst(mask, &hdir, 0x00, &findbuf,
sizeof(findbuf), &usSearchCount, 0L)))
do {
strcpy(flname, path);
strcat(flname, findbuf.achName);
DosQFileMode(flname, &mode, 0L);
DosSetFileMode(flname, mode | HIDE, 0L);
if (hptr == NULL) {
if ( (hptr = file_alloc()) == NULL ) {
printf("NO: Too many files to hide");
return(1);
}
ptr = hptr;
}
else {
if ( (ptr->next = file_alloc()) == NULL ) {
printf("NO: Too many files to hide");
return(1);
}
ptr = ptr->next;
}
strcpy(ptr->flname, findbuf.achName);
ptr -> next = NULL;
}
while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
else
if (retcode == ERROR_PATH_NOT_FOUND) {
printf("NO: Incorrect File Spec: %s", mask);
return(2);
}
return(0);
}
unhide()
{
USHORT mode;
char flname[80];
ptr = hptr;
while (ptr !=NULL) {
strcpy(flname, path);
strcat(flname, ptr->flname);
DosQFileMode(flname, &mode, 0L);
DosSetFileMode(flname, mode & 0xFFFD, 0L);
ptr = ptr->next;
}
return(0);
}
check(num)
int num;
{
switch (num) {
case 1: case 2:
printf("Syntax: NO filespec command [parameters]");
exit(num);
}
return(num);
}
FILEPTR file_alloc()
{
void *malloc();
return((FILEPTR) malloc(sizeof(FILENODE)));
}