Example #1
0
File: init.c Project: UIKit0/eXtace
void read_config(void)
{
	ConfigFile *cfgfile;
	gchar *filename;
	int fd;
	gchar *temp_cmap = NULL;
	Color_map.filename = NULL;
	filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL);
	cfgfile = cfg_open_file(filename);
	if (cfgfile)
	{
		cfg_read_int(cfgfile, "Global", "major_ver", &major_ver);
		cfg_read_int(cfgfile, "Global", "minor_ver", &minor_ver);
		cfg_read_int(cfgfile, "Global", "micro_ver", &micro_ver);
		if ((major_ver == 1) && (minor_ver == 8))
		{
			printf("Config file structure changed. using defaults. \nClosing eXtace will save your NEW settings.\n");
			cfg_free(cfgfile);
			unlink(filename);
			g_free(filename);
			return;

		}
		cfg_read_string(cfgfile, "Global", "last_colormap", &temp_cmap);
		if (temp_cmap != NULL)
		{
			fd = open(temp_cmap, O_RDONLY);
			if (fd > 0)
			{
				Color_map.filename = g_strdup(temp_cmap);
				close(fd);
			}
			else
				Color_map.filename = NULL;

			g_free(temp_cmap);
		}
		cfg_read_boolean(cfgfile, "Global", "landtilt", &landtilt);
		cfg_read_boolean(cfgfile, "Global", "spiketilt", &spiketilt);
		cfg_read_float(cfgfile, "Global", "low_freq", &low_freq);
		cfg_read_float(cfgfile, "Global", "high_freq", &high_freq);
		cfg_read_int(cfgfile, "Window", "width", &width);
		cfg_read_int(cfgfile, "Window", "height", &height);
		cfg_read_int(cfgfile, "Window", "main_x_origin", &main_x_origin);
		cfg_read_int(cfgfile, "Window", "main_y_origin", &main_y_origin);
		cfg_read_int(cfgfile, "Window", "grad_x_origin", &grad_x_origin);
		cfg_read_int(cfgfile, "Window", "grad_y_origin", &grad_y_origin);
		cfg_read_int(cfgfile, "Window", "dir_x_origin", &dir_x_origin);
		cfg_read_int(cfgfile, "Window", "dir_y_origin", &dir_y_origin);

		cfg_read_int(cfgfile, "Global", "mode", &mode);
		{
		  int i;
		  if(cfg_read_int(cfgfile, "Global", "data_source", &i))
		  data_source=i;
		}
		cfg_read_int(cfgfile, "Global", "decimation_factor", &decimation_factor);
		cfg_read_int(cfgfile, "Global", "fft_signal_source", &fft_signal_source);
		cfg_read_float(cfgfile, "Global", "scope_zoom", &scope_zoom);
		cfg_read_int(cfgfile, "Global", "refresh_rate", &refresh_rate);
		cfg_read_int(cfgfile, "Global", "landflip", &landflip);
		cfg_read_int(cfgfile, "Global", "spikeflip", &spikeflip);
		cfg_read_boolean(cfgfile, "Global", "outlined", &outlined);
		cfg_read_int(cfgfile, "Global", "sub_mode_3D", &sub_mode_3D);
		cfg_read_int(cfgfile, "Global", "scope_sub_mode", &scope_sub_mode);
		cfg_read_boolean(cfgfile, "Global", "dir_win_present", &dir_win_present);
		cfg_read_int(cfgfile, "Global", "nsamp", &nsamp);

		cfg_read_int(cfgfile, "Global", "window_func", &window_func);
		cfg_read_int(cfgfile, "Global", "win_width", &win_width);
		cfg_read_int(cfgfile, "Global", "axis_type", &axis_type);
		cfg_read_int(cfgfile, "Global", "bands", &bands);
		cfg_read_int(cfgfile, "Global", "lag", &lag);
		cfg_read_float(cfgfile, "Global", "noise_floor", &noise_floor);
		cfg_read_int(cfgfile, "Global", "seg_height", &seg_height);
		cfg_read_int(cfgfile, "Global", "seg_space", &seg_space);
		cfg_read_boolean(cfgfile, "Global", "bar_decay", &bar_decay);
		cfg_read_boolean(cfgfile, "Global", "peak_decay", &peak_decay);
		cfg_read_int(cfgfile, "Global", "decay_speed", &bar_decay_speed);
		cfg_read_boolean(cfgfile, "Global", "stabilized", &stabilized);
		cfg_read_boolean(cfgfile, "Global", "show_graticule", &show_graticule);
		cfg_read_int(cfgfile, "Global", "peak_decay_speed", &peak_decay_speed);
		cfg_read_int(cfgfile, "Global", "peak_hold_time", &peak_hold_time);
		cfg_read_int(cfgfile, "Global", "tape_scroll", &tape_scroll);
		cfg_read_int(cfgfile, "Global", "xdet_scroll", &xdet_scroll);
		cfg_read_int(cfgfile, "Global", "zdet_scroll", &zdet_scroll);
		cfg_read_float(cfgfile, "Global", "xdet_start", &xdet_start);
		cfg_read_float(cfgfile, "Global", "xdet_end", &xdet_end);
		cfg_read_float(cfgfile, "Global", "ydet_start", &ydet_start);
		cfg_read_float(cfgfile, "Global", "ydet_end", &ydet_end);
		cfg_read_float(cfgfile, "Global", "x3d_start", &x3d_start);
		cfg_read_float(cfgfile, "Global", "x3d_end", &x3d_end);
		cfg_read_float(cfgfile, "Global", "y3d_start", &y3d_start);
		cfg_read_float(cfgfile, "Global", "y3d_end", &y3d_end);
		cfg_read_float(cfgfile, "Global", "multiplier", &multiplier);
		cfg_read_int(cfgfile, "Global", "x3d_scroll", &x3d_scroll);
		cfg_read_int(cfgfile, "Global", "z3d_scroll", &z3d_scroll);
		cfg_read_boolean(cfgfile, "Global", "show_leader", &show_leader);
		cfg_read_int(cfgfile, "Global", "scope_sync_source", &scope_sync_source);
		cfg_read_int(cfgfile, "Global", "horiz_spec_start", &horiz_spec_start);
		cfg_read_int(cfgfile, "Global", "vert_spec_start", &vert_spec_start);
		if (horiz_spec_start > width)
			horiz_spec_start = width-10; 
		if (vert_spec_start > height)
			vert_spec_start = height-10;
		if (horiz_spec_start < 60)
			horiz_spec_start = 60; 
		if (vert_spec_start < 120)
			vert_spec_start = 120;


		cfg_free(cfgfile);

	}
	else
		printf("Config file not found, using defaults\n");
	g_free(filename);

}
Example #2
0
/*!
  \brief Binds remaing keys in cfgfile to the object
  \param object is the pointer to object where we bind the data to
  \param cfgfile is the pointer to configfile  where we pull the data from
  \param section is the section name within cfgfile to gt the data from
  \param keys is the array of char *'s, list of keys to read and store
  \param num_keys is the number of elements in the keys array
  */
