time.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * $Id: time.c,v 4.2 2008/11/16 23:56:59 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-2008 by Bruce Korb - all rights reserved
  8. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  9. *
  10. * AutoOpts is available under any one of two licenses. The license
  11. * in use must be one of these two and the choice is under the control
  12. * of the user of the license.
  13. *
  14. * The GNU Lesser General Public License, version 3 or later
  15. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  16. *
  17. * The Modified Berkeley Software Distribution License
  18. * See the file "COPYING.mbsd"
  19. *
  20. * These files have the following md5sums:
  21. *
  22. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  23. * fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
  24. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  25. */
  26. #ifndef HAVE_PARSE_DURATION
  27. #include <time.h>
  28. static inline char *
  29. ao_xstrdup(char const * pz)
  30. {
  31. char * str;
  32. AGDUPSTR(str, pz, "time val str");
  33. return str;
  34. }
  35. #define xstrdup(_s) ao_xstrdup(_s)
  36. #include "parse-duration.c"
  37. #undef xstrdup
  38. #endif
  39. /*=export_func optionTimeVal
  40. * private:
  41. *
  42. * what: process an option with a time value.
  43. * arg: + tOptions* + pOpts + program options descriptor +
  44. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  45. *
  46. * doc:
  47. * Decipher a time duration value.
  48. =*/
  49. void
  50. optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
  51. {
  52. long val;
  53. if ((pOD->fOptState & OPTST_RESET) != 0)
  54. return;
  55. val = parse_duration(pOD->optArg.argString);
  56. if (errno != 0)
  57. goto bad_time;
  58. if (pOD->fOptState & OPTST_ALLOC_ARG) {
  59. AGFREE(pOD->optArg.argString);
  60. pOD->fOptState &= ~OPTST_ALLOC_ARG;
  61. }
  62. pOD->optArg.argInt = val;
  63. return;
  64. bad_time:
  65. fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
  66. if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
  67. (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
  68. pOD->optArg.argInt = ~0;
  69. }
  70. /*
  71. * Local Variables:
  72. * mode: C
  73. * c-file-style: "stroustrup"
  74. * indent-tabs-mode: nil
  75. * End:
  76. * end of autoopts/numeric.c */