numeric.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * $Id: numeric.c,v 4.13 2007/07/04 21:36:37 bkorb Exp $
  3. * Time-stamp: "2007-07-04 10:21:59 bkorb"
  4. *
  5. * This file is part of AutoOpts, a companion to AutoGen.
  6. * AutoOpts is free software.
  7. * AutoOpts is copyright (c) 1992-2007 by Bruce Korb - all rights reserved
  8. *
  9. * AutoOpts is available under any one of two licenses. The license
  10. * in use must be one of these two and the choice is under the control
  11. * of the user of the license.
  12. *
  13. * The GNU Lesser General Public License, version 3 or later
  14. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  15. *
  16. * The Modified Berkeley Software Distribution License
  17. * See the file "COPYING.mbsd"
  18. *
  19. * These files have the following md5sums:
  20. *
  21. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  22. * fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
  23. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  24. */
  25. /*=export_func optionNumericVal
  26. * private:
  27. *
  28. * what: Decipher a boolean value
  29. * arg: + tOptions* + pOpts + program options descriptor +
  30. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  31. *
  32. * doc:
  33. * Decipher a numeric value.
  34. =*/
  35. void
  36. optionNumericVal( tOptions* pOpts, tOptDesc* pOD )
  37. {
  38. char* pz;
  39. long val;
  40. /*
  41. * Numeric options may have a range associated with it.
  42. * If it does, the usage procedure requests that it be
  43. * emitted by passing a NULL pOD pointer.
  44. */
  45. if ((pOD == NULL) || (pOD->optArg.argString == NULL))
  46. return;
  47. val = strtol( pOD->optArg.argString, &pz, 0 );
  48. if (*pz != NUL) {
  49. fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
  50. (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
  51. }
  52. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  53. AGFREE(pOD->optArg.argString);
  54. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  55. }
  56. pOD->optArg.argInt = val;
  57. }
  58. /*
  59. * Local Variables:
  60. * mode: C
  61. * c-file-style: "stroustrup"
  62. * indent-tabs-mode: nil
  63. * End:
  64. * end of autoopts/numeric.c */