boolean.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * $Id: boolean.c,v 4.10 2007/02/04 17:44:12 bkorb Exp $
  3. * Time-stamp: "2007-01-13 10:10:39 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. /*
  11. * Automated Options copyright 1992-2007 Bruce Korb
  12. *
  13. * Automated Options is free software.
  14. * You may redistribute it and/or modify it under the terms of the
  15. * GNU General Public License, as published by the Free Software
  16. * Foundation; either version 2, or (at your option) any later version.
  17. *
  18. * Automated Options is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with Automated Options. See the file "COPYING". If not,
  25. * write to: The Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor,
  27. * Boston, MA 02110-1301, USA.
  28. *
  29. * As a special exception, Bruce Korb gives permission for additional
  30. * uses of the text contained in his release of AutoOpts.
  31. *
  32. * The exception is that, if you link the AutoOpts library with other
  33. * files to produce an executable, this does not by itself cause the
  34. * resulting executable to be covered by the GNU General Public License.
  35. * Your use of that executable is in no way restricted on account of
  36. * linking the AutoOpts library code into it.
  37. *
  38. * This exception does not however invalidate any other reasons why
  39. * the executable file might be covered by the GNU General Public License.
  40. *
  41. * This exception applies only to the code released by Bruce Korb under
  42. * the name AutoOpts. If you copy code from other sources under the
  43. * General Public License into a copy of AutoOpts, as the General Public
  44. * License permits, the exception does not apply to the code that you add
  45. * in this way. To avoid misleading anyone as to the status of such
  46. * modified files, you must delete this exception notice from them.
  47. *
  48. * If you write modifications of your own for AutoOpts, it is your choice
  49. * whether to permit this exception to apply to your modifications.
  50. * If you do not wish that, delete this exception notice.
  51. */
  52. /*=export_func optionBooleanVal
  53. * private:
  54. *
  55. * what: Decipher a boolean value
  56. * arg: + tOptions* + pOpts + program options descriptor +
  57. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  58. *
  59. * doc:
  60. * Decipher a true or false value for a boolean valued option argument.
  61. * The value is true, unless it starts with 'n' or 'f' or "#f" or
  62. * it is an empty string or it is a number that evaluates to zero.
  63. =*/
  64. void
  65. optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
  66. {
  67. char* pz;
  68. ag_bool res = AG_TRUE;
  69. switch (*(pOD->optArg.argString)) {
  70. case '0':
  71. {
  72. long val = strtol( pOD->optArg.argString, &pz, 0 );
  73. if ((val != 0) || (*pz != NUL))
  74. break;
  75. /* FALLTHROUGH */
  76. }
  77. case 'N':
  78. case 'n':
  79. case 'F':
  80. case 'f':
  81. case NUL:
  82. res = AG_FALSE;
  83. break;
  84. case '#':
  85. if (pOD->optArg.argString[1] != 'f')
  86. break;
  87. res = AG_FALSE;
  88. }
  89. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  90. AGFREE(pOD->optArg.argString);
  91. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  92. }
  93. pOD->optArg.argBool = res;
  94. }
  95. /*
  96. * Local Variables:
  97. * mode: C
  98. * c-file-style: "stroustrup"
  99. * indent-tabs-mode: nil
  100. * End:
  101. * end of autoopts/boolean.c */