summaryrefslogtreecommitdiffstats
path: root/RichString.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-11-19 23:17:52 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-11-19 23:17:52 -0200
commit9faf4938b8195a0fb5d62cf1702f9f5c07523031 (patch)
tree84732ab7ef1bf66d55feefaf97216ccfc9bf2fad /RichString.c
parent300af4b829c6552d7efdfcde43220cf318b5a265 (diff)
Refactored key handlers.
Made the logic more modular, hopefully easier to follow, and removed repeated code. Plus, some optimization in RichString code.
Diffstat (limited to 'RichString.c')
-rw-r--r--RichString.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/RichString.c b/RichString.c
index 34720c1b..fb2f2578 100644
--- a/RichString.c
+++ b/RichString.c
@@ -10,7 +10,7 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <string.h>
-#define RICHSTRING_MAXLEN 300
+#define RICHSTRING_MAXLEN 350
/*{
#include "config.h"
@@ -52,8 +52,8 @@ in the source distribution for its full text.
typedef struct RichString_ {
int chlen;
- CharType chstr[RICHSTRING_MAXLEN+1];
CharType* chptr;
+ CharType chstr[RICHSTRING_MAXLEN+1];
} RichString;
}*/
@@ -64,7 +64,7 @@ typedef struct RichString_ {
#define charBytes(n) (sizeof(CharType) * (n))
-static inline void RichString_setLen(RichString* this, int len) {
+static void RichString_extendLen(RichString* this, int len) {
if (this->chlen <= RICHSTRING_MAXLEN) {
if (len > RICHSTRING_MAXLEN) {
this->chptr = malloc(charBytes(len+1));
@@ -83,6 +83,8 @@ static inline void RichString_setLen(RichString* this, int len) {
this->chlen = len;
}
+#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
+
#ifdef HAVE_LIBNCURSESW
static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) {
@@ -92,10 +94,11 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
return;
int newLen = from + len;
RichString_setLen(this, newLen);
- 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;
+ CharType* c = &(this->chptr[i]);
+ c->attr = attrs;
+ c->chars[0] = data[j];
+ c->chars[1] = 0;
}
this->chptr[newLen].chars[0] = 0;
}
@@ -171,4 +174,4 @@ void RichString_appendn(RichString* this, int attrs, const char* data, int len)
void RichString_write(RichString* this, int attrs, const char* data) {
RichString_writeFrom(this, attrs, data, 0, strlen(data));
-}
+} \ No newline at end of file

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