diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-09-26 15:45:58 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-09-26 15:45:58 +0800 |
commit | ffc167572a9d56c52908aebefe62ba3e3e2a9cf8 (patch) | |
tree | 9878d068dc4994dcad32c37ea6321f0995193ab2 /discover/grub2/parser.y | |
parent | 300859ca50c0ea5d9c17d27fd3e3538ce966e08a (diff) | |
download | talos-petitboot-ffc167572a9d56c52908aebefe62ba3e3e2a9cf8.tar.gz talos-petitboot-ffc167572a9d56c52908aebefe62ba3e3e2a9cf8.zip |
discover/grub2: Clean up error-handling for grub2 parser & lexer
Rather than printf() & exit(), use the pb logging functions and abort
the parse.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/grub2/parser.y')
-rw-r--r-- | discover/grub2/parser.y | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y index 02ca7b2..8ab17a6 100644 --- a/discover/grub2/parser.y +++ b/discover/grub2/parser.y @@ -6,17 +6,15 @@ %{ #include <talloc/talloc.h> +#include <log/log.h> #include "grub2.h" #include "parser.h" #include "lexer.h" -static void print_token(FILE *fp, int type, YYSTYPE value); - #define YYLEX_PARAM parser->scanner -#define YYPRINT(f, t, v) print_token(f, t, v) -static void yyerror(struct grub2_parser *, char const *s); +void yyerror(struct grub2_parser *parser, const char *fmt, ...); %} %union { @@ -148,18 +146,17 @@ word: TOKEN_WORD } %% -void yyerror(struct grub2_parser *parser, char const *s) +void yyerror(struct grub2_parser *parser, const char *fmt, ...) { - fprintf(stderr, "%d: error: %s '%s'\n", - yyget_lineno(parser->scanner), - s, yyget_text(parser->scanner)); -} + const char *str; + va_list ap; -static void print_token(FILE *fp, int type, YYSTYPE value) -{ - if (type != TOKEN_WORD) - return; - fprintf(fp, "%s", value.word->text); + va_start(ap, fmt); + str = talloc_vasprintf(parser, fmt, ap); + va_end(ap); + + pb_log("parse error: %d('%s'): %s\n", yyget_lineno(parser->scanner), + yyget_text(parser->scanner), str); } struct grub2_statements *create_statements(struct grub2_parser *parser) |