numeric.c 3.2 KB

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