xref: /freebsd/contrib/ntp/sntp/libopts/boolean.c (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
1 
2 /*
3  *  $Id: boolean.c,v 4.10 2007/02/04 17:44:12 bkorb Exp $
4  * Time-stamp:      "2007-01-13 10:10:39 bkorb"
5  *
6  *   Automated Options Paged Usage module.
7  *
8  *  This routine will run run-on options through a pager so the
9  *  user may examine, print or edit them at their leisure.
10  */
11 
12 /*
13  *  Automated Options copyright 1992-2007 Bruce Korb
14  *
15  *  Automated Options is free software.
16  *  You may redistribute it and/or modify it under the terms of the
17  *  GNU General Public License, as published by the Free Software
18  *  Foundation; either version 2, or (at your option) any later version.
19  *
20  *  Automated Options is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with Automated Options.  See the file "COPYING".  If not,
27  *  write to:  The Free Software Foundation, Inc.,
28  *             51 Franklin Street, Fifth Floor,
29  *             Boston, MA  02110-1301, USA.
30  *
31  * As a special exception, Bruce Korb gives permission for additional
32  * uses of the text contained in his release of AutoOpts.
33  *
34  * The exception is that, if you link the AutoOpts library with other
35  * files to produce an executable, this does not by itself cause the
36  * resulting executable to be covered by the GNU General Public License.
37  * Your use of that executable is in no way restricted on account of
38  * linking the AutoOpts library code into it.
39  *
40  * This exception does not however invalidate any other reasons why
41  * the executable file might be covered by the GNU General Public License.
42  *
43  * This exception applies only to the code released by Bruce Korb under
44  * the name AutoOpts.  If you copy code from other sources under the
45  * General Public License into a copy of AutoOpts, as the General Public
46  * License permits, the exception does not apply to the code that you add
47  * in this way.  To avoid misleading anyone as to the status of such
48  * modified files, you must delete this exception notice from them.
49  *
50  * If you write modifications of your own for AutoOpts, it is your choice
51  * whether to permit this exception to apply to your modifications.
52  * If you do not wish that, delete this exception notice.
53  */
54 
55 /*=export_func  optionBooleanVal
56  * private:
57  *
58  * what:  Decipher a boolean value
59  * arg:   + tOptions* + pOpts    + program options descriptor +
60  * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
61  *
62  * doc:
63  *  Decipher a true or false value for a boolean valued option argument.
64  *  The value is true, unless it starts with 'n' or 'f' or "#f" or
65  *  it is an empty string or it is a number that evaluates to zero.
66 =*/
67 void
68 optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
69 {
70     char* pz;
71     ag_bool  res = AG_TRUE;
72 
73     switch (*(pOD->optArg.argString)) {
74     case '0':
75     {
76         long  val = strtol( pOD->optArg.argString, &pz, 0 );
77         if ((val != 0) || (*pz != NUL))
78             break;
79         /* FALLTHROUGH */
80     }
81     case 'N':
82     case 'n':
83     case 'F':
84     case 'f':
85     case NUL:
86         res = AG_FALSE;
87         break;
88     case '#':
89         if (pOD->optArg.argString[1] != 'f')
90             break;
91         res = AG_FALSE;
92     }
93 
94     if (pOD->fOptState & OPTST_ALLOC_ARG) {
95         AGFREE(pOD->optArg.argString);
96         pOD->fOptState &= ~OPTST_ALLOC_ARG;
97     }
98     pOD->optArg.argBool = res;
99 }
100 /*
101  * Local Variables:
102  * mode: C
103  * c-file-style: "stroustrup"
104  * indent-tabs-mode: nil
105  * End:
106  * end of autoopts/boolean.c */
107