[Lexer] Fix lexer parsing default theme from resource.

This commit is contained in:
Dave Davenport 2021-08-24 21:37:57 +02:00 committed by Dave Davenport
parent f1272e4af3
commit 6c0d0c4572
2 changed files with 33 additions and 38 deletions

View File

@ -86,7 +86,6 @@ typedef struct _ParseObject {
} ParseObject; } ParseObject;
GList *imported_files = NULL;
GList *prev_imported_files = NULL; GList *prev_imported_files = NULL;
GQueue *file_queue = NULL; GQueue *file_queue = NULL;
GQueue *queue = NULL; GQueue *queue = NULL;
@ -145,6 +144,7 @@ static double rofi_theme_parse_convert_hex ( char high, char low)
} else {\ } else {\
result = 0;\ result = 0;\
}\ }\
break;\
}\ }\
}\ }\
}\ }\
@ -280,7 +280,7 @@ C_COMMENT_OPEN "/*"
INCLUDE "@import" INCLUDE "@import"
THEME "@theme" THEME "@theme"
DEFAULT (?i:\"default\"?) DEFAULT (?i:\"default\"?)
MEDIA "@media" MEDIA "@media"
@ -371,25 +371,31 @@ if ( queue == NULL ) {
/** Parse path. Last element in this INCLUDE */ /** Parse path. Last element in this INCLUDE */
<INCLUDE>{DEFAULT} { <INCLUDE>{DEFAULT} {
yytext[yyleng-1] = '\0'; ParseObject *top = g_queue_peek_head ( file_queue );
/** Add Parse object */ g_assert ( top != NULL );
GBytes *theme_data = g_resource_lookup_data( resources_get_resource(), GBytes *theme_data = g_resource_lookup_data( resources_get_resource(),
"/org/qtools/rofi/default.rasi", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); "/org/qtools/rofi/default.rasi", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
if (theme_data) { if (theme_data) {
const char *theme = g_bytes_get_data(theme_data, NULL); const char *theme = g_bytes_get_data(theme_data, NULL);
file_queue = g_queue_new (); top->location = *yylloc;
ParseObject *po = g_malloc0(sizeof(ParseObject)); ParseObject *po = g_malloc0(sizeof(ParseObject));
po->type = PT_STRING_ALLOC; po->type = PT_STRING_ALLOC;
po->malloc_str = g_strdup(theme); po->malloc_str = g_strdup(theme);
po->input_str = po->malloc_str; po->input_str = po->malloc_str;
po->str_len = strlen(po->malloc_str); po->str_len = strlen(po->malloc_str)-1;
current = po; current = po;
g_queue_push_head ( file_queue, po ); g_queue_push_head ( file_queue, po );
g_bytes_unref(theme_data); g_bytes_unref(theme_data);
yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE ));
yylloc->first_line = yylloc->last_line = 1;
yylloc->first_column = yylloc->last_column = 1;
yylloc->filename = NULL;//"default theme";
} }
// Pop out of include. */ // Pop out of include.
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
} }
<INCLUDE>{STRING} { <INCLUDE>{STRING} {
yytext[yyleng-1] = '\0'; yytext[yyleng-1] = '\0';
ParseObject *top = g_queue_peek_head ( file_queue ); ParseObject *top = g_queue_peek_head ( file_queue );
@ -397,32 +403,26 @@ if ( queue == NULL ) {
char *file2 = helper_get_theme_path ( &yytext[1], ".rasi" ); char *file2 = helper_get_theme_path ( &yytext[1], ".rasi" );
char *filename = rofi_theme_parse_prepare_file ( file2, top->filename ); char *filename = rofi_theme_parse_prepare_file ( file2, top->filename );
g_free ( file2 ); g_free ( file2 );
if ( g_list_find_custom ( imported_files, filename, (GCompareFunc)g_strcmp0 ) != NULL ) { FILE *f = fopen ( filename, "rb" );
g_debug ( "Skipping file: '%s' already parsed.", filename ); if ( f ) {
} else { top->location = *yylloc;
g_debug ( "Parsing file: '%s'", filename ); ParseObject *po = g_malloc0(sizeof(ParseObject));
FILE *f = fopen ( filename, "rb" ); po->type = PT_FILE;
if ( f ) { po->filename = filename;
top->location = *yylloc; po->filein = f;
ParseObject *po = g_malloc0(sizeof(ParseObject)); current = po;
po->type = PT_FILE; g_queue_push_head ( file_queue, po );
po->filename = filename;
po->filein = f;
current = po;
g_queue_push_head ( file_queue, po );
imported_files = g_list_append ( imported_files, po->filename );
yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE )); yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE ));
yylloc->first_line = yylloc->last_line = 1; yylloc->first_line = yylloc->last_line = 1;
yylloc->first_column = yylloc->last_column = 1; yylloc->first_column = yylloc->last_column = 1;
yylloc->filename = current->filename; yylloc->filename = current->filename;
} else { } else {
char *str = g_markup_printf_escaped ( "Failed to open theme: <i>%s</i>\nError: <b>%s</b>", char *str = g_markup_printf_escaped ( "Failed to open theme: <i>%s</i>\nError: <b>%s</b>",
filename, strerror ( errno ) ); filename, strerror ( errno ) );
rofi_add_error_message ( g_string_new ( str ) ); rofi_add_error_message ( g_string_new ( str ) );
g_free ( str ); g_free ( str );
g_free(filename); g_free(filename);
}
} }
// Pop out of include. */ // Pop out of include. */
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
@ -542,7 +542,6 @@ if ( queue == NULL ) {
po->str_len = strlen(val); po->str_len = strlen(val);
current = po; current = po;
g_queue_push_head ( file_queue, po ); g_queue_push_head ( file_queue, po );
imported_files = g_list_append ( imported_files, po->filename );
yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE )); yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE ));
yylloc->first_line = yylloc->last_line = 1; yylloc->first_line = yylloc->last_line = 1;
@ -829,7 +828,6 @@ gboolean rofi_theme_parse_file ( const char *file )
po->filename = filename; po->filename = filename;
po->filein = yyin; po->filein = yyin;
current = po; current = po;
imported_files = g_list_append ( imported_files, po->filename );
g_queue_push_head ( file_queue, po ); g_queue_push_head ( file_queue, po );
g_debug ( "Parsing top file: '%s'", filename ); g_debug ( "Parsing top file: '%s'", filename );
@ -849,9 +847,7 @@ gboolean rofi_theme_parse_file ( const char *file )
} }
} }
// Free up. // Free up.
g_list_free_full ( imported_files, g_free );
g_queue_free ( file_queue ); g_queue_free ( file_queue );
imported_files = NULL;
file_queue = NULL; file_queue = NULL;
if ( parser_retv != 0 ) { if ( parser_retv != 0 ) {
return TRUE; return TRUE;
@ -887,8 +883,6 @@ gboolean rofi_theme_parse_string ( const char *string )
} }
} }
// Free up. // Free up.
g_list_free_full ( imported_files, g_free );
imported_files = NULL;
g_queue_free ( file_queue ); g_queue_free ( file_queue );
file_queue = NULL; file_queue = NULL;
if ( parser_retv != 0 ) { if ( parser_retv != 0 ) {

View File

@ -344,6 +344,7 @@ t_entry_list {
$$ =$1; $$ =$1;
} }
| t_entry_list_included T_RESET_THEME t_entry_list { | t_entry_list_included T_RESET_THEME t_entry_list {
rofi_theme_reset(); rofi_theme_reset();
rofi_theme_free($1); rofi_theme_free($1);
$$ = $3; $$ = $3;