示例#1
0
/* 
   Read the RC file and configure the corresponding variables 
*/
void rcfile_read(void)
{
	FILE *txt;
	char buffer[256];
	char *p;
	int l=0;

	rcfile_get_path(&rc_file);

	txt=fopen(rc_file, "rt");
	g_free(rc_file);
	if(txt == NULL) {
		tiemu_info(_("Configuration file not found, use default values. You can create one by the 'File|Save config' command menu."));
		return;
	}

	while(!feof(txt)) {
		if (!fgets(buffer, 256, txt))
			break;
		l++;
		buffer[strlen(buffer)-1]='\0';

	if(!strcmp(buffer, "RC_END")) {
	  fclose(txt);
	  return;
	}

	if(buffer[0]=='#' || !strlen(buffer)) continue;
      
	/* Common part with TiLP: hardware section */
	if ((p = find_str(buffer, "cable_model="))) 
	{
		linkp.cable_model = ticables_string_to_model(p);
		continue;
	}
	
	if ((p = find_str(buffer, "cable_port="))) 
	{
		linkp.cable_port = ticables_string_to_port(p);
		continue;
	}
	
	if ((p = find_str(buffer, "cable_timeout="))) 
	{
		sscanf(p, "%i", &(linkp.cable_timeout));
		continue;
	}
	
	if ((p = find_str(buffer, "cable_delay="))) {
		sscanf(p, "%i", &(linkp.cable_delay));
		continue;
	}

	if( (p=find_str(buffer, "qs_file=")) ) 
	{
	  g_free(options.qs_file);
	  options.qs_file = g_strdup(p);
	  continue;
	}

	if( (p=find_str(buffer, "qs_enabled=")) ) 
	{
	  sscanf(p, "%i", &(options.qs_enabled));
	  continue;
	}

      /* GtkTiEmu specific part: emulator section */
	if( (p=find_str(buffer, "rom_file=")) ) 
	{
	  g_free(params.rom_file);
	  params.rom_file = g_strdup(p);
	  continue;
	}

	if( (p=find_str(buffer, "img_file=")) ) 
	{
	  g_free(params.rom_file);
	  params.rom_file = g_strdup(p);
	  continue;
	}

	if( (p=find_str(buffer, "tib_file=")) )
	{
	  g_free(params.tib_file);
	  params.tib_file = g_strdup(p);
	  continue;
	}

    if( (p=find_str(buffer, "sav_file=")) )
	{
	  g_free(params.sav_file);
	  params.sav_file = g_strdup(p);
	  continue;
	}

	if( (p=find_str(buffer, "skin=")) ) 
	{
	  sscanf(p, "%i", &(options.skin));
	  continue;
	}

	if( (p=find_str(buffer, "view_mode=")) )
	{
	  if(!strcmp(p, "normal")) options.view = VIEW_NORMAL;
	  else if(!strcmp(p, "large")) options.view = VIEW_LARGE;
	  else if(!strcmp(p, "full")) options.view = VIEW_FULL;
	  else if(!strncmp(p, "custom", strlen("custom"))) 
	  {
		  //char *q;
		  options.view = VIEW_CUSTOM;
		  p=find_str(buffer, "view_mode=custom");
		  /*q = strchr(p, ',');
		  if(q) *q = '.';*/
		  sscanf(p, " (%f)", &(options.scale));
		  if(options.scale < 0.01)
			  options.scale = 1.0;
	  }
	  else stop(l);
	  continue;
	}

	if( (p=find_str(buffer, "cpu_rate=")) )
	{
	  sscanf(p, "%u", &(params.cpu_rate));
	  continue;
	}

	if( (p=find_str(buffer, "hw_rate=")) )
	{
	  sscanf(p, "%u", &(params.hw_rate));
	  continue;
	}

	if( (p=find_str(buffer, "lcd_rate=")) )
	{
	  sscanf(p, "%i", &(params.lcd_rate));
	  continue;
	}

	if( (p=find_str(buffer, "hw_protect=")) )
	{
	  sscanf(p, "%i", &(params.hw_protect));
	  continue;
	}

	if( (p=find_str(buffer, "img_format=")) )
	{
	  if(!strcmp(p, "jpg")) options2.format=IMG_JPG;
	  else if(!strcmp(p, "png")) options2.format=IMG_PNG;
	  else if(!strcmp(p, "ico")) options2.format=IMG_ICO;
	  else if(!strcmp(p, "eps")) options2.format=IMG_EPS;
	  else if(!strcmp(p, "pdf")) options2.format=IMG_PDF;
	  else if(!strcmp(p, "bmp")) options2.format=IMG_BMP;
	  else stop(l);
	  continue;
	}
      
	if( (p=find_str(buffer, "img_type=")) )
	{
	  if(!strcmp(p, "bw")) options2.type = IMG_BW;
	  else if(!strcmp(p, "color")) options2.type = IMG_COL;
	  else stop(l);
	  continue;
	}
      
	if( (p=find_str(buffer, "img_size=")) )
	{
	  if(!strcmp(p, "lcd")) options2.size = IMG_LCD;
	  else if(!strcmp(p, "skin")) options2.size = IMG_SKIN;
	  else stop(l);
	  continue;
	}

	if( (p=find_str(buffer, "screen_folder=")) )
	{
	  g_free(options2.folder);
	  options2.folder = g_strdup(p);
	  continue;
	}
      
	if( (p=find_str(buffer, "screen_file=")) )
	{
	  g_free(options2.file);
	  options2.file = g_strdup(p);
	  continue;
	}
      
	if( (p=find_str(buffer, "screen_counter=")) )
	{
	  sscanf(p, "%i", &(options2.counter));
	  continue;
	}

	if( (p=find_str(buffer, "screen_shots=")) )
	{
	  sscanf(p, "%i", &(options2.shots));
	  continue;
	}

	if( (p=find_str(buffer, "screen_skips=")) )
	{
	  sscanf(p, "%i", &(options2.skips));
	  continue;
	}

	if( (p=find_str(buffer, "clipboard=")) )
	{
	  if(!strcmp(p, "no")) options2.clipboard = 0;
	  else if(!strcmp(p, "yes")) options2.clipboard = 1;

	  continue;
	}
	
	if( (p=find_str(buffer, "console=")) )
	{
	  if(!strcmp(p, "no")) options.console = 0;
	  else if(!strcmp(p, "yes")) options.console = 1;
	  else if(!strcmp(p, "boot")) options.console = 2;
	  else stop(l);
	  continue;
	}

	if( (p=find_str(buffer, "kbd_dbg=")) )
	{
	  if(!strcmp(p, "no")) options.kbd_dbg = 0;
	  else if(!strcmp(p, "yes")) options.kbd_dbg = 1;
	}

	if( (p=find_str(buffer, "fs_type=")) )
	{
	  if(!strcmp(p, "old")) options.fs_type = 0;
	  else if(!strcmp(p, "new")) options.fs_type = 1;
	  else if(!strcmp(p, "native") || !strcmp(p, "win32")) options.fs_type = 2;
	  else if(!strcmp(p, "kde")) options.fs_type = 3;
	}
	
	if( (p=find_str(buffer, "skin_file=")) )
	{
	  g_free(options.skin_file);
	  options.skin_file = g_strdup(p);
	  continue;
	}

    if( (p=find_str(buffer, "keys_file=")) )
	{
	  g_free(options.keys_file);
	  options.keys_file = g_strdup(p);
	  continue;
	}

	if( (p=find_str(buffer, "calc_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.calc.rect.x), &(options3.calc.rect.y), 
		  &(options3.calc.rect.w), &(options3.calc.rect.h),
		  &(options3.calc.minimized), &(options3.calc.closed)
		  );
	  continue;
	}

	if( (p=find_str(buffer, "bkpts_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.bkpts.rect.x), &(options3.bkpts.rect.y), 
		  &(options3.bkpts.rect.w), &(options3.bkpts.rect.h),
		  &(options3.bkpts.minimized), &(options3.bkpts.closed)
		  );
	  continue;
	}
	if( (p=find_str(buffer, "code_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.code.rect.x), &(options3.code.rect.y), 
		  &(options3.code.rect.w), &(options3.code.rect.h),
		  &(options3.code.minimized), &(options3.code.closed));
	  continue;
	}
	if( (p=find_str(buffer, "mem_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.mem.rect.x), &(options3.mem.rect.y), 
		  &(options3.mem.rect.w), &(options3.mem.rect.h),
		  &(options3.mem.minimized), &(options3.mem.closed));
	  continue;
	}
	if( (p=find_str(buffer, "regs_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.regs.rect.x), &(options3.regs.rect.y), 
		  &(options3.regs.rect.w), &(options3.regs.rect.h),
		  &(options3.regs.minimized), &(options3.regs.closed));
	  continue;
	}
	if( (p=find_str(buffer, "pclog_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.pclog.rect.x), &(options3.pclog.rect.y), 
		  &(options3.pclog.rect.w), &(options3.pclog.rect.h),
		  &(options3.pclog.minimized), &(options3.pclog.closed));
	  continue;
	}
	if( (p=find_str(buffer, "stack_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.stack.rect.x), &(options3.stack.rect.y), 
		  &(options3.stack.rect.w), &(options3.stack.rect.h),
		  &(options3.stack.minimized), &(options3.stack.closed));
	  continue;
	}
	if( (p=find_str(buffer, "heap_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.heap.rect.x), &(options3.heap.rect.y), 
		  &(options3.heap.rect.w), &(options3.heap.rect.h),
		  &(options3.heap.minimized), &(options3.heap.closed));
	  continue;
	}	
	if( (p=find_str(buffer, "iop_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.iop.rect.x), &(options3.iop.rect.y), 
		  &(options3.iop.rect.w), &(options3.iop.rect.h),
		  &(options3.iop.minimized), &(options3.iop.closed));
	  continue;
	}
	if( (p=find_str(buffer, "dock_wnd=")) )
	{
	  sscanf(p, "(%i;%i;%i;%i;%i;%i)", 
		  &(options3.dock.rect.x), &(options3.dock.rect.y), 
		  &(options3.dock.rect.w), &(options3.dock.rect.h),
		  &(options3.dock.minimized), &(options3.dock.closed));
	  continue;
	}
	if( (p=find_str(buffer, "wnd_transient=")) )
	{
	  if(!strcmp(p, "no")) options3.transient = 0;
	  else if(!strcmp(p, "yes")) options3.transient = 1;
	  else stop(l);
	  continue;
	}

	if( (p=find_str(buffer, "dbg_font_type=")) )
	{
	  if(!strcmp(p, "default")) options3.dbg_font_type = 0;
	  else if(!strcmp(p, "custom")) options3.dbg_font_type = 1;
	  else stop(l);
	  continue;
	}
	if( (p=find_str(buffer, "dbg_font_name=")) )
	{
		g_free(options3.dbg_font_name);
		options3.dbg_font_name = g_strdup(p);
		continue;
	}

	if( (p=find_str(buffer, "dbg_dock=")) )
	{
	  if(!strcmp(p, "no")) options3.dbg_dock = 0;
	  else if(!strcmp(p, "yes")) options3.dbg_dock = 1;
	  else stop(l);
	  continue;
	}

    }
  fclose(txt);

  return;
}
示例#2
0
/* Search for command line options and build file list (pseudo-selection) */
int tilp_cmdline_scan(int *argc, char ***argv)
{
	GOptionContext* context;
	GError *error = NULL;
	gint ret = 0;

	// parse command line
	context = g_option_context_new ("- Tilp Is a Linking Program");
	g_option_context_add_main_entries(context, entries, ""/*GETTEXT_PACKAGE*/);
	g_option_context_set_help_enabled(context, TRUE);
	g_option_context_set_ignore_unknown_options(context, FALSE);
	g_option_context_parse(context, argc, argv, &error);
	g_option_context_free(context);

	// report error
	if (error) 
	{
		tilp_warning("Failed to parse cmdline: %s\n", error->message);
		g_error_free(error);
	}

	if(show_version)
	{
		exit(0);
	}

	// convert name to value
	if(calc != NULL)
	{
		options.calc_model = ticalcs_string_to_model(calc);
		g_free(calc);
	}

	// convert name to value
	if(cable != NULL)
	{
		options.cable_model = ticables_string_to_model(cable);
		g_free(cable);
	}

	// look for short-options
	if(array != NULL)
	{
		gchar **p;
		gint len;
		int i;

		// check for no extensions
		for(p = array, len = 0; *p != NULL; p++, len++)
		{
			if(strrchr(*p, '.') == NULL)
			{
				for(i = 0; i < CABLE_MAX; i++)
				{
					if(!g_strcasecmp(ticables_model_to_string(i), *p))
						options.cable_model = i;
				}

				for(i = 0; i < CALC_MAX; i++)
				{
					if(!g_strcasecmp(ticalcs_model_to_string(i), *p))
						options.calc_model = i;
				}
			}
		}
	}

	// remap for USB handhelds
	options.calc_model = ticalcs_remap_model_to_usb(options.cable_model, options.calc_model);

	if(!options.cable_port)
	{
		switch(options.cable_model)
		{
		case CABLE_VTI:
		case CABLE_TIE:
			options.cable_port = PORT_0;
			break;
		default:
			options.cable_port = PORT_1;
			break;
		}
	}

	// are files passed ?
	if(array != NULL)
	{
		gchar **p, **q;
		gint len;

		working_mode = MODE_CMD;

		// count files
		for(p = array, len = 0; *p != NULL; p++, len++);

		// allocate list of files
		flist = g_malloc0((len + 1) * sizeof(gchar *));

		// rebuild a list of file with full path
		for(p = array, q = flist; *p != NULL; p++, q++)
		{
			// skip short-options
			if(strrchr(*p, '.') == NULL)
			{
				q--;
				continue;
			}

			// check whether path is local or absolute
			if (!g_path_is_absolute(*p))
				*q = g_strconcat(g_get_current_dir(), G_DIR_SEPARATOR_S, *p, NULL);
			else
				*q = g_strdup(*p);
		}

		// build a pseudo file selection for TiLP
		for(q = flist; *q != NULL; q++)
		{
			if(g_file_test(*q, G_FILE_TEST_EXISTS))
			{
				tilp_local_selection_add(*q);
			}
			else
			{
				gchar *str;

				str = g_strdup_printf(_("The file <%s> does not exist."), *q);
				gif->msg_box1(_("Error"), str);
				g_free(str);
				ret = -1;
			}
		}

		g_strfreev(array);
		g_strfreev(flist);
	}

	// don't use GUI ?
	if(dont_use_gui)
		working_mode &= ~MODE_GUI;
	else
		working_mode |= MODE_GUI;

	return ret;
}
示例#3
0
int tilp_config_read(void)
{
	char* ini_file;
	gboolean result;
	GKeyFile* kf;
	GError* error = NULL;
	gchar* s;

	if(!tilp_config_exist())
		return -1;

	// get file location
	ini_file = get_config_path();

	// and read
	kf = g_key_file_new();
	result = g_key_file_load_from_file(kf, ini_file, G_KEY_FILE_NONE, &error);
	if (result == FALSE)
	{
		if (error != NULL)
		{
			g_key_file_free(kf);
			g_free(ini_file);
			fprintf (stderr, "Unable to read file: %s\n", error->message);
			g_error_free(error);
			return -1;
		}
	}

	// Section [DEVICE]
	s = g_key_file_get_string(kf, SECTION_DEVICE, "calc_model", &error);
	if(s != NULL)
		options.calc_model = ticalcs_string_to_model(s);
	g_free(s);

	s = g_key_file_get_string(kf, SECTION_DEVICE, "cable_model", &error);
	if(s != NULL)
		options.cable_model = ticables_string_to_model(s);
	g_free(s);
	
	options.calc_model = ticalcs_remap_model_to_usb(options.cable_model, options.calc_model);

	s = g_key_file_get_string(kf, SECTION_DEVICE, "cable_port", &error);
	if(s != NULL)
		options.cable_port = ticables_string_to_port(s);
	g_free(s);

	options.cable_timeout = 
		g_key_file_get_integer(kf, SECTION_DEVICE, "cable_timeout", &error);

	options.cable_delay = 
		g_key_file_get_integer(kf, SECTION_DEVICE, "cable_delay", &error);

	// Section GUI
	options.pane_x_size = g_key_file_get_integer(kf, SECTION_GUI, "pane_x_size", &error);
	options.pane_y_size = g_key_file_get_integer(kf, SECTION_GUI, "pane_y_size", &error);

	options.wnd_x_size1 = g_key_file_get_integer(kf, SECTION_GUI, "wnd_x_size1", &error);
	options.wnd_y_size2 = g_key_file_get_integer(kf, SECTION_GUI, "wnd_y_size2", &error);

	options.wnd_x_size1 = g_key_file_get_integer(kf, SECTION_GUI, "wnd_x_size1", &error);
	options.wnd_y_size2 = g_key_file_get_integer(kf, SECTION_GUI, "wnd_y_size2", &error);

	options.local_sort = 
		g_key_file_get_integer(kf, SECTION_GUI, "local_sort", &error);
	options.local_sort_order = 
		g_key_file_get_integer(kf, SECTION_GUI, "local_sort_order", &error);

	options.remote_sort = 
		g_key_file_get_integer(kf, SECTION_GUI, "remote_sort", &error);
	options.remote_sort_order = 
		g_key_file_get_integer(kf, SECTION_GUI, "remote_sort_order", &error);

	if (g_key_file_has_key(kf, SECTION_GUI, "filesel_type", &error))
		options.filesel_type = 
			g_key_file_get_integer(kf, SECTION_GUI, "filesel_type", &error);
	else
		options.filesel_type = 2;
	/* Copy filesel_type to fs_type. If fs_type is 2 (native), it will be changed to the
	   appropriate number based on the platform, whereas filesel_type stays at 2. */
	options.fs_type = options.filesel_type;
	options.full_gui = 
		g_key_file_get_integer(kf, SECTION_GUI, "full_gui", &error);

	// Section [OPTIONS]
	options.auto_detect = 
		g_key_file_get_integer(kf, SECTION_OPTIONS, "auto_detect", &error);
	options.show_all = 
		g_key_file_get_integer(kf, SECTION_OPTIONS, "show_all", &error);
	options.overwrite = 
		g_key_file_get_integer(kf, SECTION_OPTIONS, "overwrite", &error);
	options.recv_as_group = 
		g_key_file_get_integer(kf, SECTION_OPTIONS, "recv_as_group", &error);
	options.backup_as_tigroup = 
		g_key_file_get_integer(kf, SECTION_OPTIONS, "backup_as_tigroup", &error);
	s = 
		g_key_file_get_string(kf, SECTION_OPTIONS, "working_dir", &error);
	if(s != NULL)
	{
		g_free(options.working_dir);
		options.working_dir = s;
	}

	// Section FONTS
	s = g_key_file_get_string(kf, SECTION_FONTS, "local_font_name", &error);
	if(s != NULL)
	{
		g_free(options.local_font_name);
		options.local_font_name = s;
	}

	s = g_key_file_get_string(kf, SECTION_FONTS, "remote_font_name", &error);
	if(s != NULL)
	{
		g_free(options.remote_font_name);
		options.remote_font_name = s;
	}

	// Section [SCREEN]
	options.screen_format = 
		g_key_file_get_integer(kf, SECTION_SCREEN, "screen_format", &error);
	options.screen_scaling = 
		g_key_file_get_integer(kf, SECTION_SCREEN, "screen_scaling", &error);
	options.screen_clipping = 
		g_key_file_get_integer(kf, SECTION_SCREEN, "screen_clipping", &error);
	options.screen_blurry = 
		g_key_file_get_integer(kf, SECTION_SCREEN, "screen_blurry", &error);

	// free structures
	g_key_file_free(kf);
	g_free(ini_file);

	if(options.calc_model == CALC_NSPIRE)
		options.recv_as_group = 0;

	return 0;
}