-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpilot-datebook-data.h
533 lines (432 loc) · 16.3 KB
/
pilot-datebook-data.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
* Pilot Datebook processing utility
* Matthias Hessler <pilot-datebook@mhessler.de> December 2000
*
* This is free software, licensed under the GNU Public License V2.
* See the file COPYING for details.
*/
#ifndef _PILOT_DATEBOOK_DATA
#define _PILOT_DATEBOOK_DATA
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h> /* isspace */
#include <stdarg.h> /* va_arg, vprintf stuff */
#include "pi-source.h"
#include "pi-socket.h"
#include "pi-dlp.h"
#include "pi-file.h"
#include "pi-datebook.h"
#ifdef sun
extern char* optarg;
extern int optind;
#endif
/* Public constants */
extern const int DATEBOOK_MAX_CATEGORIES;
extern const int WEEKDAY_LEN;
extern const int MONTH_LEN;
/* Field names */
extern const char DATEBOOK_FIELD_UID[];
extern const char DATEBOOK_FIELD_ATTRIBUTES[];
extern const char DATEBOOK_FIELD_CATEGORY[];
extern const char DATEBOOK_FIELD_UNTIMED[];
extern const char DATEBOOK_FIELD_BEGIN[];
extern const char DATEBOOK_FIELD_BEGIN_DATE[];
extern const char DATEBOOK_FIELD_BEGIN_TIME[];
extern const char DATEBOOK_FIELD_END[];
extern const char DATEBOOK_FIELD_END_DATE[];
extern const char DATEBOOK_FIELD_END_TIME[];
extern const char DATEBOOK_FIELD_ALARM[];
extern const char DATEBOOK_FIELD_ADVANCE[];
extern const char DATEBOOK_FIELD_ADVANCE_UNIT[];
extern const char DATEBOOK_FIELD_REPEAT_TYPE[];
extern const char DATEBOOK_FIELD_REPEAT_FOREVER[];
extern const char DATEBOOK_FIELD_REPEAT_END[];
extern const char DATEBOOK_FIELD_REPEAT_END_DATE[];
extern const char DATEBOOK_FIELD_REPEAT_END_TIME[];
extern const char DATEBOOK_FIELD_REPEAT_FREQUENCY[];
extern const char DATEBOOK_FIELD_REPEAT_DAY[];
extern const char DATEBOOK_FIELD_REPEAT_WEEKSTART[];
extern const char DATEBOOK_FIELD_REPEAT_WEEKDAYS[];
extern const char DATEBOOK_FIELD_REPEAT_EXCEPTION_NUM[];
extern const char DATEBOOK_FIELD_REPEAT_EXCEPTION[];
/* Leave out repeatException for now
* (complicated array compare)
*/
extern const char DATEBOOK_FIELD_DESCRIPTION[];
extern const char DATEBOOK_FIELD_NOTE[];
/* Transient calculation/scratch fields */
extern const char DATEBOOK_FIELD_XLONG[];
extern const char DATEBOOK_FIELD_YLONG[];
extern const char DATEBOOK_FIELD_ZLONG[];
extern const char DATEBOOK_FIELD_XINT[];
extern const char DATEBOOK_FIELD_YINT[];
extern const char DATEBOOK_FIELD_ZINT[];
extern const char DATEBOOK_FIELD_XTIME[];
extern const char DATEBOOK_FIELD_YTIME[];
extern const char DATEBOOK_FIELD_ZTIME[];
extern const char DATEBOOK_FIELD_XSECONDS[];
extern const char DATEBOOK_FIELD_YSECONDS[];
extern const char DATEBOOK_FIELD_ZSECONDS[];
extern const char DATEBOOK_FIELD_XSTR[];
extern const char DATEBOOK_FIELD_YSTR[];
extern const char DATEBOOK_FIELD_ZSTR[];
/* enum */
typedef enum { FALSE=0, TRUE=1 } BOOLEAN;
/* File data format */
enum DATA_FORMAT {
/* invalid data format */
DATA_FORMAT_INVALID = 0,
/* direct hotsync to PalmPilot via pilotlink */
DATA_FORMAT_HOTSYNC = 1,
/* PDB data format (= file format of pilotlink) */
DATA_FORMAT_PDB = 2,
/* CSV separated list */
DATA_FORMAT_CSV = 3,
/* Windows desktop file format (*.dat) */
DATA_FORMAT_WINDAT = 4,
/* human readable long text format */
DATA_FORMAT_LONGTXT = 5,
/* former install-datebook input */
DATA_FORMAT_SHORTTXT = 6,
/* former reminders output */
DATA_FORMAT_REMIND = 7,
/* former read-ical output */
DATA_FORMAT_ICAL = 8
};
/* Message verbose level */
enum MESSAGE_VERBOSE_LEVEL {
MESSAGE_VERBOSE_ERROR = 0,
MESSAGE_VERBOSE_WARN = 1,
MESSAGE_VERBOSE_INFO = 2,
MESSAGE_VERBOSE_DEBUG = 3
};
/* Field types */
enum DATEBOOK_FIELD_TYPE {
DATEBOOK_FIELD_LONG = 0,
DATEBOOK_FIELD_INT = 1,
DATEBOOK_FIELD_TIME = 2,
DATEBOOK_FIELD_SECONDS = 3,
DATEBOOK_FIELD_STR = 4,
DATEBOOK_FIELD_TIMES = 5 // multiple times for exceptions
};
/* Assign types */
enum DATEBOOK_ASSIGN_TYPE {
DATEBOOK_ASSIGN = 0,
DATEBOOK_ASSIGN_ADD = 1,
DATEBOOK_ASSIGN_SUBTRACT = 2
};
/* Condition types */
enum DATEBOOK_COND_TYPE {
DATEBOOK_COND_EQUAL = 0,
DATEBOOK_COND_NOT_EQUAL = 1,
DATEBOOK_COND_LESS = 2,
DATEBOOK_COND_LESS_EQUAL = 3,
DATEBOOK_COND_GREATER = 4,
DATEBOOK_COND_GREATER_EQUAL = 5
};
/* Selection types */
enum DATEBOOK_SELECT_TYPE {
DATEBOOK_SELECT_UNKNOWN = 0,
DATEBOOK_SELECT_YES = 1,
DATEBOOK_SELECT_NO = 2
};
/* Data structures */
/* Datebook header data
* (read data will be converted into this data form, and write data will
* be formatted out of this record data)
*/
struct header_data {
/* Valid data in header structure? */
int isValid;
/* Pilotlink header structure */
struct DBInfo info;
/* Datebook application header data */
int app_info_size;
struct AppointmentAppInfo aai;
/* Datebook sort header data */
void * sort_info;
int sort_info_size;
};
/* Datebook record data
* (read data will be converted into this data form, and write data will
* be formatted out of this record data)
*/
struct row_data {
/* Valid data in row structure? */
int isValid;
/* Has row been selected by compare function? */
enum DATEBOOK_SELECT_TYPE isSelected;
/* Row number within read file (=temporary data) */
int record_num;
/* Unique identifying number */
unsigned long uid;
/* Status Attributes (backed up, deleted, added, ...) */
int attributes;
/* Category (0 = Unfiled) */
int category;
/* Pilotlink data structure for datebook data */
struct Appointment appointment;
/* Transient calculation/scratch fields
* (will not be stored, but can be used for intermediate calculations)
*/
/* Long */
unsigned long xLong;
unsigned long yLong;
unsigned long zLong;
/* Int */
int xInt;
int yInt;
int zInt;
/* Time */
struct tm xTime;
struct tm yTime;
struct tm zTime;
/* Seconds */
long xSeconds;
long ySeconds;
long zSeconds;
/* Str */
char * xStr;
char * yStr;
char * zStr;
};
/* Datebook field data
* (contains generic details on how to access datebook data fields,
* used for sort, modify,...)
*/
struct field_data {
enum DATEBOOK_FIELD_TYPE type;
const char * name;
union {
unsigned long (*get_long) (struct row_data * row);
int (*get_int) (struct row_data * row);
struct tm (*get_time) (struct row_data * row);
long (*get_seconds) (struct row_data * row);
char * (*get_str) (struct row_data * row);
struct tm* (*get_times) (struct row_data * row);
} get_func;
union {
void (*set_long) (struct row_data * row, unsigned long new_long);
void (*set_int) (struct row_data * row, int new_int);
void (*set_time) (struct row_data * row, struct tm new_time);
void (*set_seconds) (struct row_data * row, long new_seconds);
void (*set_str) (struct row_data * row, char * new_str);
void (*set_times) (struct row_data * row, struct tm * new_time);
} set_func;
};
/* Datebook value data
* (contains values to/of datebook data fields,
* used in expressions)
*/
struct value_data {
enum DATEBOOK_FIELD_TYPE type;
union {
/* Literal */
unsigned long lit_long;
int lit_int;
struct tm lit_time;
long lit_seconds;
char * lit_str;
struct tm * lit_times;
} literal;
};
/* Datebook expression data
* (contains values to/of datebook data fields,
* used in assignments)
*/
struct expr_data {
char * name;
int isField;
union {
/* Constant value */
struct value_data constant;
/* Field */
struct field_data field;
} content;
};
/* Datebook assignment data
* (contains generic details on how to assign values to datebook data fields,
* used for update)
*/
struct assign_data {
char * name;
struct field_data left;
enum DATEBOOK_ASSIGN_TYPE op;
enum DATEBOOK_FIELD_TYPE expr_type;
struct expr_data right;
};
/* Datebook condition data
* (contains generic details on how to compare datebook data fields,
* used for if)
*/
struct cond_data {
char * name;
struct field_data left;
enum DATEBOOK_COND_TYPE op;
enum DATEBOOK_FIELD_TYPE expr_type;
struct expr_data right;
};
/* Functions */
/* From parsedate.c */
extern time_t parsedate(char * p);
/* public */
enum DATA_FORMAT txt2dataformat (char * txt);
const char * dataformat2txt (enum DATA_FORMAT format);
const char * int2weekday (int weekday_num);
int weekday2int (char * weekday_str);
const char * int2month (int month_num);
int month2int (char * month_str);
/* Helper functions */
void write_dump (FILE * out_file, void *buf, int n);
void write_human_date_str (time_t t, char * buffer, int buffer_size);
void write_human_time_str (time_t t, char * buffer, int buffer_size);
void write_human_gmtime_str (time_t t, char * buffer, int buffer_size);
void write_human_full_time_str (time_t t, char * buffer, int buffer_size);
void write_iso_date_str (time_t t, char * buffer, int buffer_size);
void write_iso_time_str (time_t t, char * buffer, int buffer_size);
void write_iso_gmtime_str (time_t t, char * buffer, int buffer_size);
void write_iso_full_time_str (time_t t, char * buffer, int buffer_size);
time_t read_iso_date_str1 (char * date_buffer);
time_t read_iso_time_str4n (int num_read, char * buffer1, char * buffer2, char * buffer3, char * buffer4);
time_t read_iso_time_str2 (char * date_buffer, char * time_buffer);
time_t read_iso_time_str1 (char * date_buffer);
/* String handling */
char * data_index(const char * search_string, char search_char);
char * data_rindex(const char * search_string, char search_char);
int data_stricmp(const char * pos1, const char * pos2);
int data_strincmp(const char * pos1, const char * pos2, int max_len);
void text_quote(const char * in_start, char * out_start, int max_len);
void text_unquote(const char * in_start, char * out_start, int max_len);
/* Error handling */
void error_message(char * format, ...);
void warn_message(char * format, ...);
void info_message(char * format, ...);
void debug_message(char * format, ...);
enum MESSAGE_VERBOSE_LEVEL get_message_verbose (void);
void set_message_verbose (enum MESSAGE_VERBOSE_LEVEL verbose_level);
/* Find delimiter location */
char * data_find_delimiter (const char * pos1, char delimiter);
/* Value handling */
void value_init (struct value_data * value, const char * value_start, const char * value_end);
void value_exit (struct value_data * value);
/* Field handling */
void field_init (struct field_data * field, const char * field_start, const char * field_end);
void field_exit (struct field_data * field);
int field_cmp_rows (struct field_data * field, struct row_data * row1, struct row_data * row2);
struct value_data row_get_field (struct row_data * row, struct field_data * field);
void row_set_field (struct row_data * row, struct field_data * field, struct value_data * value);
/* Expression handling */
void expr_init (struct expr_data * expr, enum DATEBOOK_FIELD_TYPE expect_type, const char * expr_start, const char * expr_end);
void expr_exit (struct expr_data * expr);
struct value_data expr_row (struct expr_data * expr, struct row_data * row);
/* Assignment handling */
void assign_init (struct assign_data * assign, const char * assign_start, const char * assign_end);
void assign_exit (struct assign_data * assign);
void assign_row (struct assign_data * assign, struct row_data * row);
/* Condition handling */
void cond_init (struct cond_data * cond, const char * cond_start, const char * cond_end);
void cond_exit (struct cond_data * cond);
int cond_row (struct cond_data * cond, struct row_data * row);
/* Getters */
/* General data */
int getRowIsValid(struct row_data * row);
enum DATEBOOK_SELECT_TYPE getRowIsSelected(struct row_data * row);
int getRowRecordNum(struct row_data * row);
unsigned long getRowUid(struct row_data * row);
int getRowAttributes(struct row_data * row);
int getRowCategory(struct row_data * row);
/* Datebook specific data */
struct Appointment getRowAppointment(struct row_data * row);
int getRowUntimed(struct row_data * row);
struct tm getRowBegin(struct row_data * row);
struct tm getRowBeginDate(struct row_data * row);
long getRowBeginTime(struct row_data * row);
struct tm getRowEnd(struct row_data * row);
struct tm getRowEndDate(struct row_data * row);
long getRowEndTime(struct row_data * row);
int getRowAlarm(struct row_data * row);
int getRowAdvance(struct row_data * row);
int getRowAdvanceUnit(struct row_data * row);
int getRowRepeatType(struct row_data * row);
int getRowRepeatForever(struct row_data * row);
struct tm getRowRepeatEnd(struct row_data * row);
struct tm getRowRepeatEndDate(struct row_data * row);
long getRowRepeatEndTime(struct row_data * row);
int getRowRepeatFrequency(struct row_data * row);
int getRowRepeatDay(struct row_data * row);
int getRowRepeatWeekdays(struct row_data * row);
int getRowRepeatWeekstart(struct row_data * row);
int getRowRepeatExceptionNum(struct row_data * row);
struct tm * getRowRepeatException(struct row_data * row);
char * getRowDescription(struct row_data * row);
char * getRowNote(struct row_data * row);
/* Transient calculation/scratch fields */
unsigned long getRowXLong(struct row_data * row);
unsigned long getRowYLong(struct row_data * row);
unsigned long getRowZLong(struct row_data * row);
int getRowXInt(struct row_data * row);
int getRowYInt(struct row_data * row);
int getRowZInt(struct row_data * row);
struct tm getRowXTime(struct row_data * row);
struct tm getRowYTime(struct row_data * row);
struct tm getRowZTime(struct row_data * row);
long getRowXSeconds(struct row_data * row);
long getRowYSeconds(struct row_data * row);
long getRowZSeconds(struct row_data * row);
char * getRowXStr(struct row_data * row);
char * getRowYStr(struct row_data * row);
char * getRowZStr(struct row_data * row);
/* Setters */
/* General data */
void rowInit(struct row_data * row);
void rowExit(struct row_data * row);
void setRowIsValid(struct row_data * row, int isValid);
void setRowIsSelected(struct row_data * row, enum DATEBOOK_SELECT_TYPE isSelected);
void setRowRecordNum(struct row_data * row, int record_num);
void setRowUid(struct row_data * row, unsigned long uid);
void setRowAttributes(struct row_data * row, int attributes);
void setRowCategory(struct row_data * row, int category);
/* Datebook specific data */
void setRowAppointment(struct row_data * row, struct Appointment appointment);
void setRowUntimed(struct row_data * row, int untimed);
void setRowBegin(struct row_data * row, struct tm begin);
void setRowBeginDate(struct row_data * row, struct tm begin);
void setRowBeginTime(struct row_data * row, long begin);
void setRowEnd(struct row_data * row, struct tm end);
void setRowEndDate(struct row_data * row, struct tm end);
void setRowEndTime(struct row_data * row, long end);
void setRowAlarm(struct row_data * row, int alarm);
void setRowAdvance(struct row_data * row, int advance);
void setRowAdvanceUnit(struct row_data * row, int advanceUnit);
void setRowRepeatType(struct row_data * row, int repeatType);
void setRowRepeatForever(struct row_data * row, int repeatForever);
void setRowRepeatEnd(struct row_data * row, struct tm repeatEnd);
void setRowRepeatEndDate(struct row_data * row, struct tm repeatEnd);
void setRowRepeatEndTime(struct row_data * row, long repeatEnd);
void setRowRepeatFrequency(struct row_data * row, int repeatFrequency);
void setRowRepeatDay(struct row_data * row, int repeatDay);
void setRowRepeatWeekdays(struct row_data * row, int repeatWeekdays);
void setRowRepeatWeekstart(struct row_data * row, int repeatWeekstart);
void setRowRepeatExceptionNum(struct row_data * row, int exceptionNum);
void setRowRepeatException(struct row_data * row, struct tm * exception);
void setRowDescription(struct row_data * row, char * description);
void setRowNote(struct row_data * row, char * note);
/* Transient calculation/scratch fields */
void setRowXLong(struct row_data * row, unsigned long xLong);
void setRowYLong(struct row_data * row, unsigned long yLong);
void setRowZLong(struct row_data * row, unsigned long zLong);
void setRowXInt(struct row_data * row, int xInt);
void setRowYInt(struct row_data * row, int yInt);
void setRowZInt(struct row_data * row, int zInt);
void setRowXTime(struct row_data * row, struct tm xTime);
void setRowYTime(struct row_data * row, struct tm yTime);
void setRowZTime(struct row_data * row, struct tm zTime);
void setRowXSeconds(struct row_data * row, long xSeconds);
void setRowYSeconds(struct row_data * row, long ySeconds);
void setRowZSeconds(struct row_data * row, long zSeconds);
void setRowXStr(struct row_data * row, char * xStr);
void setRowYStr(struct row_data * row, char * xStr);
void setRowZStr(struct row_data * row, char * xStr);
#endif