void update_table_file(char *name, int version) { if (!phonetic_char_dynamic_sequence) return; char fname_user[256]; char fname_version[256]; char fname_sys[256]; char version_name[256]; strcat(strcpy(version_name, name), ".version"); get_hime_user_fname(version_name, fname_version); get_hime_user_fname(name, fname_user); get_sys_table_file_name(name, fname_sys); FILE *fp; if ((fp=fopen(fname_version, "r"))) { int ver=0; fscanf(fp, "%d", &ver); fclose(fp); if (ver >= version) return; } char cmd[256]; sprintf(cmd, "mv -f %s %s.old && cp %s %s && echo %d > %s", fname_user, fname_user, fname_sys, fname_user, version, fname_version); dbg("exec %s\n", cmd); system(cmd); }
gboolean init_tsin_table_fname(INMD *p, char *fname) { char fname_idx[256], gtab_phrase_src[256], gtabfname[256]; if (p->filename_append) { // dbg("filename_append %s\n",p->filename_append); strcpy(fname, p->filename_append); strcpy(gtabfname, fname); } else if (p->filename) { get_hime_user_fname(p->filename, fname); get_hime_user_or_sys_fname(p->filename, gtabfname); } else { dbg("no file name\n"); return FALSE; } strcat(fname, ".tsin-db"); strcat(strcpy(fname_idx, fname), ".idx"); strcat(strcpy(gtab_phrase_src, fname), ".src"); // dbg("init_tsin_table %s\n", fname); putenv("HIME_NO_RELOAD="); if (access(fname, W_OK) < 0 || access(fname_idx, W_OK) < 0) { unix_exec(HIME_BIN_DIR"/hime-tsin2gtab-phrase %s %s", gtabfname, gtab_phrase_src); unix_exec(HIME_BIN_DIR"/hime-tsa2d32 %s %s", gtab_phrase_src, fname); } return TRUE; }
static void cb_ts_export() { GtkWidget *file_selector = gtk_file_chooser_dialog_new( _("Please input filename for exporting data"), GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_alternative_button_order( GTK_DIALOG(file_selector), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1); char hime_dir[512]; get_hime_dir(hime_dir); char cmd[512]; char fname[256]; char *filename=inmd[default_input_method].filename; char tt[256]; if (inmd[default_input_method].method_type==method_type_TSIN) { get_hime_user_fname(tsin32_f, fname); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (file_selector), tsin32_f); } else if (filename) { strcat(strcpy(tt, filename), ".append.gtab.tsin-db"); if (!get_hime_user_fname(tt, fname)) { strcat(strcpy(tt, filename), ".tsin-db"); if (!get_hime_user_fname(tt, fname)) p_err("cannot find %s", fname); } gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (file_selector), tt); } gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (file_selector), TRUE); if (gtk_dialog_run (GTK_DIALOG (file_selector)) == GTK_RESPONSE_ACCEPT) { gchar *selected_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_selector)); snprintf(cmd, sizeof(cmd), HIME_BIN_DIR"/hime-tsd2a32 %s -o %s", fname, selected_filename); dbg("exec %s\n", cmd); int res = system(cmd); res = 0; // some problem in system(), the exit code is not reliable create_result_win(res, cmd); } gtk_widget_destroy (file_selector); }
void get_icon_path(char *iconame, char fname[]) { char uu[128]; sprintf(uu, "icons/%s", iconame); if (!get_hime_user_fname(uu, fname)) { sys_icon_fname(iconame, fname); } }
void get_hime_user_or_sys_fname(char *name, char fname[]) { if (!getenv("HIME_TABLE_DIR")) { if (get_hime_user_fname(name, fname)) return; } get_sys_table_file_name(name, fname); }
void load_gtab_list(gboolean skip_disabled) { char ttt[128]; FILE *fp; get_hime_user_fname(gtab_list, ttt); if ((fp=fopen(ttt, "rb"))==NULL) { get_sys_table_file_name(gtab_list, ttt); if ((fp=fopen(ttt, "rb"))==NULL) p_err("cannot open %s", ttt); } dbg("load_gtab_list %s\n", ttt); skip_utf8_sigature(fp); int i; for (i=0; i < inmdN; i++) { INMD *pinmd = &inmd[i]; free(pinmd->filename); pinmd->filename=NULL; free(pinmd->cname); pinmd->cname=NULL; free(pinmd->icon); pinmd->icon=NULL; } inmdN = 0; char *def_file = strrchr(default_input_method_str, ' '); if (def_file) def_file++; while (!feof(fp)) { char line[256]; char name_ar[32], *name=name_ar; char key[32]; char file[32]; char icon[128]; inmd = trealloc(inmd, INMD, inmdN); name[0]=0; key[0]=0; file[0]=0; icon[0]=0; line[0]=0; myfgets(line, sizeof(line), fp); if (strlen(line) < 2) continue; if (line[0]=='#') continue; if (skip_disabled && line[0]=='!') continue; sscanf(line, "%s %s %s %s", name, key, file, icon); // dbg("%s %c\n", line, key[0]); if (strlen(name) < 1) break; int inmd_idx; INMD *pinmd = &inmd[inmd_idx = inmdN++]; bzero(pinmd, sizeof(INMD)); pinmd->key_ch = key[0]; pinmd->in_cycle = strchr(hime_str_im_cycle, key[0]) != NULL; // dbg("%d %d '%c'\n",inmdN, pinmd->in_cycle, pinmd->key_ch); if (!strcmp(file, "!ANTHY")) { strcpy(file, "anthy-module.so"); } if (!strcmp(file, "!INT_CODE")) { strcpy(file, "intcode-module.so"); } pinmd->filename = strdup(file); if (strstr(file, ".so") || strstr(file, ".dll")) { pinmd->method_type = method_type_MODULE; dbg("%s is module file\n", file); } else { int i; for(i=0; method_codes[i].id; i++) if (!strcmp(file, method_codes[i].id)) break; if (method_codes[i].id) pinmd->method_type = method_codes[i].method_type; } if (name[0]=='!') { name++; pinmd->disabled = TRUE; } if (default_input_method_str[0]==key[0] && !pinmd->disabled && (!def_file || !strcmp(file, def_file))) { default_input_method = inmd_idx; dbg("default_input_method %s %s %s %d\n", name, default_input_method_str, key, default_input_method); } pinmd->cname = strdup(name); if (strlen(icon)) pinmd->icon = strdup(icon); } fclose(fp); }