=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.139 retrieving revision 1.140 diff -c -r1.139 -r1.140 *** src/usr.bin/tmux/format.c 2017/05/29 15:43:48 1.139 --- src/usr.bin/tmux/format.c 2017/05/29 18:06:34 1.140 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.139 2017/05/29 15:43:48 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.140 2017/05/29 18:06:34 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 848,866 **** return (0); } ! /* ! * Replace a key/value pair in buffer. #{blah} is expanded directly, ! * #{?blah,a,b} is replace with a if blah exists and is nonzero else b. ! */ static int format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { ! char *copy, *copy0, *endptr, *ptr, *found, *new, *value; ! char *from = NULL, *to = NULL, *left, *right; ! size_t valuelen, newlen, fromlen, tolen, used; ! long limit = 0; ! int modifiers = 0, compare = 0; /* Make a copy of the key. */ copy0 = copy = xmalloc(keylen + 1); --- 848,864 ---- return (0); } ! /* Replace a key. */ static int format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { ! struct window_pane *wp = ft->wp; ! char *copy, *copy0, *endptr, *ptr, *found, *new; ! char *value, *from = NULL, *to = NULL, *left, *right; ! size_t valuelen, newlen, fromlen, tolen, used; ! long limit = 0; ! int modifiers = 0, compare = 0, search = 0; /* Make a copy of the key. */ copy0 = copy = xmalloc(keylen + 1); *************** *** 875,880 **** --- 873,896 ---- compare = -2; copy += 2; break; + case 'C': + if (copy[1] != ':') + break; + search = 1; + copy += 2; + break; + case '|': + if (copy[1] != '|' || copy[2] != ':') + break; + compare = -3; + copy += 3; + break; + case '&': + if (copy[1] != '&' || copy[2] != ':') + break; + compare = -4; + copy += 3; + break; case '!': if (copy[1] == '=' && copy[2] == ':') { compare = -1; *************** *** 940,952 **** } /* Is this a comparison or a conditional? */ ! if (compare != 0) { /* Comparison: compare comma-separated left and right. */ if (format_choose(copy, &left, &right) != 0) goto fail; left = format_expand(ft, left); right = format_expand(ft, right); ! if (compare == 1 && strcmp(left, right) == 0) value = xstrdup("1"); else if (compare == -1 && strcmp(left, right) != 0) value = xstrdup("1"); --- 956,980 ---- } /* Is this a comparison or a conditional? */ ! if (search) { ! /* Search in pane. */ ! if (wp == NULL) ! value = xstrdup("0"); ! else ! xasprintf(&value, "%u", window_pane_search(wp, copy)); ! } else if (compare != 0) { /* Comparison: compare comma-separated left and right. */ if (format_choose(copy, &left, &right) != 0) goto fail; left = format_expand(ft, left); right = format_expand(ft, right); ! if (compare == -3 && ! (format_true(left) || format_true(right))) ! value = xstrdup("1"); ! else if (compare == -4 && ! (format_true(left) && format_true(right))) ! value = xstrdup("1"); ! else if (compare == 1 && strcmp(left, right) == 0) value = xstrdup("1"); else if (compare == -1 && strcmp(left, right) != 0) value = xstrdup("1");