aboutsummaryrefslogtreecommitdiffstats
path: root/RichString.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:22 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:22 +0200
commitc74c38760df69bb87e93dff18cf91464e5d02f37 (patch)
treeee2a19a0ef3a808bdfc8c1e6a00e96d79966dcb0 /RichString.c
parent9379132a8234eeedf62d37ef57713e52c12db6ab (diff)
downloaddebian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.tar.gz
debian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.tar.bz2
debian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.zip
Imported Upstream version 0.8.1upstream/0.8.1
Diffstat (limited to 'RichString.c')
-rw-r--r--RichString.c100
1 files changed, 84 insertions, 16 deletions
diff --git a/RichString.c b/RichString.c
index 2cc7d17..c397f3f 100644
--- a/RichString.c
+++ b/RichString.c
@@ -1,12 +1,20 @@
#include "RichString.h"
+#ifndef CONFIG_H
+#define CONFIG_H
+#include "config.h"
+#endif
+
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include "debug.h"
#include <assert.h>
+#ifdef HAVE_LIBNCURSESW
+#include <wchar.h>
+#endif
#define RICHSTRING_MAXLEN 300
@@ -15,9 +23,23 @@
#define RichString_init(this) (this)->len = 0
#define RichString_initVal(this) (this).len = 0
+#ifdef HAVE_LIBNCURSESW
+#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, this.chstr)
+#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, this.chstr + off, n)
+#define RichString_getCharVal(this, i) (this.chstr[i].chars[0] & 255)
+#else
+#define RichString_printVal(this, y, x) mvaddchstr(y, x, this.chstr)
+#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, this.chstr + off, n)
+#define RichString_getCharVal(this, i) (this.chstr[i])
+#endif
+
typedef struct RichString_ {
int len;
+#ifdef HAVE_LIBNCURSESW
+ cchar_t chstr[RICHSTRING_MAXLEN+1];
+#else
chtype chstr[RICHSTRING_MAXLEN+1];
+#endif
} RichString;
}*/
@@ -26,37 +48,83 @@ typedef struct RichString_ {
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
-inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
+#ifdef HAVE_LIBNCURSESW
+
+inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) {
+ wchar_t data[RICHSTRING_MAXLEN];
+ len = mbstowcs(data, data_c, RICHSTRING_MAXLEN);
+ if (len<0)
+ return;
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
- for (int i = this->len, j = 0; i < last; i++, j++)
- this->chstr[i] = data[j] | attrs;
- this->chstr[last] = 0;
+ for (int i = this->len, j = 0; i < last; i++, j++) {
+ memset(&this->chstr[i], 0, sizeof(this->chstr[i]));
+ this->chstr[i].chars[0] = data[j];
+ this->chstr[i].attr = attrs;
+ }
+ this->chstr[last].chars[0] = 0;
this->len = last;
}
-inline void RichString_append(RichString* this, int attrs, char* data) {
- RichString_appendn(this, attrs, data, strlen(data));
+inline void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
+ cchar_t* ch = this->chstr + start;
+ for (int i = start; i <= finish; i++) {
+ ch->attr = attrs;
+ ch++;
+ }
}
-void RichString_write(RichString* this, int attrs, char* data) {
- RichString_init(this);
- RichString_append(this, attrs, data);
+int RichString_findChar(RichString *this, char c, int start) {
+ wchar_t wc = btowc(c);
+ cchar_t* ch = this->chstr + start;
+ for (int i = start; i < this->len; i++) {
+ if (ch->chars[0] == wc)
+ return i;
+ ch++;
+ }
+ return -1;
}
-void RichString_setAttr(RichString *this, int attrs) {
- chtype* ch = this->chstr;
- for (int i = 0; i < this->len; i++) {
+#else
+
+inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) {
+ int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
+ for (int i = this->len, j = 0; i < last; i++, j++)
+ this->chstr[i] = data_c[j] | attrs;
+ this->chstr[last] = 0;
+ this->len = last;
+}
+
+void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
+ chtype* ch = this->chstr + start;
+ for (int i = start; i <= finish; i++) {
*ch = (*ch & 0xff) | attrs;
ch++;
}
}
-void RichString_applyAttr(RichString *this, int attrs) {
- chtype* ch = this->chstr;
- for (int i = 0; i < this->len; i++) {
- *ch |= attrs;
+int RichString_findChar(RichString *this, char c, int start) {
+ chtype* ch = this->chstr + start;
+ for (int i = start; i < this->len; i++) {
+ if ((*ch & 0xff) == c)
+ return i;
ch++;
}
+ return -1;
+}
+
+#endif
+
+void RichString_setAttr(RichString *this, int attrs) {
+ RichString_setAttrn(this, attrs, 0, this->len - 1);
+}
+
+inline void RichString_append(RichString* this, int attrs, char* data) {
+ RichString_appendn(this, attrs, data, strlen(data));
+}
+
+void RichString_write(RichString* this, int attrs, char* data) {
+ RichString_init(this);
+ RichString_append(this, attrs, data);
}
RichString RichString_quickString(int attrs, char* data) {

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