Example #1
0
/**
 * tifiles_content_dup_regular:
 *
 * Allocates and copies a new #FileContent structure.
 *
 * Return value: none.
 **/
TIEXPORT2 FileContent* TICALL tifiles_content_dup_regular(FileContent *content)
{
	FileContent *dup = NULL;
	int i;

	if (content != NULL)
	{
		dup = tifiles_content_create_regular(content->model);
		if (dup != NULL)
		{
			memcpy(dup, content, sizeof(FileContent));
			dup->entries = tifiles_ve_create_array(content->num_entries);

			if (dup->entries != NULL)
			{
				for (i = 0; i < content->num_entries; i++) 
					dup->entries[i] = tifiles_ve_dup(content->entries[i]);
			}
		}
	}
	else
	{
		tifiles_critical("%s(NULL)", __FUNCTION__);
	}
	return dup;
}
Example #2
0
/**
 * tifiles_group_contents:
 * @src_contents: a pointer on an array of #FileContent structures. The array must be NULL-terminated.
 * @dst_content: the address of a pointer. This pointer will see the allocated group file.
 *
 * Must be freed when no longer needed as well as the content of each #FileContent structure
 * (use #tifiles_content_delete_regular as usual).
 *
 * Group several #FileContent structures into a single one.
 *
 * Return value: an error code if unsuccessful, 0 otherwise.
 **/
TIEXPORT2 int TICALL tifiles_group_contents(FileContent **src_contents, FileContent **dst_content)
{
	FileContent *dst;
	int i, j, n;

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

	for (n = 0; src_contents[n] != NULL; n++)
	{
		if(src_contents[n]->model == CALC_NSPIRE)
		{
			return ERR_BAD_CALC;
		}
	}

	dst = (FileContent *)g_malloc0(sizeof(FileContent));
	if (dst == NULL)
		return ERR_MALLOC;

	if (n > 0)
	{
		memcpy(dst, src_contents[0], sizeof(FileContent));
	}

	dst->num_entries = n;
	dst->entries = g_malloc0((n + 1) * sizeof(VarEntry*));
	if (dst->entries == NULL)
	{
		free(dst);
		return ERR_MALLOC;
	}

	for (i = 0; i < n; i++)
	{
		FileContent *src = src_contents[i];

		for(j = 0; j < src->num_entries; j++)
			dst->entries[i] = tifiles_ve_dup(src->entries[j]);
	}

	*dst_content = dst;

	return 0;
}
Example #3
0
/**
 * tifiles_ungroup_content:
 * @src_content: a pointer on the structure to unpack.
 * @dst_contents: the address of your pointer. This pointers will point on a 
 * dynamically allocated array of structures. The array is terminated by NULL.
 *
 * Ungroup a TI file by exploding the structure into an array of structures.
 *
 * Array must be freed when no longer needed as well as the content of each #FileContent 
 * structure (use #tifiles_content_delete_regular as usual).
 *
 * Return value: an error code if unsuccessful, 0 otherwise.
 **/
TIEXPORT2 int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest)
{
	int i;
	FileContent **dst;

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

	if(src->model == CALC_NSPIRE)
		return ERR_BAD_CALC;

	// allocate an array of FileContent structures (NULL terminated)
	dst = *dest = (FileContent **)g_malloc0((src->num_entries + 1) * sizeof(FileContent *));
	if (dst == NULL)
		return ERR_MALLOC;

	// parse each entry and duplicate it into a single content
	for (i = 0; i < src->num_entries; i++)
	{
		VarEntry *dst_entry = NULL;

		// allocate and duplicate content
		dst[i] = (FileContent *)g_malloc0(sizeof(FileContent));
		if (dst[i] == NULL)
			return ERR_MALLOC;
		memcpy(dst[i], src, sizeof(FileContent));

		// allocate and duplicate entry
		dst[i]->entries = g_malloc0((1+1) * sizeof(VarEntry*));
		dst_entry = dst[i]->entries[0] = tifiles_ve_dup(src->entries[i]);

		// update some fields
		dst[i]->num_entries = 1;
		dst[i]->checksum += tifiles_checksum((uint8_t *) dst_entry, 15);
		dst[i]->checksum += tifiles_checksum(dst_entry->data, dst_entry->size);
	}
	dst[i] = NULL;

	return 0;
}
Example #4
0
/**
 * tifiles_group_add_file:
 * @src_filename: the file to add to group file
 * @dst_filename: the group file
 *
 * Add src_filename content to dst_filename content and write to dst_filename.
 *
 * Return value: 0 if successful, an error code otherwise.
 **/
TIEXPORT2 int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_filename)
{
	CalcModel src_model;
	CalcModel dst_model;
	FileContent* src_content = NULL;
	FileContent* dst_content = NULL;
	int i;
	int ret = 0;

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

	// src can be single/group file and dst must be group file
	if(!tifiles_file_is_group(dst_filename))
		return -1;

	src_model = tifiles_file_get_model(src_filename);
	dst_model = tifiles_file_get_model(dst_filename);

	src_content = tifiles_content_create_regular(src_model);
	dst_content = tifiles_content_create_regular(dst_model);

	ret = tifiles_file_read_regular(src_filename, src_content);
	if(ret) goto tgaf;
	ret = tifiles_file_read_regular(dst_filename, dst_content);
	if(ret) goto tgaf;

	for(i = 0; i < src_content->num_entries; i++)
		tifiles_content_add_entry(dst_content, tifiles_ve_dup(src_content->entries[i]));

	ret = tifiles_file_write_regular(dst_filename, dst_content, NULL);
	if(ret) goto tgaf;

tgaf:
	tifiles_content_delete_regular(src_content);
	tifiles_content_delete_regular(dst_content);

	return ret;
}
Example #5
0
static void renderer_edited(GtkCellRendererText * cell,
			    const gchar * path_string,
			    const gchar * new_text, gpointer user_data)
{
	GtkTreeModel *model = GTK_TREE_MODEL(tree);
	GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
	GtkTreeIter iter;
	const char *old_text;
	VarEntry *ve;
	gchar *str;
	VarEntry *arg;

	if (!gtk_tree_model_get_iter(model, &iter, path))
		return;

	gtk_tree_model_get(model, &iter, COLUMN_NAME, &old_text, -1);
	gtk_tree_model_get(model, &iter, COLUMN_DATA, &ve, -1);

	// tokenize and check for existence
	str = ticonv_varname_tokenize(GFMFile.model, new_text, ve->type);
	arg = tifiles_ve_dup(ve);
	if(strlen(str) > 8)
		str[8] = '\0';
	strcpy(arg->name, str);
	ticonv_varname_free(str);

	if(ticalcs_dirlist_ve_exist(GFMFile.trees.vars, arg))
	{
		msgbox_one(MSGBOX_INFO, _("The name already exists. Please choose another one..."));
		tifiles_ve_delete(arg);
		return;
	}

	// update entry
	strcpy(ve->name, arg->name);
	tifiles_ve_delete(arg);

	gtk_tree_store_set(tree, &iter, COLUMN_NAME, new_text, -1);
	gtk_tree_path_free(path);

	enable_save(TRUE);
}
Example #6
0
/**
 * ticalcs_dirlist_ve_add:
 * @tree: source tree.
 * @entry: entry to add.
 *
 * Add an entry into the main tree (if it doesn't exist yet).
 *
 * Return value: none.
 **/
TIEXPORT3 void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry)
{
	TreeInfo *info;
	int i, j;
	int found = 0;

	GNode *parent = NULL;
	VarEntry *fe = NULL;

	GNode *child;
	VarEntry *ve;

	const char *folder;

	if (tree == NULL || entry == NULL)
	{
		ticalcs_critical("ticalcs_dirlist_ve_add: an argument is NULL");
		return;
	}

	info = (TreeInfo *)(tree->data);
	if (info == NULL)
	{
		return;
	}

	if (strcmp(info->type, VAR_NODE_NAME) && strcmp(info->type, APP_NODE_NAME))
	{
		return;
	}

	if (!strcmp(entry->folder, "") && tifiles_has_folder(info->model))
	{
		folder = "main";
	}
	else
	{
		folder = entry->folder;
	}

	// If TI8x tree is empty, create pseudo-folder (NULL)
	if (!g_node_n_children(tree) && !tifiles_has_folder(info->model))
	{
		parent = g_node_new(NULL);
		g_node_append(tree, parent);
	}

	// Check for one folder at least...
	if (g_node_n_children(tree) > 0)
	{
		// Parse folders
		for (found = 0, i = 0; i < (int)g_node_n_children(tree); i++)
		{
			parent = g_node_nth_child(tree, i);
			fe = (VarEntry *) (parent->data);

			if (fe == NULL)
			{
				break;
			}

			if (!strcmp(fe->name, folder))
			{
				found = !0;
				break;
			}
		}
	}

	// folder doesn't exist? => create!
	if ((!found && fe) ||
	    (!g_node_n_children(tree) && tifiles_has_folder(info->model)))
	{
		fe = tifiles_ve_create();
		if (fe != NULL)
		{
			ticalcs_strlcpy(fe->name, entry->folder, sizeof(fe->name));
			fe->type = TI89_DIR;

			parent = g_node_new(fe);
			g_node_append(tree, parent);
		}
	}

	if (!strcmp(entry->name, ""))
	{
		return;
	}

	// next, add variables beneath this folder
	for (found = 0, j = 0; j < (int)g_node_n_children(parent); j++)
	{
		child = g_node_nth_child(parent, j);
		ve = (VarEntry *) (child->data);

		if (!strcmp(ve->name, entry->name))
		{
			found = !0;
			break;
		}
	}

	if (!found)
	{
		ve = tifiles_ve_dup(entry);
		if (ve != NULL)
		{
			child = g_node_new(ve);
			g_node_append(parent, child);
		}
	}

	if (fe && found)
	{
		fe->size++;
	}
}
Example #7
0
static int		recv_var_ns	(CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr)
{
  int nvar = 0;
  int err = 0;
  char *utf8;
  uint16_t ve_size;

  g_snprintf(update_->text, sizeof(update_->text), _("Waiting for var(s)..."));
  update_label();

  content->model = CALC_TI82;

  for (nvar = 0;; nvar++) 
  {
    VarEntry *ve;

	content->entries = tifiles_ve_resize_array(content->entries, nvar+1);
    ve = content->entries[nvar] = tifiles_ve_create();

    do 
	{
      update_refresh();
      if (update_->cancel)
		return ERR_ABORT;

      err = ti82_recv_VAR(&ve_size, &(ve->type), ve->name);
      ve->size = ve_size;
    }
    while (err == ERROR_READ_TIMEOUT);

    TRYF(ti82_send_ACK());
    if (err == ERR_EOT) 
	  goto exit;
    TRYF(err);

    TRYF(ti82_send_CTS());
    TRYF(ti82_recv_ACK(NULL));

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

	ve->data = tifiles_ve_alloc_data(ve->size);
    TRYF(ti82_recv_XDP(&ve_size, ve->data));
    ve->size = ve_size;
    TRYF(ti82_send_ACK());
  }

exit:
  content->num_entries = nvar;
  if(nvar == 1)
  {
	strcpy(content->comment, tifiles_comment_set_single());
	*vr = tifiles_ve_dup(content->entries[0]);
  }
  else
  {
	strcpy(content->comment, tifiles_comment_set_group());
	*vr = NULL;
  }

  return 0;
}
Example #8
0
static int		recv_var_ns	(CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr)
{
	uint32_t unused;
	int nvar, err;
    char tipath[18];
    char *tiname;
	char *utf8;

	content->model = handle->model;

	// receive packets
	for(nvar = 1;; nvar++)
	{
		VarEntry *ve;

		content->entries = tifiles_ve_resize_array(content->entries, nvar+1);
		ve = content->entries[nvar-1] = tifiles_ve_create();;
		strcpy(ve->folder, "main");	

		err = ti92_recv_VAR(&ve->size, &ve->type, tipath);
		TRYF(ti92_send_ACK());

		if(err == ERR_EOT)	// end of transmission
			goto exit;
		else
			content->num_entries = nvar;

		// from Christian (TI can send varname or fldname/varname)
        if ((tiname = strchr(tipath, '\\')) != NULL) 
		{
			*tiname = '\0';
            strcpy(ve->folder, tipath);
            strcpy(ve->name, tiname + 1);
        }
        else 
		{
            strcpy(ve->folder, "main");
            strcpy(ve->name, tipath);
        }

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

		TRYF(ti92_send_CTS());
		TRYF(ti92_recv_ACK(NULL));

		ve->data = tifiles_ve_alloc_data(ve->size + 4);
		TRYF(ti92_recv_XDP(&unused, ve->data));
		memmove(ve->data, ve->data + 4, ve->size);
		TRYF(ti92_send_ACK());
	}

exit:
	nvar--;
	if(nvar > 1) 
		*vr = NULL;
	else
		*vr = tifiles_ve_dup(content->entries[0]);

	return 0;
}
Example #9
0
static int		recv_var_ns	(CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr)
{
	int nvar = 0;
	int ret = 0;
	uint16_t ve_size;

	ticalcs_strlcpy(update_->text, _("Waiting for var(s)..."), sizeof(update_->text));
	update_label();

	content->model = handle->model;
	content->num_entries = 0;

	for (nvar = 0;; nvar++)
	{
		VarEntry *ve = tifiles_ve_create();
		int ret2;

		do
		{
			update_refresh();
			if (update_->cancel)
			{
				ret = ERR_ABORT;
				goto error;
			}

			ret = RECV_VAR(handle, &ve_size, &(ve->type), ve->name);
			ve->size = ve_size;
		}
		while (ret == ERROR_READ_TIMEOUT);

		ret2 = SEND_ACK(handle);

		if (ret)
		{
			if (ret == ERR_EOT)	// end of transmission
			{
				ret = 0;
			}
			goto error;
		}
		if (ret2)
		{
			ret = ret2;
			goto error;
		}

		ret = SEND_CTS(handle);
		if (!ret)
		{
			ret = RECV_ACK(handle, NULL);
			if (!ret)
			{
				ticonv_varname_to_utf8_sn(handle->model, ve->name, update_->text, sizeof(update_->text), ve->type);
				update_label();

				ve->data = tifiles_ve_alloc_data(ve->size);
				ret = RECV_XDP(handle, &ve_size, ve->data);
				if (!ret)
				{
					ve->size = ve_size;
					ret = SEND_ACK(handle);
				}
			}
		}

		if (!ret)
		{
			tifiles_content_add_entry(content, ve);
		}
		else
		{
error:
			tifiles_ve_delete(ve);
			break;
		}
	}

	if (nvar == 1)
	{
		ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment));
		*vr = tifiles_ve_dup(content->entries[0]);
	}
	else
	{
		ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment));
		*vr = NULL;
	}

	return ret;
}