home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
maint
/
part01
/
args.c
next >
Wrap
C/C++ Source or Header
|
1992-05-13
|
6KB
|
235 lines
/******************************************************************************
*******************************************************************************
Site: Western Michigan University Academic Computer Center
System: Directory/File System Maintenance
Program: maint
Version=01 Level=00 01/24/92 Leonard J. Peirce
Purpose: Routine(s) for parsing run-time arguments.
Arguments: See individual routine(s).
External variables: See below
Maint external functions:
Defined: get_args
Called: None
Files accessed: None
Return codes: None
Compiling instructions: See Makefile
Linking instructions: See Makefile
Other information: (C) Copyright 1992, Leonard J. Peirce
********************************************************************************
*******************************************************************************/
/******************************************************************************/
/* */
/* # I N C L U D E F I L E S */
/* */
/******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "maint.h"
/******************************************************************************/
/* */
/* # D E F I N E S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
extern char *optarg; /* getopt() externals */
extern int optind,
opterr;
void get_args();
/******************************************************************************/
/* */
/* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
/*******************************************************************************
********************************************************************************
Function: get_args
Purpose: Process the command-line arguments, setting the flags for
what arguments are specified and determining the slot width.
Also calculate the entry size memory allocation factor for
allocating memory pools.
Global variables:
Name Examine/Modify/Use/Read/Write
---- -----------------------------
opt_size X X X
optarg X X
Return Codes:
Code Reason
---- ------
none
********************************************************************************
*******************************************************************************/
void get_args(argc,argv,args)
/******* FORMAL PARAMETERS *******/
int argc; /* number of run-time arguments */
char **argv; /* run-time arguments */
register ARG_DEF *args; /* run-time argument flags */
{ /*** get_args ***/
/******** LOCAL VARIABLES ********/
int c; /* argument from getopt() */
size_t opt_size; /* length of an option string */
/* start parsing the arguments; when we're done, look at what they
* are and set some values accordingly
*/
args->sort = FILENAME; /* assume we want to sort by filename */
while((c = getopt(argc,argv,"acdfgopstwAFS:")) != EOF)
{
switch(c)
{
case('a'):
args->dot_files = TRUE;
break;
case('A'):
args->auto_feed = TRUE;
break;
case('c'):
args->confirm = TRUE;
break;
case('d'):
args->date = TRUE;
break;
case('f'):
args->date = TRUE;
args->size = TRUE;
args->prot = TRUE;
args->owner = TRUE;
args->group = TRUE;
break;
case('g'):
args->group = TRUE;
break;
case('o'):
args->owner = TRUE;
break;
case('p'):
args->prot = TRUE;
break;
case('s'):
args->size = TRUE;
break;
case('t'):
args->text = DISPLAY_TEXT;
args->text_startup = TRUE;
break;
case('w'):
args->wide = TRUE;
break;
case('S'):
/* see what we should sort by */
opt_size = strlen(optarg);
if(opt_size)
{
/* something specified after the option; see what it is */
if(strncmp("date",optarg,opt_size) == 0)
{
args->sort = DATE;
}
else if(strncmp("size",optarg,opt_size) == 0)
{
args->sort = SIZE;
}
else if(strncmp("filename",optarg,opt_size) == 0)
{
args->sort = FILENAME;
}
else if(strncmp("none",optarg,opt_size) == 0)
{
args->sort = 0;
}
else
{
fprintf(stderr,"maint -- illegal sort option %s\n",optarg);
exit(1);
}
}
break;
case('F'):
args->filemarks = TRUE;
break;
default:
exit(1);
}
}
return;
} /*** get_args ***/