From 474f4da5d11d975c82fcfea9ad79d6a735821d62 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 6 Oct 2017 00:00:00 -0500 Subject: [PATCH] top: utf8 utils should observe indentation conventions Gosh, all this time we used indents of 4 spaces, not 3 spaces which were always the top standard indentation. [ and we made our 'utf8_embody' a little more robust ] Signed-off-by: Jim Warner --- top/top.c | 62 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/top/top.c b/top/top.c index 1554b251..1830803d 100644 --- a/top/top.c +++ b/top/top.c @@ -507,16 +507,16 @@ static char UTF8_tab[] = { * Determine difference between total bytes versus printable * characters in that passed, potentially multi-byte, string */ static int utf8_delta (const char *str) { - const unsigned char *p = (const unsigned char *)str; - int clen, cnum = 0; + const unsigned char *p = (const unsigned char *)str; + int clen, cnum = 0; - while (*p) { - // -1 represents a decoding error, pretend it's untranslated ... - if (0 > (clen = UTF8_tab[*p])) return 0; - p += clen; - ++cnum; - } - return (int)((const char *)p - str) - cnum; + while (*p) { + // -1 represents a decoding error, pretend it's untranslated ... + if (0 > (clen = UTF8_tab[*p])) return 0; + p += clen; + ++cnum; + } + return (int)((const char *)p - str) - cnum; } // end: utf8_delta @@ -524,16 +524,18 @@ static int utf8_delta (const char *str) { * Determine a physical end within a potential multi-byte string * where maximum printable chars could be accommodated in width */ static int utf8_embody (const char *str, int width) { - const unsigned char *p = (const unsigned char *)str; - int clen, cnum = 0; + const unsigned char *p = (const unsigned char *)str; + int clen, cnum = 0; - while (*p) { - // -1 represents a decoding error, pretend it's untranslated ... - if (0 > (clen = UTF8_tab[*p])) return width; - p += clen; - if (++cnum >= width) break; - } - return (int)((const char *)p - str); + if (width > 0) { + while (*p) { + // -1 represents a decoding error, pretend it's untranslated ... + if (0 > (clen = UTF8_tab[*p])) return width; + p += clen; + if (++cnum >= width) break; + } + } + return (int)((const char *)p - str); } // end: utf8_embody @@ -556,19 +558,19 @@ static const char *utf8_justify (const char *str, int width, int justr) { * Returns a physical or logical column number given a * multi-byte string and a target column value */ static int utf8_proper_col (const char *str, int col, int tophysical) { - const unsigned char *p = (const unsigned char *)str; - int clen, tlen = 0, cnum = 0; + const unsigned char *p = (const unsigned char *)str; + int clen, tlen = 0, cnum = 0; - while (*p) { - // -1 represents a decoding error, don't encourage repositioning ... - if (0 > (clen = UTF8_tab[*p])) return col; - if (cnum + 1 > col && tophysical) break; - p += clen; - tlen += clen; - if (tlen > col && !tophysical) break; - ++cnum; - } - return tophysical ? tlen : cnum; + while (*p) { + // -1 represents a decoding error, don't encourage repositioning ... + if (0 > (clen = UTF8_tab[*p])) return col; + if (cnum + 1 > col && tophysical) break; + p += clen; + tlen += clen; + if (tlen > col && !tophysical) break; + ++cnum; + } + return tophysical ? tlen : cnum; } // end: utf8_proper_col /*###### Misc Color/Display support ####################################*/