From 1761a3b14674350f51a074f104a4b141b6c0caa8 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Tue, 25 Mar 2003 05:33:18 +0000 Subject: users/5986, 18380: arg support for echoti builtin. --- Src/Modules/terminfo.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'Src/Modules/terminfo.c') diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c index 744defc8c..c8e5c23fb 100644 --- a/Src/Modules/terminfo.c +++ b/Src/Modules/terminfo.c @@ -59,8 +59,8 @@ static Param terminfo_pm; static int bin_echoti(char *name, char **argv, Options ops, int func) { - char *s, *t; - int num; + char *s, *t, *u; + int num, argct; s = *argv++; /* This depends on the termcap stuff in init.c */ @@ -92,9 +92,28 @@ bin_echoti(char *name, char **argv, Options ops, int func) zwarnnam(name, "no such terminfo capability: %s", s, 0); return 1; } - - tputs(t, 1, putchar); + /* count the number of arguments required */ + for (argct = 0, u = t; *u; u++) + if (*u == '%') { + if (u++, (*u == 'd' || *u == '2' || *u == '3' || *u == '.' || + *u == '+')) + argct++; + } + /* check that the number of arguments provided is correct */ + if (arrlen(argv) != argct) { + zwarnnam(name, (arrlen(argv) < argct) ? "not enough arguments" : + "too many arguments", NULL, 0); + return 1; + } + /* output string, through the proper termcap functions */ + if (!argct) + tputs(t, 1, putraw); + else { + num = (argv[1]) ? atoi(argv[1]) : atoi(*argv); + tputs(tparm(t, atoi(*argv)), num, putraw); + } return 0; + } /**/ -- cgit 1.4.1