From 4bef336b9c0976a9f67f1f08924cbc71ba05fb00 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 24 Jan 2022 20:33:19 +0100 Subject: [PATCH] What is in a name. --- include/rofi-types.h | 4 +- include/theme.h | 3 +- lexer/theme-lexer.l | 116 +++++++++++++++++++-------------------- lexer/theme-parser.y | 8 +-- source/rofi-types.c | 4 +- source/theme.c | 28 +++++----- test/theme-parser-test.c | 2 +- 7 files changed, 84 insertions(+), 81 deletions(-) diff --git a/include/rofi-types.h b/include/rofi-types.h index 4e3462a3..3f3da28e 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -32,8 +32,8 @@ typedef enum { P_HIGHLIGHT, /** List */ P_LIST, - /** Set */ - P_SET, + /** Array */ + P_ARRAY, /** Orientation */ P_ORIENTATION, /** Cursor */ diff --git a/include/theme.h b/include/theme.h index 4bf7654d..384f920d 100644 --- a/include/theme.h +++ b/include/theme.h @@ -471,5 +471,6 @@ void rofi_theme_print_parsed_files(int is_term); * Returns a list of allocated RofiDistance objects that should be * freed. */ -GList *rofi_theme_get_set_distance(const widget *widget, const char *property); +GList *rofi_theme_get_array_distance(const widget *widget, + const char *property); #endif diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 781728e5..0b83342c 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -275,8 +275,8 @@ FORWARD_SLASH \/ LIST_OPEN \[ LIST_CLOSE \] -SET_OPEN \{ -SET_CLOSE \} +ARRAY_OPEN \{ +ARRAY_CLOSE \} VAR_START "var" ENV_START "env" @@ -300,7 +300,7 @@ CONFIGURATION (?i:configuration) %x PROPERTIES_ENV_VAR %x PROPERTIES_VAR_DEFAULT %x PROPERTIES_LIST -%x PROPERTIES_SET +%x PROPERTIES_ARRAY %x NAMESTR %x SECTION %x DEFAULTS @@ -500,17 +500,17 @@ if ( queue == NULL ) { /* After Namestr/Classstr we want to go to state str, then to { */ {WHITESPACE}+ ; // ignore all whitespace -{WHITESPACE}+ ; // ignore all whitespace +{WHITESPACE}+ ; // ignore all whitespace
":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; } ";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;} -(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} -{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} -{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} -{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} -{CHAR} { yytext[yyleng-1] = '\0'; yylval->cval = g_strcompress(&yytext[1])[0]; return T_CHAR;} +(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} +{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} +{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} +{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} +{CHAR} { yytext[yyleng-1] = '\0'; yylval->cval = g_strcompress(&yytext[1])[0]; return T_CHAR;} -@{WORD} { +@{WORD} { yylval->sval = g_strdup(yytext+1); return T_LINK; } @@ -523,26 +523,26 @@ if ( queue == NULL ) { return T_BOPEN; } -{EM} { return T_UNIT_EM; } -{CH} { return T_UNIT_CH; } -{PX} { return T_UNIT_PX; } -{MM} { return T_UNIT_MM; } -{PERCENT} { return T_PERCENT; } -{LS_SOLID} { return T_SOLID; } -{LS_DASH} { return T_DASH; } +{EM} { return T_UNIT_EM; } +{CH} { return T_UNIT_CH; } +{PX} { return T_UNIT_PX; } +{MM} { return T_UNIT_MM; } +{PERCENT} { return T_PERCENT; } +{LS_SOLID} { return T_SOLID; } +{LS_DASH} { return T_DASH; } -{INHERIT} { return T_INHERIT; } -{MODIFIER_ADD} { return T_MODIFIER_ADD; } -{MODIFIER_SUBTRACT} { return T_MODIFIER_SUBTRACT; } -{MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; } -{MODIFIER_MIN} { return T_MODIFIER_MIN; } -{MODIFIER_MAX} { return T_MODIFIER_MAX; } -{MODIFIER_ROUND} { return T_MODIFIER_ROUND; } -{MODIFIER_FLOOR} { return T_MODIFIER_FLOOR; } -{MODIFIER_CEIL} { return T_MODIFIER_CEIL; } -{CALC} { return T_CALC; } +{INHERIT} { return T_INHERIT; } +{MODIFIER_ADD} { return T_MODIFIER_ADD; } +{MODIFIER_SUBTRACT} { return T_MODIFIER_SUBTRACT; } +{MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; } +{MODIFIER_MIN} { return T_MODIFIER_MIN; } +{MODIFIER_MAX} { return T_MODIFIER_MAX; } +{MODIFIER_ROUND} { return T_MODIFIER_ROUND; } +{MODIFIER_FLOOR} { return T_MODIFIER_FLOOR; } +{MODIFIER_CEIL} { return T_MODIFIER_CEIL; } +{CALC} { return T_CALC; } -{ENV} { +{ENV} { yytext[yyleng-1] = '\0'; const char *val = g_getenv(yytext+2); if ( val ) { @@ -674,7 +674,7 @@ if ( queue == NULL ) { } {S_T_PARENT_LEFT} { return T_PARENT_LEFT; } {S_T_PARENT_RIGHT} { return T_PARENT_RIGHT; } -{COMMA} { return T_COMMA; } +{COMMA} { return T_COMMA; } {LIST_OPEN} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_LIST); @@ -684,46 +684,46 @@ if ( queue == NULL ) { BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); return T_LIST_CLOSE; } -{SET_OPEN} { +{ARRAY_OPEN} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); - BEGIN(PROPERTIES_SET); - return T_SET_OPEN; + BEGIN(PROPERTIES_ARRAY); + return T_ARRAY_OPEN; } -{SET_CLOSE} { +{ARRAY_CLOSE} { BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); - return T_SET_CLOSE; + return T_ARRAY_CLOSE; } -{FORWARD_SLASH} { return T_FORWARD_SLASH; } +{FORWARD_SLASH} { return T_FORWARD_SLASH; } /* Position */ -{CENTER} { return T_POS_CENTER; } -{EAST} { return T_POS_EAST; } -{WEST} { return T_POS_WEST; } -{SOUTH} { return T_POS_SOUTH; } -{NORTH} { return T_POS_NORTH; } +{CENTER} { return T_POS_CENTER; } +{EAST} { return T_POS_EAST; } +{WEST} { return T_POS_WEST; } +{SOUTH} { return T_POS_SOUTH; } +{NORTH} { return T_POS_NORTH; } /* Highlight style */ -{NONE} { return T_NONE; } -{BOLD} { return T_BOLD; } -{ITALIC} { return T_ITALIC; } -{UNDERLINE} { return T_UNDERLINE; } -{STRIKETHROUGH} { return T_STRIKETHROUGH; } -{SMALLCAPS} { return T_SMALLCAPS; } +{NONE} { return T_NONE; } +{BOLD} { return T_BOLD; } +{ITALIC} { return T_ITALIC; } +{UNDERLINE} { return T_UNDERLINE; } +{STRIKETHROUGH} { return T_STRIKETHROUGH; } +{SMALLCAPS} { return T_SMALLCAPS; } -{ANGLE_DEG} { return T_ANGLE_DEG; } -{ANGLE_RAD} { return T_ANGLE_RAD; } -{ANGLE_GRAD} { return T_ANGLE_GRAD; } -{ANGLE_TURN} { return T_ANGLE_TURN; } +{ANGLE_DEG} { return T_ANGLE_DEG; } +{ANGLE_RAD} { return T_ANGLE_RAD; } +{ANGLE_GRAD} { return T_ANGLE_GRAD; } +{ANGLE_TURN} { return T_ANGLE_TURN; } -{ORIENTATION_HORI} { return ORIENTATION_HORI; } -{ORIENTATION_VERT} { return ORIENTATION_VERT; } +{ORIENTATION_HORI} { return ORIENTATION_HORI; } +{ORIENTATION_VERT} { return ORIENTATION_VERT; } -{CURSOR_DEF} { return CURSOR_DEF; } -{CURSOR_PTR} { return CURSOR_PTR; } -{CURSOR_TXT} { return CURSOR_TXT; } +{CURSOR_DEF} { return CURSOR_DEF; } +{CURSOR_PTR} { return CURSOR_PTR; } +{CURSOR_TXT} { return CURSOR_TXT; } -{COLOR_TRANSPARENT} { +{COLOR_TRANSPARENT} { return T_COLOR_TRANSPARENT; } -{COLOR_NAME} { +{COLOR_NAME} { for ( unsigned int iter = 0; iter < num_CSSColors; iter++) { if ( strcasecmp(yytext, CSSColors[iter].name )== 0 ) { yylval->colorval.alpha = 1.0; @@ -844,7 +844,7 @@ if ( queue == NULL ) { return T_ELEMENT; } -. { +. { yytext[yyleng-1] = '\0'; return T_ERROR_PROPERTY; } diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 0e2194c0..07588fa0 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -234,8 +234,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b ) %token T_LIST_OPEN "List open ('[')" %token T_LIST_CLOSE "List close (']')" -%token T_SET_OPEN "Set open ('{')" -%token T_SET_CLOSE "Set close ('}')" +%token T_ARRAY_OPEN "Set open ('{')" +%token T_ARRAY_CLOSE "Set close ('}')" %token T_MODIFIER_ADD "Add ('+')" %token T_MODIFIER_SUBTRACT "Subtract ('-')" @@ -585,8 +585,8 @@ t_property_element $$ = rofi_theme_property_create ( P_LIST ); $$->value.list = $2; } -| T_SET_OPEN t_property_element_set_optional T_SET_CLOSE { - $$ = rofi_theme_property_create ( P_SET ); +| T_ARRAY_OPEN t_property_element_set_optional T_ARRAY_CLOSE { + $$ = rofi_theme_property_create ( P_ARRAY ); $$->value.list = $2; } | t_property_orientation { diff --git a/source/rofi-types.c b/source/rofi-types.c index 82011e8c..013a29c2 100644 --- a/source/rofi-types.c +++ b/source/rofi-types.c @@ -28,8 +28,8 @@ const char *const PropertyTypeName[P_NUM_TYPES] = { "Highlight", /** List */ "List", - /** Set */ - "Set", + /** Array */ + "Array", /** Orientation */ "Orientation", /** Cursor */ diff --git a/source/theme.c b/source/theme.c index 8ae5aa62..57c0c98f 100644 --- a/source/theme.c +++ b/source/theme.c @@ -137,7 +137,7 @@ Property *rofi_theme_property_copy(const Property *p) { retv->value.list = g_list_copy_deep(p->value.list, rofi_g_list_strdup, NULL); break; - case P_SET: + case P_ARRAY: retv->value.list = g_list_copy_deep( p->value.list, (GCopyFunc)rofi_theme_property_copy, NULL); break; @@ -210,7 +210,7 @@ void rofi_theme_property_free(Property *p) { } else if (p->type == P_LIST) { g_list_free_full(p->value.list, g_free); p->value.list = 0; - } else if (p->type == P_SET) { + } else if (p->type == P_ARRAY) { g_list_free_full(p->value.list, (GDestroyNotify)rofi_theme_property_free); p->value.list = 0; } else if (p->type == P_LINK) { @@ -375,7 +375,7 @@ static void int_rofi_theme_print_property(Property *p) { } printf(" ]"); break; - case P_SET: + case P_ARRAY: printf("{ "); for (GList *iter = p->value.list; iter != NULL; iter = g_list_next(iter)) { int_rofi_theme_print_property((Property *)iter->data); @@ -1262,28 +1262,30 @@ GList *rofi_theme_get_list(const widget *widget, const char *property, return rofi_theme_get_list_inside(p, widget, property, defaults); } -static GList *rofi_theme_get_set_inside(Property *p, const widget *widget, - const char *property, - PropertyType child_type) { +static GList *rofi_theme_get_array_inside(Property *p, const widget *widget, + const char *property, + PropertyType child_type) { if (p) { if (p->type == P_INHERIT) { if (widget->parent) { ThemeWidget *parent = rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); - Property *pv = rofi_theme_find_property(parent, P_SET, property, FALSE); - return rofi_theme_get_set_inside(pv, widget->parent, property, - child_type); + Property *pv = + rofi_theme_find_property(parent, P_ARRAY, property, FALSE); + return rofi_theme_get_array_inside(pv, widget->parent, property, + child_type); } - } else if (p->type == P_SET) { + } else if (p->type == P_ARRAY) { return p->value.list; } } return NULL; } -GList *rofi_theme_get_set_distance(const widget *widget, const char *property) { +GList *rofi_theme_get_array_distance(const widget *widget, + const char *property) { ThemeWidget *wid2 = rofi_theme_find_widget(widget->name, widget->state, TRUE); - Property *p = rofi_theme_find_property(wid2, P_SET, property, TRUE); - GList *list = rofi_theme_get_set_inside(p, widget, property, P_PADDING); + Property *p = rofi_theme_find_property(wid2, P_ARRAY, property, TRUE); + GList *list = rofi_theme_get_array_inside(p, widget, property, P_PADDING); GList *retv = NULL; for (GList *iter = g_list_first(list); iter != NULL; iter = g_list_next(iter)) { diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 8d3a2f59..563d6901 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -1294,7 +1294,7 @@ START_TEST(test_properties_types_names) { ck_assert_str_eq(PropertyTypeName[P_POSITION], "Position"); ck_assert_str_eq(PropertyTypeName[P_HIGHLIGHT], "Highlight"); ck_assert_str_eq(PropertyTypeName[P_LIST], "List"); - ck_assert_str_eq(PropertyTypeName[P_SET], "Set"); + ck_assert_str_eq(PropertyTypeName[P_ARRAY], "Array"); ck_assert_str_eq(PropertyTypeName[P_ORIENTATION], "Orientation"); } END_TEST