Skip to content

Commit

Permalink
FauxFauxGH-64: Eric Mason's patch, whitespace cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Jun 23, 2013
1 parent 1d2cd79 commit 1513cc4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
20 changes: 16 additions & 4 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#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"
Expand Down Expand Up @@ -385,19 +386,30 @@ static void printerbox_handler(union control *ctrl, void *dlg,
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);
}
dlg_editbox_set(ctrl, dlg,
(*cfg->printer ? cfg->printer :
PRINTER_DISABLED_STRING));

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))
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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions putty.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ struct config_tag {
int window_border;
char answerback[256];
char printer[128];
int printclip;
int arabicshaping;
int bidi;
/* Colour options */
Expand Down
80 changes: 73 additions & 7 deletions terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ void term_reconfig(Terminal *term, Config *cfg)
term->sco_acs = term->alt_sco_acs = 0;
term->utf = 0;
}
if (!*term->cfg.printer) {
if (!*term->cfg.printer || term->cfg.printclip) {
term_print_finish(term);
}
term_schedule_tblink(term);
Expand Down Expand Up @@ -2482,13 +2482,70 @@ static void do_osc(Terminal *term)
}
}

/*
* 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);
term->print_job = printer_start_job(term->cfg.printer);
if (term->cfg.printclip)
clipboard_init();
else
term->print_job = printer_start_job(term->cfg.printer);
}
static void term_print_flush(Terminal *term)
{
Expand All @@ -2499,7 +2556,10 @@ static void term_print_flush(Terminal *term)
bufchain_prefix(&term->printer_buf, &data, &len);
if (len > size-5)
len = size-5;
printer_job_data(term->print_job, data, len);
if (term->cfg.printclip)
clipboard_data(data, len);
else
printer_job_data(term->print_job, data, len);
bufchain_consume(&term->printer_buf, len);
}
}
Expand All @@ -2519,12 +2579,18 @@ static void term_print_finish(Terminal *term)
if (c == '\033' || c == '\233') {
bufchain_consume(&term->printer_buf, size);
break;
} else {
printer_job_data(term->print_job, &c, 1);
} else {
if (term->cfg.printclip)
clipboard_data(&c, 1);
else
printer_job_data(term->print_job, &c, 1);
bufchain_consume(&term->printer_buf, 1);
}
}
printer_finish_job(term->print_job);
if (term->cfg.printclip)
clipboard_copy();
else
printer_finish_job(term->print_job);
term->print_job = NULL;
term->printing = term->only_printing = FALSE;
}
Expand Down Expand Up @@ -3478,7 +3544,7 @@ static void term_out(Terminal *term)
compatibility(VT100);
{
if (term->esc_nargs != 1) break;
if (term->esc_args[0] == 5 && *term->cfg.printer) {
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;
Expand Down
1 change: 1 addition & 0 deletions windows/windlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static int nevents = 0, negsize = 0;
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)
{
Expand Down

0 comments on commit 1513cc4

Please sign in to comment.