G_MODULE_EXPORT void bind_keys(GObject *object, ConfigFile *cfgfile, gchar *section, gchar ** keys, gint num_keys)
{
	gint i = 0;
	gint tmpi = 0;
	gfloat tmpf = 0.0;
	gfloat *newfloat = NULL;
	gchar * tmpbuf = NULL;
	gchar * tmpstr = NULL;
	DataType keytype = MTX_STRING;

	for (i=0;i<num_keys;i++)
	{
		keytype = translate_string(keys[i]);
		switch(keytype)
		{
			case MTX_INT:
				if (cfg_read_int(cfgfile,section,keys[i],&tmpi))
				{
					MTXDBG(KEYPARSER,_("Binding INT \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					OBJ_SET(object,
							keys[i],
							GINT_TO_POINTER(tmpi));	
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_INT: read of key \"%s\" from section \"%s\"  of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_ENUM:
				if (cfg_read_string(cfgfile,section,keys[i],&tmpbuf))
				{
					tmpi = translate_string(tmpbuf);
					MTXDBG(KEYPARSER,_("Binding ENUM \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					OBJ_SET(object,
							keys[i],
							GINT_TO_POINTER(tmpi));	
					g_free(tmpbuf);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_ENUM: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_BOOL:
				if (cfg_read_boolean(cfgfile,section,keys[i],&tmpi))
				{
					MTXDBG(KEYPARSER,_("Binding BOOL \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					if (tmpi)
					{
						OBJ_SET(object,
								keys[i],
								GINT_TO_POINTER(tmpi));	
						if (strstr(keys[i],"fromecu_complex"))
							load_complex_params_obj(object,cfgfile,section);
					}
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_BOOL: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_FLOAT:
				if (cfg_read_float(cfgfile,section,keys[i],&tmpf))
				{
					newfloat = NULL;
					newfloat = g_new0(gfloat, 1);
					*newfloat = tmpf;
					OBJ_SET_FULL(object,
							keys[i],
							(gpointer)newfloat,g_free);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_FLOAT: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;

			case MTX_STRING:
				if(cfg_read_string(cfgfile,section,keys[i],&tmpbuf))
				{
					MTXDBG(KEYPARSER,_("Binding STRING key:\"%s\" value:\"%s\" to widget \"%s\"\n"),keys[i],tmpbuf,section);
					tmpstr = DATA_GET(object,keys[i]);
					/* If data already on widget, append
					 * new data and store */
					if ((tmpstr) && (g_strrstr(keys[i],"bind_to_list")!= NULL))
					{
						tmpstr = g_strconcat(tmpstr,",",tmpbuf,NULL);
						OBJ_SET_FULL(object,
								keys[i],
								g_strdup(tmpstr),
								g_free);
						g_free(tmpstr);
					}
					else
						OBJ_SET_FULL(object,keys[i],g_strdup(tmpbuf),g_free);
								
					g_free(tmpbuf);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_STRING: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			default:
				break;

		}
	}

	return;
}