aboutsummaryrefslogtreecommitdiffstats
path: root/RichString.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /RichString.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'RichString.c')
-rw-r--r--RichString.c38
1 files changed, 29 insertions, 9 deletions
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 <stdlib.h>
#include <string.h>
+#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);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy