Category : Utilities for DOS and Windows Machines
Archive   : NEWCHMOD.ZIP
Filename : CHMOD.C

 
Output of file : CHMOD.C contained in archive : NEWCHMOD.ZIP
/*//////////////////////////////////////////////////////////////////////////
// c h m o d . c
////////////////
CHMOD(1) MS DOS USER COMMANDS CHMOD(1)

NAME
chmod

SYNOPSIS
chmod [=+-][r][h][s][a] file ...

DESCRIPTION

Changes the attributes of 'file'. The file attributes can either
be set (=), or attributes can be added (+) or removed (-) from the
the current attribute. If no attributes are specified, then the file
is marked 'normal' i.e. no attributes set except the archive bit.

Newman Lab [email protected]
Cornell Univ [email protected]
Ithaca NY 14853

I retain all rights to this program. (c) Gene Cohler, January 1987
**************************************************************************/
/*
* N.B. I use tab set to 4
*
* History :
*
* Feb 14 1986 - Version 1 peeks out the window ...
*
* Modified
* :- August 1 1986
* 1) Looks more like unix version - choose to set attribute
* = or - or + to set or remove or add.
* 2) Talks a little more .. old age maybe !
* :- January 1987
* 1) Default works a little better - now Archive set is default.
* Also chmod file will set the archive bit only.
* 2) Ready to hit the streets with v 1.0
*****************************************************************************
* Written in Microsoft C v 4.0. Should be linked together with ssetargv.obj
* included in the standard library
*****************************************************************************/
#include
#include

#define SET 1
#define GET 0
#define ARCHIVE 0x20

main(argc,argv)
int argc;
char **argv;
{
unsigned attrib = ARCHIVE ;
unsigned oldattrib=0 ;
unsigned newattrib=0 ;
static int what='=' ;

register unsigned i ;
register unsigned notfile ;

if( argc == 1 )
error("No file specified");

/*
* Find what attributes are being called for
*/

for(i=1;i {
switch( argv[i][0] )
{
case '-' :
case '+' :
case '=' :
parse(&attrib, argv[i], &what);
notfile = i ;
}
}

/*
* Now set em one by one
*/

for( i=1; i {
if( i != notfile )
{
switch( what )
{
case '=' :
newattrib = attrib ;
break;
case '+' :
if((oldattrib = mode( argv[i], attrib, GET)) == -1)
{
fprintf(stderr,"Error finding mode of %s\n",argv[i]);
continue ;
}
newattrib = oldattrib | attrib ;
break ;
case '-' :
if((oldattrib = mode( argv[i], attrib, GET)) == -1)
{
fprintf(stderr,"Error finding mode of %s\n",argv[i]);
continue ;
}
newattrib = (oldattrib & (~attrib)) & 0xff;
break;
default :
error("No mode qualifier given");
}
if((oldattrib = mode( argv[i], newattrib, SET)) == -1)
{
fprintf(stderr,"Error setting mode of %s\n",argv[i]);
continue ;
}
}
}
}


/********************************************
* mode.c - change/get the mode - DOS call *
* action is 1 to set the mode :
* action is 0 to get the mode ;
*****************************************/

#define SYSCALL 0x21

int
mode(name, attrib, action )
unsigned char name[] ;
unsigned attrib ;
int action ;
{
struct SREGS segregs ;
union REGS regs ;

if( action == SET) regs.x.ax = 0x4301 ;/* Set up for a chmod */
else regs.x.ax = 0x4300 ;
regs.x.cx = attrib ;
segread(&segregs) ; /* get current ds value */
regs.x.dx = (unsigned int) name; /* name is in ds:dx */
regs.x.cflag = 0 ; /* Make sure flag is zeroed */

int86x(SYSCALL, ®s, ®s, &segregs) ; /* Do it */

if (regs.x.cflag) return (-1) ; /* Return error */
else return (regs.x.cx); /* Return attrib */
}

/*
* Attributes used in the file descriptor
*/

#define NORMAL 0x00
#define READONLY 0x01
#define HIDDEN 0x02
#define SYSTEM 0x04
#define VOLUME 0x08
#define SUBDIR 0x10

parse( attrib, arg, what)
unsigned *attrib ;
char arg[] ;
int *what ;
{
register i ;
unsigned numargs = strlen(arg) ;
*attrib = NORMAL ;
*what = arg[0] ;

if (numargs == 1) /* Set Archive as Default */
{
*attrib = ARCHIVE ;
return ;
}
for(i=1; i {
if( toupper(arg[i]) == 'R' ) *attrib |= READONLY ;
if( toupper(arg[i]) == 'S' ) *attrib |= SYSTEM ;
if( toupper(arg[i]) == 'A' ) *attrib |= ARCHIVE ;
if( toupper(arg[i]) == 'H' ) *attrib |= HIDDEN ;
}
}

error(msg)
char *msg;
{
fprintf(stderr,"Error: %s\n", msg);
fprintf(stderr,"Usage: chmod [+-=][rhsa] file(s)");
exit(1) ;
}


  3 Responses to “Category : Utilities for DOS and Windows Machines
Archive   : NEWCHMOD.ZIP
Filename : CHMOD.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/