Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: echoti and number of arguments

On Mon, May 19, 2003 at 11:28:05AM +0100, Peter Stephenson wrote:
> Stephane CHAZELAS wrote:
> > I've noticed that the number of arguments was checked with
> > echoti. It's not a good idea.
> I think we need a configure test to make sure tparm() can take nine
> arguments to make sure we don't get into compatibility problems.  That
> will depend on various curses-style things, c.f terminfo.mdd.

More than that, tparm can take 0 to 9 parameters, which can be
of type "int" or "char*" and it's the responsability of the
caller to provide enough arguments and of the right type.

For instance

TERM=hpterm echoti pfx 1 "test"

Should call

tputs(tparm(tigetstr("pfx"), 1, "test"),1,putraw)

and to know that the second parameter is not a number, well, two

1- parse tigetstr("pfx") => hard to do and redondant with
   what tparm() already does.

2- hard code the few existing capabilities that accept
   non-integers (that's what ncurses' tput(1) does using this
	TD(Num_Str,     "pkey_key",     "pfkey",        "pk"),
        TD(Num_Str,     "pkey_local",   "pfloc",        "pl"),
        TD(Num_Str,     "pkey_xmit",    "pfx",          "px"),
        TD(Num_Str,     "plab_norm",    "pln",          "pn"),
        TD(Num_Str_Str, "pkey_plab",    "pfxl",         "xl"),   
   The problem with that approach is the lack of extensibility.
   But, for the probably limited usage of echoti in zsh, that's
   probably far enough (and there already are hardcoded capnames
   in Modules/terminfo.c).
For other capabilities, tparm() should be called with 9 numeric
arguments (non-provided ones defaulting to 0).

Note that actually zsh's "bin_echoti" is quite bogus. I've spent
several minutes wondering how the 
"tputs(tparm(t, atoi(*argv)), num, putraw)" could work with
"cup" while we are actually passing only one parameter to
tparm(). It seems to be due to some side effect of the va_list
processing (I guess tparm() actually takes "num" as its second
parameter somewhere on some stack), if I change it to
z= tparm(t, atoi(*argv)); tputs(z, num, putraw), it doesn't work

Note that there are problems with echotc too when libtermcap is
ncurses. For instance, when you do a tgetstr("AB"), you actually
get the terminfo entry for "setab", in terminfo format. So, the
routine used to count the number of expected arguments doesn't
work either (as you don't have a termcap format). Note that
tcsh's echotc is fooled on that one too.

$ echotc AB 1
echotc: not enough arguments

(my setab is \E[%?%p1%{8}%<%t%p1%'('%+%e%p1%{92}%+%;%dm, which
anyway cannot be mapped to termcap format).


Messages sorted by: Reverse Date, Date, Thread, Author