boolean.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * $Id: boolean.c,v 4.16 2009/08/01 17:43:05 bkorb Exp $
  3. * Time-stamp: "2008-08-03 13:06:02 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-2009 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. * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
  27. * 06a1a2e4760c90ea5e1dad8dfaac4d39 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. if ((pOD->fOptState & OPTST_RESET) != 0)
  48. return;
  49. if (pOD->optArg.argString == NULL) {
  50. pOD->optArg.argBool = AG_FALSE;
  51. return;
  52. }
  53. switch (*(pOD->optArg.argString)) {
  54. case '0':
  55. {
  56. long val = strtol( pOD->optArg.argString, &pz, 0 );
  57. if ((val != 0) || (*pz != NUL))
  58. break;
  59. /* FALLTHROUGH */
  60. }
  61. case 'N':
  62. case 'n':
  63. case 'F':
  64. case 'f':
  65. case NUL:
  66. res = AG_FALSE;
  67. break;
  68. case '#':
  69. if (pOD->optArg.argString[1] != 'f')
  70. break;
  71. res = AG_FALSE;
  72. }
  73. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  74. AGFREE(pOD->optArg.argString);
  75. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  76. }
  77. pOD->optArg.argBool = res;
  78. }
  79. /*
  80. * Local Variables:
  81. * mode: C
  82. * c-file-style: "stroustrup"
  83. * indent-tabs-mode: nil
  84. * End:
  85. * end of autoopts/boolean.c */