コード例 #1
0
ファイル: calc_nsp.c プロジェクト: TC01/tilibs
// Helper function for multiple functions below.
static gchar * build_path(CalcModel model, VarRequest * vr)
{
	const char * dot_if_any;
	gchar * path;

	// Don't add a dot if this file type is unknown.
	if (vr->type >= NSP_MAXTYPES)
	{
		dot_if_any = "";
	}
	else
	{
		dot_if_any = ".";
	}

	if (!strcmp(vr->folder, ""))
	{
		path = g_strconcat("/", vr->name, dot_if_any, tifiles_vartype2fext(model, vr->type), NULL);
	}
	else
	{
		path = g_strconcat("/", vr->folder, "/", vr->name, dot_if_any, tifiles_vartype2fext(model, vr->type), NULL);
	}

	return path;
}
コード例 #2
0
ファイル: gui.c プロジェクト: uyjulian/tilp_and_gfm
GLADE_CB void
on_save_clicked                        (GtkToolButton   *toolbutton,
                                        gpointer         user_data)
{
	gchar *fn = NULL, *ext = NULL;
	gchar *filename = NULL;

	if(GFMFile.filename != NULL)
		filename = g_strdup(GFMFile.filename);

	if(GFMFile.type & TIFILE_TIGROUP)
	{
		ext = g_strdup("*.tig");
	}
	else if(GFMFile.type & TIFILE_GROUP)
	{
		if(ticalcs_dirlist_ve_count(GFMFile.trees.vars) > 1)
		{
			// Group file
			ext = g_strconcat("*.", tifiles_vartype2fext(GFMFile.model, 0x00), NULL);
			ext[4] = 'g';
		}
		else if(ticalcs_dirlist_ve_count(GFMFile.trees.vars) == 1)
		{
			// Single file
			GNode *parent, *child;
			VarEntry *ve;

			parent = g_node_nth_child(GFMFile.trees.vars, 0);
			child = g_node_nth_child(parent, 0);
			ve = (VarEntry *) (child->data);

			filename = g_strconcat(ticonv_varname_to_filename(GFMFile.model, ve->name, ve->type), ".", 
				tifiles_vartype2fext(GFMFile.model, ve->type), NULL);
			ext = g_strconcat("*.", tifiles_vartype2fext(GFMFile.model, ve->type), NULL);
		}
		else
		{
			g_free(filename);
			return;
		}
	}

	fn = (char *)create_fsel(inst_paths.home_dir, filename, ext, TRUE);
	if(fn == NULL)
		return;
	g_free(filename);
	g_free(ext);

	file_save(fn);

	g_free(GFMFile.filename);
	GFMFile.filename = g_strdup(fn);

	enable_save(FALSE);
}
コード例 #3
0
ファイル: misc.c プロジェクト: TI8XEmulator/graph89
/**
 * tifiles_build_filename:
 * @model: a calculator model.
 * @ve: a #VarEntry structure.
 *
 * Build a valid filename from folder name, variable name and variable type.
 * Example: real number x on TI89 in the 'main' folder will give 'main.x.89e'.
 * Note: this function is useable with FLASH apps, too (but you have to fill the #VarEntry structure yourself).
 *
 * Return value: a newly allocated string which must be freed when no longer used.
 **/
