/** * tifiles_build_filename: * @model: a calculator model. * @ve: a #VarEntry structure. * * Build a valid filename from folder name, variable name and variable type. * Example: real number x on TI89 in the 'main' folder will give 'main.x.89e'. * Note: this function is useable with FLASH apps, too (but you have to fill the #VarEntry structure yourself). * * Return value: a newly allocated string which must be freed when no longer used. **/ TIEXPORT2 char* TICALL tifiles_build_filename(CalcModel model, const VarEntry *ve) { char *filename; if (ve == NULL) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return NULL; } if(tifiles_calc_is_ti8x(model) || !strcmp(ve->folder, "") || (ve->type == tifiles_flash_type(model))) { char *part2; const char *part3; char *tmp; part2 = ticonv_varname_to_filename(model, ve->name, ve->type); part3 = tifiles_vartype2fext(model, ve->type); tmp = g_strconcat(part2, ".", part3, NULL); g_free(part2); filename = g_strdup(tmp); g_free(tmp); } else { char *part1; char *part2; const char *part3; char *tmp; part1 = ticonv_varname_to_filename(model, ve->folder, -1); part2 = ticonv_varname_to_filename(model, ve->name, ve->type); part3 = tifiles_vartype2fext(model, ve->type); tmp = g_strconcat(part1, ".", part2, ".", part3, NULL); g_free(part1); g_free(part2); filename = strdup(tmp); g_free(tmp); } return filename; }
GLADE_CB void on_save_clicked (GtkToolButton *toolbutton, gpointer user_data) { gchar *fn = NULL, *ext = NULL; gchar *filename = NULL; if(GFMFile.filename != NULL) filename = g_strdup(GFMFile.filename); if(GFMFile.type & TIFILE_TIGROUP) { ext = g_strdup("*.tig"); } else if(GFMFile.type & TIFILE_GROUP) { if(ticalcs_dirlist_ve_count(GFMFile.trees.vars) > 1) { // Group file ext = g_strconcat("*.", tifiles_vartype2fext(GFMFile.model, 0x00), NULL); ext[4] = 'g'; } else if(ticalcs_dirlist_ve_count(GFMFile.trees.vars) == 1) { // Single file GNode *parent, *child; VarEntry *ve; parent = g_node_nth_child(GFMFile.trees.vars, 0); child = g_node_nth_child(parent, 0); ve = (VarEntry *) (child->data); filename = g_strconcat(ticonv_varname_to_filename(GFMFile.model, ve->name, ve->type), ".", tifiles_vartype2fext(GFMFile.model, ve->type), NULL); ext = g_strconcat("*.", tifiles_vartype2fext(GFMFile.model, ve->type), NULL); } else { g_free(filename); return; } } fn = (char *)create_fsel(inst_paths.home_dir, filename, ext, TRUE); if(fn == NULL) return; g_free(filename); g_free(ext); file_save(fn); g_free(GFMFile.filename); GFMFile.filename = g_strdup(fn); enable_save(FALSE); }
/** * ticalcs_calc_recv_tigroup: * @handle: a previously allocated handle * @filename: name of file * @mode: which vars/apps to receive * * Receive a TiGroup file. * * Return value: 0 if ready else ERR_NOT_READY. **/ TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, TigMode mode) { int i, j; int i_max, j_max; GNode *vars, *apps; int nvars = 0; int napps = 0; int b = 0; if(handle == NULL) return ERR_INVALID_HANDLE; if (content == NULL) { ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL"); return -1; } update_->cnt3 = 0; update_->pbar(); // Do a directory list and check for something to backup TRYF(handle->calc->get_dirlist(handle, &vars, &apps)); if((mode & TIG_RAM) || (mode & TIG_ARCHIVE)) nvars = ticalcs_dirlist_ve_count(vars); if(mode & TIG_FLASH) napps = ticalcs_dirlist_ve_count(apps); update_->cnt3 = 0; update_->max3 = nvars + napps; update_->pbar(); if(!nvars && !napps) return ERR_NO_VARS; // 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 // Receive all vars i_max = g_node_n_children(vars); if((mode & TIG_RAM) || (mode & TIG_ARCHIVE)) 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); TigEntry *te; char *filename; char *varname; char *fldname; PAUSE(100); TRYF(handle->calc->is_ready(handle)); PAUSE(100); update_->cnt3++; update_->pbar(); if(((mode & TIG_ARCHIVE) && (ve->attr == ATTRB_ARCHIVED)) || ((mode & TIG_RAM) && ve->attr != ATTRB_ARCHIVED)) { fldname = ticonv_varname_to_filename(handle->model, ve->folder, -1); varname = ticonv_varname_to_filename(handle->model, ve->name, ve->type); if(handle->calc->features & FTS_FOLDER) filename = g_strconcat(fldname, ".", varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); else filename = g_strconcat(varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); g_free(fldname); g_free(varname); te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model); g_free(filename); TRYF(handle->calc->recv_var(handle, 0, te->content.regular, ve)); tifiles_content_add_te(content, te); } } } ticalcs_dirlist_destroy(&vars); // Receive all apps i_max = g_node_n_children(apps); if(mode & TIG_FLASH) for(i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(apps, 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); TigEntry *te; char *filename; char *basename; TRYF(handle->calc->is_ready(handle)); update_->cnt3++; update_->pbar(); basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type); filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); g_free(basename); te = tifiles_te_create(filename, TIFILE_FLASH, handle->model); g_free(filename); TRYF(handle->calc->recv_app(handle, te->content.flash, ve)); tifiles_content_add_te(content, te); } } ticalcs_dirlist_destroy(&apps); return 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; }
/** * ticalcs_calc_recv_tigroup: * @handle: a previously allocated handle * @filename: name of file * @mode: which vars/apps to receive * * Receive a TiGroup file. * * Return value: 0 if ready else ERR_NOT_READY. **/ TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, TigMode mode) { int i, j; GNode *vars, *apps; int nvars = 0; int napps = 0; int b = 0; int ret; VALIDATE_HANDLE(handle); if (content == NULL) { ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL"); return -1; } VALIDATE_CALCFNCTS(handle->calc); handle->updat->cnt3 = 0; ticalcs_update_pbar(handle); // Do a directory list and check for something to backup ret = handle->calc->get_dirlist(handle, &vars, &apps); if (ret) { return ret; } if ((mode & TIG_RAM) || (mode & TIG_ARCHIVE)) { nvars = ticalcs_dirlist_ve_count(vars); } if (mode & TIG_FLASH) { napps = ticalcs_dirlist_ve_count(apps); } handle->updat->cnt3 = 0; handle->updat->max3 = nvars + napps; ticalcs_update_pbar(handle); if (!nvars && !napps) { ret = ERR_NO_VARS; // THIS RETURNS ! goto end; } // 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 // Receive all vars if ((mode & TIG_RAM) || (mode & TIG_ARCHIVE)) { int 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); TigEntry *te; PAUSE(100); ret = handle->calc->is_ready(handle); if (ret) { goto end; } PAUSE(100); handle->updat->cnt3++; ticalcs_update_pbar(handle); if (((mode & TIG_ARCHIVE) && (ve->attr == ATTRB_ARCHIVED)) || ((mode & TIG_RAM) && ve->attr != ATTRB_ARCHIVED)) { char *filename; char *varname = ticonv_varname_to_filename(handle->model, ve->name, ve->type); char *fldname = ticonv_varname_to_filename(handle->model, ve->folder, -1); if (handle->calc->features & FTS_FOLDER) { filename = g_strconcat(fldname, ".", varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); } else { filename = g_strconcat(varname, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); } g_free(varname); g_free(fldname); te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model); g_free(filename); if (te != NULL) { ret = handle->calc->recv_var(handle, 0, te->content.regular, ve); if (ret) { tifiles_te_delete(te); goto end; } tifiles_content_add_te(content, te); } else { ret = ERR_MALLOC; goto end; } } } } } // Receive all apps if (mode & TIG_FLASH) { int i_max = g_node_n_children(apps); for(i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(apps, 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); TigEntry *te; char *filename; char *basename; ret = handle->calc->is_ready(handle); if (ret) { goto end; } handle->updat->cnt3++; ticalcs_update_pbar(handle); basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type); filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); g_free(basename); te = tifiles_te_create(filename, TIFILE_FLASH, handle->model); g_free(filename); if (te != NULL) { ret = handle->calc->recv_app(handle, te->content.flash, ve); if (ret) { tifiles_te_delete(te); goto end; } tifiles_content_add_te(content, te); } else { ret = ERR_MALLOC; goto end; } } } } end: ticalcs_dirlist_destroy(&apps); ticalcs_dirlist_destroy(&vars); return ret; }