コード例 #1
0
ファイル: grouped.c プロジェクト: TI8XEmulator/graph89
/**
 * tifiles_group_files:
 * @src_filenames: a NULL-terminated array of strings (list of files to group).
 * @dst_filename: the filename where to store the group.
 *
 * Group several TI files into a single one (group file).
 *
 * Return value: an error code if unsuccessful, 0 otherwise.
 **/
TIEXPORT2 int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename)
{
	int i, n;
	FileContent **src = NULL;
	FileContent *dst = NULL;
	int ret = 0;

	if (src_filenames == NULL || dst_filename == NULL)
	{
		tifiles_critical("%s: an argument is NULL", __FUNCTION__);
		return ERR_INVALID_FILE;
	}

	if(tifiles_file_get_model(src_filenames[0]) == CALC_NSPIRE)
		return ERR_BAD_CALC;

	// counter number of files to group
	for (n = 0; src_filenames[n] != NULL; n++);

	// allocate space for that
	src = (FileContent **)g_malloc0((n + 1) * sizeof(FileContent *));
	if (src == NULL)
		return ERR_MALLOC;

	// allocate each structure and load file content
	for (i = 0; i < n; i++)
	{
		src[i] = (FileContent *)g_malloc0(sizeof(FileContent));
		if (src[i] == NULL)
			return ERR_MALLOC;

		ret = tifiles_file_read_regular(src_filenames[i], src[i]);
		if(ret) goto tgf;
	}
	src[i] = NULL;

	// group the array of structures
	ret = tifiles_group_contents(src, &dst);
	if(ret) goto tgf;

	// write grouped file
	ret = tifiles_file_write_regular(dst_filename, dst, NULL);
	if(ret) goto tgf;

	// release allocated memory
tgf:
	tifiles_content_delete_group(src);
	tifiles_content_delete_regular(dst);

	return 0;
}
コード例 #2
0
ファイル: backup.c プロジェクト: debrouxl/tilp-libticalcs
int tixx_recv_backup(CalcHandle* handle, BackupContent* content)
{
	int i, j, k;
	int i_max, j_max;
	GNode *vars, *apps;
	int nvars, ivars = 0;
	int b = 0;
	FileContent **group;
	FileContent *single;

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

	// Do a directory list and check for something to backup
	TRYF(handle->calc->get_dirlist(handle, &vars, &apps));
	nvars = ticalcs_dirlist_ve_count(vars);
	if(!nvars)
		return ERR_NO_VARS;

	update_->cnt2 = update_->cnt3 = 0;
	update_->max2 = update_->max3 = nvars;
	update_->pbar();

	// 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

	// Create a group file
	k = 0;
	group = tifiles_content_create_group(nvars);

	// Receive all vars except for FLASH apps
	i_max = g_node_n_children(vars);
	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);

			update_->cnt2 = update_->cnt3 = ++ivars;
			update_->pbar();

			// we need to group files !
			TRYF(handle->calc->is_ready(handle));
			group[k] = tifiles_content_create_regular(handle->model);
			TRYF(handle->calc->recv_var(handle, 0, group[k++], ve));
		}
	}

	ticalcs_dirlist_destroy(&vars);
	ticalcs_dirlist_destroy(&apps);

	tifiles_group_contents(group, &single);
	tifiles_content_delete_group(group);

	// Swap content and single because we have a pointer on an allocated content
	{
		FileContent* cnt = (FileContent *)content;

		memcpy(content, single, sizeof(FileContent));
		cnt->entries = single->entries;
		strcpy(cnt->comment, tifiles_comment_set_group());
	}

	return 0;
}
コード例 #3
0
ファイル: backup.c プロジェクト: debrouxl/tilibs
int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content)
{
	int i, j, k;
	int i_max;
	GNode *vars, *apps;
	int nvars, ivars = 0;
	int b = 0;
	FileContent **group;
	FileContent *single;
	int ret;

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

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

	handle->updat->cnt2 = handle->updat->cnt3 = 0;
	handle->updat->max2 = handle->updat->max3 = nvars;
	ticalcs_update_pbar(handle);

	// 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

	// Create a group file
	k = 0;
	group = tifiles_content_create_group(nvars);

	// Receive all vars except for FLASH apps
	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);

			handle->updat->cnt2 = handle->updat->cnt3 = ++ivars;
			ticalcs_update_pbar(handle);

			// we need to group files !
			ret = handle->calc->is_ready(handle);
			if (ret)
			{
				goto end;
			}
			group[k] = tifiles_content_create_regular(handle->model);
			ret = handle->calc->recv_var(handle, 0, group[k++], ve);
			if (ret)
			{
				goto end;
			}
		}
	}

end:
	ticalcs_dirlist_destroy(&vars);
	ticalcs_dirlist_destroy(&apps);

	if (!ret)
	{
		FileContent * cnt;
		ret = tifiles_group_contents(group, &cnt);
		if (!ret)
		{
			cnt->model = content->model;

			// Steal contents of cnt, then clean up.
			memcpy(content, cnt, sizeof(*content));
			cnt->num_entries = 0;
			cnt->entries = NULL;
			tifiles_content_delete_regular(cnt);

			ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment));
		}
	}

	tifiles_content_delete_group(group);

	return ret;
}