zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: printf ... \'X
@ 2006-09-10 19:08 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2006-09-10 19:08 UTC (permalink / raw)
  To: Zsh hackers list

  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/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-09-10 19:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-10 19:08 PATCH: printf ... \'X Peter Stephenson

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).