Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / libopts / boolean.c
bloba3c18b4c26919147e595314235bf61db0ed6dfe1
1 /* $NetBSD$ */
4 /*
5 * Id: 329b43154b88d78564d8f960a00a83ec7d8baee0
6 * Time-stamp: "2008-08-03 13:06:02 bkorb"
8 * Automated Options Paged Usage module.
10 * This routine will run run-on options through a pager so the
11 * user may examine, print or edit them at their leisure.
13 * This file is part of AutoOpts, a companion to AutoGen.
14 * AutoOpts is free software.
15 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
17 * AutoOpts is available under any one of two licenses. The license
18 * in use must be one of these two and the choice is under the control
19 * of the user of the license.
21 * The GNU Lesser General Public License, version 3 or later
22 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
24 * The Modified Berkeley Software Distribution License
25 * See the file "COPYING.mbsd"
27 * These files have the following md5sums:
29 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
30 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
31 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
34 /*=export_func optionBooleanVal
35 * private:
37 * what: Decipher a boolean value
38 * arg: + tOptions* + pOpts + program options descriptor +
39 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
41 * doc:
42 * Decipher a true or false value for a boolean valued option argument.
43 * The value is true, unless it starts with 'n' or 'f' or "#f" or
44 * it is an empty string or it is a number that evaluates to zero.
45 =*/
46 void
47 optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
49 char* pz;
50 ag_bool res = AG_TRUE;
52 if ((pOD->fOptState & OPTST_RESET) != 0)
53 return;
55 if (pOD->optArg.argString == NULL) {
56 pOD->optArg.argBool = AG_FALSE;
57 return;
60 switch (*(pOD->optArg.argString)) {
61 case '0':
63 long val = strtol( pOD->optArg.argString, &pz, 0 );
64 if ((val != 0) || (*pz != NUL))
65 break;
66 /* FALLTHROUGH */
68 case 'N':
69 case 'n':
70 case 'F':
71 case 'f':
72 case NUL:
73 res = AG_FALSE;
74 break;
75 case '#':
76 if (pOD->optArg.argString[1] != 'f')
77 break;
78 res = AG_FALSE;
81 if (pOD->fOptState & OPTST_ALLOC_ARG) {
82 AGFREE(pOD->optArg.argString);
83 pOD->fOptState &= ~OPTST_ALLOC_ARG;
85 pOD->optArg.argBool = res;
88 * Local Variables:
89 * mode: C
90 * c-file-style: "stroustrup"
91 * indent-tabs-mode: nil
92 * End:
93 * end of autoopts/boolean.c */