=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cfg.c,v retrieving revision 1.67 retrieving revision 1.68 diff -c -r1.67 -r1.68 *** src/usr.bin/tmux/cfg.c 2019/04/03 06:43:19 1.67 --- src/usr.bin/tmux/cfg.c 2019/04/18 11:07:28 1.68 *************** *** 1,4 **** ! /* $OpenBSD: cfg.c,v 1.67 2019/04/03 06:43:19 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cfg.c,v 1.68 2019/04/18 11:07:28 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 116,122 **** } static int ! cfg_check_condition(const char *path, size_t line, const char *p, int *skip) { struct format_tree *ft; char *s; --- 116,123 ---- } static int ! cfg_check_cond(const char *path, size_t line, const char *p, int *skip, ! struct client *c, struct cmd_find_state *fs) { struct format_tree *ft; char *s; *************** *** 131,136 **** --- 132,141 ---- } ft = format_create(NULL, NULL, FORMAT_NONE, FORMAT_NOJOBS); + if (fs != NULL) + format_defaults(ft, c, fs->s, fs->wl, fs->wp); + else + format_defaults(ft, c, NULL, NULL, NULL); s = format_expand(ft, p); result = format_true(s); free(s); *************** *** 142,148 **** static void cfg_handle_if(const char *path, size_t line, struct cfg_conds *conds, ! const char *p) { struct cfg_cond *cond; struct cfg_cond *parent = TAILQ_FIRST(conds); --- 147,153 ---- static void cfg_handle_if(const char *path, size_t line, struct cfg_conds *conds, ! const char *p, struct client *c, struct cmd_find_state *fs) { struct cfg_cond *cond; struct cfg_cond *parent = TAILQ_FIRST(conds); *************** *** 154,160 **** cond = xcalloc(1, sizeof *cond); cond->line = line; if (parent == NULL || parent->met) ! cond->met = cfg_check_condition(path, line, p, &cond->skip); else cond->skip = 1; cond->saw_else = 0; --- 159,165 ---- cond = xcalloc(1, sizeof *cond); cond->line = line; if (parent == NULL || parent->met) ! cond->met = cfg_check_cond(path, line, p, &cond->skip, c, fs); else cond->skip = 1; cond->saw_else = 0; *************** *** 163,169 **** static void cfg_handle_elif(const char *path, size_t line, struct cfg_conds *conds, ! const char *p) { struct cfg_cond *cond = TAILQ_FIRST(conds); --- 168,174 ---- static void cfg_handle_elif(const char *path, size_t line, struct cfg_conds *conds, ! const char *p, struct client *c, struct cmd_find_state *fs) { struct cfg_cond *cond = TAILQ_FIRST(conds); *************** *** 174,180 **** if (cond == NULL || cond->saw_else) cfg_add_cause("%s:%zu: unexpected %%elif", path, line); else if (!cond->skip) ! cond->met = cfg_check_condition(path, line, p, &cond->skip); else cond->met = 0; } --- 179,185 ---- if (cond == NULL || cond->saw_else) cfg_add_cause("%s:%zu: unexpected %%elif", path, line); else if (!cond->skip) ! cond->met = cfg_check_cond(path, line, p, &cond->skip, c, fs); else cond->met = 0; } *************** *** 215,230 **** static void cfg_handle_directive(const char *p, const char *path, size_t line, ! struct cfg_conds *conds) { int n = 0; while (p[n] != '\0' && !isspace((u_char)p[n])) n++; if (strncmp(p, "%if", n) == 0) ! cfg_handle_if(path, line, conds, p + n); else if (strncmp(p, "%elif", n) == 0) ! cfg_handle_elif(path, line, conds, p + n); else if (strcmp(p, "%else") == 0) cfg_handle_else(path, line, conds); else if (strcmp(p, "%endif") == 0) --- 220,235 ---- static void cfg_handle_directive(const char *p, const char *path, size_t line, ! struct cfg_conds *conds, struct client *c, struct cmd_find_state *fs) { int n = 0; while (p[n] != '\0' && !isspace((u_char)p[n])) n++; if (strncmp(p, "%if", n) == 0) ! cfg_handle_if(path, line, conds, p + n, c, fs); else if (strncmp(p, "%elif", n) == 0) ! cfg_handle_elif(path, line, conds, p + n, c, fs); else if (strcmp(p, "%else") == 0) cfg_handle_else(path, line, conds); else if (strcmp(p, "%endif") == 0) *************** *** 245,251 **** --- 250,263 ---- struct cmdq_item *new_item; struct cfg_cond *cond, *cond1; struct cfg_conds conds; + struct cmd_find_state *fs = NULL; + struct client *fc = NULL; + if (item != NULL) { + fs = &item->target; + fc = cmd_find_client(item, NULL, 1); + } + TAILQ_INIT(&conds); log_debug("loading %s", path); *************** *** 271,277 **** *q-- = '\0'; if (*p == '%') { ! cfg_handle_directive(p, path, line, &conds); continue; } cond = TAILQ_FIRST(&conds); --- 283,289 ---- *q-- = '\0'; if (*p == '%') { ! cfg_handle_directive(p, path, line, &conds, fc, fs); continue; } cond = TAILQ_FIRST(&conds);