Esempio n. 1
0
int gfm_tifiles_group(const char **filenames, int type)
{
	char **ptr;
	gchar *input;
	gchar *target = NULL;
	gchar *dirname = g_path_get_dirname(filenames[0]);
	//	gchar *basename = g_path_get_basename(filenames[0]);
	int err = 0;

	// Check for selection consistency
	for(ptr = (char **)filenames; *ptr; ptr++)
	{
		if(tifiles_file_is_group(*ptr) || tifiles_file_is_tigroup(*ptr))
		{
			msgbox_one(MSGBOX_ERROR, _("Group files are not allowed in selection."));
			return -1;
		}

		if(tifiles_file_is_flash(*ptr) && type != TIFILE_TIGROUP)
		{
			msgbox_one(MSGBOX_ERROR, _("FLASH files are not allowed in group files."));
			return -1;
		}
	}

	// Ask for group name
	input = msgbox_input(_("Group files"), "group", _("Group name: "));
	if(input == NULL)
		return -1;

	// And group
	if(type == TIFILE_GROUP)
	{
		target = g_strconcat(dirname, G_DIR_SEPARATOR_S, input,	".", 
			tifiles_fext_of_group(tifiles_file_get_model(filenames[0])), NULL);
		g_free(input);

		err = tifiles_group_files((char **)filenames, target);
	}
	else if(type == TIFILE_TIGROUP)
	{
		target = g_strconcat(dirname, G_DIR_SEPARATOR_S, input,	".tig", NULL);
		g_free(input);

		err = tifiles_tigroup_files((char **)filenames, target);
	}

	if(err)
	{
		gchar *str;

		tifiles_error_get(err, &str);
		msgbox_one(MSGBOX_ERROR, str);
		g_free(str);
	}
	g_free(target);

	return 0;
}
Esempio n. 2
0
/*
  This function take as input parameter an error code and displays it
  in a message box.

  This function is 'buffered': if one or more error messages appear 
  during startup (console or terminal), they will be displayed in the GUI.
 */
