Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/list.c @ 16615

Last change on this file since 16615 was 16615, checked in by hmaislin, 5 years ago

#2929: Added updated go and plugin files

File size: 1.7 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5//#define DEBUG
6#define MAX_CHAR 255
7
8typedef struct node {
9   void *data;      //config values
10   char *name;      //config key
11   struct node *next;
12} node;
13
14static node *head = NULL;
15
16void configPrint() {
17   node *cNode = head;
18   while(cNode != NULL) {       
19      printf("Config Entry: %s\n",cNode->name);
20      cNode = cNode->next;
21   }
22}
23
24void* configGet(char *name) {
25   node *cNode = head;
26   while(cNode != NULL && strcmp(cNode->name, name) != 0) {
27      cNode = cNode->next;
28   }
29   if(cNode == NULL) {
30      #ifdef DEBUG
31         char msg[MAX_CHAR];
32         strcpy(msg, "Configsetting not found: ");
33         perror(strcat(msg, name));
34      #endif
35      return NULL;
36   } else {
37      return(void*)cNode->data;
38   }
39}
40
41void configDispose() {
42   node *cNode = head;
43   while(cNode != NULL) {       
44      node *nextN = cNode->next;
45      free(cNode->data);
46      cNode->data = NULL;
47      free(cNode->name);
48      cNode->name = NULL;
49      free(cNode);
50      cNode = nextN;
51   }
52   head = NULL;
53}
54
55void configPrepend(char *key, void *data) {
56   node *n = (node *) malloc(sizeof(node));
57   n->data = data;
58   n->name = key;
59   n->next = head;
60   head = n;
61}
62
63
64void configTest() {
65    configPrepend("pge", (void *) 10);
66    configPrepend("key2", (void *) 20);
67    configPrepend("key3", (void *)30);
68    configPrepend("key4", (void *)1);
69    configPrepend("key5", (void *) 40);
70    configPrepend("key6", (void *)56);
71
72    printf("Found %d\n", *(int *)configGet("key4"));
73    printf("Found %d\n", *(int *)configGet("key6"));
74    printf("Found %d\n", *(int *)configGet("pge"));
75    printf("Found %d\n", *(int *)configGet("nix"));
76}
Note: See TracBrowser for help on using the repository browser.