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
32 * $FreeBSD: src/usr.bin/doscmd/int17.c,v 1.4.2.3 2002/04/25 11:04:51 tg Exp $
33 * $DragonFly: src/usr.bin/doscmd/int17.c,v 1.2 2003/06/17 04:29:26 dillon Exp $
36 #include <sys/types.h>
44 static int lpt_fd
[4] = { -1, -1, -1, -1, };
45 static FILE *lpt_file
[4] = { 0, 0, 0, 0};
46 static int direct
[4] = { 0, 0, 0, 0};
47 static char *queue
[4] = { 0, 0, 0, 0};
48 static int timeout
[4] = { 30, 30, 30, 30 };
49 static int last_poll
[4] = { 0, 0, 0, 0};
50 static int last_count
[4] = { 0, 0, 0, 0};
51 static int current_count
[4] = { 0, 0, 0, 0};
53 static void open_printer(int printer
);
56 int17(regcontext_t
*REGS
)
75 R_AH
= 0x90; /* printed selected */
76 current_count
[R_DX
]++;
85 unknown_int2(0x17, R_AH
, REGS
);
98 for(i
=0; i
< 4; i
++) {
102 if (current
- last_poll
[i
] < timeout
[i
])
105 last_poll
[i
] = current
;
107 if (last_count
[i
] == current_count
[i
]) {
109 debug(D_PRINTER
, "Closing printer %d\n", i
);
112 debug(D_PRINTER
, "Closing spool printer %d\n", i
);
119 last_count
[i
] = current_count
[i
];
125 open_printer(int printer
)
127 char printer_name
[80];
134 * if printer is direct then open output device.
136 if (direct
[printer
]) {
137 if ((p
= queue
[printer
]) != 0) {
138 if ((fd
= open(p
, O_WRONLY
|O_APPEND
|O_CREAT
, 0666)) < 0) {
143 sprintf(printer_name
, "%slpt%d", _PATH_DEV
, printer
);
144 debug(D_PRINTER
, "Opening device %s\n", printer_name
);
145 if ((fd
= open(printer_name
, O_WRONLY
)) < 0) {
146 perror(printer_name
);
150 lpt_fd
[printer
] = fd
;
155 * If printer is a spooled device then open pipe to spooled device
157 if (queue
[printer
]) {
158 strncpy(printer_name
, queue
[printer
], sizeof(printer_name
));
159 printer_name
[sizeof(printer_name
) - 1] = '\0';
161 strcpy(printer_name
, "lp");
163 snprintf(command
, sizeof(command
), "lpr -P %s", printer_name
);
164 debug(D_PRINTER
, "opening pipe to %s\n", printer_name
);
166 if ((file
= popen(command
, "w")) == 0) {
170 lpt_file
[printer
] = file
;
171 lpt_fd
[printer
] = fileno(file
);
175 printer_direct(int printer
)
181 printer_spool(int printer
, char *print_queue
)
183 queue
[printer
] = print_queue
? strdup(print_queue
) : 0;
187 printer_timeout(int printer
, char *time_out
)
189 if (atoi(time_out
) <= 0) {
190 fprintf(stderr
, "Bad timeout value on lpt%d:\n", printer
+1);
193 timeout
[printer
] = atoi(time_out
);