diff -cr putty-src-orig/CONFIG.C putty-src/CONFIG.C *** putty-src-orig/CONFIG.C Sun Feb 18 18:56:16 2007 --- putty-src/CONFIG.C Fri Apr 23 17:23:14 2010 *************** *** 11,16 **** --- 11,17 ---- #include "storage.h" #define PRINTER_DISABLED_STRING "None (printing disabled)" + #define PRINT_TO_CLIPBOARD_STRING "Windows clipboard" #define HOST_BOX_TITLE "Host Name (or IP address)" #define PORT_BOX_TITLE "Port" *************** *** 303,321 **** if (ctrl->editbox.has_list) { dlg_listbox_clear(ctrl, dlg); dlg_listbox_add(ctrl, dlg, PRINTER_DISABLED_STRING); pe = printer_start_enum(&nprinters); for (i = 0; i < nprinters; i++) dlg_listbox_add(ctrl, dlg, printer_get_name(pe, i)); printer_finish_enum(pe); } ! dlg_editbox_set(ctrl, dlg, ! (*cfg->printer ? cfg->printer : ! PRINTER_DISABLED_STRING)); ! dlg_update_done(ctrl, dlg); } else if (event == EVENT_VALCHANGE) { dlg_editbox_get(ctrl, dlg, cfg->printer, sizeof(cfg->printer)); ! if (!strcmp(cfg->printer, PRINTER_DISABLED_STRING)) *cfg->printer = '\0'; } } --- 304,333 ---- if (ctrl->editbox.has_list) { dlg_listbox_clear(ctrl, dlg); dlg_listbox_add(ctrl, dlg, PRINTER_DISABLED_STRING); + dlg_listbox_add(ctrl, dlg, PRINT_TO_CLIPBOARD_STRING); pe = printer_start_enum(&nprinters); for (i = 0; i < nprinters; i++) dlg_listbox_add(ctrl, dlg, printer_get_name(pe, i)); printer_finish_enum(pe); } ! ! if (*cfg->printer) ! dlg_editbox_set(ctrl, dlg, cfg->printer); ! else if (cfg->printclip) ! dlg_editbox_set(ctrl, dlg, PRINT_TO_CLIPBOARD_STRING); ! else ! dlg_editbox_set(ctrl, dlg, PRINTER_DISABLED_STRING); ! ! dlg_update_done(ctrl, dlg); } else if (event == EVENT_VALCHANGE) { dlg_editbox_get(ctrl, dlg, cfg->printer, sizeof(cfg->printer)); ! if (!strcmp(cfg->printer, PRINTER_DISABLED_STRING)) { *cfg->printer = '\0'; + cfg->printclip = 0; + } else if (!strcmp(cfg->printer, PRINT_TO_CLIPBOARD_STRING)) { + *cfg->printer = '\0'; + cfg->printclip = 1; + } } } diff -cr putty-src-orig/PUTTY.H putty-src/PUTTY.H *** putty-src-orig/PUTTY.H Sat Feb 10 16:12:06 2007 --- putty-src/PUTTY.H Fri Apr 23 16:19:51 2010 *************** *** 544,549 **** --- 544,550 ---- int window_border; char answerback[256]; char printer[128]; + int printclip; int arabicshaping; int bidi; /* Colour options */ diff -cr putty-src-orig/TERMINAL.C putty-src/TERMINAL.C *** putty-src-orig/TERMINAL.C Wed Jan 24 12:53:28 2007 --- putty-src/TERMINAL.C Fri Apr 23 17:39:29 2010 *************** *** 1396,1402 **** term->sco_acs = term->alt_sco_acs = 0; term->utf = 0; } ! if (!*term->cfg.printer) { term_print_finish(term); } term_schedule_tblink(term); --- 1396,1402 ---- term->sco_acs = term->alt_sco_acs = 0; term->utf = 0; } ! if (!*term->cfg.printer || term->cfg.printclip) { term_print_finish(term); } term_schedule_tblink(term); *************** *** 2444,2455 **** } /* * ANSI printing routines. */ static void term_print_setup(Terminal *term) { bufchain_clear(&term->printer_buf); ! term->print_job = printer_start_job(term->cfg.printer); } static void term_print_flush(Terminal *term) { --- 2444,2512 ---- } /* + * Windows clipboard support + * Diomidis Spinellis, June 2003 + */ + static char *clip_b, *clip_bp; /* Buffer, pointer to buffer insertion point */ + static size_t clip_bsiz, clip_remsiz; /* Buffer, size, remaining size */ + static size_t clip_total; /* Total read */ + + #define CLIP_CHUNK 16384 + + static void clipboard_init(void) + { + if (clip_b) + sfree(clip_b); + clip_bp = clip_b = smalloc(clip_remsiz = clip_bsiz = CLIP_CHUNK); + clip_total = 0; + } + + static void clipboard_data(void *buff, int len) + { + memcpy(clip_bp, buff, len); + clip_remsiz -= len; + clip_total += len; + clip_bp += len; + if (clip_remsiz < CLIP_CHUNK) { + clip_b = srealloc(clip_b, clip_bsiz *= 2); + clip_remsiz = clip_bsiz - clip_total; + clip_bp = clip_b + clip_total; + } + } + + static void clipboard_copy(void) + { + HANDLE hglb; + + if (!OpenClipboard(NULL)) + return; // error("Unable to open the clipboard"); + if (!EmptyClipboard()) { + CloseClipboard(); + return; // error("Unable to empty the clipboard"); + } + + hglb = GlobalAlloc(GMEM_DDESHARE, clip_total + 1); + if (hglb == NULL) { + CloseClipboard(); + return; // error("Unable to allocate clipboard memory"); + } + memcpy(hglb, clip_b, clip_total); + ((char *)hglb)[clip_total] = '\0'; + SetClipboardData(CF_TEXT, hglb); + CloseClipboard(); + } + + + /* * ANSI printing routines. */ static void term_print_setup(Terminal *term) { bufchain_clear(&term->printer_buf); ! if (term->cfg.printclip) ! clipboard_init(); ! else ! term->print_job = printer_start_job(term->cfg.printer); } static void term_print_flush(Terminal *term) { *************** *** 2460,2466 **** bufchain_prefix(&term->printer_buf, &data, &len); if (len > size-5) len = size-5; ! printer_job_data(term->print_job, data, len); bufchain_consume(&term->printer_buf, len); } } --- 2517,2526 ---- bufchain_prefix(&term->printer_buf, &data, &len); if (len > size-5) len = size-5; ! if (term->cfg.printclip) ! clipboard_data(data, len); ! else ! printer_job_data(term->print_job, data, len); bufchain_consume(&term->printer_buf, len); } } *************** *** 2481,2491 **** bufchain_consume(&term->printer_buf, size); break; } else { ! printer_job_data(term->print_job, &c, 1); bufchain_consume(&term->printer_buf, 1); } } ! printer_finish_job(term->print_job); term->print_job = NULL; term->printing = term->only_printing = FALSE; } --- 2541,2557 ---- bufchain_consume(&term->printer_buf, size); break; } else { ! if (term->cfg.printclip) ! clipboard_data(&c, 1); ! else ! printer_job_data(term->print_job, &c, 1); bufchain_consume(&term->printer_buf, 1); } } ! if (term->cfg.printclip) ! clipboard_copy(); ! else ! printer_finish_job(term->print_job); term->print_job = NULL; term->printing = term->only_printing = FALSE; } *************** *** 3432,3438 **** compatibility(VT100); { if (term->esc_nargs != 1) break; ! if (term->esc_args[0] == 5 && *term->cfg.printer) { term->printing = TRUE; term->only_printing = !term->esc_query; term->print_state = 0; --- 3498,3504 ---- compatibility(VT100); { if (term->esc_nargs != 1) break; ! if (term->esc_args[0] == 5 && (*term->cfg.printer || term->cfg.printclip)) { term->printing = TRUE; term->only_printing = !term->esc_query; term->print_state = 0; diff -cr putty-src-orig/WINDOWS/WINDLG.C putty-src/WINDOWS/WINDLG.C *** putty-src-orig/WINDOWS/WINDLG.C Tue Jan 16 17:48:48 2007 --- putty-src/WINDOWS/WINDLG.C Fri Apr 23 16:30:16 2010 *************** *** 47,52 **** --- 47,53 ---- extern Config cfg; /* defined in window.c */ #define PRINTER_DISABLED_STRING "None (printing disabled)" + #define PRINT_TO_CLIPBOARD_STRING "Windows clipboard" void force_normal(HWND hwnd) {