/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ * and: Juergen Pfeifer *
****************************************************************************/
-
#include <curses.priv.h>
-#include <term.h>
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
-MODULE_ID("$Id: lib_print.c,v 1.11 1999/02/27 19:59:05 tom Exp $")
+MODULE_ID("$Id: lib_print.c,v 1.30 2021/04/18 14:58:57 tom Exp $")
-int mcprint(char *data, int len)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len)
/* ship binary character data to the printer via mc4/mc5/mc5p */
{
- char *mybuf, *switchon;
- size_t onsize, offsize, res;
+ int result;
+ char *mybuf = NULL, *switchon;
+ size_t onsize, offsize;
+ size_t need;
errno = 0;
- if (!cur_term || (!prtr_non && (!prtr_on || !prtr_off)))
- {
+ if (!HasTInfoTerminal(SP_PARM)
+ || len <= 0
+ || (!prtr_non && (!prtr_on || !prtr_off))) {
errno = ENODEV;
- return(ERR);
+ return (ERR);
}
- if (prtr_non)
- {
- switchon = tparm(prtr_non, len);
+ if (prtr_non) {
+ switchon = TIPARM_1(prtr_non, len);
onsize = strlen(switchon);
offsize = 0;
- }
- else
- {
+ } else {
switchon = prtr_on;
onsize = strlen(prtr_on);
offsize = strlen(prtr_off);
}
- if ((mybuf = typeMalloc(char, onsize + len + offsize + 1)) == (char *)0)
- {
+ need = onsize + (size_t) len + offsize;
+
+ if (switchon == 0
+ || (mybuf = typeMalloc(char, need + 1)) == 0) {
+ free(mybuf);
errno = ENOMEM;
- return(ERR);
+ return (ERR);
}
- (void) strcpy(mybuf, switchon);
- memcpy(mybuf + onsize, data, len);
+ _nc_STRCPY(mybuf, switchon, need);
+ memcpy(mybuf + onsize, data, (size_t) len);
if (offsize)
- (void) strcpy(mybuf + onsize + len, prtr_off);
+ _nc_STRCPY(mybuf + onsize + len, prtr_off, need);
/*
* We're relying on the atomicity of UNIX writes here. The
* data has actually been shipped to the terminal. If the write(2)
* operation is truly atomic we're protected from this.
*/
- res = write(cur_term->Filedes, mybuf, onsize + len + offsize);
+ result = (int) write(TerminalOf(SP_PARM)->Filedes, mybuf, need);
/*
* By giving up our scheduler slot here we increase the odds that the
* kernel will ship the contiguous clist items from the last write
* immediately.
*/
+#ifndef _NC_WINDOWS
(void) sleep(0);
-
+#endif
free(mybuf);
- return(res);
+ return (result);
+}
+
+#if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)
+NCURSES_EXPORT(int)
+mcprint(char *data, int len)
+{
+ return NCURSES_SP_NAME(mcprint) (CURRENT_SCREEN, data, len);
}
+#endif