-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpigetopt.h
More file actions
69 lines (57 loc) · 1.72 KB
/
pigetopt.h
File metadata and controls
69 lines (57 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
*
* pigetopt.h
*
* Author: Markku Rossi <[email protected]>
*
* Copyright (c) 2003-2005 Markku Rossi.
*
* See the LICENSE file for the details on licensing.
*
* Command line option parsing.
*
*/
#ifndef PIGETOPT_H
#define PIGETOPT_H
/* Option arguments. */
typedef enum
{
PI_GETOPT_NO_ARGUMENT,
PI_GETOPT_REQUIRED_ARGUMENT,
PI_GETOPT_OPTIONAL_ARGUMENT
} PiGetOptArgType;
/* Option description. */
struct PiGetOptOptionRec
{
char *long_option;
PiGetOptArgType arg_type;
int short_option;
};
typedef struct PiGetOptOptionRec PiGetOptOptionStruct;
typedef struct PiGetOptOptionRec *PiGetOptOption;
/* Context for option parsing. */
struct PiGetOptCtxRec
{
/* The name of the program. */
char *program;
/* Index of the next option to be processed. */
int optind;
/* Index of the current option (optind) when parsing short bundled
options. */
unsigned int short_index;
/* Option's argument. */
char *optarg;
};
typedef struct PiGetOptCtxRec PiGetOptCtxStruct;
typedef struct PiGetOptCtxRec *PiGetOptCtx;
/*********************** Parsing command line options ***********************/
/* Parse command line options array `argv' containing `argc' options.
The argument `ctx' specifies context for the parsing operation. It
must be zeroed before the first call of the pi_getopt function.
The argument `options' describes the known command line options.
The function returns the `short_option' of the matching option on
success and -1 when all options have been parsed. If the command
line options contain unknown options, the function returns '?' and
prints a warning to the stderr. */
int pi_getopt(int argc, char *argv[], PiGetOptCtx ctx, PiGetOptOption options);
#endif /* not PIGETOPT_H */