2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
23 #include <curses.priv.h>
27 MODULE_ID("$Id: lib_print.c,v 1.8 1996/12/21 14:24:06 tom Exp $")
29 int mcprint(char *data, int len)
30 /* ship binary character data to the printer via mc4/mc5/mc5p */
32 char *mybuf, *switchon;
33 size_t onsize, offsize, res;
36 if (!prtr_non && (!prtr_on || !prtr_off))
44 switchon = tparm(prtr_non, len);
45 onsize = strlen(switchon);
51 onsize = strlen(prtr_on);
52 offsize = strlen(prtr_off);
55 if ((mybuf = malloc(onsize + len + offsize + 1)) == (char *)NULL)
61 (void) strcpy(mybuf, switchon);
62 memcpy(mybuf + onsize, data, len);
64 (void) strcpy(mybuf + onsize + len, prtr_off);
67 * We're relying on the atomicity of UNIX writes here. The
68 * danger is that output from a refresh() might get interspersed
69 * with the printer data after the write call returns but before the
70 * data has actually been shipped to the terminal. If the write(2)
71 * operation is truly atomic we're protected from this.
73 res = write(cur_term->Filedes, mybuf, onsize + len + offsize);
76 * By giving up our scheduler slot here we increase the odds that the
77 * kernel will ship the contiguous clist items from the last write