Edit

kc3-lang/libxkbcommon/src/xkbcomp/include.h

Branch :

  • Show log

    Commit

  • Author : Pierre Le Marre
    Date : 2025-06-06 18:40:29
    Hash : 39b4b670
    Message : Support including keymap components using %-expansion and absolute path Enable to use the same `include` features than *rules* files in *keymap components*: - *`%`-expansion*: `%H` home directory, `%S` sytem root and `%E` extra. - absolute file paths. This is useful if one wants to overwrite the system file with a user config (i.e. same name, but in `~/.config/xkb`), but still include the system file: ``` // File: ~/.config/xkb/symbols/de xkb_symbols "basic" { include "%S/de(basic)" key <AB01> { [z, Z] }; key <AD06> { [y, Y] }; } ```` Without the commit, using a mere `include "de(basic)"` would result in an include loop. Refactored by using the same code for rules and keymap components.

  • src/xkbcomp/include.h
  • /*
     * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
     * SPDX-License-Identifier: HPND
     */
    #pragma once
    
    #include "ast.h"
    
    /* 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_REPLACE_PREFIX  '^'
    #define MERGE_DEFAULT_PREFIX  MERGE_OVERRIDE_PREFIX
    #define is_merge_mode_prefix(ch) \
        ((ch) == MERGE_OVERRIDE_PREFIX || (ch) == MERGE_AUGMENT_PREFIX || \
         (ch) == MERGE_REPLACE_PREFIX)
    static const char MERGE_MODE_PREFIXES[] =
        { MERGE_OVERRIDE_PREFIX, MERGE_AUGMENT_PREFIX, MERGE_REPLACE_PREFIX, 0 };
    
    bool
    ParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
                    char *nextop_rtrn, char **extra_data);
    
    FILE *
    FindFileInXkbPath(struct xkb_context *ctx, const char* parent_file_name,
                      const char *name, size_t name_len, enum xkb_file_type type,
                      char *buf, size_t buf_size, unsigned int *offset);
    
    bool
    ExceedsIncludeMaxDepth(struct xkb_context *ctx, unsigned int include_depth);
    
    XkbFile *
    ProcessIncludeFile(struct xkb_context *ctx, IncludeStmt *stmt,
                       enum xkb_file_type file_type);