Beispiel #1
0
Datei: main.c Projekt: bpg/RFBee
static void setup() {
	sei();

	if (config_initialized() != OK) {
		serial_init(9600);
		printf("Initializing config\r\n");
#ifdef FACTORY_SELFTEST
		if ( TestIO() != OK )
		return;
#endif
		config_reset();
	}

	setUartBaudRate();
	rfBeeInit();

	DDRC &= ~(_BV(7));
	PORTC |= _BV(7);

	// set DHT pin as input
//	DDRD &= ~(_BV(5));
//	PORTD |= _BV(5);

	printf("ok\r\n");
}
Beispiel #2
0
void config_load( )
{
    char file_name[512];
    PData *pd, *sub; 
    /* set to defaults */
    config_check_dir();
    config_reset();
    /* load config */
    sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME );
    if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) {
        fprintf( stderr, "%s\n", parser_get_error() );
        return;
    }
    /* parse config */
    parser_get_int( pd, "gametype", &config.gametype );
    parser_get_int( pd, "starting_level", &config.starting_level );
    if (config.starting_level > 9 || config.starting_level < 0) {
	    config.starting_level = 0;
    }
    parser_get_int( pd, "preview", &config.preview );
    parser_get_int( pd, "help", &config.help );
    parser_get_int( pd, "expert", &config.expert );
    parser_get_int( pd, "center_preview", &config.center_preview );
    parser_get_int( pd, "holes", &config.holes );
    parser_get_int( pd, "rand_holes", &config.rand_holes );
    parser_get_int( pd, "send_all", &config.send_all );
    parser_get_int( pd, "send_tetris", &config.send_tetris );
    if ( parser_get_pdata( pd, "player1", &sub ) )
        parse_player( sub, &config.player1 );
    if ( parser_get_pdata( pd, "player2", &sub ) )
        parse_player( sub, &config.player2 );
    if ( parser_get_pdata( pd, "player3", &sub ) )
        parse_player( sub, &config.player3 );
    parser_get_int( pd, "clear_keystate", &config.clear_keystate );
    parser_get_int( pd, "cpu_aggr", &config.cpu_aggr );
    parser_get_int( pd, "cpu_delay", &config.cpu_delay );
    parser_get_int( pd, "cpu_rot_delay", &config.cpu_rot_delay );
    parser_get_int( pd, "sound", &config.sound );
    parser_get_int( pd, "volume", &config.volume );
    parser_get_int( pd, "transparency", &config.trp );
    parser_get_int( pd, "animations", &config.anim );
    parser_get_int( pd, "fullscreen", &config.fullscreen );
    parser_get_int( pd, "fading", &config.fade );
    parser_get_int( pd, "fps", &config.fps );
    parser_get_int( pd, "background", &config.bkgnd );
    parser_get_int( pd, "static_background", &config.keep_bkgnd );
    parser_get_int( pd, "smooth_hori", &config.smooth_hori );
    parser_get_int( pd, "hori_delay", &config.hori_delay );
    parser_get_int( pd, "vert_delay", &config.vert_delay );
    parser_get_int( pd, "pause_key", &config.pause_key );
    parser_get_int( pd, "block_by_block", &config.block_by_block );
    parser_get_int( pd, "motion_mod", &config.motion_mod );
    parser_get_int( pd, "relative_motion", &config.rel_motion );
    parser_get_int( pd, "grap_input", &config.grab );
    parser_get_int( pd, "invert_mouse", &config.invert );
    parser_get_int( pd, "quick_help", &config.quick_help );
    parser_get_int( pd, "async_collision_check", &config.async_col_check );
    parser_free( &pd );
}
Beispiel #3
0
static void
config_free(struct config *conf)
{
	void	*value;

	config_reset(conf);

	while (dict_poproot(&conf->conf, &value))
		free(value);

	free(conf);
}
Beispiel #4
0
void engine_init(const char *appname)
{
	dbg_logger_stdout();
	dbg_logger_debugger();
	dbg_msg("About","DDrace Mod initially By 3DA \nVersion:%s",RACE_VERSION);
	/* */
	dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
#ifdef CONF_ARCH_ENDIAN_LITTLE
	dbg_msg("engine", "arch is little endian");
#elif defined(CONF_ARCH_ENDIAN_BIG)
	dbg_msg("engine", "arch is big endian");
#else
	dbg_msg("engine", "unknown endian");
#endif

	/* init the network */
	net_init();
	netcommon_init();
	
	/* create storage location */
	{
		char path[1024] = {0};
		fs_storage_path(appname, application_save_path, sizeof(application_save_path));
		if(fs_makedir(application_save_path) == 0)
		{		
			str_format(path, sizeof(path), "%s/screenshots", application_save_path);
			fs_makedir(path);

			str_format(path, sizeof(path), "%s/maps", application_save_path);
			fs_makedir(path);

			str_format(path, sizeof(path), "%s/downloadedmaps", application_save_path);
			fs_makedir(path);

			str_format(path, sizeof(path), "%s/demos", application_save_path);
			fs_makedir(path);
		}
	}

	/* init console and add the console logger */
	console_init();
	dbg_logger(console_print);
	
	jobs_initpool(&hostlookuppool, 1);

	//MACRO_REGISTER_COMMAND("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_dumpmem, 0x0, "Dump the memory",2);
	//MACRO_REGISTER_COMMAND("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_lognetwork, 0x0, "Log the network",2);
	
	/* reset the config */
	config_reset();
}
Beispiel #5
0
static void _list_add(Trash * trash, Config * config, char const * path,
		char const * filename, const time_t sixmonths)
{
	const char ext[] = DATA_EXTENSION;
	const char section[] = DATA_SECTION;
	BrowserPluginHelper * helper = trash->helper;
	size_t len;
	GtkTreeIter iter;
	GdkPixbuf * pixbuf;
	char * p;
	char const * q;
	struct tm tm;
	time_t t = -1;
	char const * u;
	char buf[16];

	if((len = strlen(filename)) <= sizeof(ext))
		return;
	if(strncmp(&filename[len - sizeof(ext) + 1], ext, sizeof(ext)) != 0)
		return;
	config_reset(config);
	p = g_strdup_printf("%s/%s", path, filename);
	if(config_load(config, p) != 0
			|| (q = config_get(config, section, DATA_PATH)) == NULL)
	{
		g_free(p);
		return;
	}
	pixbuf = helper->get_icon(helper->browser, q, NULL, NULL, NULL, 24);
	if((u = config_get(config, section, DATA_DELETIONDATE)) != NULL
			&& strptime(u, "%Y-%m-%dT%H:%M:%S", &tm) != NULL)
	{
		t = mktime(&tm);
		len = strftime(buf, sizeof(buf), (t >= sixmonths)
				? "%b %e %H:%M" : "%b %e %Y", &tm);
		buf[len] = '\0';
		u = buf;
	}
	else
		u = "";
	_list_get_iter(trash, &iter, p);
	gtk_list_store_set(trash->store, &iter, TC_PIXBUF, pixbuf,
			TC_FILENAME, filename, TC_PATH, p,
			TC_PATH_ORIGINAL, q, TC_DELETED, t,
			TC_DELETED_DISPLAY, u, TC_UPDATED, TRUE, -1);
	g_free(p);
}
Beispiel #6
0
static void setup()
{
	sei();

	if (config_initialized() != OK) {
		serial_init(9600);
		printf("Initializing config\r\n");
#ifdef FACTORY_SELFTEST
		if ( TestIO() != OK )
			return;
#endif 
		config_reset();
	}

	setUartBaudRate();
	rfBeeInit();
	printf("ok\r\n");
}
Beispiel #7
0
static int expac_new(expac_t **expac, const char *config_file)
{
  expac_t *e;
  enum _alpm_errno_t alpm_errno = 0;
  config_t config;
  const char *dbroot = "/";
  const char *dbpath = "/var/lib/pacman";
  int r;

  e = calloc(1, sizeof(*e));
  if(e == NULL) {
    return -ENOMEM;
  }

  memset(&config, 0, sizeof(config));

  r = config_parse(&config, config_file);
  if(r < 0) {
    return r;
  }

  if(config.dbpath) {
    dbpath = config.dbpath;
  }

  if(config.dbroot) {
    dbroot = config.dbroot;
  }

  e->alpm = alpm_initialize(dbroot, dbpath, &alpm_errno);
  if(!e->alpm) {
    return -alpm_errno;
  }

  for(int i = 0; i < config.size; ++i) {
    alpm_register_syncdb(e->alpm, config.repos[i], 0);
  }

  config_reset(&config);

  *expac = e;

  return 0;
}
/* function: config_reset */
static int tolua_config_eressea_config_reset00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
 !tolua_isnoobj(tolua_S,1,&tolua_err)
 )
 goto tolua_lerror;
 else
