#include #include #include //#define DEBUG #define MAX_CHAR 255 typedef struct node { void *data; //config values char *name; //config key struct node *next; } node; static node *head = NULL; void configPrint() { node *cNode = head; while(cNode != NULL) { printf("Config Entry: %s\n",cNode->name); cNode = cNode->next; } } void* configGet(char *name) { node *cNode = head; while(cNode != NULL && strcmp(cNode->name, name) != 0) { cNode = cNode->next; } if(cNode == NULL) { #ifdef DEBUG char msg[MAX_CHAR]; strcpy(msg, "Configsetting not found: "); perror(strcat(msg, name)); #endif return NULL; } else { return(void*)cNode->data; } } void configDispose() { node *cNode = head; while(cNode != NULL) { node *nextN = cNode->next; free(cNode->data); cNode->data = NULL; free(cNode->name); cNode->name = NULL; free(cNode); cNode = nextN; } head = NULL; } void configPrepend(char *key, void *data) { node *n = (node *) malloc(sizeof(node)); n->data = data; n->name = key; n->next = head; head = n; } void configTest() { configPrepend("pge", (void *) 10); configPrepend("key2", (void *) 20); configPrepend("key3", (void *)30); configPrepend("key4", (void *)1); configPrepend("key5", (void *) 40); configPrepend("key6", (void *)56); printf("Found %d\n", *(int *)configGet("key4")); printf("Found %d\n", *(int *)configGet("key6")); printf("Found %d\n", *(int *)configGet("pge")); printf("Found %d\n", *(int *)configGet("nix")); }