config_parse.h 1.57 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8
#ifndef INCLUDE_config_parse_h__
#define INCLUDE_config_parse_h__
9 10

#include "common.h"
11

12
#include "array.h"
13
#include "fileops.h"
14
#include "oid.h"
15
#include "parse.h"
16

17 18
extern const char *git_config_escapes;
extern const char *git_config_escaped;
19 20

typedef struct {
21
	const char *path;
22
	git_parse_ctx ctx;
23 24
} git_config_parser;

25 26
#define GIT_CONFIG_PARSER_INIT { NULL, GIT_PARSE_CTX_INIT }

27 28 29 30 31
typedef int (*git_config_parser_section_cb)(
	git_config_parser *parser,
	const char *current_section,
	const char *line,
	size_t line_len,
32
	void *payload);
33 34 35 36

typedef int (*git_config_parser_variable_cb)(
	git_config_parser *parser,
	const char *current_section,
37 38
	const char *var_name,
	const char *var_value,
39 40
	const char *line,
	size_t line_len,
41
	void *payload);
42 43 44 45 46

typedef int (*git_config_parser_comment_cb)(
	git_config_parser *parser,
	const char *line,
	size_t line_len,
47
	void *payload);
48 49 50 51

typedef int (*git_config_parser_eof_cb)(
	git_config_parser *parser,
	const char *current_section,
52
	void *payload);
53

54 55 56
int git_config_parser_init(git_config_parser *out, const char *path, const char *data, size_t datalen);
void git_config_parser_dispose(git_config_parser *parser);

57 58 59 60 61 62
int git_config_parse(
	git_config_parser *parser,
	git_config_parser_section_cb on_section,
	git_config_parser_variable_cb on_variable,
	git_config_parser_comment_cb on_comment,
	git_config_parser_eof_cb on_eof,
63
	void *payload);
64 65

#endif