Implement include config directive (#4420)
The implementation uses wordexp(3) just like sway:
https://github.com/i3/i3/issues/1197#issuecomment-226844106
Thanks to jajm for their implementation at
bb55709d0a
This required refactoring the config parser to be re-entrant
(no more global state) and to return an error instead of dying.
In case a file cannot be opened, i3 reports an error but proceeds with the
remaining configuration.
Key bindings can be overwritten or removed using the new --remove flag of the
bindsym/bindcode directive.
All files that were successfully included are displayed in i3 --moreversion.
One caveat is i3 config file variable expansion, see the note in the userguide.
fixes #4192
This commit is contained in:
committed by
GitHub
parent
4c93f61353
commit
eaa5e636f9
@ -16,6 +16,50 @@
|
||||
SLIST_HEAD(variables_head, Variable);
|
||||
extern pid_t config_error_nagbar_pid;
|
||||
|
||||
struct stack_entry {
|
||||
/* Just a pointer, not dynamically allocated. */
|
||||
const char *identifier;
|
||||
enum {
|
||||
STACK_STR = 0,
|
||||
STACK_LONG = 1,
|
||||
} type;
|
||||
union {
|
||||
char *str;
|
||||
long num;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct stack {
|
||||
struct stack_entry stack[10];
|
||||
};
|
||||
|
||||
struct parser_ctx {
|
||||
bool use_nagbar;
|
||||
bool assume_v4;
|
||||
|
||||
int state;
|
||||
Match current_match;
|
||||
|
||||
/* A list which contains the states that lead to the current state, e.g.
|
||||
* INITIAL, WORKSPACE_LAYOUT.
|
||||
* When jumping back to INITIAL, statelist_idx will simply be set to 1
|
||||
* (likewise for other states, e.g. MODE or BAR).
|
||||
* This list is used to process the nearest error token. */
|
||||
int statelist[10];
|
||||
/* NB: statelist_idx points to where the next entry will be inserted */
|
||||
int statelist_idx;
|
||||
|
||||
/*******************************************************************************
|
||||
* The (small) stack where identified literals are stored during the parsing
|
||||
* of a single config directive (like $workspace).
|
||||
******************************************************************************/
|
||||
struct stack *stack;
|
||||
|
||||
struct variables_head variables;
|
||||
|
||||
bool has_errors;
|
||||
};
|
||||
|
||||
/**
|
||||
* An intermediate reprsentation of the result of a parse_config call.
|
||||
* Currently unused, but the JSON output will be useful in the future when we
|
||||
@ -23,22 +67,34 @@ extern pid_t config_error_nagbar_pid;
|
||||
*
|
||||
*/
|
||||
struct ConfigResultIR {
|
||||
/* The JSON generator to append a reply to. */
|
||||
yajl_gen json_gen;
|
||||
struct parser_ctx *ctx;
|
||||
|
||||
/* The next state to transition to. Passed to the function so that we can
|
||||
* determine the next state as a result of a function call, like
|
||||
* cfg_criteria_pop_state() does. */
|
||||
int next_state;
|
||||
};
|
||||
|
||||
struct ConfigResultIR *parse_config(const char *input, struct context *context);
|
||||
/* Whether any error happened while processing this config directive. */
|
||||
bool has_errors;
|
||||
};
|
||||
|
||||
/**
|
||||
* launch nagbar to indicate errors in the configuration file.
|
||||
*/
|
||||
void start_config_error_nagbar(const char *configpath, bool has_errors);
|
||||
|
||||
/**
|
||||
* Releases the memory of all variables in ctx.
|
||||
*
|
||||
*/
|
||||
void free_variables(struct parser_ctx *ctx);
|
||||
|
||||
typedef enum {
|
||||
PARSE_FILE_FAILED = -1,
|
||||
PARSE_FILE_SUCCESS = 0,
|
||||
PARSE_FILE_CONFIG_ERRORS = 1,
|
||||
} parse_file_result_t;
|
||||
|
||||
/**
|
||||
* Parses the given file by first replacing the variables, then calling
|
||||
* parse_config and launching i3-nagbar if use_nagbar is true.
|
||||
@ -47,4 +103,4 @@ void start_config_error_nagbar(const char *configpath, bool has_errors);
|
||||
* parsing.
|
||||
*
|
||||
*/
|
||||
bool parse_file(const char *f, bool use_nagbar);
|
||||
parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f);
|
||||
|
Reference in New Issue
Block a user