time.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * $Id: time.c,v 4.5 2009/08/01 17:43:06 bkorb Exp $
  3. * Time-stamp: "2008-11-16 14:51:48 bkorb"
  4. *
  5. * This file is part of AutoOpts, a companion to AutoGen.
  6. * AutoOpts is free software.
  7. * AutoOpts is copyright (c) 1992-2009 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. * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
  22. * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
  23. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  24. */
  25. #ifndef HAVE_PARSE_DURATION
  26. #include <time.h>
  27. static inline char *
  28. ao_xstrdup(char const * pz)
  29. {
  30. char * str;
  31. AGDUPSTR(str, pz, "time val str");
  32. return str;
  33. }
  34. #define xstrdup(_s) ao_xstrdup(_s)
  35. #include "parse-duration.c"
  36. #undef xstrdup
  37. #endif
  38. /*=export_func optionTimeVal
  39. * private:
  40. *
  41. * what: process an option with a time value.
  42. * arg: + tOptions* + pOpts + program options descriptor +
  43. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  44. *
  45. * doc:
  46. * Decipher a time duration value.
  47. =*/
  48. void
  49. optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
  50. {
  51. long val;
  52. if ((pOD->fOptState & OPTST_RESET) != 0)
  53. return;
  54. val = parse_duration(pOD->optArg.argString);
  55. if (errno != 0)
  56. goto bad_time;
  57. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  58. AGFREE(pOD->optArg.argString);
  59. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  60. }
  61. pOD->optArg.argInt = val;
  62. return;
  63. bad_time:
  64. fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
  65. if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
  66. (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
  67. pOD->optArg.argInt = ~0;
  68. }
  69. /*
  70. * Local Variables:
  71. * mode: C
  72. * c-file-style: "stroustrup"
  73. * indent-tabs-mode: nil
  74. * End:
  75. * end of autoopts/numeric.c */