blob: 03858a15049e8c3a5422db311d4167ce97901be9 (
plain)
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
|
#ifndef PARSE_H
#define PARSE_H
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <stack>
#include "strbuf.h"
#include "vcal.h"
/*
* The standard says that no line should be longer than 75 octets.
* This sets the default amount of memory to allocate for each string,
* but strings are reallocated when needed.
*/
#define SEGSIZE 75
enum part_context {
p_key, p_value, p_param_name, p_param_value, p_escape
};
/*
* Struct holding most state information needed while parsing.
* Kept together for simplicity.
*/
struct parse_ctx {
std::string filename;
std::stack<strbuf*> key_stack;
std::stack<vcomponent*> comp_stack;
/* Number for unfolded lines */
int line = 0;
int column = 0;
/* Actuall lines and columns from file */
int pline = 1;
int pcolumn = 1;
strbuf str;
parse_ctx (const std::string& filename)
: filename(filename) { }
};
int handle_kv(
content_line* cline,
parse_ctx* ctx
);
int parse_file(char* filename, FILE* f, vcomponent* cal);
/*
* Input
* f: file to get characters from
* ctx: current parse context
* c: last read character
* output:
* 0: line folded
* 1: line ended
*
* A carrige return means that the current line is at an
* end. The following character should always be \n.
* However, if the first character on the next line is a
* whitespace then the two lines should be concatenated.
*
* NOTE
* The above is true according to the standard. But I have
* found files with only NL. The code below ends line on the
* first of NL or CR, and then ensures that the program thinks
* it got the expected CRNL.
*/
int fold(FILE* f, parse_ctx* ctx, char c);
#endif /* PARSE_H */
|