zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: printf ... \'X
Date: Sun, 10 Sep 2006 20:08:45 +0100	[thread overview]
Message-ID: <200609101908.k8AJ8jG8019141@pwslaptop.csr.com> (raw)

  printf "%d\n" \'X

is yet another way of getting the character index of character X.  I'm
guessing it's more useful for it to handle wide characters rather than
outputting the value of the first byte in a multibyte character.

Goodness knows whether string width in printf should take account of
wide character widths for %s and %b, but my guess is it should.  I
haven't done that.  In fact, I see I haven't fixed up character widths
for dopadding() yet, either.

By the way, I think the handling of "curarg" in the printf code doesn't
generally take account of the fact that curarg is unmetafied with length
curlen, right?  (This fact isn't particularly convenient here but is
pretty much inevitable given the use of getkeystring().)  I've made it
do so in this case but haven't altered the other cases.  (In the first
hunk it already does, that's just a whitespace change.)


Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.161
diff -u -r1.161 builtin.c
--- Src/builtin.c	10 Sep 2006 18:10:49 -0000	1.161
+++ Src/builtin.c	10 Sep 2006 19:00:48 -0000
@@ -3938,7 +3938,8 @@
 		    char *b;
 		    int l;
 		    if (*c == 'b') {
-			b = getkeystring(metafy(curarg, curlen, META_USEHEAP), &l,
+			b = getkeystring(metafy(curarg, curlen, META_USEHEAP),
+					 &l,
 					 OPT_ISSET(ops,'b') ? GETKEYS_BINDKEY :
 					 GETKEYS_PRINTF, &nnl);
 		    } else {
@@ -4004,11 +4005,25 @@
 
 	    if (type > 0) {
 		if (curarg && (*curarg == '\'' || *curarg == '"' )) {
+		    convchar_t cc;
+#ifdef MULTIBYTE_SUPPORT
+		    if (isset(MULTIBYTE)) {
+			mb_metacharinit();
+			(void)mb_metacharlenconv(metafy(curarg+1, curlen-1,
+							META_USEHEAP), &cc);
+		    }
+		    else
+			cc = WEOF;
+		    if (cc == WEOF)
+			cc = (curlen > 1) ? STOUC(curarg[1]) : 0;
+#else
+		    cc = (curlen > 1) ? STOUC(curarg[1]) : 0;
+#endif
 		    if (type == 2) {
-			doubleval = STOUC(curarg[1]);
+			doubleval = cc;
 			print_val(doubleval);
 		    } else {
-			intval = STOUC(curarg[1]);
+			intval = cc;
 			print_val(intval);
 		    }
 		} else {


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


                 reply	other threads:[~2006-09-10 19:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200609101908.k8AJ8jG8019141@pwslaptop.csr.com \
    --to=p.w.stephenson@ntlworld.com \
    --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).