1
2/*
3 *  $Id: 329b43154b88d78564d8f960a00a83ec7d8baee0 $
4 * Time-stamp:      "2008-08-03 13:06:02 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 *  This file is part of AutoOpts, a companion to AutoGen.
12 *  AutoOpts is free software.
13 *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
14 *
15 *  AutoOpts is available under any one of two licenses.  The license
16 *  in use must be one of these two and the choice is under the control
17 *  of the user of the license.
18 *
19 *   The GNU Lesser General Public License, version 3 or later
20 *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
21 *
22 *   The Modified Berkeley Software Distribution License
23 *      See the file "COPYING.mbsd"
24 *
25 *  These files have the following md5sums:
26 *
27 *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
28 *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
29 *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
30 */
31
32/*=export_func  optionBooleanVal
33 * private:
34 *
35 * what:  Decipher a boolean value
36 * arg:   + tOptions* + pOpts    + program options descriptor +
37 * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
38 *
39 * doc:
40 *  Decipher a true or false value for a boolean valued option argument.
41 *  The value is true, unless it starts with 'n' or 'f' or "#f" or
42 *  it is an empty string or it is a number that evaluates to zero.
43=*/
44void
45optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
46{
47    char* pz;
48    ag_bool  res = AG_TRUE;
49
50    if ((pOD->fOptState & OPTST_RESET) != 0)
51        return;
52
53    if (pOD->optArg.argString == NULL) {
54        pOD->optArg.argBool = AG_FALSE;
55        return;
56    }
57
58    switch (*(pOD->optArg.argString)) {
59    case '0':
60    {
61        long  val = strtol( pOD->optArg.argString, &pz, 0 );
62        if ((val != 0) || (*pz != NUL))
63            break;
64        /* FALLTHROUGH */
65    }
66    case 'N':
67    case 'n':
68    case 'F':
69    case 'f':
70    case NUL:
71        res = AG_FALSE;
72        break;
73    case '#':
74        if (pOD->optArg.argString[1] != 'f')
75            break;
76        res = AG_FALSE;
77    }
78
79    if (pOD->fOptState & OPTST_ALLOC_ARG) {
80        AGFREE(pOD->optArg.argString);
81        pOD->fOptState &= ~OPTST_ALLOC_ARG;
82    }
83    pOD->optArg.argBool = res;
84}
85/*
86 * Local Variables:
87 * mode: C
88 * c-file-style: "stroustrup"
89 * indent-tabs-mode: nil
90 * End:
91 * end of autoopts/boolean.c */
92