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