aboutsummaryrefslogtreecommitdiff
path: root/parse.h
blob: ae48a351ebf7f79b0b489169a13c249fb0753379 (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
#ifndef PARSE_H
#define PARSE_H

#include <stdio.h>
#include <stdlib.h>

#include "strbuf.h"
#include "vcal.h"

#define TYPE vcomponent
#include "linked_list.h"
#undef TYPE

/*
 * 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

typedef enum {
	p_key, p_value, p_param_name, p_param_value, p_escape
} part_context;

/*
 * Struct holding most state information needed while parsing.
 * Kept together for simplicity.
 */
typedef struct {
	char* filename;
	LLIST(strbuf) key_stack;
	LLIST(vcomponent) comp_stack;

	/* Number for unfolded lines */
	int line;
	int column;

	/* Actuall lines and columns from file */
	int pline;
	int pcolumn;

	strbuf str;
} parse_ctx;

INIT_F(parse_ctx, char* filename);
FREE_F(parse_ctx);

int handle_kv(
		content_line*  cline,
		parse_ctx*     ctx
		);

int parse_file(char* filename, FILE* f, vcomponent* cal);

#endif /* PARSE_H */