Skip to content

Commit

Permalink
include: Use constants for merge mode prefixes
Browse files Browse the repository at this point in the history
This will make their semantics explicit.
  • Loading branch information
wismill committed Sep 25, 2024
1 parent a898bc8 commit 88ae235
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/xkbcomp/ast-build.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
incl->modifier = extra_data;
incl->next_incl = NULL;

if (nextop == '|')
if (nextop == MERGE_AUGMENT_PREFIX)
merge = MERGE_AUGMENT;
else
merge = MERGE_OVERRIDE;
Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/include.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
/* Set up the next file for the next call, if any. */
if (*nextop_rtrn == '\0')
*str_inout = NULL;
else if (*nextop_rtrn == '|' || *nextop_rtrn == '+')
else if (is_merge_mode_prefix(*nextop_rtrn))
*str_inout = next;
else
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/xkbcomp/include.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
/* Reasonable threshold, with plenty of margin for keymaps in the wild */
#define INCLUDE_MAX_DEPTH 15

#define MERGE_OVERRIDE_PREFIX '+'
#define MERGE_AUGMENT_PREFIX '|'
#define MERGE_DEFAULT_PREFIX MERGE_OVERRIDE_PREFIX
#define is_merge_mode_prefix(ch) \
((ch) == MERGE_OVERRIDE_PREFIX || (ch) == MERGE_AUGMENT_PREFIX)

bool
ParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
char *nextop_rtrn, char **extra_data);
Expand Down
7 changes: 4 additions & 3 deletions src/xkbcomp/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ append_expanded_kccgst_value(struct matcher *m, struct scanner *s,
pfx = sfx = 0;

/* Check for prefix. */
if (str[i] == '(' || str[i] == '+' || str[i] == '|' ||
if (str[i] == '(' ||
is_merge_mode_prefix(str[i]) ||
str[i] == '_' || str[i] == '-') {
pfx = str[i];
if (str[i] == '(') sfx = ')';
Expand Down Expand Up @@ -895,9 +896,9 @@ append_expanded_kccgst_value(struct matcher *m, struct scanner *s,
*/

ch = (darray_empty(expanded) ? '\0' : darray_item(expanded, 0));
expanded_plus = (ch == '+' || ch == '|');
expanded_plus = is_merge_mode_prefix(ch);
ch = (darray_empty(*to) ? '\0' : darray_item(*to, 0));
to_plus = (ch == '+' || ch == '|');
to_plus = is_merge_mode_prefix(ch);

if (expanded_plus || darray_empty(*to))
darray_appends_nullterminate(*to, expanded.item, expanded.size);
Expand Down

0 comments on commit 88ae235

Please sign in to comment.