#endif
 {
 {
  config_reset();
 }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'reset'.",&tolua_err);
 return 0;
#endif
}
Beispiel #9
0
static int
config_connect(struct config *conf)
{
	static const struct {
		const char	*name;
		int		 cols;
	} qspec[SQL_MAX] = {
		{ "query_alias",	1 },
		{ "query_domain",	1 },
		{ "query_credentials",	2 },
		{ "query_netaddr",	1 },
		{ "query_userinfo",	3 },
		{ "query_source",	1 },
		{ "query_mailaddr",	1 },
		{ "query_addrname",	1 },
	};
	size_t	 i;
	char	*conninfo, *q;

	log_debug("debug: table-postgres: (re)connecting");

	/* Disconnect first, if needed */
	config_reset(conf);

	conninfo = dict_get(&conf->conf, "conninfo");
	if (conninfo == NULL) {
		log_warnx("warn: table-postgres: missing \"conninfo\" configuration directive");
		goto end;
	}

	conf->db = PQconnectdb(conninfo);
	if (conf->db == NULL) {
		log_warnx("warn: table-postgres: PQconnectdb return NULL");
		goto end;
	}
	if (PQstatus(conf->db) != CONNECTION_OK) {
		log_warnx("warn: table-postgres: PQconnectdb: %s",
		    PQerrorMessage(conf->db));
		goto end;
	}

	for (i = 0; i < SQL_MAX; i++) {
		q = dict_get(&conf->conf, qspec[i].name);
		if (q && (conf->statements[i] = table_postgres_prepare_stmt(
		    conf->db, q, 1, qspec[i].cols)) == NULL)
			goto end;
	}

	q = dict_get(&conf->conf, "fetch_source");
	if (q && (conf->stmt_fetch_source = table_postgres_prepare_stmt(conf->db,
	    q, 0, 1)) == NULL)
		goto end;

	log_debug("debug: table-postgres: connected");

	return (1);

    end:
	config_reset(conf);
	return (0);
}
Beispiel #10
0
static int
config_connect(struct config *conf)
{
	static const struct {
		const char	*name;
		int		 cols;
	} qspec[SQL_MAX] = {
		{ "query_alias",	1 },
		{ "query_domain",	1 },
		{ "query_credentials",	2 },
		{ "query_netaddr",	1 },
		{ "query_userinfo",	4 },
		{ "query_source",	1 },
		{ "query_mailaddr",	1 },
		{ "query_addrname",	1 },
	};
	my_bool	 reconn;
	size_t	 i;
	char	*host, *username, *password, *database, *q;

	log_debug("debug: table-mysql: (re)connecting");

	/* Disconnect first, if needed */
	config_reset(conf);

	host = dict_get(&conf->conf, "host");
	username = dict_get(&conf->conf, "username");
	database = dict_get(&conf->conf, "database");
	password = dict_get(&conf->conf, "password");

	conf->db = mysql_init(NULL);
	if (conf->db == NULL) {
		log_warnx("warn: table-mysql: mysql_init failed");
		goto end;
	}

	reconn = 1;
	if (mysql_options(conf->db, MYSQL_OPT_RECONNECT, &reconn) != 0) {
		log_warnx("warn: table-mysql: mysql_options: %s",
		    mysql_error(conf->db));
		goto end;
	}

	if (!mysql_real_connect(conf->db, host, username, password, database,
	    0, NULL, 0)) {
		log_warnx("warn: table-mysql: mysql_real_connect: %s",
		    mysql_error(conf->db));
		goto end;
	}

	for (i = 0; i < SQL_MAX; i++) {
		q = dict_get(&conf->conf, qspec[i].name);
		if (q && (conf->statements[i] = table_mysql_prepare_stmt(
		    conf->db, q, 1, qspec[i].cols)) == NULL)
			goto end;
	}

	q = dict_get(&conf->conf, "fetch_source");
	if (q && (conf->stmt_fetch_source = table_mysql_prepare_stmt(conf->db,
	    q, 0, 1)) == NULL)
		goto end;

	log_debug("debug: table-mysql: connected");

	return (1);

    end:
	config_reset(conf);
	return (0);
}
Beispiel #11
0
/* load config */
void config_load( )
{
    char *str;
    char file_name[512];
    PData *pd; 
    /* set to defaults */
    config_check_dir();
    config_reset();
    /* load config */
    sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME );
    if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) {
        fprintf( stderr, "%s\n", parser_get_error() );
        return;
    }
    /* assign */
    parser_get_int( pd, "set_id_local", &config.levelset_id_local );
    parser_get_int( pd, "set_count_local", &config.levelset_count_local );
    parser_get_int( pd, "set_id_home", &config.levelset_id_home );
    parser_get_int( pd, "set_count_home", &config.levelset_count_home );
    parser_get_int( pd, "player_count", &config.player_count );
    if ( parser_get_value( pd, "player0", &str, 0 ) )
        strcpy_lt( config.player_names[0], str, 31 );
    if ( parser_get_value( pd, "player1", &str, 0 ) )
        strcpy_lt( config.player_names[1], str, 31 );
    if ( parser_get_value( pd, "player2", &str, 0 ) )
        strcpy_lt( config.player_names[2], str, 31 );
    if ( parser_get_value( pd, "player3", &str, 0 ) )
        strcpy_lt( config.player_names[3], str, 31 );
    parser_get_int( pd, "diff", &config.diff );
    parser_get_int( pd, "starting_level", &config.startlevel );
    parser_get_int( pd, "rel_warp_limit", &config.rel_warp_limit );
    parser_get_int( pd, "add_bonus_levels", &config.addBonusLevels );
    parser_get_int( pd, "left", &config.k_left );
    parser_get_int( pd, "right", &config.k_right );
    parser_get_int( pd, "fire_left", &config.k_lfire );
    parser_get_int( pd, "fire_right", &config.k_rfire );
    parser_get_int( pd, "return", &config.k_return );
    parser_get_int( pd, "turbo", &config.k_turbo );
    parser_get_int( pd, "rel_motion", &config.rel_motion );
    parser_get_int( pd, "grab", &config.grab );
    parser_get_int( pd, "motion_mod", &config.i_motion_mod );
    config.motion_mod = 0.01 * config.i_motion_mod;
    parser_get_int( pd, "convex", &config.convex );
    parser_get_int( pd, "linear_corner", &config.linear_corner );
    parser_get_int( pd, "random_angle", &config.random_angle );
    parser_get_int( pd, "maxballspeed", &config.maxballspeed_int1000 );
    config.maxballspeed_float = (float)config.maxballspeed_int1000 / 1000;
    parser_get_int( pd, "invert", &config.invert );
    parser_get_int( pd, "sound", &config.sound );
    parser_get_int( pd, "volume", &config.volume );
    parser_get_int( pd, "speech", &config.speech );
    parser_get_int( pd, "badspeech", &config.badspeech );
    parser_get_int( pd, "audio_buffer_size", &config.audio_buffer_size );
    parser_get_int( pd, "anim", &config.anim );
    parser_get_int( pd, "fullscreen", &config.fullscreen );
    parser_get_int( pd, "fade", &config.fade );
    parser_get_int( pd, "bonus_info", &config.bonus_info );
    parser_get_int( pd, "fps", &config.fps );
    parser_get_int( pd, "ball_level", &config.ball_level );
    parser_get_int( pd, "debris_level", &config.debris_level );
    parser_get_int( pd, "i_key_speed", &config.i_key_speed );
    config.key_speed = 0.001 * config.i_key_speed;
    parser_get_int( pd, "use_hints", &config.use_hints );
    parser_get_int( pd, "return_on_click", &config.return_on_click );
    parser_get_int( pd, "theme_id", &config.theme_id );
    parser_get_int( pd, "theme_count", &config.theme_count );
    if ( parser_get_value( pd, "server", &str, 0 ) )
        strcpy_lt( config.server, str, 64 );
    if ( parser_get_value( pd, "local_port", &str, 0 ) )
        strcpy_lt( config.local_port, str, 6 );
    if ( parser_get_value( pd, "username", &str, 0 ) )
        strcpy_lt( config.username, str, 15 );
    parser_get_int( pd, "mp_diff", &config.mp_diff );
    parser_get_int( pd, "mp_rounds", &config.mp_rounds );
    parser_get_int( pd, "mp_frags", &config.mp_frags );
    parser_get_int( pd, "mp_balls", &config.mp_balls );
    parser_free( &pd );
}
Beispiel #12
0
static int _settings_browse_folder(Settings * settings, Config * config,
		char const * folder)
{
	const char ext[8] = ".desktop";
	const char section[] = "Desktop Entry";
	const char application[] = "Application";
	const int flags = GTK_ICON_LOOKUP_FORCE_SIZE;
	const gint iconsize = 48;
	GtkIconTheme * theme;
	GtkTreeModel * model;
	GtkListStore * store;
	DIR * dir;
	struct dirent * de;
	size_t len;
	String * path;
	int res;
	String const * name;
	String const * icon;
	String const * exec;
	String const * p;
	GdkPixbuf * pixbuf;
	GtkTreeIter iter;
	GError * error = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, folder);
