From: Clint Adams <clint@zsh.org>
To: Peter Stephenson <pws@csr.com>
Cc: zsh-workers@sunsite.dk
Subject: Re: some unicode issues [was Re: PATCH: fix 4, was Re: unpatch: metafying zle line]
Date: Mon, 15 Aug 2005 13:15:21 -0400 [thread overview]
Message-ID: <20050815171521.GA30174@scowler.net> (raw)
In-Reply-To: <200508151513.j7FFDmYU030329@news01.csr.com>
> Display width has not yet been looked at all. It would be good if
> someone did.
I made a huge mess, but this part of it may be useful.
--- orig/Src/Zle/zle.h
+++ mod/Src/Zle/zle.h
@@ -58,6 +58,11 @@
#define ZS_strcpy wcscpy
#define ZS_strncpy wcsncpy
#define ZS_strncmp wcsncmp
+#define ZS_zarrdup wcs_zarrdup
+#define ZS_width wcslen
+#define ZS_strchr wcschr
+#define ZS_zputs wcs_zputs
+#define ZS_nicewidth wcs_niceztrlen
#define ZC_iblank iswspace
#define ZC_icntrl iswcntrl
@@ -89,6 +94,11 @@
#define ZS_memmove memmove
#define ZS_memset memset
#define ZS_memcmp memcmp
+#define ZS_zarrdup zarrdup
+#define ZS_width ztrlen
+#define ZS_strchr strchr
+#define ZS_zputs zputs
+#define ZS_nicewidth niceztrlen
#ifdef __GNUC__
static inline size_t ZS_strlen(ZLE_STRING_T s)
--- orig/Src/string.c
+++ mod/Src/string.c
@@ -54,6 +54,22 @@
return t;
}
+#ifdef ZLE_UNICODE_SUPPORT
+/**/
+mod_export wchar_t *
+wcs_ztrdup(const wchar_t *s)
+{
+ wchar_t *t;
+
+ if (!s)
+ return NULL;
+ t = (wchar_t *)zalloc(wcslen((wchar_t *)s) + 1);
+ wcscpy(t, s);
+ return t;
+}
+#endif /* ZLE_UNICODE_SUPPORT */
+
+
/* concatenate s1, s2, and s3 in dynamically allocated buffer */
/**/
--- orig/Src/utils.c
+++ mod/Src/utils.c
@@ -243,6 +243,46 @@
return buf;
}
+#ifdef ZLE_UNICODE_SUPPORT
+/**/
+mod_export wchar_t *
+wcs_nicechar(wint_t c)
+{
+ static wchar_t buf[6];
+ wchar_t *s = buf;
+ if (iswprint(c))
+ goto done;
+ if (c > 0x80) {
+ if (isset(PRINTEIGHTBIT))
+ goto done;
+ *s++ = '\\';
+ *s++ = 'M';
+ *s++ = '-';
+ c &= 0x7f;
+ if(iswprint(c))
+ goto done;
+ }
+ if (c == 0x7f) {
+ *s++ = '^';
+ c = '?';
+ } else if (c == '\n') {
+ *s++ = '\\';
+ c = 'n';
+ } else if (c == '\t') {
+ *s++ = '\\';
+ c = 't';
+ } else if (c < 0x20) {
+ *s++ = '^';
+ c += 0x40;
+ }
+ done:
+ *s++ = c;
+ *s = 0;
+ return buf;
+}
+#endif /* ZLE_UNICODE_SUPPORT */
+
+
/* Output a string's visible representation. */
#if 0 /**/
@@ -2453,6 +2493,21 @@
return y;
}
+#ifdef ZLE_UNICODE_SUPPORT
+/**/
+mod_export wchar_t **
+wcs_zarrdup(wchar_t **s)
+{
+ wchar_t **x, **y;
+
+ y = x = (wchar_t **) zalloc(sizeof(wchar_t *) * (arrlen((char **)s) + 1));
+
+ while ((*x++ = wcs_ztrdup(*s++)));
+
+ return y;
+}
+#endif /* ZLE_UNICODE_SUPPORT */
+
/**/
static char *
spname(char *oldname)
@@ -3051,6 +3106,29 @@
return 0;
}
+#ifdef ZLE_UNICODE_SUPPORT
+/**/
+mod_export int
+wcs_zputs(wchar_t const *s, FILE *stream)
+{
+ wint_t c;
+
+ while (*s) {
+ if (*s == Meta)
+ c = *++s ^ 32;
+ else if(itok(*s)) {
+ s++;
+ continue;
+ } else
+ c = *s;
+ s++;
+ if (fputwc(c, stream) == WEOF)
+ return EOF;
+ }
+ return 0;
+}
+#endif /* ZLE_UNICODE_SUPPORT */
+
/* Create a visibly-represented duplicate of a string. */
/**/
@@ -3137,6 +3215,29 @@
return l;
}
+#ifdef ZLE_UNICODE_SUPPORT
+/**/
+mod_export size_t
+wcs_nicewidth(wchar_t const *s)
+{
+ size_t l = 0;
+ wint_t c;
+
+ while ((c = *s++)) {
+ if (itok(c)) {
+ if (c <= (wint_t)Comma)
+ c = ztokens[c - Pound];
+ else
+ continue;
+ }
+ if (c == Meta)
+ c = *s++ ^ 32;
+ l += wcswidth(wcs_nicechar(c), 6);
+ }
+ return l;
+}
+#endif /* ZLE_UNICODE_SUPPORT */
+
/* check for special characters in the string */
/**/
next prev parent reply other threads:[~2005-08-15 17:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-12 10:21 PATCH: fix 4, was Re: unpatch: metafying zle line Peter Stephenson
2005-08-12 19:50 ` David Gómez
2005-08-14 15:55 ` Andrey Borzenkov
2005-08-15 17:22 ` [PATCH] fix zrefresh recursive completion call Andrey Borzenkov
2005-08-15 9:57 ` PATCH: fix 4, was Re: unpatch: metafying zle line Peter Stephenson
2005-08-15 15:06 ` some unicode issues [was Re: PATCH: fix 4, was Re: unpatch: metafying zle line] Clint Adams
2005-08-15 15:13 ` Peter Stephenson
2005-08-15 15:17 ` Peter Stephenson
2005-08-15 17:15 ` Clint Adams [this message]
2005-08-15 17:20 ` Peter Stephenson
2005-08-15 17:44 ` Clint Adams
2005-08-16 0:45 ` Clint Adams
2005-08-16 2:02 ` Wayne Davison
2005-08-18 9:56 ` Peter Stephenson
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=20050815171521.GA30174@scowler.net \
--to=clint@zsh.org \
--cc=pws@csr.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).