xref: /netbsd/external/bsd/ntp/dist/sntp/libopts/boolean.c (revision 6550d01e)
1 /*	$NetBSD: boolean.c,v 1.1.1.1 2009/12/13 16:57:17 kardel Exp $	*/
2 
3 
4 /*
5  *  Id: 329b43154b88d78564d8f960a00a83ec7d8baee0
6  * Time-stamp:      "2008-08-03 13:06:02 bkorb"
7  *
8  *   Automated Options Paged Usage module.
9  *
10  *  This routine will run run-on options through a pager so the
11  *  user may examine, print or edit them at their leisure.
12  *
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
16  *
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.
20  *
21  *   The GNU Lesser General Public License, version 3 or later
22  *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
23  *
24  *   The Modified Berkeley Software Distribution License
25  *      See the file "COPYING.mbsd"
26  *
27  *  These files have the following md5sums:
28  *
29  *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
30  *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
31  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
32  */
33 
34 /*=export_func  optionBooleanVal
35  * private:
36  *
37  * what:  Decipher a boolean value
38  * arg:   + tOptions* + pOpts    + program options descriptor +
39  * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
40  *
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 )
48 {
49     char* pz;
50     ag_bool  res = AG_TRUE;
51 
52     if ((pOD->fOptState & OPTST_RESET) != 0)
53         return;
54 
55     if (pOD->optArg.argString == NULL) {
56         pOD->optArg.argBool = AG_FALSE;
57         return;
58     }
59 
60     switch (*(pOD->optArg.argString)) {
61     case '0':
62     {
63         long  val = strtol( pOD->optArg.argString, &pz, 0 );
64         if ((val != 0) || (*pz != NUL))
65             break;
66         /* FALLTHROUGH */
67     }
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;
79     }
80 
81     if (pOD->fOptState & OPTST_ALLOC_ARG) {
82         AGFREE(pOD->optArg.argString);
83         pOD->fOptState &= ~OPTST_ALLOC_ARG;
84     }
85     pOD->optArg.argBool = res;
86 }
87 /*
88  * Local Variables:
89  * mode: C
90  * c-file-style: "stroustrup"
91  * indent-tabs-mode: nil
92  * End:
93  * end of autoopts/boolean.c */
94