#endif
	if((path = string_new_append(folder, "/applications", NULL)) == NULL)
		return -_settings_error(error_get(NULL), 1);
	dir = opendir(path);
	string_delete(path);
	if(dir == NULL)
		return -_settings_error(strerror(errno), 1);
	theme = gtk_icon_theme_get_default();
	model = _settings_get_model(settings);
	store = GTK_LIST_STORE(model);
	while((de = readdir(dir)) != NULL)
	{
		if((len = strlen(de->d_name)) <= sizeof(ext))
			continue;
		if(strncmp(&de->d_name[len - sizeof(ext)], ext, sizeof(ext))
				!= 0)
			continue;
		if((path = string_new_append(folder, "/applications/",
						de->d_name, NULL)) == NULL)
		{
			_settings_error(error_get(NULL), 1);
			continue;
		}
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, path);
#endif
		config_reset(config);
		res = config_load(config, path);
		string_delete(path);
		if(res != 0)
		{
			_settings_error(error_get(NULL), 1);
			continue;
		}
		p = config_get(config, section, "Type");
		name = config_get(config, section, "Name");
		exec = config_get(config, section, "Exec");
		if(p == NULL || name == NULL || exec == NULL
				|| strcmp(exec, PROGNAME) == 0)
			continue;
		if(strcmp(p, application) != 0)
			continue;
		if((p = config_get(config, section, "Categories")) == NULL
				|| string_find(p, "Settings") == NULL)
			continue;
		if((p = config_get(config, section, "TryExec")) != NULL
				&& _settings_browse_folder_access(path, X_OK)
				!= 0 && errno == ENOENT)
				continue;
		if((icon = config_get(config, section, "Icon")) == NULL)
			icon = GTK_STOCK_PREFERENCES;
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() \"%s\" %s\n", __func__, name,
				icon);
