added support for numerical values in option struct
[libgliar] / src / cfg.c
index 4f317d2..124449e 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -1,3 +1,25 @@
+/*
+libgliar - a library that can fake the OpenGL context info returned by
+the glGet OpenGL calls
+
+Copyright (C) 2013 Canonical Ltd
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Author: Eleni Maria Stea <elene.mst@gmail.com>
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -42,7 +64,9 @@ struct cfgopt *gliar_load_cfg(const char *fname)
                        if((opt = malloc(sizeof *opt))) {
                                if((opt->key = malloc(strlen(line) + 1))) {
                                        strcpy(opt->key, line);
-                                       opt->val = 0;
+                                       opt->str_val = 0;
+          opt->num_val = 0;
+          opt->type = unknown;
                                } else {
                                        free(opt);
                                        opt = 0;
@@ -50,15 +74,16 @@ struct cfgopt *gliar_load_cfg(const char *fname)
                        }
                } else {
                        char *tmp;
-                       int prev_len = opt->val ? strlen(opt->val) : 0;
+                       int prev_len = opt->str_val ? strlen(opt->str_val) : 0;
 
-                       if(opt && (tmp = realloc(opt->val, prev_len + strlen(line) + 2))) {
-                               opt->val = tmp;
+                       if(opt && (tmp = realloc(opt->str_val, prev_len + strlen(line) + 2))) {
+        opt->type = str;
+                               opt->str_val = tmp;
                                if(prev_len) {
-                                       strcat(opt->val, " ");
-                                       strcat(opt->val, line);
+                                       strcat(opt->str_val, " ");
+                                       strcat(opt->str_val, line);
                                } else {
-                                       strcpy(opt->val, line);
+                                       strcpy(opt->str_val, line);
                                }
                        }
                }
@@ -81,7 +106,7 @@ const char *gliar_find_opt(struct cfgopt *list, const char *name)
 
        while(list) {
                if(strcmp(list->key, name) == 0) {
-                       return list->val;
+                       return list->str_val;
                }
                list = list->next;
        }
@@ -92,7 +117,7 @@ void gliar_print_opt(struct cfgopt *list)
 {
        printf("OPTIONS\n");
        while(list) {
-               printf("\"%s\" -> \"%s\"\n", list->key, list->val);
+               printf("\"%s\" -> \"%s\"\n", list->key, list->str_val);
                list = list->next;
        }
 }