boolean.c 3.4 KB

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