#endif
		if((pixbuf = gtk_icon_theme_load_icon(theme, icon, iconsize,
						flags, &error)) == NULL)
		{
			_settings_error(error->message, 0);
			g_error_free(error);
			error = NULL;
		}
#if GTK_CHECK_VERSION(2, 6, 0)
		gtk_list_store_insert_with_values(store, &iter, -1,
#else
		gtk_list_store_append(store, &iter);
		gtk_list_store_set(store, &iter,
#endif
				SC_ICON, pixbuf, SC_NAME, name, SC_EXEC, exec,
				/* FIXME detect privileged settings */
				SC_PRIVILEGED, FALSE, -1);
	}
	closedir(dir);
	return FALSE;
}
Beispiel #13
0
int resetConfig() {
	config_reset();
	return OK;
}
Beispiel #14
0
/* note_load */
int note_load(Note * note)
{
	config_reset(note->config);
	return config_load(note->config, note->filename);
}
Beispiel #15
0
static int
config_connect(struct config *conf)
{
	static const struct {
		const char	*name;
		const char	*default_query;
	} qspec[SQL_MAX] = {
		{ "query_alias",	"GET alias:%s" },
		{ "query_domain",	"GET domain:%s" },
		{ "query_credentials",	"GET credentials:%s" },
		{ "query_netaddr",	"GET netaddr:%s" },
		{ "query_userinfo",	"GET userinfo:%s" },
		{ "query_source",	"GET source:%s" },
		{ "query_mailaddr",	"GET mailaddr:%s" },
		{ "query_addrname",	"GET addrname:%s" },
	};
	size_t	 i;

	char	*host;
	int	port;

	char	*q;

	char		*value;
	const char	*e;
	long long	 ll;

	host = "127.0.0.1";
	port = 6379;

	log_debug("debug: table-redis: (re)connecting");

	/* Disconnect first, if needed */
	config_reset(conf);

	if ((value = dict_get(&conf->conf, "host")))
		host = value;

	if ((value = dict_get(&conf->conf, "port"))) {
		e = NULL;
		ll = strtonum(value, 0, 65535, &e);
		if (e) {
			log_warnx("warn: table-redis: bad value for port: %s", e);
			goto end;
		}
		port = ll;
	}

	conf->db = redisConnect(host, port);
	if (conf->db == NULL) {
		log_warnx("warn: table-redis: redisConnect return NULL");
		goto end;
	}

	for (i = 0; i < SQL_MAX; i++) {
		q = dict_get(&conf->conf, qspec[i].name);
		if (q)
			conf->statements[i] = strdup(q);
		else
			conf->statements[i] = strdup(qspec[i].default_query);
	}

	log_debug("debug: table-redis: connected");

	return (1);

end:
	config_reset(conf);
	return (0);
}