2017-07-15 13:20:51 -06:00
|
|
|
/* $XTermId: print.c,v 1.161 2017/06/19 08:11:13 tom Exp $ */
|
2011-09-17 05:51:57 -06:00
|
|
|
|
|
|
|
/*
|
2017-07-15 13:20:51 -06:00
|
|
|
* Copyright 1997-2016,2017 by Thomas E. Dickey
|
2011-09-17 05:51:57 -06:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the
|
|
|
|
* sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization.
|
|
|
|
*/
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
#include <xterm.h>
|
|
|
|
#include <data.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <error.h>
|
2010-03-25 16:03:51 -06:00
|
|
|
#include <xstrings.h>
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2011-08-18 13:47:42 -06:00
|
|
|
#include <sys/stat.h>
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
#undef CTRL
|
|
|
|
#define CTRL(c) ((c) & 0x1f)
|
|
|
|
|
|
|
|
#define SHIFT_IN '\017'
|
|
|
|
#define SHIFT_OUT '\016'
|
|
|
|
|
|
|
|
#define CSET_IN 'A'
|
|
|
|
#define CSET_OUT '0'
|
|
|
|
|
|
|
|
#define isForm(c) ((c) == '\r' || (c) == '\n' || (c) == '\f')
|
2011-08-18 13:47:42 -06:00
|
|
|
#define Strlen(a) strlen((const char *)a)
|
|
|
|
#define Strcmp(a,b) strcmp((const char *)a,(const char *)b)
|
|
|
|
#define Strncmp(a,b,c) strncmp((const char *)a,(const char *)b,c)
|
|
|
|
|
|
|
|
#define SPS PrinterOf(screen)
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
#ifdef VMS
|
|
|
|
#define VMS_TEMP_PRINT_FILE "sys$scratch:xterm_print.txt"
|
|
|
|
#endif
|
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
static void charToPrinter(XtermWidget /* xw */ ,
|
|
|
|
unsigned /* chr */ );
|
|
|
|
static void printLine(XtermWidget /* xw */ ,
|
|
|
|
int /* row */ ,
|
2010-03-25 16:03:51 -06:00
|
|
|
unsigned /* chr */ ,
|
|
|
|
PrinterFlags * /* p */ );
|
2009-09-05 09:58:09 -06:00
|
|
|
static void send_CharSet(XtermWidget /* xw */ ,
|
|
|
|
LineData * /* ld */ );
|
|
|
|
static void send_SGR(XtermWidget /* xw */ ,
|
|
|
|
unsigned /* attr */ ,
|
|
|
|
unsigned /* fg */ ,
|
|
|
|
unsigned /* bg */ );
|
|
|
|
static void stringToPrinter(XtermWidget /* xw */ ,
|
2009-10-31 08:11:57 -06:00
|
|
|
const char * /*str */ );
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2013-01-04 09:40:18 -07:00
|
|
|
static void
|
2009-09-05 09:58:09 -06:00
|
|
|
closePrinter(XtermWidget xw GCC_UNUSED)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
if (xtermHasPrinter(xw) != 0) {
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
2011-08-18 13:47:42 -06:00
|
|
|
#ifdef VMS
|
2006-11-26 04:11:12 -07:00
|
|
|
char pcommand[256];
|
|
|
|
(void) sprintf(pcommand, "%s %s;",
|
2011-08-18 13:47:42 -06:00
|
|
|
SPS.printer_command,
|
2006-11-26 04:11:12 -07:00
|
|
|
VMS_TEMP_PRINT_FILE);
|
|
|
|
#endif
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (SPS.fp != 0) {
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("closePrinter\n");
|
2013-01-04 09:40:18 -07:00
|
|
|
pclose(SPS.fp);
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("closed printer, waiting...\n"));
|
|
|
|
#ifdef VMS /* This is a quick hack, really should use
|
|
|
|
spawn and check status or system services
|
|
|
|
and go straight to the queue */
|
|
|
|
(void) system(pcommand);
|
|
|
|
#else /* VMS */
|
2013-06-02 13:55:50 -06:00
|
|
|
while (nonblocking_wait() > 0) {
|
|
|
|
;
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif /* VMS */
|
2011-08-18 13:47:42 -06:00
|
|
|
SPS.fp = 0;
|
|
|
|
SPS.isOpen = False;
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("closed printer\n"));
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("...closePrinter (done)\n");
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-05 09:58:09 -06:00
|
|
|
printCursorLine(XtermWidget xw)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
TRACE(("printCursorLine\n"));
|
2010-03-25 16:03:51 -06:00
|
|
|
printLine(xw, screen->cur_row, '\n', getPrinterFlags(xw, NULL, 0));
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NO_COLOR ((unsigned)-1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEC's manual doesn't document whether trailing blanks are removed, or what
|
|
|
|
* happens with a line that is entirely blank. This function prints the
|
|
|
|
* characters that xterm would allow as a selection (which may include blanks).
|
|
|
|
*/
|
|
|
|
static void
|
2014-07-14 02:30:10 -06:00
|
|
|
printLine(XtermWidget xw, int row, unsigned chr, PrinterFlags *p)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
int inx = ROW2INX(screen, row);
|
2009-09-05 09:58:09 -06:00
|
|
|
LineData *ld;
|
2006-11-26 04:11:12 -07:00
|
|
|
int last = MaxCols(screen);
|
|
|
|
#if OPT_ISO_COLORS && OPT_PRINT_COLORS
|
2009-09-05 09:58:09 -06:00
|
|
|
#define ColorOf(ld,col) (ld->color[col])
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif
|
2017-07-15 13:20:51 -06:00
|
|
|
unsigned fg = NO_COLOR;
|
|
|
|
unsigned bg = NO_COLOR;
|
|
|
|
#if OPT_PRINT_COLORS
|
|
|
|
unsigned last_fg = NO_COLOR;
|
|
|
|
unsigned last_bg = NO_COLOR;
|
|
|
|
#endif
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
ld = getLineData(screen, inx);
|
2010-03-25 16:03:51 -06:00
|
|
|
if (ld == 0)
|
|
|
|
return;
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("printLine(row=%d/%d, top=%d:%d, chr=%d):%s\n",
|
|
|
|
row, ROW2INX(screen, row), screen->topline, screen->max_row, chr,
|
2009-09-05 09:58:09 -06:00
|
|
|
visibleIChars(ld->charData, (unsigned) last)));
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
while (last > 0) {
|
2009-09-05 09:58:09 -06:00
|
|
|
if ((ld->attribs[last - 1] & CHARDRAWN) == 0)
|
2006-11-26 04:11:12 -07:00
|
|
|
last--;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2016-08-07 15:27:36 -06:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
if (last) {
|
2016-08-07 15:27:36 -06:00
|
|
|
int col;
|
|
|
|
int cs = CSET_IN;
|
|
|
|
int last_cs = CSET_IN;
|
|
|
|
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->print_attributes) {
|
2009-09-05 09:58:09 -06:00
|
|
|
send_CharSet(xw, ld);
|
|
|
|
send_SGR(xw, 0, NO_COLOR, NO_COLOR);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
for (col = 0; col < last; col++) {
|
2016-08-07 15:27:36 -06:00
|
|
|
IAttr attr = 0;
|
|
|
|
unsigned ch = ld->charData[col];
|
2006-11-26 04:11:12 -07:00
|
|
|
#if OPT_PRINT_COLORS
|
|
|
|
if (screen->colorMode) {
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->print_attributes > 1) {
|
2009-09-05 09:58:09 -06:00
|
|
|
fg = (ld->attribs[col] & FG_COLOR)
|
|
|
|
? extract_fg(xw, ColorOf(ld, col), ld->attribs[col])
|
2006-11-26 04:11:12 -07:00
|
|
|
: NO_COLOR;
|
2009-09-05 09:58:09 -06:00
|
|
|
bg = (ld->attribs[col] & BG_COLOR)
|
|
|
|
? extract_bg(xw, ColorOf(ld, col), ld->attribs[col])
|
2006-11-26 04:11:12 -07:00
|
|
|
: NO_COLOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-05 09:58:09 -06:00
|
|
|
if ((((ld->attribs[col] & SGR_MASK) != attr)
|
2006-11-26 04:11:12 -07:00
|
|
|
#if OPT_PRINT_COLORS
|
|
|
|
|| (last_fg != fg) || (last_bg != bg)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
&& ch) {
|
2014-07-14 02:30:10 -06:00
|
|
|
attr = ld->attribs[col] & SGR_MASK;
|
2010-08-22 07:38:11 -06:00
|
|
|
#if OPT_PRINT_COLORS
|
2006-11-26 04:11:12 -07:00
|
|
|
last_fg = fg;
|
|
|
|
last_bg = bg;
|
2010-08-22 07:38:11 -06:00
|
|
|
#endif
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->print_attributes)
|
2009-09-05 09:58:09 -06:00
|
|
|
send_SGR(xw, attr, fg, bg);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == 0)
|
|
|
|
ch = ' ';
|
|
|
|
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
if (screen->utf8_mode)
|
|
|
|
cs = CSET_IN;
|
|
|
|
else
|
|
|
|
#endif
|
2007-06-15 13:29:55 -06:00
|
|
|
cs = (ch >= ' ' && ch != ANSI_DEL) ? CSET_IN : CSET_OUT;
|
2006-11-26 04:11:12 -07:00
|
|
|
if (last_cs != cs) {
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->print_attributes) {
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw,
|
|
|
|
(unsigned) ((cs == CSET_OUT)
|
2006-11-26 04:11:12 -07:00
|
|
|
? SHIFT_OUT
|
|
|
|
: SHIFT_IN));
|
|
|
|
}
|
|
|
|
last_cs = cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: we shouldn't have to map back from the
|
|
|
|
* alternate character set, except that the
|
|
|
|
* corresponding charset information is not encoded
|
|
|
|
* into the CSETS array.
|
|
|
|
*/
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw,
|
|
|
|
((cs == CSET_OUT)
|
2007-06-15 13:29:55 -06:00
|
|
|
? (ch == ANSI_DEL ? 0x5f : (ch + 0x5f))
|
2006-11-26 04:11:12 -07:00
|
|
|
: ch));
|
|
|
|
if_OPT_WIDE_CHARS(screen, {
|
2009-09-05 09:58:09 -06:00
|
|
|
size_t off;
|
|
|
|
for_each_combData(off, ld) {
|
2009-09-18 18:03:36 -06:00
|
|
|
ch = ld->combData[off][col];
|
2009-09-05 09:58:09 -06:00
|
|
|
if (ch == 0)
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, ch);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->print_attributes) {
|
2009-09-05 09:58:09 -06:00
|
|
|
send_SGR(xw, 0, NO_COLOR, NO_COLOR);
|
2006-11-26 04:11:12 -07:00
|
|
|
if (cs != CSET_IN)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, SHIFT_IN);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
2010-03-25 16:03:51 -06:00
|
|
|
|
|
|
|
/* finish line (protocol for attributes needs a CR */
|
|
|
|
if (p->print_attributes)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, '\r');
|
2010-03-25 16:03:51 -06:00
|
|
|
|
|
|
|
if (chr && !(p->printer_newline)) {
|
|
|
|
if (LineTstWrapped(ld))
|
|
|
|
chr = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chr)
|
|
|
|
charToPrinter(xw, chr);
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
return;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 16:03:51 -06:00
|
|
|
#define PrintNewLine() (unsigned) (((top < bot) || p->printer_newline) ? '\n' : '\0')
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
static void
|
2014-07-14 02:30:10 -06:00
|
|
|
printLines(XtermWidget xw, int top, int bot, PrinterFlags *p)
|
2011-08-18 13:47:42 -06:00
|
|
|
{
|
|
|
|
TRACE(("printLines, rows %d..%d\n", top, bot));
|
|
|
|
while (top <= bot) {
|
|
|
|
printLine(xw, top, PrintNewLine(), p);
|
|
|
|
++top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
void
|
2014-07-14 02:30:10 -06:00
|
|
|
xtermPrintScreen(XtermWidget xw, Bool use_DECPEX, PrinterFlags *p)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
if (XtIsRealized((Widget) xw)) {
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
2010-03-25 16:03:51 -06:00
|
|
|
Bool extent = (use_DECPEX && p->printer_extent);
|
2011-08-18 13:47:42 -06:00
|
|
|
Boolean was_open = SPS.isOpen;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
printLines(xw,
|
|
|
|
extent ? 0 : screen->top_marg,
|
|
|
|
extent ? screen->max_row : screen->bot_marg,
|
|
|
|
p);
|
2010-03-25 16:03:51 -06:00
|
|
|
if (p->printer_formfeed)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, '\f');
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (!was_open || SPS.printer_autoclose) {
|
2009-09-05 09:58:09 -06:00
|
|
|
closePrinter(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-08-22 07:38:11 -06:00
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-08-18 13:47:42 -06:00
|
|
|
* If p->print_everything is zero, use this behavior:
|
2006-11-26 04:11:12 -07:00
|
|
|
* If the alternate screen is active, we'll print only that. Otherwise, print
|
|
|
|
* the normal screen plus all scrolled-back lines. The distinction is made
|
|
|
|
* because the normal screen's buffer is part of the overall scrollback buffer.
|
2011-08-18 13:47:42 -06:00
|
|
|
*
|
|
|
|
* Otherwise, decode bits:
|
|
|
|
* 1 = current screen
|
|
|
|
* 2 = normal screen
|
|
|
|
* 4 = alternate screen
|
|
|
|
* 8 = saved lines
|
2006-11-26 04:11:12 -07:00
|
|
|
*/
|
2009-09-05 09:58:09 -06:00
|
|
|
void
|
2014-07-14 02:30:10 -06:00
|
|
|
xtermPrintEverything(XtermWidget xw, PrinterFlags *p)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2011-08-18 13:47:42 -06:00
|
|
|
Boolean was_open = SPS.isOpen;
|
|
|
|
int save_which = screen->whichBuf;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("xtermPrintEverything\n");
|
2016-08-07 15:27:36 -06:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (p->print_everything) {
|
2016-08-07 15:27:36 -06:00
|
|
|
int done_which = 0;
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (p->print_everything & 8) {
|
|
|
|
printLines(xw, -screen->savedlines, -(screen->topline + 1), p);
|
|
|
|
}
|
|
|
|
if (p->print_everything & 4) {
|
|
|
|
screen->whichBuf = 1;
|
|
|
|
done_which |= 2;
|
|
|
|
printLines(xw, 0, screen->max_row, p);
|
|
|
|
screen->whichBuf = save_which;
|
|
|
|
}
|
|
|
|
if (p->print_everything & 2) {
|
|
|
|
screen->whichBuf = 0;
|
|
|
|
done_which |= 1;
|
|
|
|
printLines(xw, 0, screen->max_row, p);
|
|
|
|
screen->whichBuf = save_which;
|
|
|
|
}
|
|
|
|
if (p->print_everything & 1) {
|
|
|
|
if (!(done_which & (1 << screen->whichBuf))) {
|
|
|
|
printLines(xw, 0, screen->max_row, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int top = 0;
|
|
|
|
int bot = screen->max_row;
|
|
|
|
if (!screen->whichBuf) {
|
|
|
|
top = -screen->savedlines - screen->topline;
|
|
|
|
bot -= screen->topline;
|
|
|
|
}
|
|
|
|
printLines(xw, top, bot, p);
|
2010-03-25 16:03:51 -06:00
|
|
|
}
|
|
|
|
if (p->printer_formfeed)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, '\f');
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (!was_open || SPS.printer_autoclose) {
|
2009-09-05 09:58:09 -06:00
|
|
|
closePrinter(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-07-14 02:30:10 -06:00
|
|
|
send_CharSet(XtermWidget xw, LineData *ld)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
#if OPT_DEC_CHRSET
|
2009-10-31 08:11:57 -06:00
|
|
|
const char *msg = 0;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
switch (GetLineDblCS(ld)) {
|
2006-11-26 04:11:12 -07:00
|
|
|
case CSET_SWL:
|
|
|
|
msg = "\033#5";
|
|
|
|
break;
|
|
|
|
case CSET_DHL_TOP:
|
|
|
|
msg = "\033#3";
|
|
|
|
break;
|
|
|
|
case CSET_DHL_BOT:
|
|
|
|
msg = "\033#4";
|
|
|
|
break;
|
|
|
|
case CSET_DWL:
|
|
|
|
msg = "\033#6";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (msg != 0)
|
2009-09-05 09:58:09 -06:00
|
|
|
stringToPrinter(xw, msg);
|
2006-11-26 04:11:12 -07:00
|
|
|
#else
|
2009-09-05 09:58:09 -06:00
|
|
|
(void) xw;
|
|
|
|
(void) ld;
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif /* OPT_DEC_CHRSET */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-05 09:58:09 -06:00
|
|
|
send_SGR(XtermWidget xw, unsigned attr, unsigned fg, unsigned bg)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
char msg[80];
|
2011-08-18 13:47:42 -06:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
strcpy(msg, "\033[0");
|
|
|
|
if (attr & BOLD)
|
|
|
|
strcat(msg, ";1");
|
2014-07-14 02:30:10 -06:00
|
|
|
#if OPT_WIDE_ATTRS
|
|
|
|
if (attr & ATR_FAINT)
|
|
|
|
strcat(msg, ";2");
|
|
|
|
if (attr & ATR_ITALIC)
|
|
|
|
strcat(msg, ";3");
|
|
|
|
#endif
|
2006-11-26 04:11:12 -07:00
|
|
|
if (attr & UNDERLINE)
|
|
|
|
strcat(msg, ";4"); /* typo? DEC documents this as '2' */
|
|
|
|
if (attr & BLINK)
|
|
|
|
strcat(msg, ";5");
|
|
|
|
if (attr & INVERSE) /* typo? DEC documents this as invisible */
|
|
|
|
strcat(msg, ";7");
|
|
|
|
#if OPT_PRINT_COLORS
|
|
|
|
if (bg != NO_COLOR) {
|
|
|
|
sprintf(msg + strlen(msg), ";%u", (bg < 8) ? (40 + bg) : (92 + bg));
|
|
|
|
}
|
|
|
|
if (fg != NO_COLOR) {
|
|
|
|
#if OPT_PC_COLORS
|
2010-03-25 16:03:51 -06:00
|
|
|
if (TScreenOf(xw)->boldColors
|
2006-11-26 04:11:12 -07:00
|
|
|
&& fg > 8
|
|
|
|
&& (attr & BOLD) != 0)
|
|
|
|
fg -= 8;
|
|
|
|
#endif
|
|
|
|
sprintf(msg + strlen(msg), ";%u", (fg < 8) ? (30 + fg) : (82 + fg));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void) bg;
|
|
|
|
(void) fg;
|
|
|
|
#endif
|
|
|
|
strcat(msg, "m");
|
2009-09-05 09:58:09 -06:00
|
|
|
stringToPrinter(xw, msg);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This implementation only knows how to write to a pipe.
|
|
|
|
*/
|
|
|
|
static void
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(XtermWidget xw, unsigned chr)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (!SPS.isOpen && xtermHasPrinter(xw)) {
|
|
|
|
switch (SPS.toFile) {
|
2011-06-07 13:21:06 -06:00
|
|
|
/*
|
|
|
|
* write to a pipe.
|
|
|
|
*/
|
|
|
|
case False:
|
|
|
|
#ifdef VMS
|
|
|
|
/*
|
|
|
|
* This implementation only knows how to write to a file. When the
|
|
|
|
* file is closed the print command executes. Print command must
|
|
|
|
* be of the form:
|
|
|
|
* print/que=name/delete [/otherflags].
|
|
|
|
*/
|
2011-08-18 13:47:42 -06:00
|
|
|
SPS.fp = fopen(VMS_TEMP_PRINT_FILE, "w");
|
2006-11-26 04:11:12 -07:00
|
|
|
#else
|
2011-06-07 13:21:06 -06:00
|
|
|
{
|
|
|
|
int my_pipe[2];
|
2011-08-18 13:47:42 -06:00
|
|
|
pid_t my_pid;
|
2011-06-07 13:21:06 -06:00
|
|
|
|
|
|
|
if (pipe(my_pipe))
|
|
|
|
SysError(ERROR_FORK);
|
2011-08-18 13:47:42 -06:00
|
|
|
if ((my_pid = fork()) < 0)
|
2011-06-07 13:21:06 -06:00
|
|
|
SysError(ERROR_FORK);
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (my_pid == 0) {
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("charToPrinter: subprocess for printer\n");
|
2011-06-07 13:21:06 -06:00
|
|
|
TRACE_CLOSE();
|
|
|
|
close(my_pipe[1]); /* printer is silent */
|
|
|
|
close(screen->respond);
|
|
|
|
|
|
|
|
close(fileno(stdout));
|
|
|
|
dup2(fileno(stderr), 1);
|
|
|
|
|
|
|
|
if (fileno(stderr) != 2) {
|
|
|
|
dup2(fileno(stderr), 2);
|
|
|
|
close(fileno(stderr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't want privileges! */
|
|
|
|
if (xtermResetIds(screen) < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
SPS.fp = popen(SPS.printer_command, "w");
|
2013-01-04 09:40:18 -07:00
|
|
|
if (SPS.fp != 0) {
|
2016-08-07 15:27:36 -06:00
|
|
|
FILE *input;
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("charToPrinter: opened pipe to printer\n");
|
2017-07-15 13:20:51 -06:00
|
|
|
if ((input = fdopen(my_pipe[0], "r")) != 0) {
|
|
|
|
clearerr(input);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (ferror(input)) {
|
|
|
|
DEBUG_MSG("charToPrinter: break on ferror\n");
|
|
|
|
break;
|
|
|
|
} else if (feof(input)) {
|
|
|
|
DEBUG_MSG("charToPrinter: break on feof\n");
|
|
|
|
break;
|
|
|
|
} else if ((c = fgetc(input)) == EOF) {
|
|
|
|
DEBUG_MSG("charToPrinter: break on EOF\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fputc(c, SPS.fp);
|
|
|
|
if (isForm(c))
|
|
|
|
fflush(SPS.fp);
|
2013-06-02 13:55:50 -06:00
|
|
|
}
|
2013-01-04 09:40:18 -07:00
|
|
|
}
|
2013-06-02 13:55:50 -06:00
|
|
|
DEBUG_MSG("charToPrinter: calling pclose\n");
|
2013-01-04 09:40:18 -07:00
|
|
|
pclose(SPS.fp);
|
2017-07-15 13:20:51 -06:00
|
|
|
if (input)
|
|
|
|
fclose(input);
|
2011-06-07 13:21:06 -06:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
close(my_pipe[0]); /* won't read from printer */
|
2013-06-02 13:55:50 -06:00
|
|
|
if ((SPS.fp = fdopen(my_pipe[1], "w")) != 0) {
|
|
|
|
DEBUG_MSG("charToPrinter: opened printer in parent\n");
|
|
|
|
TRACE(("opened printer from pid %d/%d\n",
|
|
|
|
(int) getpid(), (int) my_pid));
|
|
|
|
} else {
|
|
|
|
TRACE(("failed to open printer:%s\n", strerror(errno)));
|
|
|
|
DEBUG_MSG("charToPrinter: could not open in parent\n");
|
|
|
|
}
|
2011-06-07 13:21:06 -06:00
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
#endif
|
2011-06-07 13:21:06 -06:00
|
|
|
break;
|
|
|
|
case True:
|
2011-08-18 13:47:42 -06:00
|
|
|
TRACE(("opening \"%s\" as printer output\n", SPS.printer_command));
|
|
|
|
SPS.fp = fopen(SPS.printer_command, "w");
|
2011-06-07 13:21:06 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-08-18 13:47:42 -06:00
|
|
|
SPS.isOpen = True;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
2011-08-18 13:47:42 -06:00
|
|
|
if (SPS.fp != 0) {
|
2006-11-26 04:11:12 -07:00
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
if (chr > 127) {
|
|
|
|
Char temp[10];
|
|
|
|
*convertToUTF8(temp, chr) = 0;
|
2011-08-18 13:47:42 -06:00
|
|
|
fputs((char *) temp, SPS.fp);
|
2006-11-26 04:11:12 -07:00
|
|
|
} else
|
|
|
|
#endif
|
2011-08-18 13:47:42 -06:00
|
|
|
fputc((int) chr, SPS.fp);
|
2006-11-26 04:11:12 -07:00
|
|
|
if (isForm(chr))
|
2011-08-18 13:47:42 -06:00
|
|
|
fflush(SPS.fp);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-31 08:11:57 -06:00
|
|
|
stringToPrinter(XtermWidget xw, const char *str)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
while (*str)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, CharOf(*str++));
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This module implements the MC (Media Copy) and related printing control
|
|
|
|
* sequences for VTxxx emulation. This is based on the description in the
|
|
|
|
* VT330/VT340 Programmer Reference Manual EK-VT3XX-TP-001 (Digital Equipment
|
|
|
|
* Corp., March 1987).
|
|
|
|
*/
|
|
|
|
void
|
2009-09-05 09:58:09 -06:00
|
|
|
xtermMediaControl(XtermWidget xw, int param, int private_seq)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
TRACE(("MediaCopy param=%d, private=%d\n", param, private_seq));
|
|
|
|
|
|
|
|
if (private_seq) {
|
|
|
|
switch (param) {
|
|
|
|
case 1:
|
2009-09-05 09:58:09 -06:00
|
|
|
printCursorLine(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 4:
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(xw, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 5:
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(xw, 1);
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 10: /* VT320 */
|
2010-03-25 16:03:51 -06:00
|
|
|
xtermPrintScreen(xw, False, getPrinterFlags(xw, NULL, 0));
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 11: /* VT320 */
|
2010-03-25 16:03:51 -06:00
|
|
|
xtermPrintEverything(xw, getPrinterFlags(xw, NULL, 0));
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (param) {
|
|
|
|
case -1:
|
|
|
|
case 0:
|
2010-03-25 16:03:51 -06:00
|
|
|
xtermPrintScreen(xw, True, getPrinterFlags(xw, NULL, 0));
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 4:
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(xw, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
|
|
|
case 5:
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(xw, 2);
|
2006-11-26 04:11:12 -07:00
|
|
|
break;
|
2016-08-07 15:27:36 -06:00
|
|
|
#if OPT_SCREEN_DUMPS
|
|
|
|
case 10:
|
|
|
|
xtermDumpHtml(xw);
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
xtermDumpSvg(xw);
|
|
|
|
break;
|
|
|
|
#endif
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When in autoprint mode, the printer prints a line from the screen when you
|
|
|
|
* move the cursor off that line with an LF, FF, or VT character, or an
|
|
|
|
* autowrap occurs. The printed line ends with a CR and the character (LF, FF
|
|
|
|
* or VT) that moved the cursor off the previous line.
|
|
|
|
*/
|
|
|
|
void
|
2009-09-05 09:58:09 -06:00
|
|
|
xtermAutoPrint(XtermWidget xw, unsigned chr)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
if (SPS.printer_controlmode == 1) {
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("AutoPrint %d\n", chr));
|
2010-03-25 16:03:51 -06:00
|
|
|
printLine(xw, screen->cursorp.row, chr, getPrinterFlags(xw, NULL, 0));
|
2011-08-18 13:47:42 -06:00
|
|
|
if (SPS.fp != 0)
|
|
|
|
fflush(SPS.fp);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When in printer controller mode, the terminal sends received characters to
|
|
|
|
* the printer without displaying them on the screen. The terminal sends all
|
|
|
|
* characters and control sequences to the printer, except NUL, XON, XOFF, and
|
|
|
|
* the printer controller sequences.
|
|
|
|
*
|
|
|
|
* This function eats characters, returning 0 as long as it must buffer or
|
|
|
|
* divert to the printer. We're only invoked here when in printer controller
|
|
|
|
* mode, and handle the exit from that mode.
|
|
|
|
*/
|
|
|
|
#define LB '['
|
|
|
|
|
|
|
|
int
|
2009-09-05 09:58:09 -06:00
|
|
|
xtermPrinterControl(XtermWidget xw, int chr)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
/* *INDENT-OFF* */
|
2011-08-18 13:47:42 -06:00
|
|
|
static const struct {
|
|
|
|
const Char seq[5];
|
2006-11-26 04:11:12 -07:00
|
|
|
int active;
|
|
|
|
} tbl[] = {
|
2007-06-15 13:29:55 -06:00
|
|
|
{ { ANSI_CSI, '5', 'i' }, 2 },
|
|
|
|
{ { ANSI_CSI, '4', 'i' }, 0 },
|
|
|
|
{ { ANSI_ESC, LB, '5', 'i' }, 2 },
|
|
|
|
{ { ANSI_ESC, LB, '4', 'i' }, 0 },
|
2006-11-26 04:11:12 -07:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
static Char bfr[10];
|
|
|
|
static size_t length;
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
TRACE(("In printer:%04X\n", chr));
|
|
|
|
|
|
|
|
switch (chr) {
|
|
|
|
case 0:
|
|
|
|
case CTRL('Q'):
|
|
|
|
case CTRL('S'):
|
|
|
|
return 0; /* ignored by application */
|
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
case ANSI_CSI:
|
|
|
|
case ANSI_ESC:
|
2006-11-26 04:11:12 -07:00
|
|
|
case '[':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case 'i':
|
2009-01-10 11:08:42 -07:00
|
|
|
bfr[length++] = CharOf(chr);
|
2006-11-26 04:11:12 -07:00
|
|
|
for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); n++) {
|
|
|
|
size_t len = Strlen(tbl[n].seq);
|
|
|
|
|
|
|
|
if (length == len
|
|
|
|
&& Strcmp(bfr, tbl[n].seq) == 0) {
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(xw, tbl[n].active);
|
2011-08-18 13:47:42 -06:00
|
|
|
if (SPS.printer_autoclose
|
|
|
|
&& SPS.printer_controlmode == 0)
|
2009-09-05 09:58:09 -06:00
|
|
|
closePrinter(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
length = 0;
|
|
|
|
return 0;
|
|
|
|
} else if (len > length
|
|
|
|
&& Strncmp(bfr, tbl[n].seq, length) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length--;
|
|
|
|
|
|
|
|
/* FALLTHRU */
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (n = 0; n < length; n++)
|
2009-09-05 09:58:09 -06:00
|
|
|
charToPrinter(xw, bfr[n]);
|
2009-01-10 11:08:42 -07:00
|
|
|
bfr[0] = CharOf(chr);
|
2006-11-26 04:11:12 -07:00
|
|
|
length = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is no printer command, we will ignore printer controls.
|
2013-01-04 09:40:18 -07:00
|
|
|
*
|
|
|
|
* If we do have a printer command, we still have to verify that it will
|
|
|
|
* (perhaps) work if we pass it to popen(). At a minimum, the program
|
|
|
|
* must exist and be executable. If not, warn and disable the feature.
|
2006-11-26 04:11:12 -07:00
|
|
|
*/
|
|
|
|
Bool
|
2009-09-05 09:58:09 -06:00
|
|
|
xtermHasPrinter(XtermWidget xw)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-09-05 09:58:09 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2013-01-04 09:40:18 -07:00
|
|
|
Bool result = SPS.printer_checked;
|
|
|
|
|
|
|
|
if (strlen(SPS.printer_command) != 0 && !result) {
|
|
|
|
char **argv = x_splitargs(SPS.printer_command);
|
2013-03-09 07:45:38 -07:00
|
|
|
if (argv) {
|
|
|
|
if (argv[0]) {
|
|
|
|
char *myShell = xtermFindShell(argv[0], False);
|
|
|
|
if (myShell == 0) {
|
|
|
|
xtermWarning("No program found for printerCommand: %s\n", SPS.printer_command);
|
|
|
|
SPS.printer_command = x_strdup("");
|
|
|
|
} else {
|
|
|
|
free(myShell);
|
|
|
|
SPS.printer_checked = True;
|
|
|
|
result = True;
|
|
|
|
}
|
2013-01-04 09:40:18 -07:00
|
|
|
}
|
2013-03-09 07:45:38 -07:00
|
|
|
x_freeargs(argv);
|
2013-01-04 09:40:18 -07:00
|
|
|
}
|
|
|
|
TRACE(("xtermHasPrinter:%d\n", result));
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2013-01-04 09:40:18 -07:00
|
|
|
return result;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define showPrinterControlMode(mode) \
|
|
|
|
(((mode) == 0) \
|
|
|
|
? "normal" \
|
|
|
|
: ((mode) == 1 \
|
|
|
|
? "autoprint" \
|
|
|
|
: "printer controller"))
|
|
|
|
|
|
|
|
void
|
2009-09-05 09:58:09 -06:00
|
|
|
setPrinterControlMode(XtermWidget xw, int mode)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
if (xtermHasPrinter(xw)
|
2011-08-18 13:47:42 -06:00
|
|
|
&& SPS.printer_controlmode != mode) {
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("%s %s mode\n",
|
|
|
|
(mode
|
|
|
|
? "set"
|
|
|
|
: "reset"),
|
|
|
|
(mode
|
|
|
|
? showPrinterControlMode(mode)
|
2011-08-18 13:47:42 -06:00
|
|
|
: showPrinterControlMode(SPS.printer_controlmode))));
|
|
|
|
SPS.printer_controlmode = mode;
|
2006-11-26 04:11:12 -07:00
|
|
|
update_print_redir();
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 16:03:51 -06:00
|
|
|
|
|
|
|
PrinterFlags *
|
2014-07-14 02:30:10 -06:00
|
|
|
getPrinterFlags(XtermWidget xw, String *params, Cardinal *param_count)
|
2010-03-25 16:03:51 -06:00
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const struct {
|
|
|
|
const char *name;
|
|
|
|
unsigned offset;
|
|
|
|
int value;
|
|
|
|
} table[] = {
|
|
|
|
{ "noFormFeed", XtOffsetOf(PrinterFlags, printer_formfeed), 0 },
|
|
|
|
{ "FormFeed", XtOffsetOf(PrinterFlags, printer_formfeed), 1 },
|
|
|
|
{ "noNewLine", XtOffsetOf(PrinterFlags, printer_newline), 0 },
|
|
|
|
{ "NewLine", XtOffsetOf(PrinterFlags, printer_newline), 1 },
|
|
|
|
{ "noAttrs", XtOffsetOf(PrinterFlags, print_attributes), 0 },
|
|
|
|
{ "monoAttrs", XtOffsetOf(PrinterFlags, print_attributes), 1 },
|
|
|
|
{ "colorAttrs", XtOffsetOf(PrinterFlags, print_attributes), 2 },
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
PrinterFlags *result = &(screen->printer_flags);
|
|
|
|
|
|
|
|
TRACE(("getPrinterFlags %d params\n", param_count ? *param_count : 0));
|
|
|
|
|
2011-08-18 13:47:42 -06:00
|
|
|
result->printer_extent = SPS.printer_extent;
|
|
|
|
result->printer_formfeed = SPS.printer_formfeed;
|
|
|
|
result->printer_newline = SPS.printer_newline;
|
|
|
|
result->print_attributes = SPS.print_attributes;
|
|
|
|
result->print_everything = SPS.print_everything;
|
2010-03-25 16:03:51 -06:00
|
|
|
|
|
|
|
if (param_count != 0 && *param_count != 0) {
|
|
|
|
Cardinal j;
|
|
|
|
unsigned k;
|
|
|
|
for (j = 0; j < *param_count; ++j) {
|
|
|
|
TRACE(("param%d:%s\n", j, params[j]));
|
|
|
|
for (k = 0; k < XtNumber(table); ++k) {
|
|
|
|
if (!x_strcasecmp(params[j], table[k].name)) {
|
2011-03-07 13:41:27 -07:00
|
|
|
int *ptr = (int *) (void *) ((char *) result + table[k].offset);
|
2010-03-25 16:03:51 -06:00
|
|
|
TRACE(("...PrinterFlags(%s) %d->%d\n",
|
|
|
|
table[k].name,
|
|
|
|
*ptr,
|
|
|
|
table[k].value));
|
|
|
|
*ptr = table[k].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-08-18 13:47:42 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a timestamped copy of everything.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xtermPrintImmediately(XtermWidget xw, String filename, int opts, int attrs)
|
|
|
|
{
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
PrinterState save_state = screen->printer_state;
|
|
|
|
char *my_filename = malloc(TIMESTAMP_LEN + strlen(filename));
|
|
|
|
|
|
|
|
if (my_filename != 0) {
|
2017-07-15 13:20:51 -06:00
|
|
|
mode_t save_umask = umask(0177);
|
2011-08-18 13:47:42 -06:00
|
|
|
|
|
|
|
timestamp_filename(my_filename, filename);
|
|
|
|
SPS.fp = 0;
|
|
|
|
SPS.isOpen = False;
|
|
|
|
SPS.toFile = True;
|
|
|
|
SPS.printer_command = my_filename;
|
|
|
|
SPS.printer_autoclose = True;
|
|
|
|
SPS.printer_formfeed = False;
|
|
|
|
SPS.printer_newline = True;
|
|
|
|
SPS.print_attributes = attrs;
|
|
|
|
SPS.print_everything = opts;
|
|
|
|
xtermPrintEverything(xw, getPrinterFlags(xw, NULL, 0));
|
|
|
|
|
|
|
|
umask(save_umask);
|
|
|
|
screen->printer_state = save_state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xtermPrintOnXError(XtermWidget xw, int n)
|
|
|
|
{
|
|
|
|
#if OPT_PRINT_ON_EXIT
|
|
|
|
/*
|
|
|
|
* The user may have requested that the contents of the screen will be
|
|
|
|
* written to a file if an X error occurs.
|
|
|
|
*/
|
|
|
|
if (TScreenOf(xw)->write_error && !IsEmpty(resource.printFileOnXError)) {
|
|
|
|
Boolean printIt = False;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case ERROR_XERROR:
|
|
|
|
/* FALLTHRU */
|
|
|
|
case ERROR_XIOERROR:
|
|
|
|
/* FALLTHRU */
|
|
|
|
case ERROR_ICEERROR:
|
|
|
|
printIt = True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (printIt) {
|
|
|
|
xtermPrintImmediately(xw,
|
|
|
|
resource.printFileOnXError,
|
|
|
|
resource.printOptsOnXError,
|
|
|
|
resource.printModeOnXError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void) xw;
|
|
|
|
(void) n;
|
|
|
|
#endif
|
|
|
|
}
|