5 * Time-stamp: "2012-01-29 12:52:31 bkorb"
7 * This file is part of AutoOpts, a companion to AutoGen.
8 * AutoOpts is free software.
9 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
11 * AutoOpts is available under any one of two licenses. The license
12 * in use must be one of these two and the choice is under the control
13 * of the user of the license.
15 * The GNU Lesser General Public License, version 3 or later
16 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
18 * The Modified Berkeley Software Distribution License
19 * See the file "COPYING.mbsd"
21 * These files have the following md5sums:
23 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
24 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
25 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
28 /*=export_func optionTimeVal
31 * what: process an option with a time duration.
32 * arg: + tOptions* + pOpts + program options descriptor +
33 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
36 * Decipher a time duration value.
39 optionTimeVal(tOptions
* pOpts
, tOptDesc
* pOD
)
43 if ((pOD
->fOptState
& OPTST_RESET
) != 0)
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
);
53 if (pOD
->fOptState
& OPTST_ALLOC_ARG
) {
54 AGFREE(pOD
->optArg
.argString
);
55 pOD
->fOptState
&= ~OPTST_ALLOC_ARG
;
58 pOD
->optArg
.argInt
= (unsigned long)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
;
127 optionTimeVal(pOpts
, pOD
);
128 if (pOD
->optArg
.argInt
!= BAD_TIME
)
129 pOD
->optArg
.argInt
+= (unsigned long)time(NULL
);
134 * c-file-style: "stroustrup"
135 * indent-tabs-mode: nil
137 * end of autoopts/time.c */