예제 #1
0
파일: states.c 프로젝트: macosunity/rengine
static void set_style(struct game_state *s, const char *name, const char *def) {
	char *n = my_strlower(strdup(name)); /* For case-insensitivity */
	const char *value = ini_get(game_ini, s->name, n, NULL);	
	if(!value)
		value = ini_get(game_ini, "styles", n, def);
	ht_insert(s->styles, n, (char*)value);
	free(n);
}
예제 #2
0
파일: states.c 프로젝트: macosunity/rengine
static void set_style_gt0(struct game_state *s, const char *name, const char *def) {
	/* For styles that must be greater than 0 */
	char *n = my_strlower(strdup(name));
	const char *value = ini_get(game_ini, s->name, n, NULL);	
	if(!value)
		value = ini_get(game_ini, "styles", n, def);
	if(atoi(value) < 0)
		ht_insert(s->styles, n, "0");
	else
		ht_insert(s->styles, n, (char*)value);
	free(n);
}
예제 #3
0
bool ini_addSection(Ini* ini, const char* sectionName) {
	if (ini == NULL) {
		logWarn("Invalid ini object");
		return false;
	}

	if (sectionName == NULL) {
		logWarn("Section name is NULL");
		return false;
	}

	if (ini_get(ini, sectionName) != NULL) {
		logWarn("Section '%s' already exist", sectionName);
		return false;
	}

	Section* section = memory_new(Section, true);
	str_ncpy(section->name, sectionName, sizeof(section->name));
	section->keys = list_new(true);
	section->values = list_new(true);

	list_add(ini->sections, (Any)section);

	return true;
}
예제 #4
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_unknown_line_after_first_section_crlf(void)
{
	Ini *ini;
	const char *value1, *value2;

	ini = ini_parse("[section]\r\nname1=value1\r\nabc\r\nname2=value2");

	value1 = ini_get(ini, "section", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section", "name2");
	PCU_ASSERT_PTR_NULL(value2);

	ini_delete(ini);
}
예제 #5
0
int ini_save(ini_t * self)
{
	FILE *stream;
	dict_t *vars;
	unsigned i, j;

	assert(self);

	stream = fopen(self->filepath, "w");

	if (!stream)
		return -1;

	for (i = 0; i < self->sections->length; i++) {
		fprintf(stream, "[%s]\n", self->sections->elements[i]->key);
		vars = self->sections->elements[i]->value;
		for (j = 0; j < vars->length; j++)
			fprintf(stream, "%s = %s\n",
				(char *)vars->elements[j]->key, ini_get(self,
									self->
									sections->
									elements
									[i]->
									key,
									(char *)
									vars->
									elements
									[j]->
									key));

		fprintf(stream, "\n");
	}
	fclose(stream);
	return 0;
}
예제 #6
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_ignore_comment_line_crlf(void)
{
	Ini *ini;
	const char *value1, *value2;

	ini = ini_parse(" ;comment1\r\n[section]\r\n\t;comment2\r\nname1=value1\r\n;comment3\r\nname2=value2\r\n;comment4");

	value1 = ini_get(ini, "section", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section", "name2");
	PCU_ASSERT_PTR_NOT_NULL(value2);
	PCU_ASSERT_STRING_EQUAL("value2", value2);

	ini_delete(ini);
}
예제 #7
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_ignore_spacetab_line_cr(void)
{
	Ini *ini;
	const char *value1, *value2;

	ini = ini_parse(" \t\r[section]\r \t\rname1=value1\r \t\rname2=value2 \t\r");

	value1 = ini_get(ini, "section", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section", "name2");
	PCU_ASSERT_PTR_NOT_NULL(value2);
	PCU_ASSERT_STRING_EQUAL("value2", value2);

	ini_delete(ini);
}
예제 #8
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_ignore_empty_line(void)
{
	Ini *ini;
	const char *value1, *value2;

	ini = ini_parse("\n[section]\n\nname1=value1\n\nname2=value2");

	value1 = ini_get(ini, "section", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section", "name2");
	PCU_ASSERT_PTR_NOT_NULL(value2);
	PCU_ASSERT_STRING_EQUAL("value2", value2);

	ini_delete(ini);
}
예제 #9
0
파일: iniloader.c 프로젝트: KWMalik/tau
/*
 * API
 * 
 * returns an integer value associated with the given key. if the key was not
 * found, returns INI_STATUS_ERROR; otherwise returns INI_STATUS_OK and sets
 * the `value` argument to the integral value of the string.
 */
int ini_get_integer(const inifile_t * ini, const char * key, int * value)
{
	const char * text = ini_get(ini, key);
	if (text == NULL) {
		return INI_STATUS_ERROR;
	}
	*value = atoi(text);
	return INI_STATUS_OK;
}
예제 #10
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_two_keys_crlf(void)
{
	Ini *ini;
	const char *value1, *value2;

	ini = ini_parse("[section]\r\nname1=value1\r\nname2=value2");
	PCU_ASSERT_PTR_NOT_NULL(ini);

	value1 = ini_get(ini, "section", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section", "name2");
	PCU_ASSERT_PTR_NOT_NULL(value2);
	PCU_ASSERT_STRING_EQUAL("value2", value2);

	ini_delete(ini);
}
예제 #11
0
void Speech_ParseINI(Asset &asset, ini_t *ini) {
	const char *text = ini_get(ini, asset.name, "text");

	if (text == nullptr) {
		Con_Errorf(ERR_FATAL, "asset %s is missing required field \"text\"", asset.name);
		return;
	}
	
	asset.path = sdsnew(text);
}
예제 #12
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
/* 空行でもコメントでもないが、無効な行がある場合 */
static void test_ini_get_unknown_line_before_first_section(void)
{
	Ini *ini;
	const char *value;

	ini = ini_parse("abc");

	value = ini_get(ini, "section", "name");
	PCU_ASSERT_PTR_NULL(value);

	ini_delete(ini);
}
예제 #13
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get_two_sections(void)
{
	Ini *ini;
	const char *value1, *value2, *value3;

	ini = ini_parse("[section1]\nname1=value1\n[section2]\nname2=value2\nname3=value3");

	value1 = ini_get(ini, "section1", "name1");
	PCU_ASSERT_PTR_NOT_NULL(value1);
	PCU_ASSERT_STRING_EQUAL("value1", value1);

	value2 = ini_get(ini, "section2", "name2");
	PCU_ASSERT_PTR_NOT_NULL(value2);
	PCU_ASSERT_STRING_EQUAL("value2", value2);

	value3 = ini_get(ini, "section2", "name3");
	PCU_ASSERT_PTR_NOT_NULL(value3);
	PCU_ASSERT_STRING_EQUAL("value3", value3);

	ini_delete(ini);
}
예제 #14
0
파일: test_ini.c 프로젝트: kazuyamamoto/ini
static void test_ini_get(void)
{
	Ini *ini;
	const char *value;

	ini = ini_parse("[section]\nname=value");
	PCU_ASSERT_PTR_NOT_NULL(ini);

	value = ini_get(ini, "section", "name");
	PCU_ASSERT_PTR_NOT_NULL(value);
	PCU_ASSERT_STRING_EQUAL("value", value);

	ini_delete(ini);
}
예제 #15
0
파일: ini.c 프로젝트: rxi/ini
int ini_sget(
  ini_t *ini, const char *section, const char *key,
  const char *scanfmt, void *dst
) {
  const char *val = ini_get(ini, section, key);
  if (!val) {
    return 0;
  }
  if (scanfmt) {
    sscanf(val, scanfmt, dst);
  } else {
    *((const char**) dst) = val;
  }
  return 1;
}
예제 #16
0
void ini_dump(ini_t * self)
{
	unsigned i, j;
	dict_t *vars;

	assert(self);

	for (i = 0; i < self->sections->length; i++) {
		printf("[%s]\n", self->sections->elements[i]->key);
		vars = self->sections->elements[i]->value;
		for (j = 0; j < vars->length; j++)
			printf("%s = %s\n", (char *)vars->elements[j]->key,
			       ini_get(self, self->sections->elements[i]->key,
				       (char *)vars->elements[j]->key));

		printf("\n");
	}
}
예제 #17
0
파일: libini.c 프로젝트: yiwitzki/wifi
int ini_get_int(INI *pini,const char *key)
{
	char value[VINT_LEN];
	return atoi(ini_get(pini,key,value));
}
예제 #18
0
conf_t *conf_init(void)
{
	conf_t *self;
	ini_t *ini;
	char *tmp, **splitted;
	int nsplits;
	unsigned i;
	dict_t *vars;

	self = xmalloc(sizeof(conf_t));
	self->post_pkgadd = NULL;
	self->ask_for_update = 1;
	self->not_found_policy = ASK;

	ini = ini_new(CONF_FILE);
	ini_add(ini, "ilenia");
	ini_set_default(ini, "ilenia", "post_pkgadd", xstrdup(""));
	ini_set_default(ini, "ilenia", "ask_for_update", xstrdup("1"));
	ini_set_default(ini, "ilenia", "not_found_policy", xstrdup("ASK"));
	ini_set_default(ini, "ilenia", "repositories_hierarchy", xstrdup(""));
	ini_set_default(ini, "ilenia", "enable_colors", xstrdup("Yes"));
	ini_set_default(ini, "ilenia", "verbose", xstrdup("No"));
	ini_add(ini, "favourite_repositories");
	ini_add(ini, "locked_versions");
	ini_add(ini, "aliases");
	ini_add(ini, "pkgmk_confs");
	ini_load(ini);

	if ((tmp = getenv("POST_PKGADD")) == NULL)
		tmp = ini_get(ini, "ilenia", "post_pkgadd");
	self->post_pkgadd = xstrdup(tmp);

	if ((tmp = getenv("ASK_FOR_UPDATE")) == NULL)
		tmp = ini_get(ini, "ilenia", "ask_for_update");
	if (!strcasecmp(tmp, "NO"))
		self->ask_for_update = 0;
	else
		self->ask_for_update = 1;

	if ((tmp = getenv("NOT_FOUND_POLICY")) == NULL)
		tmp = ini_get(ini, "ilenia", "not_found_policy");
	if (!strcasecmp(tmp, "NEVERMIND"))
		self->not_found_policy = NEVERMIND;
	else if (!strcasecmp(tmp, "STOP"))
		self->not_found_policy = STOP;
	else
		self->not_found_policy = ASK;

	tmp = ini_get(ini, "ilenia", "repositories_hierarchy");
	if (tmp != NULL) {
		strreplace(&tmp, "\t", " ", -1);
		while (strstr(tmp, "  "))
			strreplace(&tmp, "  ", " ", -1);

		splitted = NULL;
		nsplits = strsplit(tmp, ' ', &splitted);
		self->repositories_hierarchy =
		    list_new_from_array((void **)splitted, nsplits);
		free(splitted);
	} else
		self->repositories_hierarchy = list_new();

	if ((tmp = getenv("ENABLE_COLORS")) == NULL)
		tmp = ini_get(ini, "ilenia", "enable_colors");
	if (!strcasecmp(tmp, "NO"))
		self->enable_colors = 0;
	else
		self->enable_colors = 1;

	if ((tmp = getenv("VERBOSE")) == NULL)
		tmp = ini_get(ini, "ilenia", "verbose");
	if (strcasecmp(tmp, "Yes") == 0)
		self->verbose = 1;
	else
		self->verbose = 0;

	self->favourite_repositories = dict_new();
	vars = ini_get_vars(ini, "favourite_repositories");

	for (i = 0; vars && i < vars->length; i++)
		dict_add(self->favourite_repositories, vars->elements[i]->key,
			 xstrdup(vars->elements[i]->value));

	self->locked_versions = dict_new();
	vars = ini_get_vars(ini, "locked_versions");
	for (i = 0; vars && i < vars->length; i++)
		dict_add(self->locked_versions, vars->elements[i]->key,
			 xstrdup(vars->elements[i]->value));

	self->aliases = dict_new();
	vars = ini_get_vars(ini, "aliases");
	for (i = 0; vars != NULL && i < vars->length; i++) {
		tmp = vars->elements[i]->value;

		strreplace(&tmp, "\t", " ", -1);
		while (strstr(tmp, "  "))
			strreplace(&tmp, "  ", " ", -1);

		splitted = NULL;
		nsplits = strsplit(tmp, ' ', &splitted);
		if (nsplits == 0)
			continue;
		dict_add(self->aliases, vars->elements[i]->key,
			 list_new_from_array((void **)splitted, nsplits));
		free(splitted);
	}

	self->pkgmk_confs = dict_new();
	vars = ini_get_vars(ini, "pkgmk_confs");

	for (i = 0; vars && i < vars->length; i++)
		dict_add(self->pkgmk_confs, vars->elements[i]->key,
			 xstrdup(vars->elements[i]->value));

	ini_free(ini);
	return self;
}
예제 #19
0
파일: game.c 프로젝트: wernsey/rengine
int main(int argc, char *argv[]) {
	int opt;

	int fullscreen = 0, resizable = 0, borderless = 0;

	const char *appTitle = DEFAULT_APP_TITLE;

	const char *game_dir = NULL;
	const char *pak_filename = "game.pak";

	const char *rlog_filename = "rengine.log";

	const char *startstate;

	struct game_state *gs = NULL;

	int demo = 0;

	SDL_version compiled, linked;

	log_init(rlog_filename);
	json_error = rerror;

	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) {
		rerror("SDL_Init: %s", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);

	while((opt = getopt(argc, argv, "p:g:l:d?")) != -1) {
		switch(opt) {
			case 'p': {
				pak_filename = optarg;
			} break;
			case 'g' : {
				game_dir = optarg;
				pak_filename = NULL;
			} break;
			case 'l': {
				rlog_filename = optarg;
			} break;
			case 'd': {
				demo = 1;
			} break;
			case '?' : {
				usage(argv[0]);
				return 1;
			}
		}
	}

	if(!getcwd(initial_dir, sizeof initial_dir)) {
		rerror("error in getcwd(): %s", strerror(errno));
		return 1;
	}
	rlog("Running engine from %s", initial_dir);

	if(!gdb_new()) {
		rerror("Unable to create Game Database");
		return 1;
	}
	re_initialize();
	states_initialize();
	if(!snd_init()) {
		rerror("Terminating because of audio problem.");
		return 1;
	}

	/* Don't quite know how to use this in Windows yet.
	*/
	SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
	SDL_Log("Testing Log capability.");
    
	SDL_VERSION(&compiled);
	SDL_GetVersion(&linked);
	rlog("SDL version %d.%d.%d (compile)", compiled.major, compiled.minor, compiled.patch);
	rlog("SDL version %d.%d.%d (link)", linked.major, linked.minor, linked.patch);

	if(!demo) {
		if(pak_filename) {
			rlog("Loading game PAK file: %s", pak_filename);
			if(!rs_read_pak(pak_filename)) {
				rerror("Unable to open PAK file '%s'; Playing demo mode.", pak_filename);
				goto start_demo;
			}
		} else {
			rlog("Not using a PAK file. Using '%s' instead.", game_dir);
			if(chdir(game_dir)) {
				rerror("Unable to change to '%s': %s", game_dir, strerror(errno));
				return 1;
			}
		}

		game_ini = re_get_ini(GAME_INI);
		if(game_ini) {
			appTitle = ini_get(game_ini, "init", "appTitle", "Rengine");

			screenWidth = atoi(ini_get(game_ini, "screen", "width", PARAM(SCREEN_WIDTH)));
			screenHeight = atoi(ini_get(game_ini, "screen", "height", PARAM(SCREEN_HEIGHT)));
			resizable = atoi(ini_get(game_ini, "screen", "resizable", "0")) ? SDL_WINDOW_RESIZABLE : 0;
			borderless = atoi(ini_get(game_ini, "screen", "borderless", "0")) ? SDL_WINDOW_BORDERLESS : 0;
			fullscreen = atoi(ini_get(game_ini, "screen", "fullscreen", "0")) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
			fps = atoi(ini_get(game_ini, "screen", "fps", PARAM(DEFAULT_FPS)));
			if(fps <= 0)
				fps = DEFAULT_FPS;

			filter = !my_stricmp(ini_get(game_ini, "screen", "filter", "nearest"), "linear")? "1": "0";

			virt_width = atoi(ini_get(game_ini, "virtual", "width", PARAM(VIRT_WIDTH)));
			virt_height = atoi(ini_get(game_ini, "virtual", "height", PARAM(VIRT_HEIGHT)));

            show_cursor = atoi(ini_get(game_ini, "mouse", "show-cursor", PARAM(1)))? 1 : 0;

			startstate = ini_get(game_ini, "init", "startstate", NULL);
			if(startstate) {
                gs = get_state(startstate);
				if(!gs) {
					rerror("Unable to get initial state: %s", startstate);
					return 1;
				}
			} else {
				rerror("No initial state in %s", GAME_INI);
				return 1;
			}
		} else {
			rerror("Unable to load %s", GAME_INI);
			return 1;
		}
	} else {
start_demo:
		rlog("Starting demo mode");
		gs = get_demo_state("demo");
	}

	rlog("Initialising...");

	if(!init(appTitle, fullscreen | borderless | resizable)) {
		return 1;
	}
	
	if(!bmf_init()){	
        rlog("Quiting; Unable to start FreeType font library");
        return 1;
	}

    assert(gs);
	rlog("Entering initial state...");
    if(!change_state(gs)) {
        rlog("Quiting, because of earlier problems with the initial state");
        return 1;
    }
	
    frameStart = SDL_GetTicks();

	rlog("Event loop starting...");

	while(!quit) {
		gs = current_state();
		if(!gs) {
			break;
		}

		if(gs->update)
			gs->update(gs, bmp);

		advanceFrame();
	}

	rlog("Event loop stopped.");

	gs = current_state();
	if(gs && gs->deinit)
		gs->deinit(gs);

	bm_free(bmp);

	SDL_DestroyTexture(tex);
	SDL_DestroyRenderer(ren);
	SDL_DestroyWindow(win);

	SDL_Quit();

	ini_free(game_ini);

	re_clean_up();

	bmf_deinit();
	
	gdb_save("dump.db"); /* For testing the game database functionality. Remove later. */

	gdb_close();
	snd_deinit();
	rlog("Engine shut down.");

	return 0;
}