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

Try to improve error handling and messages

This commit is contained in:
Dave Davenport 2017-01-09 22:29:31 +01:00
parent b010da57d7
commit ca01af6338
6 changed files with 39 additions and 19 deletions

View file

@ -4,7 +4,6 @@
%{
#include <stdio.h>
#include "lexer/theme-parser.h"
int last_state = 0;
GQueue *queue = NULL;
@ -341,6 +340,18 @@ if ( queue == NULL ){
<INITIAL>. {
return T_ERROR;
}
<ENTRY>. {
return T_ERROR_ENTRY;
}
<PROPERTIES>. {
return T_ERROR_PROPERTY;
}
<NAMESTR>. {
return T_ERROR_NAMESTRING;
}
<DEFAULTS>. {
return T_ERROR_DEFAULTS;
}
<*>. {
return T_ERROR;
}

View file

@ -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 <stdlib.h>
#include <glib.h>
#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 <ival> T_END 0 "end of file"
%token <ival> T_ERROR 1 "error from file parser"
%token <ival> T_END 0 "end of file"
%token <ival> T_ERROR 1 "error from file parser"
%token <ival> T_ERROR_PROPERTY 2 "invalid property value"
%token <ival> T_ERROR_ENTRY 3 "invalid property name"
%token <ival> T_ERROR_NAMESTRING 4 "invalid element name"
%token <ival> T_ERROR_DEFAULTS 5 "invalid defaults name"
%token <ival> T_INT
%token <fval> T_DOUBLE
%token <sval> T_STRING
%token <sval> N_STRING
%token <sval> N_STRING "property name"
%token <ival> T_POSITION;
%token <ival> T_HIGHLIGHT_STYLE
%token <sval> NAME_ELEMENT "Element name"

View file

@ -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 <b>%d</b> 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;

View file

@ -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 ("<big><b>Error while parsing theme file:</b></big>\n");
char *what_esc = g_markup_escape_text ( what, -1);
GString *str = g_string_new("");
g_string_printf ( str, "<big><b>Error while parsing them:</b></big> <i>%s</i>\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: <i>%s</i>\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 ();

View file

@ -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;

View file

@ -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 } };