zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane CHAZELAS <Stephane_CHAZELAS@yahoo.fr>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: echoti and number of arguments
Date: Sat, 17 May 2003 10:01:16 +0200	[thread overview]
Message-ID: <20030517100115.A128@pcchazelas.free.fr> (raw)

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


             reply	other threads:[~2003-05-17  8:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-17  8:01 Stephane CHAZELAS [this message]
2003-05-17  8:34 ` Stephane CHAZELAS
2003-05-19 10:28 ` Peter Stephenson
2003-05-19 14:51   ` Stephane CHAZELAS
2003-06-24 18:04     ` PATCH: " Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030517100115.A128@pcchazelas.free.fr \
    --to=stephane_chazelas@yahoo.fr \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).