From 266ab52b3a741a58fb17c48b0f7939d7c5d266de Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:19 +0200 Subject: Imported Upstream version 0.6 --- ListItem.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'ListItem.c') diff --git a/ListItem.c b/ListItem.c index 840ca98..95b5677 100644 --- a/ListItem.c +++ b/ListItem.c @@ -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 #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); +} + -- cgit v1.2.3