diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
commit | 52e25213825024b8bb446eb26b03bedc9d5c2103 (patch) | |
tree | da70bf44b2423f6f8e9a070c063fed79d190b489 /DynamicColumn.c | |
parent | Initial commit. (diff) | |
download | htop-a3acf87a6f5b793b4b57b4512821b2e970a8b7bc.tar.xz htop-a3acf87a6f5b793b4b57b4512821b2e970a8b7bc.zip |
Adding upstream version 3.2.2.upstream/3.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'DynamicColumn.c')
-rw-r--r-- | DynamicColumn.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/DynamicColumn.c b/DynamicColumn.c new file mode 100644 index 0000000..bd038df --- /dev/null +++ b/DynamicColumn.c @@ -0,0 +1,66 @@ +/* +htop - DynamicColumn.c +(C) 2021 Sohaib Mohammed +(C) 2021 htop dev team +(C) 2021 Red Hat, Inc. All Rights Reserved. +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "DynamicColumn.h" + +#include <stddef.h> + +#include "Platform.h" +#include "RichString.h" +#include "XUtils.h" + + +Hashtable* DynamicColumns_new(void) { + return Platform_dynamicColumns(); +} + +void DynamicColumns_delete(Hashtable* dynamics) { + if (dynamics) { + Platform_dynamicColumnsDone(dynamics); + Hashtable_delete(dynamics); + } +} + +const char* DynamicColumn_init(unsigned int key) { + return Platform_dynamicColumnInit(key); +} + +typedef struct { + const char* name; + const DynamicColumn* data; + unsigned int key; +} DynamicIterator; + +static void DynamicColumn_compare(ht_key_t key, void* value, void* data) { + const DynamicColumn* column = (const DynamicColumn*)value; + DynamicIterator* iter = (DynamicIterator*)data; + if (String_eq(iter->name, column->name)) { + iter->data = column; + iter->key = key; + } +} + +const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, unsigned int* key) { + DynamicIterator iter = { .key = 0, .data = NULL, .name = name }; + if (dynamics) + Hashtable_foreach(dynamics, DynamicColumn_compare, &iter); + if (key) + *key = iter.key; + return iter.data; +} + +const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key) { + return (const DynamicColumn*) Hashtable_get(dynamics, key); +} + +bool DynamicColumn_writeField(const Process* proc, RichString* str, unsigned int key) { + return Platform_dynamicColumnWriteField(proc, str, key); +} |