Example #1
0
static int config_parse_file(struct darray *sections, const char *file,
		bool always_open)
{
	char *file_data;
	struct lexer lex;
	FILE *f;

	f = os_fopen(file, "rb");
	if (always_open && !f)
		f = os_fopen(file, "w+");
	if (!f)
		return CONFIG_FILENOTFOUND;

	os_fread_utf8(f, &file_data);
	fclose(f);

	if (!file_data)
		return CONFIG_SUCCESS;

	lexer_init(&lex);
	lexer_start_move(&lex, file_data);

	parse_config_data(sections, &lex);

	lexer_free(&lex);
	return CONFIG_SUCCESS;
}
Example #2
0
int config_open_string(config_t **config, const char *str)
{
	struct lexer lex;

	if (!config)
		return CONFIG_ERROR;

	*config = bzalloc(sizeof(struct config_data));
	if (!*config)
		return CONFIG_ERROR;

	(*config)->file = NULL;

	lexer_init(&lex);
	lexer_start(&lex, str);
	parse_config_data(&(*config)->sections, &lex);
	lexer_free(&lex);

	return CONFIG_SUCCESS;
}
Example #3
0
state_t parse_file(const char* fname) {
	state_t state;

	
        //check if it is a lua script
        if(strcmp(fname+strlen(fname)-4, ".lua") == 0) {
                read_lua_script(fname, &state);
        }
        else {

                state.outfile = NULL;
                state.spp = -1;
                state.image_w = -1;
                state.image_h = -1;
                state.gpu_enabled = false;
                state.st_enabled = false;

                state.primitives = (primitive_t*)malloc(sizeof(transform_t));
                state.n_primitives = 0;

                state.transforms = (transform_t*)malloc(sizeof(transform_t));
                state.n_transforms = 0;

                state.n_verts = 0;
                state.verts = (vec3*)malloc(sizeof(vec3));

                state.n_bsdfs = 0;
                state.bsdfs = (bsdf_t*)malloc(sizeof(bsdf_t));

                state.n_lights = 0;
                state.lights = (light_t*)malloc(sizeof(light_t));

                //open the file
                FILE* f = fopen(fname, "r");
                qr_assert(f!=NULL, "parser", "Could not open file %s", fname);

                char line[4096];

                while(fgets(line, 4096, f) != NULL) {
                        if(line[0] != '#') {

                                //get rid of the newline
                                line[strlen(line)-1] = '\0';

                                if(strlen(line) != 0) {
                                        if(strcmp(line,"Config")==0) {
                                                parse_config_data(&state, f);
                                        }
                                        else if(strcmp(line,"World")==0) {
                                                parse_world(&state, f);
                                        }
                                        else {
                                                ERROR("parser", "Unknown directive: %s",line);
                                        }
                                }
                        }
                }

                fclose(f);
        }

	return state;
}