1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 #ifndef INCLUDE_config_parse_h__
8 #define INCLUDE_config_parse_h__
9 
10 #include "common.h"
11 
12 #include "array.h"
13 #include "futils.h"
14 #include "oid.h"
15 #include "parse.h"
16 
17 extern const char *git_config_escapes;
18 extern const char *git_config_escaped;
19 
20 typedef struct {
21 	const char *path;
22 	git_parse_ctx ctx;
23 } git_config_parser;
24 
25 #define GIT_CONFIG_PARSER_INIT { NULL, GIT_PARSE_CTX_INIT }
26 
27 typedef int (*git_config_parser_section_cb)(
28 	git_config_parser *parser,
29 	const char *current_section,
30 	const char *line,
31 	size_t line_len,
32 	void *payload);
33 
34 typedef int (*git_config_parser_variable_cb)(
35 	git_config_parser *parser,
36 	const char *current_section,
37 	const char *var_name,
38 	const char *var_value,
39 	const char *line,
40 	size_t line_len,
41 	void *payload);
42 
43 typedef int (*git_config_parser_comment_cb)(
44 	git_config_parser *parser,
45 	const char *line,
46 	size_t line_len,
47 	void *payload);
48 
49 typedef int (*git_config_parser_eof_cb)(
50 	git_config_parser *parser,
51 	const char *current_section,
52 	void *payload);
53 
54 int git_config_parser_init(git_config_parser *out, const char *path, const char *data, size_t datalen);
55 void git_config_parser_dispose(git_config_parser *parser);
56 
57 int git_config_parse(
58 	git_config_parser *parser,
59 	git_config_parser_section_cb on_section,
60 	git_config_parser_variable_cb on_variable,
61 	git_config_parser_comment_cb on_comment,
62 	git_config_parser_eof_cb on_eof,
63 	void *payload);
64 
65 #endif
66