read_switch
[ XITE Reference Manual | XITE home ]
Name
read_switch, read_bswitch, read_iswitch, read_dswitch -
read switches from command line
Syntax
#include <xite/readarg.h>
char *read_switch( int* argc, char** argv,
char* name, int args, char* defreturn );
int read_bswitch( int* argc, char** argv,
char* name );
int read_iswitch( int* argc, char** argv,
char* name, int defval );
double read_dswitch( int* argc, char** argv,
char* name, double defval );
Description
read_switch reads a switch/option from the command line. The
routine searches for the switch name. If name is found
and args is zero, a pointer to the switch is returned.
If name is found and args is nonzero, a string
containing the switch argument(s) is returned.
Otherwise, if name does not occur in the
command line, defreturn is returned.
read_bswitch returns TRUE if name is a switch
in the command line, FALSE otherwise.
read_iswitch searches for switch name and returns
its argument (converted to integer), otherwise it
returns defval.
read_dswitch searches for switch name and returns
its argument (converted to double), otherwise it
returns defval.
The switch and its argument are removed from
argv, and argc is decremented.
Examples
#include <math.h>
#include <xite/readarg.h>
char *res, *fn;
double d;
int i, j, l;
d = atof(read_switch(&argc, argv, "-scale", 1, "0.5"));
sscanf(read_switch(&argc, argv, "-offset", 2, "128 128"),
"%d%d", &i, &j);
l = read_switch(&argc, argv, "-log", 0, NULL) != NULL;
res = read_switch(&argc, argv, "-yes", 0, "-no");
fn = argv[1];
or:
d = read_dswitch(&argc, argv, "-scale", 0.5);
sscanf(read_switch(&argc, argv, "-offset", 2, "128 128"),
"%d%d", &i, &j);
l = read_bswitch(&argc, argv, "-log");
res = read_switch(&argc, argv, "-yes", 0, "-no");
fn = argv[1];
commandline: prog -offset 3 3 -scale 2 -log filename
d : 2.0
i : 3
j : 3
l : TRUE
res : "-no"
fn : "filename"
Author
Otto Milvang
Id
$Id: readswitch.c,v 1.27 1996/06/04 14:56:33 svein Exp $