void ctree_set_basetree(void) { GtkTreeIter clc_node; GtkTreeIter *top_node = NULL; GtkTreeIter lcd_node, rom_node, idl_node, clk_node; gchar* str; // clear tree gtk_tree_store_clear(tree); // top node #if 1 str = g_strdup_printf(_("%s -> %s:#%i"), tifiles_model_to_string(options.calc_model), ticables_model_to_string(options.cable_model), options.cable_port); top_node = &clc_node; gtk_tree_store_append(tree, top_node, NULL); gtk_tree_store_set(tree, &clc_node, COLUMN_NAME, str, COLUMN_DATA, (gpointer) NULL, -1); g_free(str); #endif // lcd, rom, vars & apps nodes gtk_tree_store_append(tree, &lcd_node, top_node); gtk_tree_store_set(tree, &lcd_node, COLUMN_NAME, NODE1, COLUMN_DATA, (gpointer) NULL, -1); gtk_tree_store_append(tree, &rom_node, top_node); gtk_tree_store_set(tree, &rom_node, COLUMN_NAME, NODE2, COLUMN_DATA, (gpointer) NULL, -1); gtk_tree_store_append(tree, &vars_node, top_node); gtk_tree_store_set(tree, &vars_node, COLUMN_NAME, NODE3, COLUMN_DATA, (gpointer) NULL, -1); if (tifiles_is_flash(options.calc_model)) { gtk_tree_store_append(tree, &apps_node, top_node); gtk_tree_store_set(tree, &apps_node, COLUMN_NAME, NODE4, COLUMN_DATA, (gpointer) NULL, -1); gtk_tree_store_append(tree, &idl_node, top_node); gtk_tree_store_set(tree, &idl_node, COLUMN_NAME, NODE5, COLUMN_DATA, (gpointer) NULL, -1); gtk_tree_store_append(tree, &clk_node, top_node); gtk_tree_store_set(tree, &clk_node, COLUMN_NAME, NODE6, COLUMN_DATA, (gpointer) NULL, -1); } gtk_tree_view_expand_all(GTK_TREE_VIEW(ctree_wnd)); }
TILP_EXPORT void on_rom_dump1_activate(GtkMenuItem* menuitem, gpointer user_data) { char* src_filename; const char *dst_filename; const char *dst_filename2; char filename[128]; if (tilp_calc_rom_dump()) return; src_filename = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, TMPFILE_ROMDUMP, NULL); sprintf(filename, "dump%s", tifiles_model_to_string(options.calc_model)); dst_filename = create_fsel(local.cwdir, filename, "*.rom", TRUE); if (!dst_filename) { g_free(src_filename); return; } if (!strcmp(tifiles_fext_get(dst_filename), "")) dst_filename2 = g_strconcat(dst_filename, ".", "rom", NULL); else dst_filename2 = g_strdup(dst_filename); //g_free((void *)dst_filename); if (dst_filename2) { tilp_file_move_with_check(src_filename, dst_filename2); } g_free(src_filename); g_free((void *)dst_filename2); tilp_dirlist_local(); clist_refresh(); labels_refresh(); }
/* * Write out a PDF file. */ gboolean screen_write_pdf(const gchar *filename, GError **error) { int h, w; FILE *fp; long obj5, obj6, obj7, xref, slen, slenp; struct tm *t; time_t tt; guchar *buf; gboolean ret; GError *err = NULL; fp = fopen(filename, "wb"); if (fp == NULL) { g_set_error(error, 0, 0, _("Couldn't open destination file for writing!")); return FALSE; } h = screen.height; w = screen.width; tt = time(NULL); t = gmtime(&tt); fprintf(fp, "%%PDF-1.5\n"); fprintf(fp, "\n"); fprintf(fp, "1 0 obj\n"); fprintf(fp, " << /Type /Catalog\n"); fprintf(fp, " /Outlines 2 0 R\n"); fprintf(fp, " /Pages 3 0 R\n"); fprintf(fp, " >>\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); fprintf(fp, "2 0 obj\n"); fprintf(fp, " << /Type /Outlines\n"); fprintf(fp, " /Count 0\n"); fprintf(fp, " >>\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); fprintf(fp, "3 0 obj\n"); fprintf(fp, " << /Type /Pages\n"); fprintf(fp, " /Kids [4 0 R]\n"); fprintf(fp, " /Count 1\n"); fprintf(fp, " >>\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); fprintf(fp, "4 0 obj\n"); fprintf(fp, " << /Type /Page\n"); fprintf(fp, " /Parent 3 0 R\n"); fprintf(fp, " /MediaBox [0 0 %d %d]\n", w, h); fprintf(fp, " /Contents 5 0 R\n"); fprintf(fp, " /Resources << /ProcSet 6 0 R >>\n"); fprintf(fp, " >>\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); /* Offset of object 5, for xref */ obj5 = ftell(fp); fprintf(fp, "5 0 obj\n"); fprintf(fp, " << /Length >>\n"); /* Position of the stream length, to be written later on */ slenp = ftell(fp) - 12; fprintf(fp, "stream\n"); /* Start of the stream data */ slen = ftell(fp); fprintf(fp, "q\n"); fprintf(fp, "%d 0 0 %d 0 0 cm\n", w, h); fprintf(fp, "BI\n"); fprintf(fp, " /W %d\n", w); fprintf(fp, " /H %d\n", h); if (options.screen_blurry) { /* RGB, 8 bits per component, ASCIIHex encoding */ fprintf(fp, " /CS /RGB\n"); fprintf(fp, " /BPC 8\n"); fprintf(fp, " /F [/A85 /FlateDecode]\n"); fprintf(fp, "ID\n"); buf = g_malloc(3 * w * h); ret = ticalcs_screen_convert_bw_to_blurry_rgb888(screen.bitmap, w, h, buf); if (!ret) { ret = write_compressed_a85_screen(fp, buf, (h * w * 3), FALSE, &err); } else { ret = 0; g_set_error(&err, 0, 0, _("Couldn't convert screen!")); } g_free(buf); if (!ret) { g_propagate_error(error, err); fclose(fp); unlink(filename); return FALSE; } } else { /* GrayLevel, 1 bit per component, ASCIIHex encoding */ fprintf(fp, " /CS /G\n"); fprintf(fp, " /BPC 1\n"); fprintf(fp, " /F [/A85 /FlateDecode]\n"); fprintf(fp, "ID\n"); ret = write_compressed_a85_screen(fp, screen.bitmap, (h * w) / 8, TRUE, &err); if (!ret) { g_propagate_error(error, err); fclose(fp); unlink(filename); return FALSE; } } fprintf(fp, "EI\n"); fprintf(fp, "Q\n"); /* Go back and write the length of the stream */ slen = ftell(fp) - slen - 1; fseek(fp, slenp, SEEK_SET); fprintf(fp, "%lu", slen); fseek(fp, 0L, SEEK_END); fprintf(fp, "endstream\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); /* Offset of object 6, for xref */ obj6 = ftell(fp); fprintf(fp, "6 0 obj\n"); fprintf(fp, " [/PDF]\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); /* Offset of object 7, for xref */ obj7 = ftell(fp); fprintf(fp, "7 0 obj\n"); fprintf(fp, " << /Title (TiLP %s screenshot)\n", tifiles_model_to_string(options.calc_model)); fprintf(fp, " /Creator (TiLP / PDF output Copyright (C) 2005 Julien BLACHE)\n"); fprintf(fp, " /Producer (TiLP %s)\n", TILP_VERSION); fprintf(fp, " /CreationDate (D:%04d%02d%02d%02d%02d%02d+00'00')\n", 1900 + t->tm_year, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); fprintf(fp, " >>\n"); fprintf(fp, "endobj\n"); fprintf(fp, "\n"); /* Offset of xref, for startxref below */ xref = ftell(fp); fprintf(fp, "xref\n"); fprintf(fp, "0 8\n"); fprintf(fp, "0000000000 65535 f \n"); fprintf(fp, "0000000010 00000 n \n"); fprintf(fp, "0000000094 00000 n \n"); fprintf(fp, "0000000153 00000 n \n"); fprintf(fp, "0000000229 00000 n \n"); fprintf(fp, "%010lu 00000 n \n", obj5); fprintf(fp, "%010lu 00000 n \n", obj6); fprintf(fp, "%010lu 00000 n \n", obj7); fprintf(fp, "\n"); fprintf(fp, "trailer\n"); fprintf(fp, " << /Size 8\n"); fprintf(fp, " /Root 1 0 R\n"); fprintf(fp, " /Info 7 0 R\n"); fprintf(fp, " >>\n"); fprintf(fp, "startxref\n"); fprintf(fp, "%lu\n", xref); fprintf(fp, "%%%%EOF\n"); fclose(fp); return TRUE; }
/* * Write out an Encapsulated PostScript file. */ gboolean screen_write_eps(const gchar *filename, GError **error) { int h, w; FILE *fp; guchar *buf; time_t t; gboolean ret; GError *err = NULL; fp = fopen(filename, "wb"); if (fp == NULL) { g_set_error(error, 0, 0, _("Couldn't open destination file for writing!")); return FALSE; } h = screen.height; w = screen.width; time(&t); fprintf(fp, "%%!PS-Adobe-3.0 EPSF-3.0\n"); fprintf(fp, "%%%%Creator: TiLP %s / PostScript output Copyright (C) 2005 Julien BLACHE\n", TILP_VERSION); fprintf(fp, "%%%%Title: TiLP %s screenshot\n", tifiles_model_to_string(options.calc_model)); fprintf(fp, "%%%%CreationDate: %s", ctime(&t)); fprintf(fp, "%%%%LanguageLevel: 3\n"); fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", w, h); fprintf(fp, "\n"); fprintf(fp, "%d %d scale\n", w, h); if (options.screen_blurry) { fprintf(fp, "%d %d 8 [%d 0 0 -%d 0 %d] currentfile /ASCII85Decode filter /FlateDecode filter false 3 colorimage\n", w, h, w, h, h); buf = g_malloc(3 * w * h); ret = ticalcs_screen_convert_bw_to_blurry_rgb888(screen.bitmap, w, h, buf); if (!ret) { ret = write_compressed_a85_screen(fp, buf, (h * w * 3), FALSE, &err); } else { ret = 0; g_set_error(&err, 0, 0, _("Couldn't convert screen!")); } g_free(buf); if (!ret) { g_propagate_error(error, err); fclose(fp); unlink(filename); return FALSE; } } else { fprintf(fp, "%d %d 1 [%d 0 0 -%d 0 %d] currentfile /ASCII85Decode filter /FlateDecode filter image\n", w, h, w, h, h); ret = write_compressed_a85_screen(fp, screen.bitmap, (h * w) / 8, TRUE, &err); if (!ret) { g_propagate_error(error, err); fclose(fp); unlink(filename); return FALSE; } } fprintf(fp, "%%%%EOF\n"); fclose(fp); return TRUE; }
GLADE_CB gboolean on_treeview1_button_press_event(GtkWidget * widget, GdkEventButton * event, gpointer user_data) { GtkTreeView *view = GTK_TREE_VIEW(ctree_wnd); GtkTreeModel *model = GTK_TREE_MODEL(tree); GtkTreePath *path; GtkTreeViewColumn *column; GtkTreeIter parent; VarEntry *ve; gint tx = (gint) event->x; gint ty = (gint) event->y; gint cx, cy; gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx, &cy); if (path == NULL) return FALSE; gtk_tree_model_get_iter(model, &parent, path); gtk_tree_model_get(model, &parent, COLUMN_DATA, &ve, -1); path_to_drag = path; gtk_tree_model_get(model, &parent, COLUMN_NAME, &name_to_drag, -1); if(event->type == GDK_BUTTON_PRESS) { if(event->button == 1) { /* printf("clicked !\n"); ctree_select_vars(!0); printf("selected ?!\n"); */ } else if (event->button == 3) { GdkEventButton *bevent = (GdkEventButton *) (event); gtk_menu_popup(GTK_MENU(create_ctree_rbm()), NULL, NULL, NULL, NULL, bevent->button, bevent->time); return TRUE; } } if (event->type == GDK_2BUTTON_PRESS) { gchar *name; gtk_tree_model_get(model, &parent, COLUMN_NAME, &name, -1); if (!strcmp(name, NODE1)) display_screenshot_dbox(); else if (!strcmp(name, NODE2)) on_rom_dump1_activate(NULL, NULL); else if (!strcmp(name, NODE3)) on_tilp_button3_clicked(NULL, NULL); else if(!strcmp(name, NODE5)) tilp_calc_idlist(0); else if(!strcmp(name, NODE6)) display_clock_dbox(); else if(!strncmp(name, tifiles_model_to_string(options.calc_model), 4)) { CalcInfos infos; tilp_calc_get_infos(&infos); } return TRUE; } if (ve == NULL) return FALSE; if (ve->type != tifiles_folder_type(options.calc_model)) return FALSE; name_to_drag = NODEx; return FALSE; // pass the event on }
// 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; }
/** * ticalcs_probe_calc_1: * @handle: a previously allocated handle * @type: the calculator model * * Check if the calculator is ready and detect the type. * Works only on FLASH calculators with an AMS2.08 or OS2.00 by requesting the * version. A previous version was based on MID but TI83+/84+, TI89/TI89t, TI92+/V200 * could not be distinguished ;-( * * Return value: 0 if successful, an error code otherwise. **/ static int ticalcs_probe_calc_1(CalcHandle* handle, CalcModel* model) { uint8_t host, cmd; uint16_t status; uint8_t buffer[256]; int i, err; CalcInfos infos; // init value *model = CALC_NONE; // test for FLASH hand-helds (00 68 00 00 -> XX 56 00 00) // where XX is 0x98: TI89/89t, 0x88: TI92+/V200, 0x73: TI83+/84+, 0x74: TI73 ticalcs_info(_("Check for TIXX... ")); for(i = 0; i < 2; i++) { ticalcs_info(" PC->TI: RDY?"); err = dbus_send(handle, PC_TIXX, CMD_RDY, 2, NULL); if(err) continue; err = dbus_recv_2(handle, &host, &cmd, &status, buffer); ticalcs_info(" TI->PC: ACK"); if(err) continue; break; } // test for TI73 if(!err) { if(host == TI73_PC) { *model = CALC_TI73; return 0; } else if(host == TI92_PC) { *model = CALC_TI92; return 0; } } // test for TI92 (09 68 00 00 -> 89 56 00 00) else if(err) { ticalcs_info(_("Check for TI92... ")); ticables_cable_reset(handle->cable); PAUSE(DEAD_TIME); // needed ! for(i = 0; i < 2; i++) { ticalcs_info(" PC->TI: RDY?"); err = dbus_send(handle, PC_TI92, CMD_RDY, 2, NULL); if(err) continue; err = dbus_recv_2(handle, &host, &cmd, &status, buffer); ticalcs_info(" TI->PC: ACK"); if(err) continue; break; } if(!err) *model = CALC_TI92; } if (cmd != CMD_ACK) return ERR_INVALID_CMD; if ((status & 1) != 0) return ERR_NOT_READY; // test for TI9x FLASH hand-helds again (request version and analyze HW_ID) if(!err && (host != TI73_PC) && (host != TI83p_PC)) { ticalcs_info(_("Check for TI9X... ")); handle->model = CALC_TI89; handle->calc = (CalcFncts *)&calc_89; memset(&infos, 0, sizeof(CalcInfos)); TRYF(ticalcs_calc_get_version(handle, &infos)); *model = infos.model; } else { ticalcs_info(_("Check for TI8X... ")); handle->model = CALC_TI83P; handle->calc = (CalcFncts *)&calc_83p; memset(&infos, 0, sizeof(CalcInfos)); TRYF(ticalcs_calc_get_version(handle, &infos)); *model = infos.model; } ticalcs_info(_("Calculator type: %s"), tifiles_model_to_string(*model)); return (*model == CALC_NONE) ? ERR_NO_CALC : 0; }