From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2131 invoked from network); 17 May 2003 08:05:39 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 17 May 2003 08:05:39 -0000 Received: (qmail 22180 invoked by alias); 17 May 2003 08:05:34 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18544 Received: (qmail 22169 invoked from network); 17 May 2003 08:05:33 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 17 May 2003 08:05:33 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [213.228.0.176] by sunsite.dk (MessageWall 1.0.8) with SMTP; 17 May 2003 8:5:33 -0000 Received: from pcchazelas.free.fr (grenoble-1-a7-62-147-72-98.dial.proxad.net [62.147.72.98]) by postfix4-2.free.fr (Postfix) with ESMTP id 00CD7C11E for ; Sat, 17 May 2003 10:05:32 +0200 (CEST) Received: (from chazelas@localhost) by pcchazelas.free.fr (8.9.3/8.9.3) id KAA00979 for zsh-workers@sunsite.dk; Sat, 17 May 2003 10:01:16 +0200 Date: Sat, 17 May 2003 10:01:16 +0200 From: Stephane CHAZELAS To: Zsh hackers list Subject: echoti and number of arguments Message-ID: <20030517100115.A128@pcchazelas.free.fr> Mail-Followup-To: Zsh hackers list Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.3.14i I've noticed that the number of arguments was checked with echoti. It's not a good idea. Mainly because it's hard or even impossible to guess that number from the terminfo string. For instance, "sgr" accepts 9 parameters, but terminals don't all support the 9 fields (for instance, xterm-r5 has: sgr=\E[%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;m, only fields 1 to 6 are supported, but it's valid to pass 9 parameters). If you look at how ncurses' tput works: if no argument is passed, the string is returned asis; if at least one argument is provided, % escape sequences are handled, and 9 parameters are used (if some are used but not provided, they default to 0 or "" depending on their type). Then, the way the argument count is checked in zsh is nonsense: /* 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++; } Those flags have nothing to do with the argument count. %d may be provided twice even when there's only one argument. For instance, setf on xterm-16color has two %d but takes only one argument, u6 (cursor position report) has two %d but doesn't take any argument. sgr takes 9 arguments but argct above would be zero. >>From terminfo(5): %% outputs `%' %[[:]flags][width[.precision]][doxXs] as in printf, flags are [-+#] and space %c print pop() like %c in printf() %s print pop() like %s in printf() %p[1-9] push i'th parm %P[a-z] set dynamic variable [a-z] to pop() %g[a-z] get dynamic variable [a-z] and push it %P[A-Z] set static variable [a-z] to pop() %g[A-Z] get static variable [a-z] and push it %'c' char constant c %{nn} integer constant nn %l push strlen(pop) %+ %- %* %/ %m arithmetic (%m is mod): push(pop() op pop()) %& %| %^ bit operations: push(pop() op pop()) %= %> %< logical operations: push(pop() op pop()) %A, %O logical and & or operations (for conditionals) %! %~ unary operations push(op pop()) %i add 1 to first two parameters (for ANSI terminals) %? expr %t thenpart %e elsepart %; if-then-else, %e elsepart is optional. else-if's are possible a la Algol 68: %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %; ci are conditions, bi are bodies. So, to my mind, echoti should only check that there are no more than 9 parameters. -- Stéphane