Dear tech@,
This is an attempt to solve a problem I previously reported [1] to misc@
(without receiving any feedback, so far).
>From terminfo(5), I understand that the stack mechanism is the only way
to parametrize a string in terminfo db; this should mean that parameter
count should't take into account "%d", "%s" and "%[1-9]" codes.
On top of that, cp[1] usage in the original code sounds like a mistake.
Please consider that I'm not a C programmer and this is only a "work for
me" proposal (even if I tested it with typical tput usage and the resulting
code seems closer to NetBSD's implementation).
Just let me know your thoughts.
[....................snip....................]
--- /usr/src/usr.bin/tput/tput.c.orig Fri Jan 16 07:40:13 2015
+++ /usr/src/usr.bin/tput/tput.c Sat Nov 21 12:26:13 2015
@@ -190,47 +190,30 @@
process(char *cap, char *str, char **argv)
{
char *cp, *s, *nargv[9];
- int arg_need, popcount, i;
+ int arg_need, i;
/* Count how many values we need for this capability. */
- for (cp = str, arg_need = popcount = 0; *cp != '\0'; cp++) {
+ for (cp = str, arg_need = 0; *cp != '\0'; cp++) {
if (*cp == '%') {
switch (*++cp) {
case '%':
cp++;
break;
case 'i':
- if (popcount < 2)
- popcount = 2;
+ if (arg_need < 2)
+ arg_need = 2;
break;
case 'p':
cp++;
- if (isdigit((unsigned char)cp[1]) &&
- popcount < cp[1] - '0')
- popcount = cp[1] - '0';
+ if (isdigit((unsigned char)cp[0]) &&
+ arg_need < cp[0] - '0')
+ arg_need = cp[0] - '0';
break;
- case 'd':
- case 's':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '.':
- case '+':
- arg_need++;
- break;
default:
break;
}
}
}
- arg_need = MAXIMUM(arg_need, popcount);
if (arg_need > 9)
errx(2, "too many arguments (%d) for capability `%s'",
arg_need, cap);
[....................snip....................]
[1] http://marc.info/?l=openbsd-misc&m=144800414402238&w=2
--
Alessandro DE LAURENZIS
[mailto:[email protected]]
LinkedIn: http://it.linkedin.com/in/delaurenzis