/** * tifiles_content_del_entry: * @content: a file content (single/group only). * @ve: the entry to remove * * Search for entry name and remove it from file content (not tested !). * * Return value: the number of entries or -1 if not found. **/ TIEXPORT2 int TICALL tifiles_content_del_entry(FileContent *content, VarEntry *ve) { int i, j; if (content != NULL) { if (ve == NULL) { tifiles_critical("%s: deleting NULL VarEntry ???", __FUNCTION__); return content->num_entries; } // Search for entry for(i = 0; i < content->num_entries; i++) { VarEntry *s = content->entries[i]; if(!strcmp(s->folder, ve->folder) && !strcmp(s->name, ve->name)) break; } // Not found ? Exit ! if(i == content->num_entries) return -1; // Release tifiles_ve_delete(content->entries[i]); // And shift for(j = i; j < content->num_entries; j++) content->entries[j] = content->entries[j+1]; content->entries[j] = NULL; // And resize content->entries = tifiles_ve_resize_array(content->entries, content->num_entries - 1); content->num_entries--; return content->num_entries; } else { tifiles_critical("%s: content is NULL", __FUNCTION__); return 0; } }
/** * tifiles_content_add_entry: * @content: a file content (single/group only). * @ve: the entry to add * * Adds the entry to the file content and updates internal structures. * Beware: the entry is not duplicated. * * Return value: the number of entries. **/ TIEXPORT2 int TICALL tifiles_content_add_entry(FileContent *content, VarEntry *ve) { if (content != NULL) { content->entries = tifiles_ve_resize_array(content->entries, content->num_entries + 1); if (ve == NULL) { tifiles_critical("%s: adding NULL VarEntry ???", __FUNCTION__); } content->entries[content->num_entries] = ve; content->num_entries++; return content->num_entries; } else { tifiles_critical("%s: content is NULL", __FUNCTION__); } 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; }
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; }
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; }