diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:33 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:33 +0200 |
commit | f75ab6d2c11e8a8e18191b087564aedebbeb96c5 (patch) | |
tree | 2a046e11678e798f3f9c7f7af4f9ac205c8d2731 /RichString.c | |
parent | 2004bbc3ef28ada3acca05f5d5fa9108121a6784 (diff) | |
download | debian_htop-f75ab6d2c11e8a8e18191b087564aedebbeb96c5.tar.gz debian_htop-f75ab6d2c11e8a8e18191b087564aedebbeb96c5.tar.bz2 debian_htop-f75ab6d2c11e8a8e18191b087564aedebbeb96c5.zip |
Imported Upstream version 1.0.3upstream/1.0.3
Diffstat (limited to 'RichString.c')
-rw-r--r-- | RichString.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/RichString.c b/RichString.c index eca2293..34720c1 100644 --- a/RichString.c +++ b/RichString.c @@ -21,6 +21,8 @@ in the source distribution for its full text. #include <ncursesw/curses.h> #elif HAVE_NCURSES_NCURSES_H #include <ncurses/ncurses.h> +#elif HAVE_NCURSES_CURSES_H +#include <ncurses/curses.h> #elif HAVE_NCURSES_H #include <ncurses.h> #elif HAVE_CURSES_H @@ -83,16 +85,15 @@ static inline void RichString_setLen(RichString* this, int len) { #ifdef HAVE_LIBNCURSESW -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { +static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { wchar_t data[len+1]; len = mbstowcs(data, data_c, len); if (len<0) return; - int oldLen = this->chlen; - int newLen = len + oldLen; + int newLen = from + len; RichString_setLen(this, newLen); - for (int i = oldLen, j = 0; i < newLen; i++, j++) { - memset(&this->chptr[i], 0, sizeof(this->chptr[i])); + memset(&this->chptr[from], 0, sizeof(CharType) * (newLen - from)); + for (int i = from, j = 0; i < newLen; i++, j++) { this->chptr[i].chars[0] = data[j]; this->chptr[i].attr = attrs; } @@ -120,11 +121,10 @@ int RichString_findChar(RichString* this, char c, int start) { #else -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { - int oldLen = this->chlen; - int newLen = len + oldLen; +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 = oldLen, j = 0; i < newLen; i++, j++) + for (int i = from, j = 0; i < newLen; i++, j++) this->chptr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs; this->chptr[newLen] = 0; } @@ -154,17 +154,21 @@ void RichString_prune(RichString* this) { free(this->chptr); this->chptr = this->chstr; this->chlen = 0; + RichString_setChar(this, 0, 0); } void RichString_setAttr(RichString* this, int attrs) { RichString_setAttrn(this, attrs, 0, this->chlen - 1); } -inline void RichString_append(RichString* this, int attrs, const char* data) { - RichString_appendn(this, attrs, data, strlen(data)); +void RichString_append(RichString* this, int attrs, const char* data) { + RichString_writeFrom(this, attrs, data, this->chlen, strlen(data)); +} + +void RichString_appendn(RichString* this, int attrs, const char* data, int len) { + RichString_writeFrom(this, attrs, data, this->chlen, len); } void RichString_write(RichString* this, int attrs, const char* data) { - RichString_setLen(this, 0); - RichString_appendn(this, attrs, data, strlen(data)); + RichString_writeFrom(this, attrs, data, 0, strlen(data)); } |