From 193ebdb96e9608291a84af0958993da091fa3558 Mon Sep 17 00:00:00 2001 From: reinelt Date: Fri, 16 Jan 2004 07:26:25 +0000 Subject: [lcd4linux @ 2004-01-16 07:26:25 by reinelt] moved various /proc parsing to own functions made some progress with /proc/stat parsing git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@315 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- hash.c | 93 ++++-------------------------------------------------------------- 1 file changed, 5 insertions(+), 88 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index fb9e8c1..32be0a9 100644 --- a/hash.c +++ b/hash.c @@ -1,4 +1,4 @@ -/* $Id: hash.c,v 1.2 2004/01/16 05:04:53 reinelt Exp $ +/* $Id: hash.c,v 1.3 2004/01/16 07:26:25 reinelt Exp $ * * hashes (associative arrays) * @@ -23,6 +23,10 @@ * * * $Log: hash.c,v $ + * Revision 1.3 2004/01/16 07:26:25 reinelt + * moved various /proc parsing to own functions + * made some progress with /proc/stat parsing + * * Revision 1.2 2004/01/16 05:04:53 reinelt * started plugin proc_stat which should parse /proc/stat * which again is a paint in the a** @@ -62,16 +66,6 @@ static int hash_lookup_f (const void *a, const void *b) } -// bsearch compare function for filter entries -static int filter_lookup_f (const void *a, const void *b) -{ - char *key=(char*)a; - FILTER_ITEM *item=(FILTER_ITEM*)b; - - return strcmp(key, item->key); -} - - // qsort compare function for hash tables static int hash_sort_f (const void *a, const void *b) { @@ -82,17 +76,6 @@ static int hash_sort_f (const void *a, const void *b) } -// qsort compare function for filter tables -static int filter_sort_f (const void *a, const void *b) -{ - FILTER_ITEM *ha=(FILTER_ITEM*)a; - FILTER_ITEM *hb=(FILTER_ITEM*)b; - - return strcasecmp(ha->key, hb->key); -} - - - // insert a key/val pair into the hash table // the tbale will be searched linearly if the entry // does already exist, for the table may not be sorted. @@ -155,69 +138,3 @@ void hash_destroy (HASH *Hash) Hash->Items=NULL; } - -// insert a key/val pair into the filter table -// the tbale will be searched linearly if the entry -// does already exist, for the table may not be sorted. -// the table will be flagged 'unsorted' afterwards -void filter_set (FILTER *Filter, char *key, char *val) -{ - int i; - - // entry already exists? - for (i=0;inItems; i++) { - if (strcmp(key, Filter->Items[i].key)==0) { - // if (Filter->Items[i].val) free (Filter->Items[i].val); - // Filter->Items[i].val=strdup(val); - return; - } - } - - // add entry - Filter->sorted=0; - Filter->nItems++; - Filter->Items=realloc(Filter->Items,Filter->nItems*sizeof(FILTER_ITEM)); - Filter->Items[i].key=strdup(key); - - - Filter->Items[i].Slots=strdup(val); -} - - -double filter_get (FILTER *Filter, char *key) -{ - FILTER_ITEM *Item; - - if (!Filter->sorted) { - qsort(Filter->Items, Filter->nItems, sizeof(FILTER_ITEM), filter_sort_f); - Filter->sorted=1; - } - - Item=bsearch(key, Filter->Items, Filter->nItems, sizeof(FILTER_ITEM), filter_lookup_f); - if (Item==NULL) return 0.0; - if (Item->Slots==NULL) return 0.0; - return Item->Slots[0].val; - -} - - -void filter_destroy (FILTER *Filter) -{ - int i; - - if (Filter->Items) { - - // free all entries - for (i=0;inItems; i++) { - if (Filter->Items[i].key) free (Filter->Items[i].key); - if (Filter->Items[i].Slots) free (Filter->Items[i].Slots); - } - - // free filter table - free (Filter->Items); - } - - Filter->nItems=0; - Filter->sorted=0; - Filter->Items=NULL; -} -- cgit v1.2.3