static void selection_received(GtkClipboard *pclip, const char *text, gpointer data) { if (!text) { dbg("empty\n"); return; } char *out; if (b_trad2sim) trad2sim((char *)text, strlen(text), &out); else sim2trad((char *)text, strlen(text), &out); gtk_text_buffer_set_text (buffer, out, -1); free(out); all_wrap(); }
void set_output_buffer_bak_to_clipboard() { char *text, *utf8_gbtext=NULL; if (gb_output) { trad2sim(output_buffer_raw_bak, strlen(output_buffer_raw_bak), &utf8_gbtext); text = utf8_gbtext; } else text = output_buffer_raw_bak; #if UNIX && 0 GtkClipboard *pclipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); #else GtkClipboard *pclipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); #endif gtk_clipboard_set_text(pclipboard, text, -1); free(utf8_gbtext); }
void send_text(char *text) { #if WIN32 if (test_mode) return; #endif char *filter; if (!text) return; int len = strlen(text); add_ch_time_str(text); append_str(&output_buffer_raw, &output_buffer_rawN, text, len); char *utf8_gbtext = NULL; if (gb_output) { len = trad2sim(text, len, &utf8_gbtext); text = utf8_gbtext; } //direct: #if UNIX filter = getenv("HIME_OUTPUT_FILTER"); char filter_text[512]; if (filter) { int pfdr[2], pfdw[2]; if (pipe(pfdr) == -1) { dbg("cannot pipe r\n"); goto next; } if (pipe(pfdw) == -1) { dbg("cannot pipe w\n"); goto next; } int pid = fork(); if (pid < 0) { dbg("cannot fork filter\n"); goto next; } if (pid) { close(pfdw[0]); close(pfdr[1]); write(pfdw[1], text, len); close(pfdw[1]); int rn = read(pfdr[0], filter_text, sizeof(filter_text) - 1); filter_text[rn] = 0; // puts(filter_text); close(pfdr[0]); text = filter_text; len = rn; } else { close(pfdr[0]); close(pfdw[1]); dup2(pfdw[0], 0); dup2(pfdr[1], 1); if (execl(filter, filter, NULL) < 0) { dbg("execl %s err", filter); goto next; } } } #endif next: if (len) { append_str(&output_buffer, &output_bufferN, text, len); } free(utf8_gbtext); }