From 65357c8c46154de4e4eca14075bfe5523bb5fc14 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 7 Dec 2020 10:26:01 +0100 Subject: New upstream version 3.0.3 --- RichString.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'RichString.c') diff --git a/RichString.c b/RichString.c index b97e34e..790c15a 100644 --- a/RichString.c +++ b/RichString.c @@ -1,17 +1,19 @@ /* htop - RichString.c (C) 2004,2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ #include "RichString.h" -#include "XAlloc.h" -#include "Macros.h" #include #include +#include "Macros.h" +#include "XUtils.h" + + #define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { @@ -34,15 +36,23 @@ static void RichString_extendLen(RichString* this, int len) { this->chlen = len; } -#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) +static void RichString_setLen(RichString* this, int len) { + if (len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { + RichString_setChar(this, len, 0); + this->chlen = len; + } else { + RichString_extendLen(this, len); + } +} #ifdef HAVE_LIBNCURSESW static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { - wchar_t data[len+1]; + wchar_t data[len + 1]; len = mbstowcs(data, data_c, len); if (len < 0) return; + int newLen = from + len; RichString_setLen(this, newLen); for (int i = from, j = 0; i < newLen; i++, j++) { @@ -70,13 +80,14 @@ int RichString_findChar(RichString* this, char c, int start) { return -1; } -#else +#else /* HAVE_LIBNCURSESW */ static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { int newLen = from + len; RichString_setLen(this, newLen); - for (int i = from, j = 0; i < newLen; i++, j++) - this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs; + for (int i = from, j = 0; i < newLen; i++, j++) { + this->chptr[i] = (((unsigned char)data_c[j]) >= 32 ? ((unsigned char)data_c[j]) : '?') | attrs; + } this->chptr[newLen] = 0; } @@ -99,7 +110,7 @@ int RichString_findChar(RichString* this, char c, int start) { return -1; } -#endif +#endif /* HAVE_LIBNCURSESW */ void RichString_prune(RichString* this) { if (this->chlen > RICHSTRING_MAXLEN) @@ -108,6 +119,15 @@ void RichString_prune(RichString* this) { this->chptr = this->chstr; } +void RichString_appendChr(RichString* this, char c, int count) { + int from = this->chlen; + int newLen = from + count; + RichString_setLen(this, newLen); + for (int i = from; i < newLen; i++) { + RichString_setChar(this, i, c); + } +} + void RichString_setAttr(RichString* this, int attrs) { RichString_setAttrn(this, attrs, 0, this->chlen - 1); } -- cgit v1.2.3