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 <james.warner@comcast.net>
This commit is contained in:
parent
fba7a919fb
commit
ac76afee36
62
top/top.c
62
top/top.c
@ -668,16 +668,16 @@ static char UTF8_tab[] = {
|
|||||||
* Determine difference between total bytes versus printable
|
* Determine difference between total bytes versus printable
|
||||||
* characters in that passed, potentially multi-byte, string */
|
* characters in that passed, potentially multi-byte, string */
|
||||||
static int utf8_delta (const char *str) {
|
static int utf8_delta (const char *str) {
|
||||||
const unsigned char *p = (const unsigned char *)str;
|
const unsigned char *p = (const unsigned char *)str;
|
||||||
int clen, cnum = 0;
|
int clen, cnum = 0;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
// -1 represents a decoding error, pretend it's untranslated ...
|
// -1 represents a decoding error, pretend it's untranslated ...
|
||||||
if (0 > (clen = UTF8_tab[*p])) return 0;
|
if (0 > (clen = UTF8_tab[*p])) return 0;
|
||||||
p += clen;
|
p += clen;
|
||||||
++cnum;
|
++cnum;
|
||||||
}
|
}
|
||||||
return (int)((const char *)p - str) - cnum;
|
return (int)((const char *)p - str) - cnum;
|
||||||
} // end: utf8_delta
|
} // end: utf8_delta
|
||||||
|
|
||||||
|
|
||||||
@ -685,16 +685,18 @@ static int utf8_delta (const char *str) {
|
|||||||
* Determine a physical end within a potential multi-byte string
|
* Determine a physical end within a potential multi-byte string
|
||||||
* where maximum printable chars could be accommodated in width */
|
* where maximum printable chars could be accommodated in width */
|
||||||
static int utf8_embody (const char *str, int width) {
|
static int utf8_embody (const char *str, int width) {
|
||||||
const unsigned char *p = (const unsigned char *)str;
|
const unsigned char *p = (const unsigned char *)str;
|
||||||
int clen, cnum = 0;
|
int clen, cnum = 0;
|
||||||
|
|
||||||
while (*p) {
|
if (width > 0) {
|
||||||
// -1 represents a decoding error, pretend it's untranslated ...
|
while (*p) {
|
||||||
if (0 > (clen = UTF8_tab[*p])) return width;
|
// -1 represents a decoding error, pretend it's untranslated ...
|
||||||
p += clen;
|
if (0 > (clen = UTF8_tab[*p])) return width;
|
||||||
if (++cnum >= width) break;
|
p += clen;
|
||||||
}
|
if (++cnum >= width) break;
|
||||||
return (int)((const char *)p - str);
|
}
|
||||||
|
}
|
||||||
|
return (int)((const char *)p - str);
|
||||||
} // end: utf8_embody
|
} // end: utf8_embody
|
||||||
|
|
||||||
|
|
||||||
@ -717,19 +719,19 @@ static const char *utf8_justify (const char *str, int width, int justr) {
|
|||||||
* Returns a physical or logical column number given a
|
* Returns a physical or logical column number given a
|
||||||
* multi-byte string and a target column value */
|
* multi-byte string and a target column value */
|
||||||
static int utf8_proper_col (const char *str, int col, int tophysical) {
|
static int utf8_proper_col (const char *str, int col, int tophysical) {
|
||||||
const unsigned char *p = (const unsigned char *)str;
|
const unsigned char *p = (const unsigned char *)str;
|
||||||
int clen, tlen = 0, cnum = 0;
|
int clen, tlen = 0, cnum = 0;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
// -1 represents a decoding error, don't encourage repositioning ...
|
// -1 represents a decoding error, don't encourage repositioning ...
|
||||||
if (0 > (clen = UTF8_tab[*p])) return col;
|
if (0 > (clen = UTF8_tab[*p])) return col;
|
||||||
if (cnum + 1 > col && tophysical) break;
|
if (cnum + 1 > col && tophysical) break;
|
||||||
p += clen;
|
p += clen;
|
||||||
tlen += clen;
|
tlen += clen;
|
||||||
if (tlen > col && !tophysical) break;
|
if (tlen > col && !tophysical) break;
|
||||||
++cnum;
|
++cnum;
|
||||||
}
|
}
|
||||||
return tophysical ? tlen : cnum;
|
return tophysical ? tlen : cnum;
|
||||||
} // end: utf8_proper_col
|
} // end: utf8_proper_col
|
||||||
|
|
||||||
/*###### Misc Color/Display support ####################################*/
|
/*###### Misc Color/Display support ####################################*/
|
||||||
|
Loading…
Reference in New Issue
Block a user