Commit f454ee26 authored by Peter Stephenson's avatar Peter Stephenson

35114: zformat -a multibyte char widths

parent 29fdde5f
2015-05-13 Peter Stephenson <p.w.stephenson@ntlworld.com> 2015-05-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 35114: Src/Modules/zutil.c: zformat -a multibyte char widths.
* Christian Hesse: 35107: Completion/Unix/Command/_ip: new ip * Christian Hesse: 35107: Completion/Unix/Command/_ip: new ip
options. options.
......
...@@ -914,6 +914,9 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) ...@@ -914,6 +914,9 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
{ {
char **ap, *cp; char **ap, *cp;
int nbc = 0, colon = 0, pre = 0, suf = 0; int nbc = 0, colon = 0, pre = 0, suf = 0;
#ifdef MULTIBYTE_SUPPORT
int prechars = 0;
#endif /* MULTIBYTE_SUPPORT */
for (ap = args + 2; *ap; ap++) { for (ap = args + 2; *ap; ap++) {
for (nbc = 0, cp = *ap; *cp && *cp != ':'; cp++) for (nbc = 0, cp = *ap; *cp && *cp != ':'; cp++)
...@@ -921,10 +924,23 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) ...@@ -921,10 +924,23 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
cp++, nbc++; cp++, nbc++;
if (*cp == ':' && cp[1]) { if (*cp == ':' && cp[1]) {
int d; int d;
#ifdef MULTIBYTE_SUPPORT
int dchars = 0;
#endif /* MULTIBYTE_SUPPORT */
colon++; colon++;
if ((d = cp - *ap - nbc) > pre) if ((d = cp - *ap - nbc) > pre)
pre = d; pre = d;
#ifdef MULTIBYTE_SUPPORT
if (isset(MULTIBYTE)) {
*cp = '\0';
dchars = MB_METASTRWIDTH(*ap) - nbc;
*cp = ':';
} else
dchars = d;
if (dchars > prechars)
prechars = dchars;
#endif /* MULTIBYTE_SUPPORT */
if ((d = strlen(cp + 1)) > suf) if ((d = strlen(cp + 1)) > suf)
suf = d; suf = d;
} }
...@@ -937,8 +953,10 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) ...@@ -937,8 +953,10 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
ret = (char **) zalloc((arrlen(args + 2) + 1) * ret = (char **) zalloc((arrlen(args + 2) + 1) *
sizeof(char *)); sizeof(char *));
#ifndef MULTIBYTE_SUPPORT
memcpy(buf + pre, args[1], sl); memcpy(buf + pre, args[1], sl);
suf = pre + sl; suf = pre + sl;
#endif /* MULTIBYTE_SUPPORT */
for (rp = ret, ap = args + 2; *ap; ap++) { for (rp = ret, ap = args + 2; *ap; ap++) {
copy = dupstring(*ap); copy = dupstring(*ap);
...@@ -950,9 +968,27 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) ...@@ -950,9 +968,27 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
oldc = *cpp; oldc = *cpp;
*cpp = '\0'; *cpp = '\0';
if (((cpp == cp && oldc == ':') || *cp == ':') && cp[1]) { if (((cpp == cp && oldc == ':') || *cp == ':') && cp[1]) {
#ifdef MULTIBYTE_SUPPORT
int rempad;
char *ptr;
memcpy(buf, copy, (cpp - copy));
*cp = '\0';
if (isset(MULTIBYTE))
rempad = prechars - MB_METASTRWIDTH(copy);
else
rempad = prechars - strlen(copy);
ptr = buf + (cpp - copy);
if (rempad)
memset(ptr, ' ', rempad);
ptr += rempad;
memcpy(ptr, args[1], sl);
ptr += sl;
strcpy(ptr, cp + 1);
#else /* MULTIBYTE_SUPPORT */
memset(buf, ' ', pre); memset(buf, ' ', pre);
memcpy(buf, copy, (cpp - copy)); memcpy(buf, copy, (cpp - copy));
strcpy(buf + suf, cp + 1); strcpy(buf + suf, cp + 1);
#endif /* MULTIBYTE_SUPPORT */
*rp++ = ztrdup(buf); *rp++ = ztrdup(buf);
} else } else
*rp++ = ztrdup(copy); *rp++ = ztrdup(copy);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment