Пример #1
0
static int		rename_var	(CalcHandle* handle, VarRequest* oldname, VarRequest* newname)
{
	char *utf81, *utf82;
	char *path1, *path2;
	int ret;

	ret = nsp_session_open(handle, NSP_SID_FILE_MGMT);
	if (ret)
	{
		return ret;
	}

	path1 = build_path(handle->model, oldname);
	path2 = build_path(handle->model, newname);
	utf81 = ticonv_varname_to_utf8(handle->model, path1, oldname->type);
	utf82 = ticonv_varname_to_utf8(handle->model, path2, newname->type);
	ticalcs_slprintf(update_->text, sizeof(update_->text), _("Renaming %s to %s..."), utf81, utf82);
	ticonv_utf8_free(utf82);
	ticonv_utf8_free(utf81);
	update_label();

	ret = nsp_cmd_s_rename_file(handle, path1, path2);
	g_free(path2);
	g_free(path1);
	if (!ret)
	{
		ret = nsp_cmd_r_rename_file(handle);
	}

	DO_CLOSE_SESSION(handle);

	return ret;
}
Пример #2
0
static int		new_folder  (CalcHandle* handle, VarRequest* vr)
{
	char *utf8;
	char *path;
	int ret;

	ret = nsp_session_open(handle, NSP_SID_FILE_MGMT);
	if (ret)
	{
		return ret;
	}

	path = g_strconcat("/", vr->folder, NULL);
	utf8 = ticonv_varname_to_utf8(handle->model, path, -1);
	ticalcs_slprintf(update_->text, sizeof(update_->text), _("Creating %s..."), utf8);
	ticonv_utf8_free(utf8);
	update_label();

	ret = nsp_cmd_s_new_folder(handle, path);
	g_free(path);
	if (!ret)
	{
		ret = nsp_cmd_r_new_folder(handle);
	}

	DO_CLOSE_SESSION(handle);

	return ret;
}
Пример #3
0
static int		del_var		(CalcHandle* handle, VarRequest* vr)
{
	char *utf8;
	char *path;
	int ret;

	ret = nsp_session_open(handle, NSP_SID_FILE_MGMT);
	if (ret)
	{
		return ret;
	}

	path = build_path(handle->model, vr);
	utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type);
	ticalcs_slprintf(update_->text, sizeof(update_->text), _("Deleting %s..."), utf8);
	ticonv_utf8_free(utf8);
	update_label();

	ret = nsp_cmd_s_del_file(handle, path);
	g_free(path);
	if (!ret)
	{
		ret = nsp_cmd_r_del_file(handle);
	}

	DO_CLOSE_SESSION(handle);

	return ret;
}
Пример #4
0
static void display_node(TreeInfo * info, VarEntry * ve, unsigned char type)
{
	char * utf8 = ticonv_varname_to_utf8(info->model, ve->name, type);
	int k;

	printf("| ");
	for (k = 0; k < 8; k++)
	{
		printf("%02X", (uint8_t) (ve->name)[k]);
	}
	printf(" | ");
	printf("%8s", utf8);
	printf(" | ");
	printf("%2i", ve->attr);
	printf(" | ");
	printf("%02X", ve->type);
	printf(" | ");
	printf("%08X", ve->size);
	printf(" | ");
	printf("%8s", ve->folder);
	printf(" |");
	printf("\n");

	ticonv_utf8_free(utf8);
}
Пример #5
0
static int		del_var		(CalcHandle* handle, VarRequest* vr)
{
	int ret = 0;
	static const uint16_t keys[] = {
		0x40, 0x09, 0x09,			/* Quit, Clear, Clear, */
		0x3e, 0x9d, 0x04,			/* Catalog, D, Down */
		0x04, 0x04, 0x05		/* Down, Down, Enter */
	};
	unsigned int i;
	char *utf8;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	ticalcs_slprintf(update_->text, sizeof(update_->text), _("Deleting %s..."), utf8);
	ticonv_utf8_free(utf8);
	update_label();

	// Input keys by remote control
	for (i = 0; !ret && i < sizeof(keys) / sizeof(keys[0]); i++)
	{
		ret = send_key(handle, (uint32_t)(keys[i]));
	}

	for (i = 0; !ret && i < strlen(vr->name); i++)
	{
		char c = toupper(vr->name[i]);

		if (isdigit(c))
		{
			ret = send_key(handle, (uint32_t)(0x008e + c - '0'));
		}
		else
		{
			ret = send_key(handle, (uint32_t)(0x009a + c - 'A'));
		}
	}

	if (!ret)
	{
		ret = send_key(handle, 0x0005);	// Enter
	}

	return ret;
}
Пример #6
0
static int		del_var		(CalcHandle* handle, VarRequest* vr)
{
	int ret;
	char *utf8;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8);
	ticonv_utf8_free(utf8);
	ticalcs_update_label(handle);

	ret = SEND_DEL(handle, (uint16_t)vr->size, vr->type, vr->name, vr->attr);
	if (!ret)
	{
		ret = RECV_ACK(handle, NULL);
		if (!ret)
		{
			ret = RECV_ACK(handle, NULL);
		}
	}

	return ret;
}
Пример #7
0
static char* ticonv_utf16_to_usb(const unsigned short *utf16, char *ti)
{
	char *tmp;

	if (utf16 == NULL || ti == NULL)
	{
		return NULL;
	}

	tmp = ticonv_utf16_to_utf8(utf16);
	if (tmp == NULL)
	{
		return NULL;
	}

	if (ti != NULL)
	{
		strcpy(ti, tmp);
	}
	ticonv_utf8_free(tmp);

	return ti;
}
Пример #8
0
/*
  The main function
*/
int main(int argc, char **argv)
{
	int i, j;
	unsigned int n = 0;
	int is_utf8 = ticonv_environment_is_utf8();

	charsets[0] = ti73_charset;
	charsets[1] = ti82_charset;
	charsets[2] = ti83_charset;
	charsets[3] = ti83p_charset;
	charsets[4] = ti85_charset;
	charsets[5] = ti86_charset;
	charsets[6] = ti9x_charset;

	// test ticonv.c
	printf("Library version : <%s>\n", ticonv_version_get());
	printf("--\n");

	printf("Choose your charset: ");
	if (!scanf("%u", &n))
	{
		n = 0;
	}
	if (n >= 7)
	{
		n = 6;
	}

	printf("  0 1 2 3 4 5 6 7 8 9 A B C D E F\n");

	for(i = 0; i < 16; i++)
	{
		printf("%x ", i);
		for(j = 0; j < 16; j++)
		{
			unsigned long wc = charsets[n][16*i+j];
			gchar *str = NULL;

			if (wc && wc != '\n')
			{
				gunichar2 buf[4] = { 0 };

				buf[0] = (gunichar2)wc;
				str = ticonv_utf16_to_utf8(buf);

				if (!is_utf8 && str)
				{
					gchar *tmp = g_locale_from_utf8(str, -1, NULL, NULL, NULL);
					ticonv_utf8_free(str);
					str = tmp;
				}
			}
			else
			{
				str = NULL;
			}

			if (str)
			{
				printf("%s ", str);
			}

			ticonv_utf8_free(str);
		}
		printf("\n");
	}

	{
		char ti82_varname[9] = { 0 };
		char ti92_varname[9] = { 0 };
		char ti84p_varname[36] = { 0 };
		char *utf8;
		char *filename;
		char *varname;

		ti82_varname[0] = 0x5d;			// L1
		ti82_varname[1] = 0x01;
		ti82_varname[2] = 0;

		ti92_varname[0] = (char)132;	// delta
		ti92_varname[1] = (char)0xE9; // e acute.
		ti92_varname[2] = 0;

		ti84p_varname[0] = 'L';			// L1 in TI-UTF-8
		ti84p_varname[1] = (char)0xE2;
		ti84p_varname[2] = (char)0x82;
		ti84p_varname[3] = (char)0x81;

		// TI -> UTF-8
		utf8 = ticonv_varname_to_utf8(CALC_TI82, ti82_varname, -1);
		printf("UTF-8 varname: <%s> (%i)\n", ti82_varname, (int)strlen(ti82_varname));
		ticonv_utf8_free(utf8);

		utf8 = ticonv_varname_to_utf8(CALC_TI92, ti92_varname, -1);
		printf("UTF-8 varname: <%s> (%i)\n", ti92_varname, (int)strlen(ti92_varname));
		ticonv_utf8_free(utf8);

		utf8 = ticonv_varname_to_utf8(CALC_TI84P_USB, ti84p_varname, -1);
		printf("UTF-8 varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
		ticonv_utf8_free(utf8);


		// TI -> filename
		printf("raw varname: <%s> (%i)\n", ti92_varname, (int)strlen(ti92_varname));
		filename = ticonv_varname_to_filename(CALC_TI92, ti92_varname, -1);
		printf("filename: <%s>\n", filename);
		ticonv_gfe_free(filename);

		printf("raw varname: <%s> (%i)\n", ti82_varname, (int)strlen(ti82_varname));
		filename = ticonv_varname_to_filename(CALC_TI82, ti82_varname, -1);
		printf("filename: <%s>\n", filename);
		ticonv_gfe_free(filename);

		printf("raw varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
		filename = ticonv_varname_to_filename(CALC_TI84P_USB, ti84p_varname, -1);
		printf("filename: <%s>\n", filename);
		ticonv_gfe_free(filename);

		// varname -> varname
		printf("raw varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
		varname = ticonv_varname_to_tifile(CALC_TI84P_USB, ti84p_varname, -1);
		printf("varname: <%s>\n", varname);
		ticonv_gfe_free(varname);
	}

#ifdef __WIN32__
	while(!_kbhit());
#endif

	return 0;
}
Пример #9
0
static int		get_dirlist	(CalcHandle* handle, GNode** vars, GNode** apps)
{
	int ret;
	uint16_t unused;
	TreeInfo *ti;
	GNode *folder, *node;
	char *utf8;

	ret = dirlist_init_trees(handle, vars, apps);
	if (ret)
	{
		return ret;
	}
	ti = (*vars)->data;

	ret = SEND_REQ(handle, 0x0000, (handle->model == CALC_TI83) ? TI83_DIR : TI86_DIR, "\0\0\0\0\0\0\0");
	if (!ret)
	{
		ret = RECV_ACK(handle, &unused);
		if (!ret)
		{
			ret = RECV_XDP(handle, &unused, handle->buffer2);
			if (!ret)
			{
				ret = SEND_ACK(handle);
			}
		}
	}

	if (!ret)
	{
		VarEntry *ve;
		uint8_t * mem = (uint8_t *)handle->buffer2;

		folder = dirlist_create_append_node(NULL, vars);

		if (handle->model == CALC_TI83)
		{
			ti->mem_free = (((uint32_t)(mem[1])) << 8) | mem[0]; // Clamp mem_free to a 16-bit value.

			// Add permanent variables (Window, RclWindow, TblSet aka WINDW, ZSTO, TABLE)
			ve = tifiles_ve_create();
			ve->type = TI83_WINDW;
			node = dirlist_create_append_node(ve, &folder);
			if (node != NULL)
			{
				ve = tifiles_ve_create();
				ve->type = TI83_ZSTO;
				node = dirlist_create_append_node(ve, &folder);
				if (node != NULL)
				{
					ve = tifiles_ve_create();
					ve->type = TI83_TABLE;
					node = dirlist_create_append_node(ve, &folder);
				}
			}
		}
		else
		{
			ti->mem_free = (((uint32_t)(mem[0])) << 16) | (((uint32_t)(mem[1])) << 8) | mem[2];

			// Add permanent variables (Func, Pol, Param, DifEq, ZRCL as WIND, WIND, WIND, WIND, WIND)
			ve = tifiles_ve_create();
			ve->type = TI86_FUNC;
			node = dirlist_create_append_node(ve, &folder);
			if (node != NULL)
			{
				ve = tifiles_ve_create();
				ve->type = TI86_POL;
				node = dirlist_create_append_node(ve, &folder);
				if (node != NULL)
				{
					ve = tifiles_ve_create();
					ve->type = TI86_PARAM;
					node = dirlist_create_append_node(ve, &folder);
					if (node != NULL)
					{
						ve = tifiles_ve_create();
						ve->type = TI86_DIFEQ;
						node = dirlist_create_append_node(ve, &folder);
						if (node != NULL)
						{
							ve = tifiles_ve_create();
							ve->type = TI86_ZRCL;
							node = dirlist_create_append_node(ve, &folder);
						}
					}
				}
			}
		}

		if (!node)
		{
			ret = ERR_MALLOC;
		}
		else
		{
			for (;;)
			{
				uint16_t ve_size;
				int ret2;

				ve = tifiles_ve_create();
				ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name);
				ve->size = ve_size;
				ret2 = SEND_ACK(handle);
				if (ret)
				{
					if (ret == ERR_EOT)	// end of transmission
					{
						ret = 0;
					}
error:
					tifiles_ve_delete(ve);
					break;
				}
				if (ret2)
				{
					ret = ret2;
					goto error;
				}

				node = dirlist_create_append_node(ve, &folder);
				if (!node)
				{
					return ERR_MALLOC;
				}

				utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type);
				ticalcs_slprintf(update_->text, sizeof(update_->text), _("Parsing %s"), utf8);
				ticonv_utf8_free(utf8);
				update_label();
			}
		}
	}

	return ret;
}
Пример #10
0
void ctree_refresh(void)
{
	GdkPixbuf *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7;
	GdkPixbuf *pix9 = NULL;
	GtkTreeIter pareng_node;
	GtkTreeIter child_node;
	GNode *vars, *apps;
	int i, j;

	if (GFMFile.trees.vars == NULL)
		return;

	// place base nodes
	ctree_set_basetree();
	memcpy(&pareng_node, &vars_node, sizeof(GtkTreeIter));

	// load pixmaps
	pix1 = create_pixbuf("ctree_open_dir.xpm");
	pix2 = create_pixbuf("TIicon2.ico");
	pix3 = create_pixbuf("ctree_open_dir.xpm");
	pix4 = create_pixbuf("attr_locked.xpm");
	pix5 = create_pixbuf("attr_archived.xpm");
	pix6 = create_pixbuf("TIicon4.ico");
	pix7 = create_pixbuf("attr_none.xpm");

	// variables tree
	vars = GFMFile.trees.vars;
	for (i = 0; i < (int)g_node_n_children(vars); i++) 
	{
		GNode *parent = g_node_nth_child(vars, i);
		VarEntry *fe = (VarEntry *) (parent->data);

		if ((fe != NULL) || tifiles_calc_is_ti9x(GFMFile.model))
		{
			char *utf8 = ticonv_varname_to_utf8(GFMFile.model, fe->name, -1);

			gtk_tree_store_append(tree, &pareng_node, &vars_node);
			gtk_tree_store_set(tree, &pareng_node, 
					   COLUMN_NAME, utf8, 
					   COLUMN_DATA, (gpointer) fe,
					   COLUMN_ICON, pix1, 
					   COLUMN_EDIT, FALSE,
					   -1);
			ticonv_utf8_free(utf8);
		}

		for (j = 0; j < (int)g_node_n_children(parent); j++) 
		{
			GNode *node = g_node_nth_child(parent, j);
			gchar **row_text = g_malloc0((CTREE_NCOLS + 1) * sizeof(gchar *));
			VarEntry *ve = (VarEntry *) (node->data);
			char icon_name[256];
			char * utf8 = ticonv_varname_to_utf8(GFMFile.model, ve->name, ve->type);

			row_text[0] = g_strdup(utf8); ticonv_utf8_free(utf8);
			row_text[2] = g_strdup_printf("%s", tifiles_vartype2string(GFMFile.model, ve->type));
			tilp_var_get_size(ve, &row_text[3]);

			strcpy(icon_name, tifiles_vartype2icon(GFMFile.model, ve->type));
			strcat(icon_name, ".ico");
			tilp_file_underscorize(icon_name);
			pix9 = create_pixbuf(icon_name);

			// ticonv wrapper
			tilp_vars_translate(row_text[0]);

			gtk_tree_store_append(tree, &child_node, &pareng_node);
			gtk_tree_store_set(tree, &child_node, COLUMN_NAME,
					   row_text[0],
					   COLUMN_TYPE,
					   row_text[2], COLUMN_SIZE,
					   row_text[3], COLUMN_DATA,
					   (gpointer) ve, COLUMN_ICON, pix9,
					   COLUMN_FONT, FONT_NAME,
					   COLUMN_EDIT, TRUE,
					   -1);

			switch (ve->attr) 
			{
			case ATTRB_NONE:
				gtk_tree_store_set(tree, &child_node, COLUMN_ATTR, pix7, -1);
				break;
			case ATTRB_LOCKED:
				gtk_tree_store_set(tree, &child_node, COLUMN_ATTR, pix4, -1);
				break;
			case ATTRB_ARCHIVED:
				gtk_tree_store_set(tree, &child_node, COLUMN_ATTR, pix5, -1);
				break;
			default:
				break;
			}
			g_object_unref(pix9);
			g_strfreev(row_text);
		}
	}

	// appplications tree
	apps = GFMFile.trees.apps;
	for (i = 0; i < (int)g_node_n_children(apps) && tifiles_is_flash(GFMFile.model); i++) 
	{
		GNode *parent = g_node_nth_child(apps, i);

		for (j = 0; j < (int)g_node_n_children(parent); j++) 
		{
			GNode *node = g_node_nth_child(parent, j);
			gchar **row_text = g_malloc0((CTREE_NCOLS + 1) * sizeof(gchar *));
			VarEntry *ve = (VarEntry *) (node->data);
			char icon_name[256];
			char * utf8 = ticonv_varname_to_utf8(GFMFile.model, ve->name, ve->type);

			row_text[0] = g_strdup(utf8); ticonv_utf8_free(utf8);
			row_text[2] = g_strdup_printf("%s", tifiles_vartype2string(GFMFile.model, ve->type));
			row_text[3] = g_strdup_printf("%u", (int) (ve->size));

			strcpy(icon_name, tifiles_vartype2icon(GFMFile.model, ve->type));
			strcat(icon_name, ".ico");
			tilp_file_underscorize(icon_name);
			pix9 = create_pixbuf(icon_name);

			gtk_tree_store_append(tree, &child_node, &apps_node);
			gtk_tree_store_set(tree, &child_node, 
					COLUMN_NAME, row_text[0], 
					COLUMN_TYPE, row_text[2],
					COLUMN_SIZE, row_text[3], 
					COLUMN_DATA, (gpointer) ve, 
					COLUMN_ICON, pix9,
					COLUMN_FONT, FONT_NAME,
					   -1);
			g_object_unref(pix9);
			g_strfreev(row_text);
		}
	}
	gtk_tree_view_expand_all(GTK_TREE_VIEW(gfm_widget.tree));

	g_object_unref(pix1);
	g_object_unref(pix2);
	g_object_unref(pix3);
	g_object_unref(pix4);
	g_object_unref(pix5);
	g_object_unref(pix6);
}
Пример #11
0
static int		get_dirlist	(CalcHandle* handle, GNode** vars, GNode** apps)
{
	int ret;
	TreeInfo *ti;
	GNode *folder, *root, *node;
	uint16_t unused;
	uint32_t memory;
	char *utf8;

	ret = dirlist_init_trees(handle, vars, apps);
	if (ret)
	{
		return ret;
	}
	ti = (*vars)->data;

	ret = SEND_REQ(handle, 0x0000, TI73_DIR, "\0\0\0\0\0\0\0", 0x00, 0x00);
	if (!ret)
	{
		ret = RECV_ACK(handle, &unused);
		if (!ret)
		{
			ret = RECV_XDP(handle, &unused, handle->buffer2);
			if (!ret)
			{
				ret = SEND_ACK(handle);
				if (!ret)
				{
					uint8_t * mem = (uint8_t *)handle->buffer2;
					memory = (((uint32_t)(mem[1])) << 8) | mem[0]; // Clamp mem_free to a 16-bit value.
				}
			}
		}
	}
	if (ret)
	{
		return ret;
	}

	ti->mem_free = memory;

	folder = dirlist_create_append_node(NULL, vars);
	if (!folder)
	{
		return ERR_MALLOC;
	}
	root = dirlist_create_append_node(NULL, apps);
	if (!root)
	{
		return ERR_MALLOC;
	}

	// Add permanent variables (Window, RclWindow, TblSet aka WINDW, ZSTO, TABLE)
	{
		VarEntry *ve;

		ve = tifiles_ve_create();
		ve->type = TI84p_WINDW;
		node = dirlist_create_append_node(ve, &folder);

		if (node != NULL)
		{
			if (handle->model != CALC_TI73)
			{
				ve = tifiles_ve_create();
				ve->type = TI84p_ZSTO;
				node = dirlist_create_append_node(ve, &folder);
			}

			if (node != NULL)
			{
				ve = tifiles_ve_create();
				ve->type = TI84p_TABLE;
				node = dirlist_create_append_node(ve, &folder);
			}
		}
	}

	if (!node)
	{
		return ERR_MALLOC;
	}

	for (;;) 
	{
		VarEntry *ve = tifiles_ve_create();
		uint16_t ve_size;
		int ret2;

		ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name, &ve->attr, &ve->version);
		ve->size = ve_size;
		ret2 = SEND_ACK(handle);
		if (ret)
		{
			if (ret == ERR_EOT)
			{
				ret = 0;
			}
error:
			tifiles_ve_delete(ve);
			break;
		}
		if (ret2)
		{
			ret = ret2;
			goto error;
		}

		if (ve->type == TI73_APPL)
		{
			/* Size is reported as a number of pages -- compute amount
			   of space consumed (the actual application may be
			   somewhat smaller.)  Note: the MSB of the "size" word is
			   the application's starting page number. */
			ve->size = (ve->size & 0xff) * 0x4000;
		}

		node = dirlist_create_append_node(ve, (ve->type != TI73_APPL) ? &folder : &root);
		if (!node)
		{
			return ERR_MALLOC;
		}

		utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type);
		ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s"), utf8);
		ticonv_utf8_free(utf8);
		ticalcs_update_label(handle);
	}

	return ret;
}