From 6de2da7f73135fcff28d33845e3b73f293125f60 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 1 Aug 2022 11:22:59 -0300 Subject: git, keyword: Move `parse_key_value_file()` to `keyword.{c,h}` --- git.c | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) (limited to 'git.c') diff --git a/git.c b/git.c index 2a09841..931ba09 100644 --- a/git.c +++ b/git.c @@ -280,55 +280,6 @@ int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val va return 1; } -int parse_key_value_file(void *ret, void *ctx, const keyword **keywords, char *buf, const char *delm, parse_callback *parse_cb) { - if (buf != NULL) { - int ret_val = 0; - for (;;) { - char *lhs, *rhs; - /* Find the keyword before the delimiter(s). */ - lhs = strtok_r(skip_whitespace(buf), delm, &buf); - /* Remove any whitespace ahead of us. */ - lhs = strtok_r(lhs, " \t\v\r\n", &rhs); - - /* Did we hit EOF? */ - if (is_empty(lhs) || is_empty(buf)) { - break; - } else { - int error; - char *tmp = skip_whitespace(buf); - - /* Does the right hand side start with a double, or single quote? */ - if (*tmp == '\"' || *tmp == '\'') { - const char *delm = (*delm == '\"') ? "\"" : "\'"; - /* Get the string in between the start, and end qoute. */ - rhs = get_str_delm_range(tmp, delm, delm, &buf); - } else { - /* Get the rest of the line. */ - rhs = strtok_r(tmp, "\n", &buf); - } - - /* Did we fail to parse the keyword? */ - if (error = parse_keywords(keywords, lhs, rhs, ret, ctx)) { - log(LOG_WARNING, "Failed to parse keyword \"%s\". Error code: %i", lhs, error); - ret_val = error; - } - } - - /* Do we have a parse callback? */ - if (parse_cb != NULL) { - /* Did the callback return an error. */ - if (parse_cb(&ret, ctx, buf) < 0) { - ret_val = 7; - break; - } - } - } - return ret_val; - } else { - return 8; - } -} - static int is_end_of_comment(void **ret, void *ctx, char *buf) { /* Do we have at least one blank line? */ if (strspn(buf, "\n") >= 1) { -- cgit v1.2.3-13-gbd6f