TIEXPORT2 char* TICALL tifiles_build_filename(CalcModel model, const VarEntry *ve)
{
	char *filename;

	if (ve == NULL)
	{
		tifiles_critical("%s: an argument is NULL", __FUNCTION__);
		return NULL;
	}


	if(tifiles_calc_is_ti8x(model) || !strcmp(ve->folder, "") || 
		(ve->type == tifiles_flash_type(model)))
	{
		char *part2;
		const char *part3;
		char *tmp;

		part2 = ticonv_varname_to_filename(model, ve->name, ve->type);
		part3 = tifiles_vartype2fext(model, ve->type);

		tmp = g_strconcat(part2, ".", part3, NULL);
		g_free(part2);

		filename = g_strdup(tmp);
		g_free(tmp);
	}
	else
	{
		char *part1;
		char *part2;
		const char *part3;
		char *tmp;

		part1 = ticonv_varname_to_filename(model, ve->folder, -1);
		part2 = ticonv_varname_to_filename(model, ve->name, ve->type);
		part3 = tifiles_vartype2fext(model, ve->type);

		tmp = g_strconcat(part1, ".", part2, ".", part3, NULL);
		g_free(part1);
		g_free(part2);

		filename = strdup(tmp);
		g_free(tmp);
	}

	return filename;
}
コード例 #4
0
ファイル: calc_nsp.c プロジェクト: debrouxl/tilp-libticalcs
static int		del_var		(CalcHandle* handle, VarRequest* vr)
{
	char *utf8;
	char *path;
	int err;
	const char * dot_if_any = ".";

	TRYF(nsp_session_open(handle, SID_FILE_MGMT));

	// Don't add a dot if this file type is unknown.
	if (vr->type >= NSP_MAXTYPES)
		dot_if_any = "";

	path = g_strconcat("/", vr->folder, "/", vr->name, dot_if_any,
		tifiles_vartype2fext(handle->model, vr->type), NULL);
	utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), _("Deleting %s..."), utf8);
	g_free(utf8);
	update_label();

	err = nsp_cmd_s_del_file(handle, path);
	g_free(path);
	if (err)
	{
		return err;
	}
	TRYF(nsp_cmd_r_del_file(handle));

	TRYF(nsp_session_close(handle));

	return 0;
}
コード例 #5
0
ファイル: calc_nsp.c プロジェクト: debrouxl/tilp-libticalcs
static int		recv_var	(CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr)
{
	char *path;
	uint8_t *data = NULL;
	VarEntry *ve;
	char *utf8;
	int err;
	const char * dot_if_any = ".";

	TRYF(nsp_session_open(handle, SID_FILE_MGMT));

	// Don't add a dot if this file type is unknown.
	if (vr->type >= NSP_MAXTYPES)
		dot_if_any = "";

	path = g_strconcat("/", vr->folder, "/", vr->name, dot_if_any, 
		tifiles_vartype2fext(handle->model, vr->type), NULL);
	utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	err = nsp_cmd_s_get_file(handle, path);
	g_free(path);
	if (err)
	{
		return err;
	}
	TRYF(nsp_cmd_r_get_file(handle, &(vr->size)));

	TRYF(nsp_cmd_s_file_ok(handle));
	if (vr->size)
		TRYF(nsp_cmd_r_file_contents(handle, &(vr->size), &data));
	TRYF(nsp_cmd_s_status(handle, ERR_OK));

	content->model = handle->model;
	strcpy(content->comment, tifiles_comment_set_single());
	content->num_entries = 1;

	content->entries = tifiles_ve_create_array(1);
	ve = content->entries[0] = tifiles_ve_create();
	memcpy(ve, vr, sizeof(VarEntry));

	ve->data = tifiles_ve_alloc_data(ve->size);
	if (data && ve->data)
	{
		memcpy(ve->data, data, ve->size);
	}
	g_free(data);

	// XXX don't check the result of this call, to enable reception of variables from Nspires running OS >= 1.7.
	// Those versions send a martian packet:
	// * a src port never seen before in the conversation;
	// * an improper dest port;
	// * a 1-byte payload containing 02 (i.e. an invalid address for the next packet).
	// * .ack = 0x00 (instead of 0x0A).
	nsp_session_close(handle);

	return 0;
}
コード例 #6
0
ファイル: calc_nsp.c プロジェクト: debrouxl/tilp-libticalcs
static int		rename_var	(CalcHandle* handle, VarRequest* oldname, VarRequest* newname)
{
	char *utf81, *utf82;
	char *path1, *path2;
	int err;
	const char * dot_if_any = ".";

	TRYF(nsp_session_open(handle, SID_FILE_MGMT));

	// Don't add a dot if this file type is unknown.
	if (oldname->type >= NSP_MAXTYPES)
		dot_if_any = "";
	path1 = g_strconcat("/", oldname->folder, "/", oldname->name, dot_if_any,
		tifiles_vartype2fext(handle->model, oldname->type), NULL);

	dot_if_any = ".";
	// Don't add a dot if this file type is unknown.
	if (oldname->type >= NSP_MAXTYPES)
		dot_if_any = "";
	path2 = g_strconcat("/", newname->folder, "/", newname->name, dot_if_any,
		tifiles_vartype2fext(handle->model, newname->type), NULL);
	utf81 = ticonv_varname_to_utf8(handle->model, path1, oldname->type);
	utf82 = ticonv_varname_to_utf8(handle->model, path2, newname->type);
	g_snprintf(update_->text, sizeof(update_->text), _("Renaming %s to %s..."), utf81, utf82);
	g_free(utf82);
	g_free(utf81);
	update_label();

	err = nsp_cmd_s_rename_file(handle, path1, path2);
	g_free(path2);
	g_free(path1);
	if (err)
	{
		return err;
	}
	TRYF(nsp_cmd_r_rename_file(handle));

	TRYF(nsp_session_close(handle));

	return 0;
}
コード例 #7
0
ファイル: calc_nsp.c プロジェクト: debrouxl/tilp-libticalcs
static int		send_var	(CalcHandle* handle, CalcMode mode, FileContent* content)
{
	char *utf8;
	uint8_t status;
	const char * dot_if_any = ".";

	update_->cnt2 = 0;
	update_->max2 = 1;
	update_->pbar();

	{
		VarEntry *ve = content->entries[0];
		gchar *path;
		int err;

		if(ve->action == ACT_SKIP)
			return 0;

		if(!strlen(ve->folder))
			return ERR_ABORT;

		TRYF(nsp_session_open(handle, SID_FILE_MGMT));

		// Don't add a dot if this file type is unknown.
		if (ve->type >= NSP_MAXTYPES)
			dot_if_any = "";

		path = g_strconcat("/", ve->folder, "/", ve->name, dot_if_any, 
			tifiles_vartype2fext(handle->model, ve->type), NULL);

		utf8 = ticonv_varname_to_utf8(handle->model, path, ve->type);
		g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
		g_free(utf8);
		update_label();

		err = nsp_cmd_s_put_file(handle, path, ve->size);
		g_free(path);
		if (err)
		{
			return err;
		}
		TRYF(nsp_cmd_r_put_file(handle));

		TRYF(nsp_cmd_s_file_contents(handle, ve->size, ve->data));
		TRYF(nsp_cmd_r_status(handle, &status));

		TRYF(nsp_session_close(handle));
	}

	return 0;
}
コード例 #8
0
ファイル: backup.c プロジェクト: debrouxl/tilp-libticalcs
/**
 * ticalcs_calc_recv_tigroup:
 * @handle: a previously allocated handle
 * @filename: name of file
 * @mode: which vars/apps to receive
 *
 * Receive a TiGroup file.
 *
 * Return value: 0 if ready else ERR_NOT_READY.
 **/
TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, TigMode mode)
{
	int i, j;
	int i_max, j_max;
	GNode *vars, *apps;
	int nvars = 0;
	int napps = 0;
	int b = 0;

	if(handle == NULL) return ERR_INVALID_HANDLE;
	if (content == NULL)
	{
		ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL");
		return -1;
	}

	update_->cnt3 = 0;
	update_->pbar();

	// Do a directory list and check for something to backup
	TRYF(handle->calc->get_dirlist(handle, &vars, &apps));
	if((mode & TIG_RAM) || (mode & TIG_ARCHIVE))
		nvars = ticalcs_dirlist_ve_count(vars);
	if(mode & TIG_FLASH)
		napps = ticalcs_dirlist_ve_count(apps);

	update_->cnt3 = 0;
	update_->max3 = nvars + napps;
	update_->pbar();

	if(!nvars && !napps)
		return ERR_NO_VARS;

	// Check whether the last folder is empty
	b = g_node_n_children(g_node_nth_child(vars, g_node_n_children(vars) - 1));
	PAUSE(100); // needed by TI84+/USB

	// Receive all vars
	i_max = g_node_n_children(vars);
	if((mode & TIG_RAM) || (mode & TIG_ARCHIVE))
	for(i = 0; i < i_max; i++) 
	{
		GNode *parent = g_node_nth_child(vars, i);

		j_max = g_node_n_children(parent);
		for(j = 0; j < j_max; j++) 
		{
			GNode *node = g_node_nth_child(parent, j);
			VarEntry *ve = (VarEntry *) (node->data);
			TigEntry *te;
			char *filename;
			char *varname;
			char *fldname;

			PAUSE(100);
			TRYF(handle->calc->is_ready(handle));
			PAUSE(100);

			update_->cnt3++;
			update_->pbar();

			if(((mode & TIG_ARCHIVE) && (ve->attr == ATTRB_ARCHIVED)) ||
			   ((mode & TIG_RAM) && ve->attr != ATTRB_ARCHIVED))
			{
				fldname = ticonv_varname_to_filename(handle->model, ve->folder, -1);
				varname = ticonv_varname_to_filename(handle->model, ve->name, ve->type);
				if(handle->calc->features & FTS_FOLDER)
					filename = g_strconcat(fldname, ".", varname, ".", 
						tifiles_vartype2fext(handle->model, ve->type), NULL);
				else
					filename = g_strconcat(varname, ".", 
						tifiles_vartype2fext(handle->model, ve->type), NULL);
				g_free(fldname);
				g_free(varname);

				te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model);
				g_free(filename);

				TRYF(handle->calc->recv_var(handle, 0, te->content.regular, ve));
				tifiles_content_add_te(content, te);
			}
		}
	}
	ticalcs_dirlist_destroy(&vars);

	// Receive all apps
	i_max = g_node_n_children(apps);
	if(mode & TIG_FLASH)
	for(i = 0; i < i_max; i++) 
	{
		GNode *parent = g_node_nth_child(apps, i);

		j_max = g_node_n_children(parent);
		for(j = 0; j < j_max; j++) 
		{
			GNode *node = g_node_nth_child(parent, j);
			VarEntry *ve = (VarEntry *) (node->data);
			TigEntry *te;
			char *filename;
			char *basename;

			TRYF(handle->calc->is_ready(handle));

			update_->cnt3++;
			update_->pbar();

			basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type);
			filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL);
			g_free(basename);

			te = tifiles_te_create(filename, TIFILE_FLASH, handle->model);
			g_free(filename);

			TRYF(handle->calc->recv_app(handle, te->content.flash, ve));
			tifiles_content_add_te(content, te);
		}
	}	
	ticalcs_dirlist_destroy(&apps);

	return 0;
}
コード例 #9
0
ファイル: backup.c プロジェクト: debrouxl/tilibs
/**
 * ticalcs_calc_recv_tigroup:
 * @handle: a previously allocated handle
 * @filename: name of file
 * @mode: which vars/apps to receive
 *
 * Receive a TiGroup file.
 *
 * Return value: 0 if ready else ERR_NOT_READY.
 **/
TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, TigMode mode)
{
	int i, j;
	GNode *vars, *apps;
	int nvars = 0;
	int napps = 0;
	int b = 0;
	int ret;

	VALIDATE_HANDLE(handle);
	if (content == NULL)
	{
		ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL");
		return -1;
	}
	VALIDATE_CALCFNCTS(handle->calc);

	handle->updat->cnt3 = 0;
	ticalcs_update_pbar(handle);

	// Do a directory list and check for something to backup
	ret = handle->calc->get_dirlist(handle, &vars, &apps);
	if (ret)
	{
		return ret;
	}

	if ((mode & TIG_RAM) || (mode & TIG_ARCHIVE))
	{
		nvars = ticalcs_dirlist_ve_count(vars);
	}
	if (mode & TIG_FLASH)
	{
		napps = ticalcs_dirlist_ve_count(apps);
	}

	handle->updat->cnt3 = 0;
	handle->updat->max3 = nvars + napps;
	ticalcs_update_pbar(handle);

	if (!nvars && !napps)
	{
		ret = ERR_NO_VARS; // THIS RETURNS !
		goto end;
	}

	// Check whether the last folder is empty
	b = g_node_n_children(g_node_nth_child(vars, g_node_n_children(vars) - 1));
	PAUSE(100); // needed by TI84+/USB

	// Receive all vars
	if ((mode & TIG_RAM) || (mode & TIG_ARCHIVE))
	{
		int i_max = g_node_n_children(vars);
		for (i = 0; i < i_max; i++)
		{
			GNode *parent = g_node_nth_child(vars, i);

			int j_max = g_node_n_children(parent);
			for (j = 0; j < j_max; j++)
			{
				GNode *node = g_node_nth_child(parent, j);
				VarEntry *ve = (VarEntry *) (node->data);
				TigEntry *te;

				PAUSE(100);
				ret = handle->calc->is_ready(handle);
				if (ret)
				{
					goto end;
				}
				PAUSE(100);

				handle->updat->cnt3++;
				ticalcs_update_pbar(handle);

				if (((mode & TIG_ARCHIVE) && (ve->attr == ATTRB_ARCHIVED)) ||
				    ((mode & TIG_RAM) && ve->attr != ATTRB_ARCHIVED))
				{
					char *filename;
					char *varname = ticonv_varname_to_filename(handle->model, ve->name, ve->type);
					char *fldname = ticonv_varname_to_filename(handle->model, ve->folder, -1);
					if (handle->calc->features & FTS_FOLDER)
					{
						filename = g_strconcat(fldname, ".", varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL);
					}
					else
					{
						filename = g_strconcat(varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL);
					}
					g_free(varname);
					g_free(fldname);

					te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model);
					g_free(filename);
					if (te != NULL)
					{
						ret = handle->calc->recv_var(handle, 0, te->content.regular, ve);
						if (ret)
						{
							tifiles_te_delete(te);
							goto end;
						}
						tifiles_content_add_te(content, te);
					}
					else
					{
						ret = ERR_MALLOC;
						goto end;
					}
				}
			}
		}
	}

	// Receive all apps
	if (mode & TIG_FLASH)
	{
		int i_max = g_node_n_children(apps);
		for(i = 0; i < i_max; i++) 
		{
			GNode *parent = g_node_nth_child(apps, i);

			int j_max = g_node_n_children(parent);
			for (j = 0; j < j_max; j++) 
			{
				GNode *node = g_node_nth_child(parent, j);
				VarEntry *ve = (VarEntry *) (node->data);
				TigEntry *te;
				char *filename;
				char *basename;

				ret = handle->calc->is_ready(handle);
				if (ret)
				{
					goto end;
				}

				handle->updat->cnt3++;
				ticalcs_update_pbar(handle);

				basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type);
				filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL);
				g_free(basename);

				te = tifiles_te_create(filename, TIFILE_FLASH, handle->model);
				g_free(filename);
				if (te != NULL)
				{
					ret = handle->calc->recv_app(handle, te->content.flash, ve);
					if (ret)
					{
						tifiles_te_delete(te);
						goto end;
					}
					tifiles_content_add_te(content, te);
				}
				else
				{
					ret = ERR_MALLOC;
					goto end;
				}
			}
		}
	}
end:
	ticalcs_dirlist_destroy(&apps);
	ticalcs_dirlist_destroy(&vars);

	return ret;
}