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
+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/>.
+along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#include "cfg.h"
static char *stripspace(char *s);
-
+static void concat_values(struct cfgopt *opt);
struct cfgopt *gliar_load_cfg(const char *fname)
{
if(opt) {
opt->next = optlist;
optlist = opt;
+ concat_values(opt);
}
if((opt = malloc(sizeof *opt))) {
if((opt->key = malloc(strlen(line) + 1))) {
strcpy(opt->key, line);
opt->str_val = 0;
- opt->num_val = 0;
- opt->type = unknown;
+ opt->num_val = 0;
+ opt->str_count = 0;
+ opt->type = GLIAR_STRING;
} else {
free(opt);
opt = 0;
}
}
} else {
- char *tmp;
- int prev_len = opt->str_val ? strlen(opt->str_val) : 0;
+ int new_sz = opt->str_count + 1;
+ char **tmp;
+
+ char *end;
+ int num = strtol(line, &end, 10);
- if(opt && (tmp = realloc(opt->str_val, prev_len + strlen(line) + 2))) {
- opt->type = str;
+ if(!*end) {
+ opt->num_val = line;
+ opt->type = GLIAR_NUMBER;
+ }
+
+ if(opt && (tmp = realloc(opt->str_val, new_sz * sizeof(char*)))) {
opt->str_val = tmp;
- if(prev_len) {
- strcat(opt->str_val, " ");
- strcat(opt->str_val, line);
- } else {
- strcpy(opt->str_val, line);
+ if((opt->str_val[new_sz - 1] = malloc(strlen(line) + 1))) {
+ strcpy(opt->str_val[new_sz -1], line);
+ opt->str_count = new_sz;
}
}
+
+ if(new_sz > 1) {
+ opt->type = GLIAR_STRING;
+ }
}
}
if(opt) {
opt->next = optlist;
optlist = opt;
+ concat_values(opt);
}
fclose(fp);
return optlist;
}
-const char *gliar_find_opt(struct cfgopt *list, const char *name)
+const struct cfgopt *gliar_find_opt(struct cfgopt *list, const char *name)
{
if(!list || !name) {
return 0;
while(list) {
if(strcmp(list->key, name) == 0) {
- return list->str_val;
+ return list;
}
list = list->next;
}
{
printf("OPTIONS\n");
while(list) {
- printf("\"%s\" -> \"%s\"\n", list->key, list->str_val);
+ if(list->type == GLIAR_NUMBER) {
+ printf("\"%s\" -> %d\n", list->key, list->num_val);
+ }
+ else {
+ int i;
+ for(i=0; i<list->str_count; i++) {
+ printf("\"%s\" -> \"%s\"\n", list->key, list->str_val[i]);
+ }
+ }
list = list->next;
}
}
}
return s;
}
+
+static void concat_values(struct cfgopt *opt)
+{
+ int i;
+ int sz = opt->str_count - 1;
+
+ for(i=0; i<opt->str_count; i++) {
+ sz += strlen(opt->str_val[i]);
+ }
+
+ if(!(opt->conc_vals = malloc(sz + 1))) {
+ return;
+ }
+
+ *opt->conc_vals = 0;
+ for(i=0; i<opt->str_count - 1; i++) {
+ strcat(opt->conc_vals, opt->str_val[i]);
+ strcat(opt->conc_vals, " ");
+ }
+ strcat(opt->conc_vals, opt->str_val[i]);
+}
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
+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/>.
+along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#ifndef CFG_H_
#define CFG_H_
-enum TYPE {unknown, flt, dbl, boolean, integer, str};
+enum type {GLIAR_NUMBER, GLIAR_STRING};
struct cfgopt {
char *key;
- char *str_val;
+ char **str_val;
+ int str_count;
- double num_val;
- enum TYPE type;
+ char* conc_vals;
+
+ int num_val;
+ enum type type;
struct cfgopt *next;
};
struct cfgopt *gliar_load_cfg(const char *fname);
-const char *gliar_find_opt(struct cfgopt *list, const char *name);
+const struct cfgopt *gliar_find_opt(struct cfgopt *list, const char *name);
void gliar_print_opt(struct cfgopt *list);
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
+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/>.
+along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
static const void* (*gl_get_doublev)(GLenum, GLdouble*);
static const void* (*gl_get_floatv)(GLenum, GLfloat*);
static const void* (*gl_get_integerv)(GLenum, GLint*);
-static const void* (*gl_get_integer64v)(GLenum, GLint64*);
+static const void* (*gl_get_integer64v)(GLenum, GLint64*);
static const void* (*gl_get_booleani_v)(GLenum, GLuint, GLboolean*);
static const void* (*gl_get_doublei_v)(GLenum, GLuint, GLdouble*);
}
gl_get_string = dlsym(RTLD_NEXT, "glGetString");
-/* gl_get_stringi = dlsym(RTLD_NEXT, "glGetStringi");
+/* gl_get_stringi = dlsym(RTLD_NEXT, "glGetStringi");
- gl_get_booleanv = dlsym(RTLD_NEXT, "glGetBooleanv");
- gl_get_doublev = dlsym(RTLD_NEXT, "glGetDoublev");
- gl_get_floatv = dlsym(RTLD_NEXT, "glGetFloatv");
- gl_get_integerv = dlsym(RTLD_NEXT, "glGetIntegerv");
- gl_get_integer64v = dlsym(RTLD_NEXT, "glGetInteger64v");
+ gl_get_booleanv = dlsym(RTLD_NEXT, "glGetBooleanv");
+ gl_get_doublev = dlsym(RTLD_NEXT, "glGetDoublev");
+ gl_get_floatv = dlsym(RTLD_NEXT, "glGetFloatv");
+ gl_get_integerv = dlsym(RTLD_NEXT, "glGetIntegerv");
+ gl_get_integer64v = dlsym(RTLD_NEXT, "glGetInteger64v");
- gl_get_booleani_v = dlsym(RTLD_NEXT, "glGetBooleani_v");
- gl_get_doublei_v = dlsym(RTLD_NEXT, "glGetDoublei_v");
- gl_get_floati_v = dlsym(RTLD_NEXT, "glGetFloati_v");
- gl_get_integeri_v = dlsym(RTLD_NEXT, "glGetIntegeri_v");
- gl_get_integer64i_v = dlsym(RTLD_NEXT, "glGetInteger64i_v");*/
+ gl_get_booleani_v = dlsym(RTLD_NEXT, "glGetBooleani_v");
+ gl_get_doublei_v = dlsym(RTLD_NEXT, "glGetDoublei_v");
+ gl_get_floati_v = dlsym(RTLD_NEXT, "glGetFloati_v");
+ gl_get_integeri_v = dlsym(RTLD_NEXT, "glGetIntegeri_v");
+ gl_get_integer64i_v = dlsym(RTLD_NEXT, "glGetInteger64i_v");*/
done_init = 1;
return 0;
const GLubyte *glGetString(GLenum name)
{
- const char *key, *value;
+ const char *key;
+ const struct cfgopt *option;
init();
key = "extensions";
break;
- case GL_RENDERER:
- key = "renderer";
- break;
+ case GL_RENDERER:
+ key = "renderer";
+ break;
- case GL_SHADING_LANGUAGE_VERSION:
- key = "sl version";
- break;
+ case GL_SHADING_LANGUAGE_VERSION:
+ key = "sl version";
+ break;
default:
key = 0;
}
- if(key && (value = gliar_find_opt(cfglist, key))) {
- return value;
+ if(key && (option = gliar_find_opt(cfglist, key))) {
+ return (const GLubyte*)option->conc_vals;
}
return gl_get_string(name);