diff options
author | Eugene V. Lyubimkin <jackyf@debian.org> | 2014-05-01 13:16:56 +0300 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:34 +0200 |
commit | 43997d37137cc1e4a1a5be654aa16d4992045e34 (patch) | |
tree | b89a3360498e310adb64b337d849ea25aa0e51f0 /ListItem.c | |
parent | 51516557d375ac91e0a1a6f0525c3def1d3d79b0 (diff) | |
parent | f75ab6d2c11e8a8e18191b087564aedebbeb96c5 (diff) | |
download | debian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.tar.gz debian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.tar.bz2 debian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.zip |
Imported Debian patch 1.0.3-1debian/1.0.3-1
Diffstat (limited to 'ListItem.c')
-rw-r--r-- | ListItem.c | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -26,12 +26,6 @@ typedef struct ListItem_ { }*/ -#ifdef DEBUG -char* LISTITEM_CLASS = "ListItem"; -#else -#define LISTITEM_CLASS NULL -#endif - static void ListItem_delete(Object* cast) { ListItem* this = (ListItem*)cast; free(this->value); @@ -41,27 +35,34 @@ static void ListItem_delete(Object* cast) { static void ListItem_display(Object* cast, RichString* out) { ListItem* this = (ListItem*)cast; assert (this != NULL); + /* int len = strlen(this->value)+1; char buffer[len+1]; snprintf(buffer, len, "%s", this->value); - RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer); + */ + RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); } +ObjectClass ListItem_class = { + .display = ListItem_display, + .delete = ListItem_delete, + .compare = ListItem_compare +}; + ListItem* ListItem_new(const char* value, int key) { - ListItem* this = malloc(sizeof(ListItem)); - Object_setClass(this, LISTITEM_CLASS); - ((Object*)this)->display = ListItem_display; - ((Object*)this)->delete = ListItem_delete; + ListItem* this = AllocThis(ListItem); this->value = strdup(value); this->key = key; return this; } -void ListItem_append(ListItem* this, char* text) { - char* buf = malloc(strlen(this->value) + strlen(text) + 1); - sprintf(buf, "%s%s", this->value, text); - free(this->value); - this->value = buf; +void ListItem_append(ListItem* this, const char* text) { + int oldLen = strlen(this->value); + int textLen = strlen(text); + int newLen = strlen(this->value) + textLen; + this->value = realloc(this->value, newLen + 1); + memcpy(this->value + oldLen, text, textLen); + this->value[newLen] = '\0'; } const char* ListItem_getRef(ListItem* this) { |