1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * getlopt.h
|
---|
11 | *
|
---|
12 | * Oliver Fromme <oliver.fromme@heim3.tu-clausthal.de>
|
---|
13 | * Tue Apr 8 07:13:39 MET DST 1997
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include <stdlib.h>
|
---|
17 | #include <string.h>
|
---|
18 |
|
---|
19 | extern int loptind; /* index in argv[] */
|
---|
20 | extern int loptchr; /* index in argv[loptind] */
|
---|
21 | extern char *loptarg; /* points to argument if present, else to option */
|
---|
22 |
|
---|
23 | typedef struct {
|
---|
24 | char sname; /* short option name, can be 0 */
|
---|
25 | char *lname; /* long option name, can be 0 */
|
---|
26 | int flags; /* see below */
|
---|
27 | void (*func)(char *); /* called if != 0 (after setting of var) */
|
---|
28 | void *var; /* type is *int, *char or **char, see below */
|
---|
29 | int value;
|
---|
30 | } topt;
|
---|
31 |
|
---|
32 | #define GLO_ARG 1
|
---|
33 | #define GLO_CHAR 2
|
---|
34 | #define GLO_NUM 0
|
---|
35 |
|
---|
36 | /* flags:
|
---|
37 | * bit 0 = 0 - no argument
|
---|
38 | * if var != NULL
|
---|
39 | * *var := value or (char)value [see bit 1]
|
---|
40 | * else
|
---|
41 | * loptarg = &option
|
---|
42 | * return ((value != 0) ? value : sname)
|
---|
43 | * bit 0 = 1 - argument required
|
---|
44 | * if var != NULL
|
---|
45 | * *var := atoi(arg) or strdup(arg) [see bit 1]
|
---|
46 | * else
|
---|
47 | * loptarg = &arg
|
---|
48 | * return ((value != 0) ? value : sname)
|
---|
49 | *
|
---|
50 | * bit 1 = 0 - var is a pointer to an int
|
---|
51 | * bit 1 = 1 - var is a pointer to a char (or string),
|
---|
52 | * and value is interpreted as char
|
---|
53 | *
|
---|
54 | * Note: The options definition is terminated by a topt
|
---|
55 | * containing only zeroes.
|
---|
56 | */
|
---|
57 |
|
---|
58 | #define GLO_END 0
|
---|
59 | #define GLO_UNKNOWN -1
|
---|
60 | #define GLO_NOARG -2
|
---|
61 | #define GLO_CONTINUE -3
|
---|
62 |
|
---|
63 | int getlopt (int argc, char *argv[], topt *opts);
|
---|
64 |
|
---|
65 | /* return values:
|
---|
66 | * GLO_END (0) end of options
|
---|
67 | * GLO_UNKNOWN (-1) unknown option *loptarg
|
---|
68 | * GLO_NOARG (-2) missing argument
|
---|
69 | * GLO_CONTINUE (-3) (reserved for internal use)
|
---|
70 | * else - return value according to flags (see above)
|
---|
71 | */
|
---|
72 |
|
---|
73 | /* EOF */
|
---|