diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:19 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:19 +0200 |
commit | 266ab52b3a741a58fb17c48b0f7939d7c5d266de (patch) | |
tree | b4bccc59b9a35f3acbe7560f3d633940c71aedef /ListItem.c | |
parent | 2c8c1a156130aa40be7dcaeb3ce2977a03cf50c2 (diff) | |
download | debian_htop-266ab52b3a741a58fb17c48b0f7939d7c5d266de.tar.gz debian_htop-266ab52b3a741a58fb17c48b0f7939d7c5d266de.tar.bz2 debian_htop-266ab52b3a741a58fb17c48b0f7939d7c5d266de.zip |
Imported Upstream version 0.6upstream/0.6
Diffstat (limited to 'ListItem.c')
-rw-r--r-- | ListItem.c | 44 |
1 files changed, 34 insertions, 10 deletions
@@ -1,13 +1,15 @@ /* -htop -(C) 2004 Hisham H. Muhammad +htop - ListItem.c +(C) 2004,2005 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "ListItem.h" +#include "String.h" #include "Object.h" -#include "CRT.h" +#include "RichString.h" +#include <string.h> #include "debug.h" @@ -15,7 +17,8 @@ in the source distribution for its full text. typedef struct ListItem_ { Object super; - char* text; + char* value; + int key; } ListItem; extern char* LISTITEM_CLASS; @@ -24,25 +27,46 @@ extern char* LISTITEM_CLASS; /* private property */ char* LISTITEM_CLASS = "ListItem"; -ListItem* ListItem_new(char* text) { +ListItem* ListItem_new(char* value, int key) { ListItem* this = malloc(sizeof(ListItem)); ((Object*)this)->class = LISTITEM_CLASS; ((Object*)this)->display = ListItem_display; ((Object*)this)->delete = ListItem_delete; - this->text = text; + ((Object*)this)->compare = ListItem_compare; + this->value = String_copy(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_delete(Object* cast) { ListItem* this = (ListItem*)cast; - assert (this != NULL); - - free(this->text); + free(this->value); free(this); } void ListItem_display(Object* cast, RichString* out) { ListItem* this = (ListItem*)cast; assert (this != NULL); - RichString_write(out, CRT_colors[DEFAULT_COLOR], this->text); + int len = strlen(this->value)+1; + char buffer[len+1]; + snprintf(buffer, len, "%s", this->value); + RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer); } + +const char* ListItem_getRef(ListItem* this) { + return this->value; +} + +int ListItem_compare(const Object* cast1, const Object* cast2) { + ListItem* obj1 = (ListItem*) cast1; + ListItem* obj2 = (ListItem*) cast2; + return strcmp(obj1->value, obj2->value); +} + |