Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 *   getlopt.h
3
 *
4
 *   Oliver Fromme  <oliver.fromme@heim3.tu-clausthal.de>
5
 *   Tue Apr  8 07:13:39 MET DST 1997
6
 */
7
 
8
#include <stdlib.h>
9
#include <string.h>
10
 
11
extern int loptind;     /* index in argv[] */
12
extern int loptchr;     /* index in argv[loptind] */
13
extern char *loptarg;   /* points to argument if present, else to option */
14
 
15
typedef struct {
16
        char sname;     /* short option name, can be 0 */
17
        char *lname;    /* long option name, can be 0 */
18
        int flags;      /* see below */
19
        void (*func)(char *);   /* called if != 0 (after setting of var) */
20
        void *var;      /* type is *int, *char or **char, see below */
21
        int value;
22
} topt;
23
 
24
#define GLO_ARG  1
25
#define GLO_CHAR 2
26
#define GLO_NUM  0
27
 
28
/* flags:
29
 *      bit 0 = 0 - no argument
30
 *              if var != NULL
31
 *                      *var := value or (char)value [see bit 1]
32
 *              else
33
 *                      loptarg = &option
34
 *                      return ((value != 0) ? value : sname)
35
 *      bit 0 = 1 - argument required
36
 *              if var != NULL
37
 *                      *var := atoi(arg) or strdup(arg) [see bit 1]
38
 *              else
39
 *                      loptarg = &arg
40
 *                      return ((value != 0) ? value : sname)
41
 *
42
 *      bit 1 = 0 - var is a pointer to an int
43
 *      bit 1 = 1 - var is a pointer to a char (or string),
44
 *                      and value is interpreted as char
45
 *
46
 * Note: The options definition is terminated by a topt
47
 *       containing only zeroes.
48
 */
49
 
50
#define GLO_END         0
51
#define GLO_UNKNOWN     -1
52
#define GLO_NOARG       -2
53
#define GLO_CONTINUE    -3
54
 
55
int getlopt (int argc, char *argv[], topt *opts);
56
 
57
/* return values:
58
 *      GLO_END         (0)     end of options
59
 *      GLO_UNKNOWN     (-1)    unknown option *loptarg
60
 *      GLO_NOARG       (-2)    missing argument
61
 *      GLO_CONTINUE    (-3)    (reserved for internal use)
62
 *      else - return value according to flags (see above)
63
 */
64
 
65
/* EOF */