home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
ATTR2.ZIP
/
ATTR2.C
next >
Wrap
C/C++ Source or Header
|
1989-09-09
|
4KB
|
121 lines
/***********************************************************************
* Attr2 - Modify file attributes for OS/2 *
* Copyright (C) 1989 FreeLance Programming. All rights reserved. *
***********************************************************************/
void parse_a_parm(char *argv);
void set_masks(unsigned short flag, char on_off);
#define INCL_DOS 1
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
unsigned short tot_files = 0, ANDMASK = 0xffff, ORMASK = 0, temp;
char inspec[127], inpath[127], work[127];
HFILE dirhand;
struct _FILEFINDBUF dir_entry;
#define DIRSIZE (sizeof(struct _FILEFINDBUF))
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void main(int argc, char **argv)
/***********************************************************************
* Attr2 - Modify file attributes for OS/2 *
***********************************************************************/
{
register unsigned short x;
puts("Attr2 - Modify file attributes for OS/2 - Version 1.0 - 09/09/89"
"\nCopyright (c) 1989 FreeLance Programming. All rights reserved.\n");
if (argc < 2)
{
puts("Usage: Attr2 filename.ext [/R+] [/R-] [/H+] [H-] [S+] [/S-]\n\n"
"filename.ext may be any valid file specifier, including wildcards.\n"
"Any combination of switches may be used. In the event of conflicting\n"
"specifications, the last one(s) specified will be used\n.");
exit(1);
}
for (x = 1; x < argc; x++) parse_a_parm(argv[x]);
dirhand = temp = 1;
if (DosFindFirst(&inspec[0], &dirhand, 0x0007, &dir_entry,
(USHORT)DIRSIZE, (PUSHORT)&temp, 0L))
{
puts("Error - no files found to process.\n"); exit(1);
}
while (-1)
{
tot_files++;
sprintf(work, "%s%s", inpath, dir_entry.achName);
x = (dir_entry.attrFile & ANDMASK) | ORMASK;
x = DosSetFileMode(work, (unsigned int)x, 0L);
printf("%s - %s\n", dir_entry.achName, (x) ? "error" : "ok");
if (DosFindNext(dirhand, &dir_entry,
(USHORT)DIRSIZE, (PUSHORT)&temp)) break;
}
printf("\n%u files found.\n", tot_files); exit(0);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void parse_a_parm(char *argv)
/***********************************************************************
* Parse a single parmameter entry *
***********************************************************************/
{
register int x;
if ((argv[0] == '-') || (argv[0] == '/'))
{
switch (toupper(argv[1]))
{
case '\x00': break; /* End of parm */
default : puts("Invalid option. Run Attr2 with no parameters "
"for a list of valid options.");
exit(1);
case 'R': set_masks(1, argv[2]); break;
case 'H': set_masks(2, argv[2]); break;
case 'S': set_masks(4, argv[2]); break;
}
}
else
{
strcpy(inspec, argv); x = strlen(inspec) - 1;
while ((x >= 0) &&
(inspec[x] != '\\') && (inspec[x] != ':')) x--;
strcpy(inpath, inspec); inpath[++x] = '\0';
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void set_masks(unsigned short flag, char on_off)
/***********************************************************************
* Setup the ANDMASK and ORMASK fields based on user parms *
***********************************************************************/
{
switch (on_off)
{
default: printf("Uknown option : %c\n", on_off); exit(1);
case '+': ORMASK |= flag; break;
case '-': ORMASK &= ~flag; ANDMASK &= ~flag; break;
}
}