1 | /* |
---|
2 | * This file Copyright (C) 2008-2014 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: tr-getopt.h 14615 2015-12-06 22:39:14Z jordan $ |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef TR_GETOPT_H |
---|
11 | #define TR_GETOPT_H |
---|
12 | |
---|
13 | #ifdef __cplusplus |
---|
14 | extern "C" { |
---|
15 | #endif |
---|
16 | |
---|
17 | /** |
---|
18 | * @addtogroup utils Utilities |
---|
19 | * @{ |
---|
20 | */ |
---|
21 | |
---|
22 | /** @brief Similar to optind, this is the current index into argv */ |
---|
23 | extern int tr_optind; |
---|
24 | |
---|
25 | typedef struct tr_option |
---|
26 | { |
---|
27 | int val; /* the value to return from tr_getopt () */ |
---|
28 | const char * longName; /* --long-form */ |
---|
29 | const char * description; /* option's description for tr_getopt_usage () */ |
---|
30 | const char * shortName; /* short form */ |
---|
31 | int has_arg; /* 0 for no argument, 1 for argument */ |
---|
32 | const char * argName; /* argument's description for tr_getopt_usage () */ |
---|
33 | } |
---|
34 | tr_option; |
---|
35 | |
---|
36 | enum |
---|
37 | { |
---|
38 | /* all options have been processed */ |
---|
39 | TR_OPT_DONE = 0, |
---|
40 | |
---|
41 | /* a syntax error was detected, such as a missing |
---|
42 | * argument for an option that requires one */ |
---|
43 | TR_OPT_ERR = -1, |
---|
44 | |
---|
45 | /* an unknown option was reached */ |
---|
46 | TR_OPT_UNK = -2 |
---|
47 | }; |
---|
48 | |
---|
49 | /** |
---|
50 | * @brief similar to getopt () |
---|
51 | * @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK, or the matching tr_option's `val' field |
---|
52 | */ |
---|
53 | int tr_getopt (const char * summary, |
---|
54 | int argc, |
---|
55 | const char * const * argv, |
---|
56 | const tr_option * opts, |
---|
57 | const char ** setme_optarg); |
---|
58 | |
---|
59 | /** @brief prints the `Usage' help section to stdout */ |
---|
60 | void tr_getopt_usage (const char * appName, |
---|
61 | const char * description, |
---|
62 | const tr_option * opts); |
---|
63 | |
---|
64 | #ifdef __cplusplus |
---|
65 | } /* extern "C" */ |
---|
66 | #endif |
---|
67 | |
---|
68 | /** @} */ |
---|
69 | |
---|
70 | #endif /* TR_GETOPT_H */ |
---|