2
* Printer I/O routines for Survex printer drivers
3
* Copyright (C) 1993-1997 Olly Betts
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35
/* Make DJGPP v2 use register struct-s compatible with v1 and BorlandC */
36
# if defined(__DJGPP__) && (__DJGPP__ >= 2)
37
# define _NAIVE_DOS_REGS
45
static bool fPipeOpen = fFalse;
49
prio_open(const char *fnmPrn)
53
fnmPrn++; /* skip '|' */
54
fhPrn = popen(fnmPrn, "w");
55
if (!fhPrn) fatalerror(/*Couldn't open pipe: `%s'*/17, fnmPrn);
60
fhPrn = safe_fopen(fnmPrn, "wb");
62
{ /* For DOS, check if we're talking directly to a device, and force
63
* "raw mode" if we are, so that ^Z ^S ^Q ^C don't get filtered */
65
in.x.ax = 0x4400; /* get device info */
66
in.x.bx = fileno(fhPrn);
68
/* check call worked && file is a device */
69
if (!out.x.cflag && (out.h.dl & 0x80)) {
70
in.x.ax = 0x4401; /* set device info */
71
in.x.dx = out.h.dl | 0x20; /* force binary mode */
81
fatalerror(/*Error writing printer output*/87);
89
/* pclose gives return code from program or -1, so only 0 means OK */
90
if (ferror(fhPrn) || pclose(fhPrn)) prio_writeerror();
94
if (ferror(fhPrn) || fclose(fhPrn) == EOF) prio_writeerror();
100
/* putc() returns EOF on write error */
101
if (putc(ch, fhPrn) == EOF) fatalerror(87);
105
prio_printf(const char *format, ...)
109
va_start(args, format);
110
result = vfprintf(fhPrn, format, args);
112
if (result < 0) prio_writeerror();
116
prio_print(const char *str)
118
if (fputs(str, fhPrn) < 0) prio_writeerror();
122
prio_putpstr(const pstr *p)
124
prio_putbuf(p->str, p->len);
128
prio_putbuf(const void *buf, size_t len)
130
/* fwrite() returns # of members successfuly written */
131
if (fwrite(buf, 1, len, fhPrn) != len) prio_writeerror();