boolean.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * $Id: boolean.c,v 4.5 2006/03/25 19:24:56 bkorb Exp $
  3. * Time-stamp: "2005-02-14 08:24:12 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-2006 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. long val;
  68. char* pz;
  69. ag_bool res = AG_TRUE;
  70. switch (*(pOD->pzLastArg)) {
  71. case '0':
  72. val = strtol( pOD->pzLastArg, &pz, 0 );
  73. if ((val != 0) || (*pz != NUL))
  74. break;
  75. /* FALLTHROUGH */
  76. case 'N':
  77. case 'n':
  78. case 'F':
  79. case 'f':
  80. case NUL:
  81. res = AG_FALSE;
  82. break;
  83. case '#':
  84. if (pOD->pzLastArg[1] != 'f')
  85. break;
  86. res = AG_FALSE;
  87. }
  88. pOD->pzLastArg = (char*)res;
  89. }
  90. /*
  91. * Local Variables:
  92. * mode: C
  93. * c-file-style: "stroustrup"
  94. * tab-width: 4
  95. * indent-tabs-mode: nil
  96. * End:
  97. * end of autoopts/boolean.c */