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