1 /* icalendar.h -- data structures and common code for icalendar scanner,
2  *                parser, and application code
3  *
4  * This code is Copyright (c) 2014, by the authors of nmh.  See the
5  * COPYRIGHT file in the root directory of the nmh distribution for
6  * complete copyright information.
7  */
8 
9 /*
10  * Types used in struct contentline below.
11  */
12 typedef struct value_list {
13     char *value;
14     struct value_list *next;
15 } value_list;
16 
17 typedef struct param_list {
18     char *param_name;          /* Name of property parameter. */
19     struct value_list *values; /* List of its values. */
20     struct param_list *next;   /* Next node in list of property parameters. */
21 } param_list;
22 
23 typedef enum cr_indicator {
24     CR_UNSET = 0,
25     LF_ONLY,
26     CR_BEFORE_LF
27 } cr_indicator;
28 
29 /*
30  * Each (unfolded) line in the .ics file is represented by a struct
31  * contentline.
32  */
33 typedef struct contentline {
34     char *name;                /* The name of the property, calprops,
35                                   or BEGIN. */
36     struct param_list *params; /* List parameters. */
37     char *value;               /* Everything after the ':'. */
38 
39     char *input_line;          /* The (unfolded) input line. */
40     size_t input_line_len;     /* Amount of text stored in input_line. */
41     size_t input_line_size;    /* Size of allocated input_line. */
42     charstring_t unexpected;   /* Accumulate unexpected characters in input. */
43 
44     cr_indicator cr_before_lf; /* To support CR before LF.  If the first
45                                   line of the input has a CR before its LF,
46                                   assume that all output lines need to.
47                                   Only used in root node. */
48 
49     struct contentline *next;  /* Next node in list of content lines. */
50     struct contentline *last;  /* Last node of list.  Only used in root node. */
51 } contentline;
52 
53 
54 /*
55  * List of vevents, each of which is a list of contentlines.
56  */
57 typedef struct vevent {
58     contentline *contentlines;
59     struct vevent *next;
60     /* The following is only used in the root node. */
61     struct vevent *last;
62 } vevent;
63 
64 
65 /*
66  * Exported functions.
67  */
68 void remove_contentline (contentline *);
69 contentline *add_contentline (contentline *, const char *);
70 void add_param_name (contentline *, char *);
71 void add_param_value (contentline *, char *);
72 void remove_value (value_list *);
73 struct contentline *find_contentline (contentline *, const char *,
74                                       const char *);
75 void free_contentlines (contentline *);
76 
77 typedef struct tzdesc *tzdesc_t;
78 tzdesc_t load_timezones (const contentline *);
79 void free_timezones (tzdesc_t);
80 char *format_datetime (tzdesc_t, const contentline *);
81 
82 /*
83  * The following provide access to, and by, the iCalendar parser.
84  */
85 
86 /* This YYSTYPE definition prevents problems with Solaris yacc, which
87    has declarations of two variables of type YYSTYPE * in one
88    statement. */
89 typedef char *charptr;
90 #define YYSTYPE charptr
91 
92 extern int icaldebug;
93 int icalparse (void);
94 extern vevent vevents;
95 int icallex (void);
96 extern int parser_status;
97 
98 /* And this is for the icalendar scanner. */
99 extern YYSTYPE icallval;
100 
101 /*
102  * For directing the scanner to use files other than stdin/stdout.
103  * These don't use the accessors provided by modern flex because
104  * flex 2.5.4 doesn't supply them.
105  */
106 void icalset_inputfile (FILE *);
107 void icalset_outputfile (FILE *);
108