From 25dff63006663c947c17c4edbb85c6a12fcca799 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 9 Jan 2017 22:40:11 +0100 Subject: [PATCH] Improve error handling string. --- include/widgets/textbox.h | 20 ++++++++++---------- source/dialogs/ssh.c | 2 +- source/helper.c | 2 +- source/rofi.c | 29 ++++++++++++++--------------- source/theme.c | 30 ++++++++++++++++-------------- source/widgets/container.c | 2 +- source/widgets/listview.c | 4 ++-- source/widgets/widget.c | 7 ++++--- 8 files changed, 49 insertions(+), 47 deletions(-) diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index f8469ead..d81d8806 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -48,16 +48,16 @@ typedef struct */ typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, - TB_INDICATOR = 1 << 23, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, + TB_INDICATOR = 1 << 23, } TextboxFlags; /** * Flags indicating current state of the textbox. diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index c0ba2f8c..8cfe68fd 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Evaluate one line. - unsigned int index = 0, ti = 0; + unsigned int index = 0, ti = 0; char *token = buffer; // Tokenize it. diff --git a/source/helper.c b/source/helper.c index cb30a22d..c7d417db 100644 --- a/source/helper.c +++ b/source/helper.c @@ -248,7 +248,7 @@ GRegex **tokenize ( const char *input, int case_sensitive ) } char *saveptr = NULL, *token; - GRegex **retv = NULL; + GRegex **retv = NULL; if ( !config.tokenize ) { retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv[0] = (GRegex *) create_regex ( input, case_sensitive ); diff --git a/source/rofi.c b/source/rofi.c index b64d5017..70319540 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -70,9 +70,9 @@ char *pidfile = NULL; const char *cache_dir = NULL; +/** List of error messages.*/ GList *list_of_error_msgs = NULL; - void rofi_add_error_message ( GString *str ) { list_of_error_msgs = g_list_append ( list_of_error_msgs, str ); @@ -376,11 +376,10 @@ static void cleanup () g_free ( config_path ); - if ( list_of_error_msgs ) { for ( GList *iter = g_list_first ( list_of_error_msgs ); - iter != NULL; iter = g_list_next ( iter ) ){ - g_string_free ( (GString*)iter->data, TRUE); + iter != NULL; iter = g_list_next ( iter ) ) { + g_string_free ( (GString *) iter->data, TRUE ); } g_list_free ( list_of_error_msgs ); } @@ -412,7 +411,7 @@ static int add_mode ( const char * token ) } else #endif // WINDOW_MODE - // SSh dialog + // SSh dialog if ( strcasecmp ( token, "ssh" ) == 0 ) { modi[num_modi] = &ssh_mode; num_modi++; @@ -678,17 +677,18 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) config_sanity_check ( ); TICK_N ( "Config sanity check" ); - if ( list_of_error_msgs != NULL ) { - GString *emesg = g_string_new ( "The following errors where detected when starting rofi:\n"); - GList *iter = g_list_first ( list_of_error_msgs ); - if ( iter != NULL ) { - GString *msg = (GString*)(iter->data); - g_string_append( emesg, "\n\n"); + GString *emesg = g_string_new ( "The following errors where detected when starting rofi:\n" ); + GList *iter = g_list_first ( list_of_error_msgs ); + int index = 0; + for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) { + GString *msg = (GString *) ( iter->data ); + g_string_append ( emesg, "\n\n" ); g_string_append ( emesg, msg->str ); + index++; } - if ( g_list_length(iter)> 1 ){ - g_string_append_printf(emesg, "\nThere are %d more errors.", g_list_length(iter)-1 ); + 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 ); @@ -979,9 +979,8 @@ int main ( int argc, char *argv[] ) if ( config.theme ) { TICK_N ( "Parse theme" ); - if ( ! rofi_theme_parse_file ( config.theme ) ) { + if ( !rofi_theme_parse_file ( config.theme ) ) { // TODO: instantiate fallback theme.? - } TICK_N ( "Parsed theme" ); } diff --git a/source/theme.c b/source/theme.c index 6979b07d..01196ca2 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 *,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; @@ -257,20 +257,21 @@ extern FILE* yyin; /** * @param yylloc The file location. + * @param what What we are parsing, filename or string. * @param s Error message string. * * Error handler for the lex parser. */ void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) { - 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); + 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_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 ); + char *esc = g_markup_escape_text ( s, -1 ); + 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 ); } @@ -867,11 +868,11 @@ gboolean rofi_theme_parse_file ( const char *file ) extern const char*input_str; str_len = 0; input_str = NULL; - int parser_retv = yyparse(file); + int parser_retv = yyparse ( file ); yylex_destroy (); g_free ( filename ); yyin = NULL; - if ( parser_retv != 0 ){ + if ( parser_retv != 0 ) { return TRUE; } return FALSE; @@ -883,10 +884,11 @@ gboolean rofi_theme_parse_string ( const char *string ) yyin = NULL; input_str = string; str_len = strlen ( string ); - while ( yyparse (string) ) { - ; - } + int parser_retv = yyparse ( string ); yylex_destroy (); - return TRUE; + if ( parser_retv != 0 ) { + return TRUE; + } + return FALSE; } #endif diff --git a/source/widgets/container.c b/source/widgets/container.c index d2fd6327..e820bcee 100644 --- a/source/widgets/container.c +++ b/source/widgets/container.c @@ -31,7 +31,7 @@ #include "widgets/container.h" #include "theme.h" -#define LOG_DOMAIN "Widgets.Window" +#define LOG_DOMAIN "Widgets.Window" struct _window { diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 96b8619e..7f657495 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -532,12 +532,12 @@ void listview_nav_page_next ( listview *lv ) static int listview_get_desired_height ( widget *wid ) { - listview *lv = (listview *) wid; + listview *lv = (listview *) wid; if ( lv == NULL || lv->widget.enabled == FALSE ) { return 0; } int spacing = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); - int h = lv->menu_lines; + int h = lv->menu_lines; if ( !( lv->fixed_num_lines ) ) { if ( lv->dynamic ) { h = MIN ( lv->menu_lines, lv->req_elements ); diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 03f21e4f..14235a28 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -3,7 +3,8 @@ #include "widgets/widget-internal.h" #include "theme.h" -#define WIDGET_DEFAULT_PADDING 2 +/** Default padding. */ +#define WIDGET_DEFAULT_PADDING 2 void widget_init ( widget *widget, const char *name ) { @@ -113,13 +114,13 @@ void widget_draw ( widget *widget, cairo_t *d ) widget->h - margin_top - margin_bottom ); cairo_clip ( d ); - cairo_set_source_rgba ( d, 1.0,1.0,1.0, 1.0 ); + cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 ); rofi_theme_get_color ( widget, "background", d ); cairo_paint ( d ); // Set new x/y possition. cairo_translate ( d, widget->x, widget->y ); - cairo_set_source_rgba ( d, 0.0,0.0,0.0, 1.0 ); + cairo_set_source_rgba ( d, 0.0, 0.0, 0.0, 1.0 ); int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL ); int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );