-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.h
277 lines (251 loc) · 7.68 KB
/
parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* $Id$ */
/*
* Copyright (c) 2016--2018 Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef PARSER_H
#define PARSER_H
/*
* The dive mode.
* This corresponds to libdivecomputer's enum dc_divemode_t.
*/
enum mode {
MODE_NONE,
MODE_FREEDIVE,
MODE_GAUGE,
MODE_OC,
MODE_CC
};
/*
* Ways to group dives.
*/
enum group {
GROUP_NONE, /* don't group: all in one group */
GROUP_DIVER, /* group by diver identifier */
GROUP_DATE, /* group by date */
GROUP_DIVELOG /* group by dive computer */
};
/*
* How to sort dives within groups.
*/
enum groupsort {
GROUPSORT_DATETIME,
GROUPSORT_MAXDEPTH,
GROUPSORT_MAXTIME,
GROUPSORT_RMAXDEPTH,
GROUPSORT_RMAXTIME
};
/*
* A generic event.
* This corresponds to libdivecomputer's parser_sample_event_t.
*/
enum event {
EVENT_none,
EVENT_decostop,
EVENT_rbt,
EVENT_ascent,
EVENT_ceiling,
EVENT_workload,
EVENT_transmitter,
EVENT_violation,
EVENT_bookmark,
EVENT_surface,
EVENT_safetystop,
EVENT_gaschange,
EVENT_safetystop_voluntary,
EVENT_safetystop_mandatory,
EVENT_deepstop,
EVENT_ceiling_safetystop,
EVENT_floor,
EVENT_divetime,
EVENT_maxdepth,
EVENT_olf,
EVENT_po2,
EVENT_airtime,
EVENT_rgbm,
EVENT_heading,
EVENT_tissuelevel,
EVENT_gaschange2,
EVENT__MAX
};
/*
* Type of deco sample notification.
*/
enum deco {
DECO_ndl,
DECO_safetystop,
DECO_decostop,
DECO_deepstop,
DECO__MAX
};
struct sampevent {
size_t duration; /* duration (or zero) */
unsigned int flags; /* any opaque flags (or zero) */
enum event type; /* event type */
};
/*
* Decompression information.
* If this is DECO_ndl, the duration is the current NDL time.
* Otherwise, the duration is the stop (or remaining) time.
* The "depth" value is set for deco and deep stops to be the depth of
* the decompression stop.
*/
struct sampdeco {
double depth; /* stop depth or zero */
enum deco type;
size_t duration; /* stop/time duration or zero */
};
/*
* Vendor-specific information (can be anything).
*/
struct sampvendor {
char *buf; /* hex-valued vendor information */
size_t type; /* opaque type */
};
/*
* Pressure of a tank.
* Note that the tank may not refer to a cylinder in the "cyls" of the
* dive.
* In this case, the tank is assumed to have no data attached to it and
* is "blank" (no working pressure, size, etc.).
*/
struct samppres {
size_t tank; /* tank num */
double pressure; /* bar */
};
/*
* A sample within a dive profile.
* The "flags" field (which may be zero) dictates which are the
* available records within the sample.
*/
struct samp {
size_t time; /* seconds since start */
double depth; /* metres */
double temp; /* celsius */
double cns; /* [0,1] */
struct samppres *pressure; /* tank pressure */
size_t pressuresz; /* number of pressures */
size_t rbt; /* seconds */
size_t gaschange; /* num of gas change */
struct sampevent *events; /* generic events */
size_t eventsz;
struct sampdeco deco;
struct sampvendor vendor;
#define SAMP_DEPTH 0x01 /* sets depth */
#define SAMP_TEMP 0x02 /* sets tmp */
#define SAMP_RBT 0x04 /* sets rbt */
#define SAMP_DECO 0x10 /* sets deco */
#define SAMP_VENDOR 0x20 /* sets vendor */
#define SAMP_GASCHANGE 0x40 /* sets gaschange */
#define SAMP_CNS 0x80 /* sets cns */
unsigned int flags; /* SAMP_xxx values represented */
size_t line; /* parse line */
size_t col; /* parse column */
TAILQ_ENTRY(samp) entries;
};
TAILQ_HEAD(sampq, samp);
struct dive;
TAILQ_HEAD(diveq, dive);
struct dgroup {
char *name; /* date (or NULL) */
time_t mintime; /* minimum date in group */
size_t id; /* unique identifier */
size_t ndives; /* number of dives in queue */
struct diveq dives; /* all dives */
};
/*
* A self-contained divelog article.
* This is parsed from the <divelog> element.
*/
struct dlog {
char *file; /* file or <stdin> */
size_t line; /* parse line */
char *ident; /* diver or NULL */
char *program; /* program or NULL */
char *vendor; /* vendor or NULL */
char *product; /* product or NULL */
char *model; /* model or NULL */
TAILQ_ENTRY(dlog) entries;
};
TAILQ_HEAD(dlogq, dlog);
struct divegas {
double o2; /* O2 (%) or 0 if unset */
double n2; /* N2 (%) or 0 if unset */
double he; /* He (%) or 0 if unset */
size_t num; /* identifier, never zero */
};
struct cylinder {
size_t num; /* identifier, never zero */
size_t mix; /* divegas "num" or zero */
double size; /* volume of tank in litres or zero */
double workpressure; /* working pressure (bar) or zero */
};
struct dive {
size_t pid; /* unique in parse sequence */
time_t datetime; /* time or zero */
size_t num; /* number or zero */
size_t duration; /* duration or zero */
enum mode mode; /* dive mode */
struct sampq samps; /* samples */
struct divegas *gas; /* gasmixes */
size_t gassz; /* number of gasses */
struct cylinder *cyls; /* cylinders ("tanks") */
size_t cylsz; /* number of cylinders */
double maxdepth; /* maximum sample depth */
int hastemp; /* do we have temps? */
double maxtemp; /* maximum (hottest) temp */
double mintemp; /* minimum (coldest) temp */
size_t maxtime; /* maximum sample time */
size_t nsamps; /* number of samples */
char *fprint; /* fingerprint or NULL */
struct dgroup *group; /* group identifier */
const struct dlog *log; /* source divelog */
TAILQ_ENTRY(dive) entries; /* in-dive entry */
TAILQ_ENTRY(dive) gentries; /* in-group entry */
size_t line; /* parse line */
size_t col; /* parse column */
};
struct divestat {
double maxdepth; /* maximum over all dives */
time_t timestamp_min; /* minimum timestamp */
time_t timestamp_max; /* maximum timestamp */
enum group group; /* how we're grouping dives */
enum groupsort groupsort; /* how we're sorting dives */
struct dgroup **groups; /* all groups */
size_t groupsz; /* size of "groups" */
struct dlogq dlogs; /* all divelog nodes */
};
__BEGIN_DECLS
void divecmd_init(XML_Parser *, struct diveq *,
struct divestat *, enum group, enum groupsort);
void divecmd_free(struct diveq *, struct divestat *);
int divecmd_parse(const char *, XML_Parser,
struct diveq *dq, struct divestat *);
void divecmd_print_diveq_close(FILE *);
void divecmd_print_diveq_open(FILE *);
void divecmd_print_dive(FILE *, const struct dive *);
void divecmd_print_dive_close(FILE *);
void divecmd_print_dive_fingerprint(FILE *, const struct dive *);
void divecmd_print_dive_gasmixes(FILE *, const struct dive *);
void divecmd_print_dive_open(FILE *, const struct dive *);
void divecmd_print_dive_sampleq(FILE *, const struct sampq *);
void divecmd_print_dive_sampleq_close(FILE *);
void divecmd_print_dive_sampleq_open(FILE *);
void divecmd_print_dive_sample(FILE *, const struct samp *);
void divecmd_print_dive_tanks(FILE *, const struct dive *);
void divecmd_print_close(FILE *);
void divecmd_print_open(FILE *, const struct dlog *);
extern int verbose;
__END_DECLS
#endif /* !PARSER_H */