Cejka Rudolf
2015-04-10 17:00:03 UTC
Hello,
would it be possible to allow negative length limit in format
specification? For example, #{=10:pane_title} include first 10
characters, while #{=-10:pane_title} would include last 10 characters?
Maybe something like this? (tmux-1.9a)
--- format.c.orig 2015-04-10 17:42:31.000000000 +0200
+++ format.c 2015-04-10 18:34:26.000000000 +0200
@@ -197,7 +197,7 @@
char *copy, *copy0, *endptr, *ptr, *saved;
const char *value;
size_t valuelen;
- u_long limit = ULONG_MAX;
+ long limit = LONG_MAX;
/* Make a copy of the key. */
copy0 = copy = xmalloc(keylen + 1);
@@ -210,8 +210,8 @@
switch (*copy) {
case '=':
errno = 0;
- limit = strtoul(copy + 1, &endptr, 10);
- if (errno == ERANGE && limit == ULONG_MAX)
+ limit = strtol(copy + 1, &endptr, 10);
+ if (errno == ERANGE && (limit == LONG_MAX || limit == LONG_MIN))
goto fail;
copy = endptr;
break;
@@ -259,7 +259,11 @@
valuelen = strlen(value);
/* Truncate the value if needed. */
- if (valuelen > limit)
+ if (limit < 0 && valuelen > -limit) {
+ value += valuelen + limit;
+ valuelen = -limit;
+ }
+ if (limit >= 0 && valuelen > limit)
valuelen = limit;
/* Expand the buffer and copy in the value. */
would it be possible to allow negative length limit in format
specification? For example, #{=10:pane_title} include first 10
characters, while #{=-10:pane_title} would include last 10 characters?
Maybe something like this? (tmux-1.9a)
--- format.c.orig 2015-04-10 17:42:31.000000000 +0200
+++ format.c 2015-04-10 18:34:26.000000000 +0200
@@ -197,7 +197,7 @@
char *copy, *copy0, *endptr, *ptr, *saved;
const char *value;
size_t valuelen;
- u_long limit = ULONG_MAX;
+ long limit = LONG_MAX;
/* Make a copy of the key. */
copy0 = copy = xmalloc(keylen + 1);
@@ -210,8 +210,8 @@
switch (*copy) {
case '=':
errno = 0;
- limit = strtoul(copy + 1, &endptr, 10);
- if (errno == ERANGE && limit == ULONG_MAX)
+ limit = strtol(copy + 1, &endptr, 10);
+ if (errno == ERANGE && (limit == LONG_MAX || limit == LONG_MIN))
goto fail;
copy = endptr;
break;
@@ -259,7 +259,11 @@
valuelen = strlen(value);
/* Truncate the value if needed. */
- if (valuelen > limit)
+ if (limit < 0 && valuelen > -limit) {
+ value += valuelen + limit;
+ valuelen = -limit;
+ }
+ if (limit >= 0 && valuelen > limit)
valuelen = limit;
/* Expand the buffer and copy in the value. */
--
Rudolf Cejka <cejkar at fit.vutbr.cz> http://www.fit.vutbr.cz/~cejkar
Brno University of Technology, Faculty of Information Technology
Bozetechova 2, 612 66 Brno, Czech Republic
Rudolf Cejka <cejkar at fit.vutbr.cz> http://www.fit.vutbr.cz/~cejkar
Brno University of Technology, Faculty of Information Technology
Bozetechova 2, 612 66 Brno, Czech Republic