libarmutils  1.4
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups
regex_time.h
Go to the documentation of this file.
1 /*******************************************************************************
2 *
3 * COPYRIGHT (C) 2015 Battelle Memorial Institute. All Rights Reserved.
4 *
5 ********************************************************************************
6 *
7 * Author:
8 * name: Brian Ermold
9 * phone: (509) 375-2277
10 * email: brian.ermold@pnl.gov
11 *
12 ********************************************************************************
13 *
14 * REPOSITORY INFORMATION:
15 * $Revision: 67752 $
16 * $Author: ermold $
17 * $Date: 2016-02-25 20:02:46 +0000 (Thu, 25 Feb 2016) $
18 *
19 ********************************************************************************
20 *
21 * NOTE: DOXYGEN is used to generate documentation for this file.
22 *
23 *******************************************************************************/
24 
25 /** @file regex_time.h
26  * Regex Time Utilities
27  */
28 
29 #include "armutils/time_utils.h"
30 
31 #ifndef _REGEX_TIME_H
32 #define _REGEX_TIME_H
33 
34 #define RETIME_MAX_SUBSTR_LENGTH 128 /**< maximum length of a parsed substring */
35 #define RETIME_MAX_NSUBS 32 /**< maximum number of subexpressions */
36 
37 /**
38  * @defgroup ARMUTILS_REGEX_TIME Regex Time Utils
39  */
40 /*@{*/
41 
42 /**
43  * Regular Expression with Time Format Codes.
44  */
45 typedef struct {
46 
47  char *tspattern; /**< original time string pattern */
48  char *pattern; /**< regex pattern string */
49  size_t nsubs; /**< number of subexpressions */
50  char *codes; /**< date-time codes of subexpressions */
51  regex_t preg; /**< compiled regular expression */
52  int flags; /**< reserved for control flags */
53 
54 } RETime;
55 
56 /**
57  * Result RETime pattern match.
58  */
59 typedef struct {
60 
61  int year; /**< year with century as a 4-digit integer */
62  int month; /**< month number (1-12) */
63  int mday; /**< day number in the month (1-31) */
64  int hour; /**< hour (0-23) */
65  int min; /**< minute (0-59) */
66  int sec; /**< second (0-60; 60 may occur for leap seconds) */
67  int usec; /**< micro-seconds */
68  int century; /**< century number (year/100) as a 2-digit integer */
69  int yy; /**< year number in century as a 2-digit integer */
70  int yday; /**< day number in the year (1-366) */
71  int hhmm; /**< hour * 100 + minute */
72  time_t secs1970; /**< seconds since Epoch, 1970-01-01 00:00:00 */
73  timeval_t offset; /**< time offset from %o match */
74 
75  /* used by retime_get_* functions */
76  time_t res_time; /**< result in seconds since Epoch, 1970-01-01 */
77  timeval_t res_tv; /**< result in seconds since Epoch, 1970-01-01 */
78 
79  /** pointer to the RETime that matched */
81 
82  /** arrary of matching substring offsets */
83  regmatch_t pmatch[RETIME_MAX_NSUBS];
84 
85 } RETimeRes;
86 
87 /**
88  * List of Regular Expression with Time Format Codes.
89  */
90 typedef struct {
91 
92  int npatterns; /**< number of RETime patterns in the list */
93  RETime **retimes; /**< list of RETime patterns */
94 
95 } RETimeList;
96 
98  const char *pattern,
99  int flags);
100 
101 int retime_execute(
102  RETime *retime,
103  const char *string,
104  RETimeRes *res);
105 
106 void retime_free(
107  RETime *retime);
108 
109 time_t retime_get_secs1970(
110  RETimeRes *res);
111 
113  RETimeRes *res);
114 
116  int npatterns,
117  const char **patterns,
118  int flags);
119 
121  RETimeList *retime_list,
122  const char *string,
123  RETimeRes *res);
124 
125 void retime_list_free(
126  RETimeList *retime_list);
127 
128 /*@}*/
129 
130 #endif /* _REGEX_TIME_H */