boolean.c 2.3 KB

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