1181834Sroberto 2285612Sdelphij/** 3285612Sdelphij * \file boolean.c 4181834Sroberto * 5285612Sdelphij * Handle options with true/false values for arguments. 6181834Sroberto * 7285612Sdelphij * @addtogroup autoopts 8285612Sdelphij * @{ 9285612Sdelphij */ 10285612Sdelphij/* 11181834Sroberto * This routine will run run-on options through a pager so the 12181834Sroberto * user may examine, print or edit them at their leisure. 13181834Sroberto * 14285612Sdelphij * This file is part of AutoOpts, a companion to AutoGen. 15285612Sdelphij * AutoOpts is free software. 16285612Sdelphij * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved 17181834Sroberto * 18285612Sdelphij * AutoOpts is available under any one of two licenses. The license 19285612Sdelphij * in use must be one of these two and the choice is under the control 20285612Sdelphij * of the user of the license. 21181834Sroberto * 22285612Sdelphij * The GNU Lesser General Public License, version 3 or later 23285612Sdelphij * See the files "COPYING.lgplv3" and "COPYING.gplv3" 24181834Sroberto * 25285612Sdelphij * The Modified Berkeley Software Distribution License 26285612Sdelphij * See the file "COPYING.mbsd" 27181834Sroberto * 28285612Sdelphij * These files have the following sha256 sums: 29181834Sroberto * 30285612Sdelphij * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 31285612Sdelphij * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 32285612Sdelphij * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd 33181834Sroberto */ 34181834Sroberto 35181834Sroberto/*=export_func optionBooleanVal 36181834Sroberto * private: 37181834Sroberto * 38181834Sroberto * what: Decipher a boolean value 39285612Sdelphij * arg: + tOptions * + opts + program options descriptor + 40285612Sdelphij * arg: + tOptDesc * + od + the descriptor for this arg + 41181834Sroberto * 42181834Sroberto * doc: 43181834Sroberto * Decipher a true or false value for a boolean valued option argument. 44181834Sroberto * The value is true, unless it starts with 'n' or 'f' or "#f" or 45181834Sroberto * it is an empty string or it is a number that evaluates to zero. 46181834Sroberto=*/ 47181834Srobertovoid 48285612SdelphijoptionBooleanVal(tOptions * opts, tOptDesc * od) 49181834Sroberto{ 50285612Sdelphij char * pz; 51285612Sdelphij bool res = true; 52181834Sroberto 53285612Sdelphij if (INQUERY_CALL(opts, od)) 54285612Sdelphij return; 55285612Sdelphij 56285612Sdelphij if (od->optArg.argString == NULL) { 57285612Sdelphij od->optArg.argBool = false; 58285612Sdelphij return; 59285612Sdelphij } 60285612Sdelphij 61285612Sdelphij switch (*(od->optArg.argString)) { 62181834Sroberto case '0': 63181834Sroberto { 64285612Sdelphij long val = strtol(od->optArg.argString, &pz, 0); 65181834Sroberto if ((val != 0) || (*pz != NUL)) 66181834Sroberto break; 67181834Sroberto /* FALLTHROUGH */ 68181834Sroberto } 69181834Sroberto case 'N': 70181834Sroberto case 'n': 71181834Sroberto case 'F': 72181834Sroberto case 'f': 73181834Sroberto case NUL: 74285612Sdelphij res = false; 75181834Sroberto break; 76181834Sroberto case '#': 77285612Sdelphij if (od->optArg.argString[1] != 'f') 78181834Sroberto break; 79285612Sdelphij res = false; 80181834Sroberto } 81181834Sroberto 82285612Sdelphij if (od->fOptState & OPTST_ALLOC_ARG) { 83285612Sdelphij AGFREE(od->optArg.argString); 84285612Sdelphij od->fOptState &= ~OPTST_ALLOC_ARG; 85181834Sroberto } 86285612Sdelphij od->optArg.argBool = res; 87181834Sroberto} 88285612Sdelphij/** @} 89285612Sdelphij * 90181834Sroberto * Local Variables: 91181834Sroberto * mode: C 92181834Sroberto * c-file-style: "stroustrup" 93181834Sroberto * indent-tabs-mode: nil 94181834Sroberto * End: 95181834Sroberto * end of autoopts/boolean.c */ 96