2 * Copyright (c) 1992, 1993, 1996
3 * Berkeley Software Design, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Berkeley Software
18 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * BSDI int17.c,v 2.2 1996/04/08 19:32:48 bostic Exp
35 #include <sys/types.h>
43 static int lpt_fd[4] = { -1, -1, -1, -1, };
44 static FILE *lpt_file[4] = { 0, 0, 0, 0};
45 static int direct[4] = { 0, 0, 0, 0};
46 static char *queue[4] = { 0, 0, 0, 0};
47 static int timeout[4] = { 30, 30, 30, 30 };
48 static int last_poll[4] = { 0, 0, 0, 0};
49 static int last_count[4] = { 0, 0, 0, 0};
50 static int current_count[4] = { 0, 0, 0, 0};
52 static void open_printer(int printer);
55 int17(regcontext_t *REGS)
74 R_AH = 0x90; /* printed selected */
75 current_count[R_DX]++;
84 unknown_int2(0x17, R_AH, REGS);
97 for(i=0; i < 4; i++) {
101 if (current - last_poll[i] < timeout[i])
104 last_poll[i] = current;
106 if (last_count[i] == current_count[i]) {
108 debug(D_PRINTER, "Closing printer %d\n", i);
111 debug(D_PRINTER, "Closing spool printer %d\n", i);
118 last_count[i] = current_count[i];
124 open_printer(int printer)
126 char printer_name[80];
133 * if printer is direct then open output device.
135 if (direct[printer]) {
136 if ((p = queue[printer]) != 0) {
137 if ((fd = open(p, O_WRONLY|O_APPEND|O_CREAT, 0666)) < 0) {
142 sprintf(printer_name, "%slpt%d", _PATH_DEV, printer);
143 debug(D_PRINTER, "Opening device %s\n", printer_name);
144 if ((fd = open(printer_name, O_WRONLY)) < 0) {
145 perror(printer_name);
149 lpt_fd[printer] = fd;
154 * If printer is a spooled device then open pipe to spooled device
156 if (queue[printer]) {
157 strncpy(printer_name, queue[printer], sizeof(printer_name));
158 printer_name[sizeof(printer_name) - 1] = '\0';
160 strcpy(printer_name, "lp");
162 snprintf(command, sizeof(command), "lpr -P %s", printer_name);
163 debug(D_PRINTER, "opening pipe to %s\n", printer_name);
165 if ((file = popen(command, "w")) == 0) {
169 lpt_file[printer] = file;
170 lpt_fd[printer] = fileno(file);
174 printer_direct(int printer)
180 printer_spool(int printer, char *print_queue)
182 queue[printer] = print_queue ? strdup(print_queue) : 0;
186 printer_timeout(int printer, char *time_out)
188 if (atoi(time_out) <= 0) {
189 fprintf(stderr, "Bad timeout value on lpt%d:\n", printer+1);
192 timeout[printer] = atoi(time_out);