2 libgliar - a library that can fake the OpenGL context info returned by
5 Copyright (C) 2013 Canonical Ltd
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Author: Eleni Maria Stea <elene.mst@gmail.com>
29 static char *stripspace(char *s);
32 struct cfgopt *gliar_load_cfg(const char *fname)
36 struct cfgopt *optlist = 0;
37 struct cfgopt *opt = 0;
39 if(!(fp = fopen(fname, "r"))) {
43 while(fgets(buf, sizeof buf, fp)) {
44 char *line = stripspace(buf);
46 if(!*line || *line == '#') {
51 char *end = strrchr(line, ']');
53 fprintf(stderr, "invalid config %s: %s\n", fname, line);
64 if((opt = malloc(sizeof *opt))) {
65 if((opt->key = malloc(strlen(line) + 1))) {
66 strcpy(opt->key, line);
75 int prev_len = opt->val ? strlen(opt->val) : 0;
77 if(opt && (tmp = realloc(opt->val, prev_len + strlen(line) + 2))) {
80 strcat(opt->val, " ");
81 strcat(opt->val, line);
83 strcpy(opt->val, line);
98 const char *gliar_find_opt(struct cfgopt *list, const char *name)
105 if(strcmp(list->key, name) == 0) {
113 void gliar_print_opt(struct cfgopt *list)
117 printf("\"%s\" -> \"%s\"\n", list->key, list->val);
122 static char *stripspace(char *s)
124 char *end = s + strlen(s) - 1;
126 while(isspace(*s)) s++;
128 while(isspace(*end)) {