boolean.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * $Id: boolean.c,v 4.15 2008/08/04 01:01:52 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-2008 by Bruce Korb - all rights reserved
  13. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  14. *
  15. * AutoOpts is available under any one of two licenses. The license
  16. * in use must be one of these two and the choice is under the control
  17. * of the user of the license.
  18. *
  19. * The GNU Lesser General Public License, version 3 or later
  20. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  21. *
  22. * The Modified Berkeley Software Distribution License
  23. * See the file "COPYING.mbsd"
  24. *
  25. * These files have the following md5sums:
  26. *
  27. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  28. * fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
  29. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  30. */
  31. /*=export_func optionBooleanVal
  32. * private:
  33. *
  34. * what: Decipher a boolean value
  35. * arg: + tOptions* + pOpts + program options descriptor +
  36. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  37. *
  38. * doc:
  39. * Decipher a true or false value for a boolean valued option argument.
  40. * The value is true, unless it starts with 'n' or 'f' or "#f" or
  41. * it is an empty string or it is a number that evaluates to zero.
  42. =*/
  43. void
  44. optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
  45. {
  46. char* pz;
  47. ag_bool res = AG_TRUE;
  48. if ((pOD->fOptState & OPTST_RESET) != 0)
  49. return;
  50. if (pOD->optArg.argString == NULL) {
  51. pOD->optArg.argBool = AG_FALSE;
  52. return;
  53. }
  54. switch (*(pOD->optArg.argString)) {
  55. case '0':
  56. {
  57. long val = strtol( pOD->optArg.argString, &pz, 0 );
  58. if ((val != 0) || (*pz != NUL))
  59. break;
  60. /* FALLTHROUGH */
  61. }
  62. case 'N':
  63. case 'n':
  64. case 'F':
  65. case 'f':
  66. case NUL:
  67. res = AG_FALSE;
  68. break;
  69. case '#':
  70. if (pOD->optArg.argString[1] != 'f')
  71. break;
  72. res = AG_FALSE;
  73. }
  74. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  75. AGFREE(pOD->optArg.argString);
  76. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  77. }
  78. pOD->optArg.argBool = res;
  79. }
  80. /*
  81. * Local Variables:
  82. * mode: C
  83. * c-file-style: "stroustrup"
  84. * indent-tabs-mode: nil
  85. * End:
  86. * end of autoopts/boolean.c */