int tilp_err(int errcode)
{
	char *s = NULL;	
	char *utf;
	gsize bw;

	/* Push error messages (if any)*/
	if(errcode)
		stack = g_list_append(stack, GINT_TO_POINTER(errcode));

	/* Pop error messages */
	if (!(working_mode & MODE_INI)) 
	{
		int i;
		for (i = 0; i < (int)g_list_length(stack); i++) 
		{
			int err = GPOINTER_TO_INT((g_list_nth(stack, i))->data);

			/* Retrieve the error message */
			err = ticables_error_get(err, &s);
			if (err) 
			{
				g_free(s);
				err = tifiles_error_get(err, &s);
				if (err) 
				{
					g_free(s);
					err = ticalcs_error_get(err, &s);
					if (err) 
					{
						// next level: error for TiLP
						g_free(s);
					}
					else
					{
					    // ticalcs error => reset
					    tilp_device_reset();
					}
				}
			}
			else
			{
			    // ticables error => reset
			    tilp_device_reset();
			}			

			utf = g_locale_to_utf8(s, -1, NULL, &bw, NULL);
			gif->msg_box1(_("Error"), utf);
		}
		g_list_free(stack);
		stack = NULL;
	} 
	else 
	{
		int err = errcode;

		/* Retrieve the error message */
		err = ticables_error_get(err, &s);
		if (err)
		{
			g_free(s);
			err = ticalcs_error_get(err, &s);
			if (err)
			{
				g_free(s);
				err = ticalcs_error_get(err, &s);
				if (err) 
				{
					// next level: error for TiLP
					g_free(s);
				}
			}
		}

		if(s)
			tilp_info("%s\n", s);
	}

	//free(s);
	return errcode;
}
Esempio n. 3
0
// The main function
int main(int argc, char **argv)
{
	char *msg = NULL;
	char buffer[256];
	int i;
	int ret;

	// init library
	tifiles_library_init();

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

	// test error.c
	tifiles_error_get(515, &msg);
	printf("Error message: <%s>\n", msg);
#ifndef __WIN32__
	free(msg);
#endif
	printf("--\n");

	// test type2str.c
	printf("tifiles_string_to_model: <%i> <%i>\n", CALC_TI92,
	       tifiles_string_to_model(tifiles_model_to_string(CALC_TI92)));
	printf("tifiles_string_to_attribute: <%i> <%i>\n", ATTRB_LOCKED,
	       tifiles_string_to_attribute(tifiles_attribute_to_string(ATTRB_LOCKED)));
	printf("tifiles_string_to_class: <%i> <%i>\n", TIFILE_SINGLE,
	       tifiles_string_to_class(tifiles_class_to_string(TIFILE_SINGLE)));
	printf("--\n");

	// test filetypes.c
	for(i = CALC_TI73; i <= CALC_V200; i++)
	{
		printf("%s (%i) ", tifiles_fext_of_group(i), i);
	}
	printf("\n");

	for(i = CALC_TI73; i <= CALC_V200; i++)
	{
		printf("%s ", tifiles_fext_of_backup(i));
	}
	printf("\n");

	for(i = CALC_TI73; i <= CALC_V200; i++)
	{
		printf("%s ", tifiles_fext_of_flash_os(i));
	}
	printf("\n");

	for(i = CALC_TI73; i <= CALC_V200; i++)
	{
		printf("%s ", tifiles_fext_of_flash_app(i));
	}
	printf("\n");
	printf("--\n");

	printf("<%s> <%s>\n", "foo.bar", tifiles_fext_get("foo.bar"));

	ret = tifiles_file_is_ti(PATH("misc/str.92s"));
	printf("tifiles_file_is_ti: %i\n", ret);

	ret = tifiles_file_is_single(PATH("misc/str.92s"));
	printf("tifiles_file_is_single: %i\n", ret);

	ret = tifiles_file_is_group(PATH("misc/group.92g"));
        printf("tifiles_file_is_group: %i\n", ret);

	ret = tifiles_file_is_regular(PATH("misc/str.92s"));
        printf("tifiles_file_is_regular: %i\n", ret);

	ret = tifiles_file_is_regular(PATH("misc/group.92g"));
        printf("tifiles_file_is_regular: %i\n", ret);

	ret = tifiles_file_is_backup(PATH("misc/backup.83b"));
	printf("tifiles_file_is_backup: %i\n", ret);

	ret = tifiles_file_is_flash(PATH("misc/ticabfra.89k"));
        printf("tifiles_file_is_flash: %i\n", ret);

	ret = tifiles_file_is_flash(PATH("misc/TI73_OS160.73U"));
	printf("tifiles_file_is_flash: %i\n", ret);

	ret = tifiles_file_is_tib(PATH("misc/ams100.tib"));
	printf("tifiles_file_is_tib: %i\n", ret);

	ret = tifiles_file_is_tigroup(PATH("misc/test.tig"));
	printf("tifiles_file_is_tigroup: %i\n", ret);
	printf("--\n");

	// test typesxx.c
	printf("tifiles_file_get_model: %s\n",
	       tifiles_model_to_string(tifiles_file_get_model(PATH("misc/str.92s"))));

	printf("tifiles_file_get_class: %s\n",
	       tifiles_class_to_string(tifiles_file_get_class(PATH("misc/group.92g"))));

	printf("tifiles_file_get_type: %s\n",
	       tifiles_file_get_type(PATH("misc/TI73_OS160.73U")));
	printf("tifiles_file_get_icon: %s\n",
	       tifiles_file_get_icon(PATH("misc/str.92s")));
	printf("--\n");

	// test misc.c

	printf("tifiles_calc_is_ti8x: %i\n", tifiles_calc_is_ti8x(CALC_TI83));
	printf("tifiles_calc_is_ti9x: %i\n", tifiles_calc_is_ti9x(CALC_TI89));

	printf("tifiles_has_folder: %i\n", tifiles_has_folder(CALC_TI92));
	printf("tifiles_is_flash: %i\n", tifiles_is_flash(CALC_TI73));

	printf("tifiles_get_varname: <%s>\n", tifiles_get_varname("fld\\var"));
	printf("tifiles_get_fldname: <%s>\n", tifiles_get_fldname("fld\\var"));
	tifiles_build_fullname(CALC_TI89, buffer, "fld", "var");
	printf("tifiles_build_fullname: <%s>\n", buffer);
	printf("--\n");

	// test filesxx.c & grouped.c
	do
	{
		// TI73 support
		change_dir(PATH("ti73"));
		ret = test_ti73_backup_support(); if (ret) break;
		ret = test_ti73_regular_support(); if (ret) break;
		ret = test_ti73_group_support(); if (ret) break;
		ret = test_ti73_ungroup_support(); if (ret) break;

		// TI82 support
		change_dir(PATH("ti82"));
		ret = test_ti82_backup_support(); if (ret) break;
		ret = test_ti82_regular_support(); if (ret) break;
		ret = test_ti82_group_support(); if (ret) break;
		ret = test_ti82_ungroup_support(); if (ret) break;

		// TI83 support
		change_dir(PATH("ti83"));
		ret = test_ti83_backup_support(); if (ret) break;
		ret = test_ti83_regular_support(); if (ret) break;
		ret = test_ti83_group_support(); if (ret) break;
		ret = test_ti83_ungroup_support(); if (ret) break;

		// TI84+ support
		change_dir(PATH("ti84p"));
		ret = test_ti84p_regular_support(); if (ret) break;
		ret = test_ti84p_group_support(); if (ret) break;
		ret = test_ti84p_ungroup_support(); if (ret) break;
		ret = test_ti84p_flash_support(); if (ret) break;

		// TI85 support
		change_dir(PATH("ti85"));
		ret = test_ti85_regular_support(); if (ret) break;

		// TI86 support
		change_dir(PATH("ti86"));
		ret = test_ti86_backup_support(); if (ret) break;
		ret = test_ti86_regular_support(); if (ret) break;
		ret = test_ti86_group_support(); if (ret) break;
		ret = test_ti86_ungroup_support(); if (ret) break;

		// TI89 support
		change_dir(PATH("ti89"));
		ret = test_ti89_regular_support(); if (ret) break;
		ret = test_ti89_flash_support(); if (ret) break;
		ret = test_v200_regular_support(); if (ret) break;

		// TI92 support
		change_dir(PATH("ti92"));
		ret = test_ti92_backup_support(); if (ret) break;
		ret = test_ti92_regular_support(); if (ret) break;
		ret = test_ti92_group_support(); if (ret) break;
		ret = test_ti92_ungroup_support(); if (ret) break;

		// TIXX certificates
		change_dir(PATH("certs"));
		ret = test_ti8x_cert_support(); if (ret) break;
		ret = test_ti9x_cert_support(); if (ret) break;

		// Add/Del files
		change_dir(PATH("misc"));
		ret = test_ti8x_group_merge(); if (ret) break;

		change_dir(PATH("tig"));
		ret = test_tigroup();
	} while(0);

	// end of test
	tifiles_library_exit();

	return ret;
}
Esempio n. 4
0
int gfm_tifiles_ungroup(const char *filename, int type)
{
	gchar *dirname = g_path_get_dirname(filename);
	gchar *basename = g_path_get_basename(filename);
	
	gchar *src_file;
	gchar *dst_file;
	
	gchar *folder, *tmp;
	gchar *input;	
	gchar *e;
	int err = 0;

	// Ask for folder
	folder = g_strdup(basename);
	e = strrchr(folder, '.');
	if(e) *e = '\0';

	input = msgbox_input(_("Create new directory"), folder, _("Directory where files will be ungrouped: "));
	g_free(folder);
	if (input == NULL)
		return -1;

	tmp = g_filename_from_utf8(input, -1, NULL, NULL, NULL);
	g_free(input);

	folder = g_strconcat(dirname, G_DIR_SEPARATOR_S, tmp, NULL);
	g_free(tmp);

	// Check for folder existence
	if(!strcmp(dirname, ".") || !strcmp(dirname, ""))
	{
		msgbox_one(MSGBOX_ERROR, _("You can't ungroup in this folder."));
		g_free(basename);
		g_free(dirname);
		return -1;
	}
   
	// Create folder
	if(file_mkdir(folder))
	{
		g_free(basename);
		g_free(dirname);
		return -1;
	}
	file_chdir(folder);

	// Copy file to target
	src_file = g_strdup(filename);	
	dst_file = g_strconcat(folder, G_DIR_SEPARATOR_S, basename, NULL);
	file_copy(src_file, dst_file);
	
	// Ungroup
	if(type == TIFILE_GROUP)
		err = tifiles_ungroup_file(dst_file, NULL);
	else if(type == TIFILE_TIGROUP)
		err = tifiles_untigroup_file(dst_file, NULL);
	if(err)
	{
		gchar *str;

		tifiles_error_get(err, &str);
		msgbox_one(MSGBOX_ERROR, str);
		g_free(str);
	}
	file_chdir("..");

	// And release
	g_free(basename);
	g_free(dirname);
	g_free(src_file);
	g_free(dst_file);

	return 0;
}