From ca01af6338382c75f31555160f40aa5385be6521 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 9 Jan 2017 22:29:31 +0100 Subject: [PATCH] Try to improve error handling and messages --- lexer/theme-lexer.l | 13 ++++++++++++- lexer/theme-parser.y | 17 ++++++++++------- source/rofi.c | 6 +++++- source/theme.c | 15 +++++++++------ source/widgets/container.c | 3 --- source/widgets/widget.c | 4 +++- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 117cf6f1..f920b891 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -4,7 +4,6 @@ %{ #include - #include "lexer/theme-parser.h" int last_state = 0; GQueue *queue = NULL; @@ -341,6 +340,18 @@ if ( queue == NULL ){ . { return T_ERROR; } +. { + return T_ERROR_ENTRY; +} +. { + return T_ERROR_PROPERTY; +} +. { + return T_ERROR_NAMESTRING; +} +. { + return T_ERROR_DEFAULTS; +} <*>. { return T_ERROR; } diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index fa1d8e94..61c4553e 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -1,10 +1,10 @@ %define api.pure +%locations %glr-parser %skeleton "glr.c" -%locations %debug %error-verbose - +%parse-param {const char *what} %code requires { #include "theme.h" } @@ -13,10 +13,9 @@ #include #include - #include "lexer/theme-parser.h" ThemeWidget *rofi_theme = NULL; -void yyerror(YYLTYPE *yylloc, const char* s); +void yyerror(YYLTYPE *yylloc, const char *what, const char* s); int yylex (YYSTYPE *, YYLTYPE *); %} @@ -33,12 +32,16 @@ int yylex (YYSTYPE *, YYLTYPE *); Distance distance; } -%token T_END 0 "end of file" -%token T_ERROR 1 "error from file parser" +%token T_END 0 "end of file" +%token T_ERROR 1 "error from file parser" +%token T_ERROR_PROPERTY 2 "invalid property value" +%token T_ERROR_ENTRY 3 "invalid property name" +%token T_ERROR_NAMESTRING 4 "invalid element name" +%token T_ERROR_DEFAULTS 5 "invalid defaults name" %token T_INT %token T_DOUBLE %token T_STRING -%token N_STRING +%token N_STRING "property name" %token T_POSITION; %token T_HIGHLIGHT_STYLE %token NAME_ELEMENT "Element name" diff --git a/source/rofi.c b/source/rofi.c index 12b639c6..b64d5017 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -681,11 +681,15 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) if ( list_of_error_msgs != NULL ) { GString *emesg = g_string_new ( "The following errors where detected when starting rofi:\n"); - for ( GList *iter = g_list_first ( list_of_error_msgs ); iter != NULL; iter = g_list_next ( iter ) ) { + GList *iter = g_list_first ( list_of_error_msgs ); + if ( iter != NULL ) { GString *msg = (GString*)(iter->data); g_string_append( emesg, "\n\n"); g_string_append ( emesg, msg->str ); } + if ( g_list_length(iter)> 1 ){ + g_string_append_printf(emesg, "\nThere are %d more errors.", g_list_length(iter)-1 ); + } rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); g_string_free ( emesg, TRUE ); return G_SOURCE_REMOVE; diff --git a/source/theme.c b/source/theme.c index 65810073..6979b07d 100644 --- a/source/theme.c +++ b/source/theme.c @@ -12,7 +12,7 @@ /** Logging domain for theme */ #define LOG_DOMAIN "Theme" -void yyerror ( YYLTYPE *ylloc, const char * ); +void yyerror ( YYLTYPE *ylloc, const char *,const char * ); static gboolean distance_compare ( Distance d, Distance e ) { return d.type == e.type && d.distance == e.distance && d.style == e.style; @@ -261,11 +261,14 @@ extern FILE* yyin; * * Error handler for the lex parser. */ -void yyerror ( YYLTYPE *yylloc, const char* s ) +void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) { - GString *str = g_string_new ("Error while parsing theme file:\n"); + char *what_esc = g_markup_escape_text ( what, -1); + GString *str = g_string_new(""); + g_string_printf ( str, "Error while parsing them: %s\n", what_esc); + g_free ( what_esc ); char *esc = g_markup_escape_text ( s, -1); - g_string_append_printf(str, "\tParser error: %s\n", esc ); + g_string_append_printf(str, "\tParser error: %s\n", esc ); g_free(esc); g_string_append_printf(str, "\tLocation: line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column ); rofi_add_error_message ( str ); @@ -864,7 +867,7 @@ gboolean rofi_theme_parse_file ( const char *file ) extern const char*input_str; str_len = 0; input_str = NULL; - int parser_retv = yyparse(); + int parser_retv = yyparse(file); yylex_destroy (); g_free ( filename ); yyin = NULL; @@ -880,7 +883,7 @@ gboolean rofi_theme_parse_string ( const char *string ) yyin = NULL; input_str = string; str_len = strlen ( string ); - while ( yyparse () ) { + while ( yyparse (string) ) { ; } yylex_destroy (); diff --git a/source/widgets/container.c b/source/widgets/container.c index 51150287..d2fd6327 100644 --- a/source/widgets/container.c +++ b/source/widgets/container.c @@ -33,9 +33,6 @@ #define LOG_DOMAIN "Widgets.Window" -/** The default border width of the container */ -#define DEFAULT_BORDER_WIDTH 2 - struct _window { widget widget; diff --git a/source/widgets/widget.c b/source/widgets/widget.c index d17b3db9..03f21e4f 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -3,10 +3,12 @@ #include "widgets/widget-internal.h" #include "theme.h" +#define WIDGET_DEFAULT_PADDING 2 + void widget_init ( widget *widget, const char *name ) { widget->name = g_strdup ( name ); - widget->padding = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } }; + widget->padding = (Padding){ { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID } }; widget->border = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } }; widget->margin = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };