/** * tifiles_group_del_file: * @src_filename: the file to remove from group file * @dst_filename: the group file * * Search for entry and remove it from file. * * Return value: 0 if successful, an error code otherwise. **/ TIEXPORT2 int TICALL tifiles_group_del_file(VarEntry *entry, const char *dst_filename) { CalcModel dst_model; FileContent* dst_content = NULL; int ret = 0; if (entry == 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; dst_model = tifiles_file_get_model(dst_filename); dst_content = tifiles_content_create_regular(dst_model); ret = tifiles_file_read_regular(dst_filename, dst_content); if(ret) goto tgdf; tifiles_content_del_entry(dst_content, entry); tifiles_file_display_regular(dst_content); ret = tifiles_file_write_regular(dst_filename, dst_content, NULL); if(ret) goto tgdf; tgdf: tifiles_content_delete_regular(dst_content); return ret; }
/** * tifiles_ungroup_file: * @src_filename: full path of file to ungroup. * @dst_filenames: NULL or the address of a pointer where to store a NULL-terminated * array of strings which contain the list of ungrouped files. * * Ungroup a TI 'group' file into several files. Resulting files have the * same name as the variable stored within group file. * Beware: there is no existence check; files may be overwritten ! * * %dst_filenames must be freed when no longer used. * * Return value: an error code if unsuccessful, 0 otherwise. **/ TIEXPORT2 int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) { FileContent *src = NULL; FileContent **ptr, **dst = NULL; char *real_name, **p; int i, n; int ret; if (src_filename == NULL) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } if(tifiles_file_get_model(src_filename) == CALC_NSPIRE) return ERR_BAD_CALC; // read group file src = tifiles_content_create_regular(CALC_NONE); ret = tifiles_file_read_regular(src_filename, src); if(ret) goto tuf; // ungroup structure ret = tifiles_ungroup_content(src, &dst); if(ret) goto tuf; // count number of structures and allocates array of strings for(ptr = dst, n = 0; *ptr != NULL; ptr++, n++); if(dst_filenames != NULL) *dst_filenames = (char **)g_malloc((n + 1) * sizeof(char *)); // store each structure content to file for (ptr = dst, i = 0; *ptr != NULL; ptr++, i++) { ret = tifiles_file_write_regular(NULL, *ptr, &real_name); if(ret) goto tuf; if(dst_filenames != NULL) *dst_filenames[i] = real_name; else g_free(real_name); } // release allocated memory tifiles_content_delete_regular(src); tifiles_content_delete_group(dst); return 0; tuf: if(dst_filenames != NULL) { for(p = *dst_filenames; *p; p++) g_free(*p); g_free(p); } tifiles_content_delete_regular(src); tifiles_content_delete_group(dst); return ret; }
static int test_tixx_regular_support_group(const char * message, CalcModel calculator, const char * input_group, const char * output_group) { FileContent *content; char *unused = NULL; int ret = -1; printf("%s", message); tifiles_file_display(PATH(input_group)); content = tifiles_content_create_regular(calculator); if (content != NULL) { ret = tifiles_file_read_regular(PATH(input_group), content); if (!ret) { ret = tifiles_file_write_regular(PATH(output_group), content, &unused); if (!ret) { compare_files(PATH(input_group), PATH2(output_group)); } tifiles_filename_free(unused); tifiles_content_delete_regular(content); } } return ret; }
void fs_send_file_and_debug_info(const gchar *filename) { const gchar *ext; FileContent *metadata; fs_send_file(filename); ext = strrchr(filename, '.'); if (ext) { gchar *temp; *(char *)ext = 0; temp = g_strconcat(filename, ".dbg", NULL); #ifdef WIN32 symfile = g_locale_from_utf8(temp,-1,NULL,NULL,NULL); g_free(temp); #else symfile = temp; #endif *(char *)ext = '.'; } metadata = tifiles_content_create_regular(CALC_TI89); if (!tifiles_file_read_regular(filename, metadata)) { if (metadata->num_entries > 0) { int handle = sym_find_handle (metadata->entries[0]->folder, metadata->entries[0]->name); if (handle) ti68k_bkpt_add_pgmentry (handle); } } tifiles_content_delete_regular(metadata); }
GLADE_CB void on_add_clicked (GtkToolButton *toolbutton, gpointer user_data) { char **array, **ptr; CalcModel model; FileContent *content; int ret; unsigned int i; array = create_fsels(inst_paths.home_dir, "", "*.*"); if(array == NULL) return; for(ptr = array; *ptr; ptr++) { char *fn = *ptr; if(tifiles_file_is_tigroup(fn)) { msgbox_one(MSGBOX_ERROR, _("Importing of TiGroup files is not allowed.")); return; } model = tifiles_file_get_model(fn); if(!tifiles_calc_are_compat(GFMFile.model, model)) { msgbox_one(MSGBOX_ERROR, _("File is not compatible with current target.")); return; } content = tifiles_content_create_regular(model); ret = tifiles_file_read_regular(fn, content); for(i = 0; i < content->num_entries; i++) { VarEntry *ve = content->entries[i]; if(ticalcs_dirlist_ve_exist(GFMFile.trees.vars, ve)) { msgbox_one(MSGBOX_ERROR, _("The entry already exists. Skipped!")); continue; } ticalcs_dirlist_ve_add(GFMFile.trees.vars, ve); } ret = tifiles_content_delete_regular(content); } enable_save(TRUE); enable_tree(TRUE); ctree_refresh(); labels_refresh(); }
/** * 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; }
/** * 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; }
/* Preload TI variables belonging with the selection */ void tilp_local_contents_load(void) { GList *ptr; int err; // TIGroups if (local.selection5 != NULL) { for(ptr = local.selection5; ptr; ptr = ptr->next) { FileEntry *fe5 = ptr->data; if(tifiles_file_is_tigroup(fe5->name)) { TigContent *content = NULL; FileContent **p, **contents1 = NULL; FlashContent **q, **contents2 = NULL; content = tifiles_content_create_tigroup(options.calc_model, 0); err = tifiles_file_read_tigroup(fe5->name, content); if(err) { tilp_err(err); continue; } err = tifiles_untigroup_content(content, &contents1, &contents2); if(err) { tilp_err(err); tifiles_content_delete_tigroup(content); continue; } tifiles_content_delete_tigroup(content); for(p = contents1; *p; p++) { FileEntry *fe1 = g_memdup(ptr->data, sizeof(FileEntry)); fe1->name = g_memdup(fe1->name, strlen(fe1->name)+1); fe1->content1 = *p; //g_free(fe1->name); //fe1->name = tifiles_build_filename(options.calc_model, (*p)->entries[0]); local.selection1 = g_list_append(local.selection1, fe1); } for(q = contents2; *q; q++) { FileEntry *fe3 = g_memdup(ptr->data, sizeof(FileEntry)); fe3->name = g_memdup(fe3->name, strlen(fe3->name)+1); fe3->content2 = *q; /* { VarEntry ve; g_free(fe3->name); strcpy(ve.name, (*q)->name); ve.type = (*q)->data_type; fe3->name = tifiles_build_filename(options.calc_model, &ve); }*/ local.selection3 = g_list_append(local.selection3, fe3); } } } } // Variables if (local.selection0 != NULL) { for(ptr = local.selection0; ptr; ptr = ptr->next) { FileEntry *fe0 = ptr->data; if(!g_ascii_strcasecmp(tifiles_fext_get(fe0->name), "8xidl")) continue; // doesn't send this pseudo-variable if(tifiles_file_is_single(fe0->name)) { FileEntry *fe1 = g_memdup(ptr->data, sizeof(FileEntry)); fe1->content1 = tifiles_content_create_regular(options.calc_model); err = tifiles_file_read_regular(fe1->name, fe1->content1); if(err) { // The content is already deleted by the subroutines of tifiles_file_read_regular. //tifiles_content_delete_regular(fe1->content1); g_free(fe1); continue; } local.selection1 = g_list_append(local.selection1, fe1); } else if(tifiles_file_is_group(fe0->name)) { // explode group files so that we have 1 VarEntry per item (skip/retry/cancel) FileContent **p, **dst = NULL; FileContent *src = NULL; src = tifiles_content_create_regular(options.calc_model); err = tifiles_file_read_regular(fe0->name, src); if(err) { // The content is already deleted by the subroutines of tifiles_file_read_regular. //tifiles_content_delete_regular(src); continue; } err = tifiles_ungroup_content(src, &dst); if(err) { tifiles_content_delete_regular(src); continue; } for(p = dst; *p; p++) { FileEntry *fe = g_memdup(ptr->data, sizeof(FileEntry)); fe->content1 = *p; local.selection1 = g_list_append(local.selection1, fe); } tifiles_content_delete_regular(src); } } } // Applications if(local.selection2 != NULL) { for(ptr = local.selection2; ptr; ptr = ptr->next) { FileEntry *fe2 = ptr->data; if(tifiles_file_is_app(fe2->name) || tifiles_file_test(fe2->name, TIFILE_OS, options.calc_model)) { FileEntry *fe3 = g_memdup(ptr->data, sizeof(FileEntry)); fe3->content2 = tifiles_content_create_flash(options.calc_model); err = tifiles_file_read_flash(fe2->name, fe3->content2); if(err) { tifiles_content_delete_flash(fe3->content2); g_free(fe3); continue; } local.selection3 = g_list_append(local.selection3, fe3); } } } // Reparse variables and change target folder if (local.selection1) { // replaced "" folder by "main" if(!tifiles_has_folder(options.calc_model)) return; for(ptr = local.selection1; ptr; ptr = ptr->next) { FileEntry *fe = ptr->data; FileContent *fc = fe->content1; unsigned int i; if(fc == NULL) continue; for(i = 0; i < fc->num_entries; i++) { VarEntry *ve = (fc->entries)[i]; if(!strcmp(ve->folder , "")) strcpy(ve->folder, "main"); } } } }