diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-22 06:57:14 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-22 06:57:14 +0000 |
commit | 1c6d9cb48f811bc48f63028132c388723be36cbe (patch) | |
tree | 06893614d53036dc1cb1a63a9153e1a68c8eb39f /usr.bin/tmux/arguments.c | |
parent | 0744f161eaf998420a541ce310b02cb5d5387e5f (diff) |
Change so main-pane-width and height can be given as a percentage.
Diffstat (limited to 'usr.bin/tmux/arguments.c')
-rw-r--r-- | usr.bin/tmux/arguments.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index 7ae81a45180..39ebd0d4add 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.30 2020/04/12 20:54:28 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.31 2020/04/22 06:57:13 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -352,22 +352,29 @@ long long args_percentage(struct args *args, u_char ch, long long minval, long long maxval, long long curval, char **cause) { - const char *errstr; - long long ll; + const char *value; struct args_entry *entry; - struct args_value *value; - size_t valuelen; - char *copy; if ((entry = args_find(args, ch)) == NULL) { *cause = xstrdup("missing"); return (0); } - value = TAILQ_LAST(&entry->values, args_values); - valuelen = strlen(value->value); + value = TAILQ_LAST(&entry->values, args_values)->value; + return (args_string_percentage(value, minval, maxval, curval, cause)); +} + +/* Convert a string to a number which may be a percentage. */ +long long +args_string_percentage(const char *value, long long minval, long long maxval, + long long curval, char **cause) +{ + const char *errstr; + long long ll; + size_t valuelen = strlen(value); + char *copy; - if (value->value[valuelen - 1] == '%') { - copy = xstrdup(value->value); + if (value[valuelen - 1] == '%') { + copy = xstrdup(value); copy[valuelen - 1] = '\0'; ll = strtonum(copy, 0, 100, &errstr); @@ -386,7 +393,7 @@ args_percentage(struct args *args, u_char ch, long long minval, return (0); } } else { - ll = strtonum(value->value, minval, maxval, &errstr); + ll = strtonum(value, minval, maxval, &errstr); if (errstr != NULL) { *cause = xstrdup(errstr); return (0); |