/** * 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; }
/** * 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; }
int main(int argc, char **argv) { void * ptr; tifiles_library_init(); PRINTF(tifiles_error_get, INT, -1, NULL); PRINTF(tifiles_error_free, INT, NULL); PRINTF(tifiles_model_to_string, STR, -1); PRINTF(tifiles_string_to_model, INT, NULL); PRINTF(tifiles_attribute_to_string, STR, -1); PRINTF(tifiles_string_to_attribute, INT, NULL); PRINTF(tifiles_class_to_string, STR, -1); PRINTF(tifiles_string_to_class, INT, NULL); PRINTF(tifiles_fext_of_group, STR, -1); PRINTF(tifiles_fext_of_backup, STR, -1); PRINTF(tifiles_fext_of_flash_app, STR, -1); PRINTF(tifiles_fext_of_flash_os, STR, -1); PRINTF(tifiles_fext_of_certif, STR, -1); PRINTF(tifiles_fext_get, STR, NULL); ptr = tifiles_fext_dup(NULL); PRINTF(, PTR, ptr); tifiles_fext_free(ptr); PRINTFVOID(tifiles_fext_free, NULL); PRINTF(tifiles_file_is_ti, INT, NULL); PRINTF(tifiles_file_is_single, INT, NULL); PRINTF(tifiles_file_is_group, INT, NULL); PRINTF(tifiles_file_is_regular, INT, NULL); PRINTF(tifiles_file_is_backup, INT, NULL); PRINTF(tifiles_file_is_os, INT, NULL); PRINTF(tifiles_file_is_app, INT, NULL); PRINTF(tifiles_file_is_tib, INT, NULL); PRINTF(tifiles_file_is_flash, INT, NULL); PRINTF(tifiles_file_is_tigroup, INT, NULL); PRINTF(tifiles_file_is_tno, INT, NULL); PRINTF(tifiles_file_has_ti_header, INT, NULL); PRINTF(tifiles_file_has_tib_header, INT, NULL); PRINTF(tifiles_file_has_tig_header, INT, NULL); PRINTF(tifiles_file_has_tifl_header, INT, NULL, (void *)0x12345678, (void *)0x12345678); PRINTF(tifiles_file_has_tno_header, INT, NULL); PRINTF(tifiles_model_to_dev_type, INT, -1); PRINTF(tifiles_file_test, INT, NULL, -1, -1); PRINTF(tifiles_file_get_model, INT, NULL); PRINTF(tifiles_file_get_class, INT, NULL); PRINTF(tifiles_file_get_type, STR, NULL); PRINTF(tifiles_file_get_icon, STR, NULL); PRINTF(tifiles_vartype2string, STR, -1, -1); PRINTF(tifiles_string2vartype, INT, -1, NULL); PRINTF(tifiles_vartype2fext, STR, -1, -1); PRINTF(tifiles_fext2vartype, INT, -1, NULL); PRINTF(tifiles_vartype2type, STR, -1, -1); PRINTF(tifiles_vartype2icon, STR, -1, -1); PRINTF(tifiles_calctype2signature, STR, -1); PRINTF(tifiles_signature2calctype, INT, NULL); PRINTF(tifiles_folder_type, INT, -1); PRINTF(tifiles_flash_type, INT, -1); PRINTF(tifiles_idlist_type, INT, -1); PRINTF(tifiles_calc_is_ti8x, INT, -1); PRINTF(tifiles_calc_is_ti9x, INT, -1); PRINTF(tifiles_calc_are_compat, INT, -1, -1); PRINTF(tifiles_has_folder, INT, -1); PRINTF(tifiles_is_flash, INT, -1); PRINTF(tifiles_has_backup, INT, -1); PRINTF(tifiles_checksum, INT, NULL, 1234567891); PRINTF(tifiles_hexdump, INT, NULL, 1); PRINTF(tifiles_get_varname, STR, NULL); PRINTF(tifiles_get_fldname, STR, NULL); PRINTF(tifiles_build_fullname, STR, -1, NULL, NULL, (void *)0x12345678); PRINTF(tifiles_build_fullname, STR, -1, (void *)0x12345678, NULL, NULL); PRINTF(tifiles_build_fullname, STR, -1, NULL, (void *)0x12345678, NULL); PRINTF(tifiles_build_filename, STR, -1, NULL); PRINTFVOID(tifiles_filename_free, NULL); ptr = tifiles_content_create_regular(-1); PRINTF(, PTR, ptr); tifiles_content_delete_regular(ptr); PRINTF(tifiles_content_delete_regular, INT, NULL); PRINTF(tifiles_file_read_regular, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_read_regular, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_regular, INT, NULL, NULL, (void *)0x12345678); PRINTF(tifiles_file_write_regular, INT, NULL, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_regular, INT, (void *)0x12345678, NULL, NULL); PRINTF(tifiles_file_display_regular, INT, NULL); ptr = tifiles_content_create_backup(-1); PRINTF(, PTR, ptr); tifiles_content_delete_backup(ptr); PRINTF(tifiles_content_delete_backup, INT, NULL); PRINTF(tifiles_file_read_backup, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_read_backup, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_backup, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_write_backup, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_display_backup, INT, NULL); ptr = tifiles_content_create_flash(-1); PRINTF(, PTR, ptr); tifiles_content_delete_flash(ptr); PRINTF(tifiles_file_read_flash, INT, NULL, (void *)0x12345678); PRINTF(tifiles_content_delete_flash, INT, NULL); PRINTF(tifiles_file_read_flash, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_flash, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_write_flash, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_flash2, INT, NULL, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_flash2, INT, (void *)0x12345678, NULL, NULL); PRINTF(tifiles_file_display_flash, INT, NULL); PRINTF(tifiles_content_dup_regular, PTR, NULL); PRINTF(tifiles_content_dup_flash, PTR, NULL); PRINTF(tifiles_file_display, INT, NULL); ptr = tifiles_content_create_group(0); PRINTF(, PTR, ptr); tifiles_content_delete_group(ptr); PRINTF(tifiles_content_delete_group, INT, NULL); PRINTF(tifiles_group_contents, INT, NULL, (void *)0x12345678); PRINTF(tifiles_group_contents, INT, (void *)0x12345678, NULL); PRINTF(tifiles_ungroup_content, INT, NULL, (void *)0x12345678); PRINTF(tifiles_ungroup_content, INT, (void *)0x12345678, NULL); PRINTF(tifiles_group_files, INT, NULL, (void *)0x12345678); PRINTF(tifiles_group_files, INT, (void *)0x12345678, NULL); PRINTF(tifiles_ungroup_file, INT, NULL, (void *)0x12345678); PRINTF(tifiles_content_add_entry, INT, NULL, (void *)0x12345678); PRINTF(tifiles_content_del_entry, INT, NULL, (void *)0x12345678); PRINTF(tifiles_group_add_file, INT, NULL, (void *)0x12345678); PRINTF(tifiles_group_add_file, INT, (void *)0x12345678, NULL); PRINTF(tifiles_group_del_file, INT, NULL, (void *)0x12345678); PRINTF(tifiles_group_del_file, INT, (void *)0x12345678, NULL); ptr = tifiles_content_create_tigroup(-1, -1); PRINTF(, PTR, ptr); tifiles_content_delete_tigroup(ptr); PRINTF(tifiles_content_delete_tigroup, INT, NULL); PRINTF(tifiles_file_read_tigroup, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_read_tigroup, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_write_tigroup, INT, NULL, (void *)0x12345678); PRINTF(tifiles_file_write_tigroup, INT, (void *)0x12345678, NULL); PRINTF(tifiles_file_display_tigroup, INT, NULL); PRINTF(tifiles_tigroup_contents, INT, NULL, (void *)0x12345678, NULL); PRINTF(tifiles_tigroup_contents, INT, (void *)0x12345678, NULL, NULL); PRINTF(tifiles_tigroup_contents, INT, NULL, NULL, NULL); PRINTF(tifiles_untigroup_content, INT, NULL, NULL, NULL); PRINTF(tifiles_untigroup_content, INT, NULL, NULL, NULL); PRINTF(tifiles_untigroup_content, INT, NULL, NULL, NULL); PRINTF(tifiles_tigroup_files, INT, NULL, NULL); PRINTF(tifiles_tigroup_files, INT, NULL, NULL); PRINTF(tifiles_untigroup_file, INT, NULL, NULL); PRINTF(tifiles_untigroup_file, INT, NULL, NULL); PRINTF(tifiles_content_add_te, INT, NULL, NULL); PRINTF(tifiles_content_add_te, INT, NULL, NULL); PRINTF(tifiles_content_del_te, INT, NULL, NULL); PRINTF(tifiles_content_del_te, INT, NULL, NULL); PRINTF(tifiles_tigroup_add_file, INT, NULL, NULL); PRINTF(tifiles_tigroup_add_file, INT, NULL, NULL); PRINTF(tifiles_tigroup_del_file, INT, NULL, NULL); PRINTF(tifiles_tigroup_del_file, INT, NULL, NULL); PRINTF(tifiles_te_create, PTR, NULL, -1, -1); PRINTF(tifiles_te_delete, INT, NULL); ptr = tifiles_te_create_array(0); PRINTF(, PTR, ptr); tifiles_te_delete_array(ptr); ptr = tifiles_te_resize_array(NULL, 0); PRINTF(, PTR, ptr); tifiles_te_delete_array(ptr); PRINTFVOID(tifiles_te_delete_array, NULL); PRINTF(tifiles_te_sizeof_array, INT, NULL); PRINTF(tifiles_comment_set_single, STR); PRINTF(tifiles_comment_set_group, STR); PRINTF(tifiles_comment_set_backup, STR); PRINTF(tifiles_comment_set_tigroup, STR); ptr = tifiles_ve_create(); PRINTF(, PTR, ptr); tifiles_ve_delete(ptr); ptr = tifiles_ve_create_alloc_data(0); PRINTF(, PTR, ptr); tifiles_ve_delete(ptr); ptr = tifiles_ve_create_with_data(0); PRINTF(, PTR, ptr); tifiles_ve_delete(ptr); ptr = tifiles_ve_create_with_data2(0, NULL); PRINTF(, PTR, ptr); tifiles_ve_delete(ptr); PRINTFVOID(tifiles_ve_delete, NULL); ptr = tifiles_ve_alloc_data(0); PRINTF(, PTR, ptr); tifiles_ve_free_data(ptr); ptr = tifiles_ve_realloc_data(NULL, 1); PRINTF(, PTR, ptr); tifiles_ve_free_data(ptr); PRINTFVOID(tifiles_ve_free_data, NULL); PRINTF(tifiles_ve_copy, PTR, NULL, NULL); PRINTF(tifiles_ve_dup, PTR, NULL); ptr = tifiles_ve_create_array(0); PRINTF(, PTR, ptr); tifiles_ve_delete_array(ptr); ptr = tifiles_ve_resize_array(NULL, 0); PRINTF(, PTR, ptr); tifiles_ve_delete_array(ptr); PRINTFVOID(tifiles_ve_delete_array, NULL); ptr = tifiles_fp_create(); PRINTF(, PTR, ptr); tifiles_fp_delete(ptr); ptr = tifiles_fp_create_alloc_data(0); PRINTF(, PTR, ptr); tifiles_fp_delete(ptr); ptr = tifiles_fp_create_with_data(0); PRINTF(, PTR, ptr); tifiles_fp_delete(ptr); ptr = tifiles_fp_create_with_data2(0, NULL); PRINTF(, PTR, ptr); tifiles_fp_delete(ptr); PRINTFVOID(tifiles_fp_delete, NULL); ptr = tifiles_fp_alloc_data(0); PRINTF(, PTR, ptr); tifiles_fp_free_data(ptr); ptr = tifiles_fp_realloc_data(NULL, 1); PRINTF(, PTR, ptr); tifiles_fp_free_data(ptr); PRINTFVOID(tifiles_fp_free_data, NULL); ptr = tifiles_fp_create_array(0); PRINTF(, PTR, ptr); tifiles_fp_delete_array(ptr); ptr = tifiles_fp_resize_array(NULL, 0); PRINTF(, PTR, ptr); tifiles_fp_delete_array(ptr); PRINTFVOID(tifiles_fp_delete_array, NULL); ptr = tifiles_create_table_of_entries(NULL, NULL); PRINTF(, PTR, ptr); tifiles_free_table_of_entries(ptr); PRINTFVOID(tifiles_free_table_of_entries, NULL); cert_functions_unit_test(); tifiles_library_exit(); return 0; }
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; }
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; }