/src/ntp-dev/sntp/libopts/boolean.c
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /** |
3 | | * \file boolean.c |
4 | | * |
5 | | * Handle options with true/false values for arguments. |
6 | | * |
7 | | * @addtogroup autoopts |
8 | | * @{ |
9 | | */ |
10 | | /* |
11 | | * This routine will run run-on options through a pager so the |
12 | | * user may examine, print or edit them at their leisure. |
13 | | * |
14 | | * This file is part of AutoOpts, a companion to AutoGen. |
15 | | * AutoOpts is free software. |
16 | | * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved |
17 | | * |
18 | | * AutoOpts is available under any one of two licenses. The license |
19 | | * in use must be one of these two and the choice is under the control |
20 | | * of the user of the license. |
21 | | * |
22 | | * The GNU Lesser General Public License, version 3 or later |
23 | | * See the files "COPYING.lgplv3" and "COPYING.gplv3" |
24 | | * |
25 | | * The Modified Berkeley Software Distribution License |
26 | | * See the file "COPYING.mbsd" |
27 | | * |
28 | | * These files have the following sha256 sums: |
29 | | * |
30 | | * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 |
31 | | * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 |
32 | | * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd |
33 | | */ |
34 | | |
35 | | /*=export_func optionBooleanVal |
36 | | * private: |
37 | | * |
38 | | * what: Decipher a boolean value |
39 | | * arg: + tOptions * + opts + program options descriptor + |
40 | | * arg: + tOptDesc * + od + the descriptor for this arg + |
41 | | * |
42 | | * doc: |
43 | | * Decipher a true or false value for a boolean valued option argument. |
44 | | * The value is true, unless it starts with 'n' or 'f' or "#f" or |
45 | | * it is an empty string or it is a number that evaluates to zero. |
46 | | =*/ |
47 | | void |
48 | | optionBooleanVal(tOptions * opts, tOptDesc * od) |
49 | 0 | { |
50 | 0 | char * pz; |
51 | 0 | bool res = true; |
52 | |
|
53 | 0 | if (INQUERY_CALL(opts, od)) |
54 | 0 | return; |
55 | | |
56 | 0 | if (od->optArg.argString == NULL) { |
57 | 0 | od->optArg.argBool = false; |
58 | 0 | return; |
59 | 0 | } |
60 | | |
61 | 0 | switch (*(od->optArg.argString)) { |
62 | 0 | case '0': |
63 | 0 | { |
64 | 0 | long val = strtol(od->optArg.argString, &pz, 0); |
65 | 0 | if ((val != 0) || (*pz != NUL)) |
66 | 0 | break; |
67 | | /* FALLTHROUGH */ |
68 | 0 | } |
69 | 0 | case 'N': |
70 | 0 | case 'n': |
71 | 0 | case 'F': |
72 | 0 | case 'f': |
73 | 0 | case NUL: |
74 | 0 | res = false; |
75 | 0 | break; |
76 | 0 | case '#': |
77 | 0 | if (od->optArg.argString[1] != 'f') |
78 | 0 | break; |
79 | 0 | res = false; |
80 | 0 | } |
81 | | |
82 | 0 | if (od->fOptState & OPTST_ALLOC_ARG) { |
83 | 0 | AGFREE(od->optArg.argString); |
84 | 0 | od->fOptState &= ~OPTST_ALLOC_ARG; |
85 | 0 | } |
86 | 0 | od->optArg.argBool = res; |
87 | 0 | } |
88 | | /** @} |
89 | | * |
90 | | * Local Variables: |
91 | | * mode: C |
92 | | * c-file-style: "stroustrup" |
93 | | * indent-tabs-mode: nil |
94 | | * End: |
95 | | * end of autoopts/boolean.c */ |