1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Improve error handling string.

This commit is contained in:
Dave Davenport 2017-01-09 22:40:11 +01:00
parent ca01af6338
commit 25dff63006
8 changed files with 49 additions and 47 deletions

View file

@ -48,16 +48,16 @@ typedef struct
*/ */
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1, TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16, TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17, TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18, TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19, TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21, TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22, TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23, TB_INDICATOR = 1 << 23,
} TextboxFlags; } TextboxFlags;
/** /**
* Flags indicating current state of the textbox. * Flags indicating current state of the textbox.

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time. // Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line. // Evaluate one line.
unsigned int index = 0, ti = 0; unsigned int index = 0, ti = 0;
char *token = buffer; char *token = buffer;
// Tokenize it. // Tokenize it.

View file

@ -248,7 +248,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
} }
char *saveptr = NULL, *token; char *saveptr = NULL, *token;
GRegex **retv = NULL; GRegex **retv = NULL;
if ( !config.tokenize ) { if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive ); retv[0] = (GRegex *) create_regex ( input, case_sensitive );

View file

@ -70,9 +70,9 @@
char *pidfile = NULL; char *pidfile = NULL;
const char *cache_dir = NULL; const char *cache_dir = NULL;
/** List of error messages.*/
GList *list_of_error_msgs = NULL; GList *list_of_error_msgs = NULL;
void rofi_add_error_message ( GString *str ) void rofi_add_error_message ( GString *str )
{ {
list_of_error_msgs = g_list_append ( list_of_error_msgs, str ); list_of_error_msgs = g_list_append ( list_of_error_msgs, str );
@ -376,11 +376,10 @@ static void cleanup ()
g_free ( config_path ); g_free ( config_path );
if ( list_of_error_msgs ) { if ( list_of_error_msgs ) {
for ( GList *iter = g_list_first ( list_of_error_msgs ); for ( GList *iter = g_list_first ( list_of_error_msgs );
iter != NULL; iter = g_list_next ( iter ) ){ iter != NULL; iter = g_list_next ( iter ) ) {
g_string_free ( (GString*)iter->data, TRUE); g_string_free ( (GString *) iter->data, TRUE );
} }
g_list_free ( list_of_error_msgs ); g_list_free ( list_of_error_msgs );
} }
@ -412,7 +411,7 @@ static int add_mode ( const char * token )
} }
else else
#endif // WINDOW_MODE #endif // WINDOW_MODE
// SSh dialog // SSh dialog
if ( strcasecmp ( token, "ssh" ) == 0 ) { if ( strcasecmp ( token, "ssh" ) == 0 ) {
modi[num_modi] = &ssh_mode; modi[num_modi] = &ssh_mode;
num_modi++; num_modi++;
@ -678,17 +677,18 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
config_sanity_check ( ); config_sanity_check ( );
TICK_N ( "Config sanity check" ); TICK_N ( "Config sanity check" );
if ( list_of_error_msgs != NULL ) { if ( list_of_error_msgs != NULL ) {
GString *emesg = g_string_new ( "The following errors where detected when starting rofi:\n"); GString *emesg = g_string_new ( "The following errors where detected when starting rofi:\n" );
GList *iter = g_list_first ( list_of_error_msgs ); GList *iter = g_list_first ( list_of_error_msgs );
if ( iter != NULL ) { int index = 0;
GString *msg = (GString*)(iter->data); for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
g_string_append( emesg, "\n\n"); GString *msg = (GString *) ( iter->data );
g_string_append ( emesg, "\n\n" );
g_string_append ( emesg, msg->str ); g_string_append ( emesg, msg->str );
index++;
} }
if ( g_list_length(iter)> 1 ){ if ( g_list_length ( iter ) > 1 ) {
g_string_append_printf(emesg, "\nThere are <b>%d</b> more errors.", g_list_length(iter)-1 ); g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
} }
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
g_string_free ( emesg, TRUE ); g_string_free ( emesg, TRUE );
@ -979,9 +979,8 @@ int main ( int argc, char *argv[] )
if ( config.theme ) { if ( config.theme ) {
TICK_N ( "Parse theme" ); TICK_N ( "Parse theme" );
if ( ! rofi_theme_parse_file ( config.theme ) ) { if ( !rofi_theme_parse_file ( config.theme ) ) {
// TODO: instantiate fallback theme.? // TODO: instantiate fallback theme.?
} }
TICK_N ( "Parsed theme" ); TICK_N ( "Parsed theme" );
} }

View file

@ -12,7 +12,7 @@
/** Logging domain for theme */ /** Logging domain for theme */
#define LOG_DOMAIN "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 ) static gboolean distance_compare ( Distance d, Distance e )
{ {
return d.type == e.type && d.distance == e.distance && d.style == e.style; 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 yylloc The file location.
* @param what What we are parsing, filename or string.
* @param s Error message string. * @param s Error message string.
* *
* Error handler for the lex parser. * Error handler for the lex parser.
*/ */
void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) void yyerror ( YYLTYPE *yylloc, const char *what, const char* s )
{ {
char *what_esc = g_markup_escape_text ( what, -1); char *what_esc = g_markup_escape_text ( what, -1 );
GString *str = g_string_new(""); GString *str = g_string_new ( "" );
g_string_printf ( str, "<big><b>Error while parsing them:</b></big> <i>%s</i>\n", what_esc); g_string_printf ( str, "<big><b>Error while parsing them:</b></big> <i>%s</i>\n", what_esc );
g_free ( what_esc ); g_free ( what_esc );
char *esc = g_markup_escape_text ( s, -1); char *esc = g_markup_escape_text ( s, -1 );
g_string_append_printf(str, "\tParser error: <i>%s</i>\n", esc ); g_string_append_printf ( str, "\tParser error: <i>%s</i>\n", esc );
g_free(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 ); 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 ); rofi_add_error_message ( str );
} }
@ -867,11 +868,11 @@ gboolean rofi_theme_parse_file ( const char *file )
extern const char*input_str; extern const char*input_str;
str_len = 0; str_len = 0;
input_str = NULL; input_str = NULL;
int parser_retv = yyparse(file); int parser_retv = yyparse ( file );
yylex_destroy (); yylex_destroy ();
g_free ( filename ); g_free ( filename );
yyin = NULL; yyin = NULL;
if ( parser_retv != 0 ){ if ( parser_retv != 0 ) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -883,10 +884,11 @@ gboolean rofi_theme_parse_string ( const char *string )
yyin = NULL; yyin = NULL;
input_str = string; input_str = string;
str_len = strlen ( string ); str_len = strlen ( string );
while ( yyparse (string) ) { int parser_retv = yyparse ( string );
;
}
yylex_destroy (); yylex_destroy ();
return TRUE; if ( parser_retv != 0 ) {
return TRUE;
}
return FALSE;
} }
#endif #endif

View file

@ -31,7 +31,7 @@
#include "widgets/container.h" #include "widgets/container.h"
#include "theme.h" #include "theme.h"
#define LOG_DOMAIN "Widgets.Window" #define LOG_DOMAIN "Widgets.Window"
struct _window struct _window
{ {

View file

@ -532,12 +532,12 @@ void listview_nav_page_next ( listview *lv )
static int listview_get_desired_height ( widget *wid ) static int listview_get_desired_height ( widget *wid )
{ {
listview *lv = (listview *) wid; listview *lv = (listview *) wid;
if ( lv == NULL || lv->widget.enabled == FALSE ) { if ( lv == NULL || lv->widget.enabled == FALSE ) {
return 0; return 0;
} }
int spacing = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); 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->fixed_num_lines ) ) {
if ( lv->dynamic ) { if ( lv->dynamic ) {
h = MIN ( lv->menu_lines, lv->req_elements ); h = MIN ( lv->menu_lines, lv->req_elements );

View file

@ -3,7 +3,8 @@
#include "widgets/widget-internal.h" #include "widgets/widget-internal.h"
#include "theme.h" #include "theme.h"
#define WIDGET_DEFAULT_PADDING 2 /** Default padding. */
#define WIDGET_DEFAULT_PADDING 2
void widget_init ( widget *widget, const char *name ) 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 widget->h - margin_top - margin_bottom
); );
cairo_clip ( d ); 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 ); rofi_theme_get_color ( widget, "background", d );
cairo_paint ( d ); cairo_paint ( d );
// Set new x/y possition. // Set new x/y possition.
cairo_translate ( d, widget->x, widget->y ); 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 left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL );
int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL ); int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );