5
* Time-stamp: "2010-07-17 10:36:19 bkorb"
5
* Time-stamp: "2011-03-06 11:52:23 bkorb"
7
7
* This file is part of AutoOpts, a companion to AutoGen.
8
8
* AutoOpts is free software.
9
* AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved
9
* AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
11
11
* AutoOpts is available under any one of two licenses. The license
12
12
* in use must be one of these two and the choice is under the control
25
25
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
28
#ifndef HAVE_PARSE_DURATION
32
ao_xstrdup(char const * pz)
35
AGDUPSTR(str, pz, "time val str");
39
#define xstrdup(_s) ao_xstrdup(_s)
41
#include "parse-duration.c"
46
28
/*=export_func optionTimeVal
49
* what: process an option with a time value.
31
* what: process an option with a time duration.
50
32
* arg: + tOptions* + pOpts + program options descriptor +
51
33
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
54
36
* Decipher a time duration value.
57
optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
39
optionTimeVal(tOptions * pOpts, tOptDesc * pOD)
61
43
if ((pOD->fOptState & OPTST_RESET) != 0)
64
46
val = parse_duration(pOD->optArg.argString);
47
if (val == BAD_TIME) {
48
fprintf(stderr, zNotDuration, pOpts->pzProgName, pOD->optArg.argString);
49
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
50
(*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
68
53
if (pOD->fOptState & OPTST_ALLOC_ARG) {
69
54
AGFREE(pOD->optArg.argString);
73
58
pOD->optArg.argInt = val;
61
/*=export_func optionTimeDate
64
* what: process an option with a time and date.
65
* arg: + tOptions* + pOpts + program options descriptor +
66
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
69
* Decipher a time and date value.
72
optionTimeDate(tOptions * pOpts, tOptDesc * pOD)
74
#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV)
75
if ((! HAS_pzPkgDataDir(pOpts)) || (pOpts->pzPkgDataDir == NULL))
79
* Export the DATEMSK environment variable. getdate_r() uses it to
80
* find the file with the strptime formats. If we cannot find the file
81
* we need ($PKGDATADIR/datemsk), then fall back to just a time duration.
84
static char * envptr = NULL;
87
static char const fmt[] = "DATEMSK=%s/datemsk";
88
envptr = AGALOC(sizeof(fmt) + strlen(pOpts->pzPkgDataDir), fmt);
89
sprintf(envptr, fmt, pOpts->pzPkgDataDir);
94
if (access(envptr+8, R_OK) != 0)
99
* Convert the date to a time since the epoch and stash it in a long int.
105
if (getdate_r(pOD->optArg.argString, &stm) != 0) {
106
fprintf(stderr, zNotDate, pOpts->pzProgName,
107
pOD->optArg.argString);
108
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
109
(*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
115
if (pOD->fOptState & OPTST_ALLOC_ARG) {
116
AGFREE(pOD->optArg.argString);
117
pOD->fOptState &= ~OPTST_ALLOC_ARG;
120
pOD->optArg.argInt = tm;
77
fprintf(stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString);
78
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
79
(*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
81
pOD->optArg.argInt = ~0;
127
optionTimeVal(pOpts, pOD);
128
if (pOD->optArg.argInt != BAD_TIME)
129
pOD->optArg.argInt += (unsigned long)time(NULL);
84
132
* Local Variables: