diff options
author | Petr Machata <pmachata@redhat.com> | 2012-01-06 17:48:29 +0100 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-08-29 19:02:06 +0200 |
commit | eff655b78f3f5d9119faa93461787192cf57dab0 (patch) | |
tree | e169ef2e9d83a16642d76854c7f77896bbe930f5 /read_config_file.c | |
parent | f6ec08afb96292fd3c802c1f633d8de249664c72 (diff) | |
download | ltrace-eff655b78f3f5d9119faa93461787192cf57dab0.tar.gz |
Add parse_char
Diffstat (limited to 'read_config_file.c')
-rw-r--r-- | read_config_file.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/read_config_file.c b/read_config_file.c index a4d67a5..b7110fb 100644 --- a/read_config_file.c +++ b/read_config_file.c @@ -224,6 +224,19 @@ check_int(long l) return 0; } +static int +parse_char(char **str, char expected) +{ + if (**str != expected) { + report_error(filename, line_no, + "expected '%c', got '%c'", expected, **str); + return -1; + } + + ++*str; + return 0; +} + /* * Input: * argN : The value of argument #N, counting from 1 @@ -336,14 +349,8 @@ parse_typedef(char **str) { // Skip = sign eat_spaces(str); - if (**str != '=') { - output_line(0, - "Syntax error in `%s', line %d: expected '=', got '%c'", - filename, line_no, **str); - error_count++; + if (parse_char(str, '=') < 0) return; - } - (*str)++; eat_spaces(str); // Parse the type @@ -362,9 +369,8 @@ static int parse_struct(char **str, struct arg_type_info *info) { eat_spaces(str); - if (**str != '(') + if (parse_char(str, '(') < 0) return -1; - ++*str; eat_spaces(str); // Empty arg list with whitespace inside @@ -373,13 +379,13 @@ parse_struct(char **str, struct arg_type_info *info) while (1) { eat_spaces(str); if (**str == 0 || **str == ')') { - ++*str; + parse_char(str, ')'); return 0; } /* Field delimiter. */ if (type_struct_size(info) > 0) - ++*str; + parse_char(str, ','); eat_spaces(str); int own = 0; |