xref: /titanic_51/usr/src/cmd/lp/model/drain.output.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5	*/
27 
28 #include "termio.h"
29 
30 /*
31  * The following macro computes the number of seconds to sleep
32  * AFTER waiting for the system buffers to be drained.
33  *
34  * Various choices:
35  *
36  *	- A percentage (perhaps even >100%) of the time it would
37  *	  take to print the printer's buffer. Use this if it appears
38  *	  the printers are affected if the port is closed before they
39  *	  finish printing.
40  *
41  *	- 0. Use this to avoid any extra sleep after waiting for the
42  *	  system buffers to be flushed.
43  *
44  *	- N > 0. Use this to have a fixed sleep after flushing the
45  *	  system buffers.
46  *
47  * The sleep period can be overridden by a single command line argument.
48  */
49 			/* 25% of the print-full-buffer time, plus 1 */
50 #define LONG_ENOUGH(BUFSZ,CPS)	 (1 + ((250 * BUFSZ) / CPS) / 1000)
51 
52 extern int		tidbit();
53 
54 /**
55  ** main()
56  **/
57 
58 int			main (argc, argv)
59 	int			argc;
60 	char			*argv[];
61 {
62 	extern char		*getenv();
63 
64 	short			bufsz	= -1,
65 				cps	= -1;
66 
67 	char			*TERM;
68 
69 	int			sleep_time	= 0;
70 
71 
72 	/*
73 	 * Wait for the output to drain.
74 	 */
75 	ioctl (1, TCSBRK, (struct termio *)1);
76 
77 	/*
78 	 * Decide how long to sleep.
79 	 */
80 	if (argc != 2 || (sleep_time = atoi(argv[1])) < 0)
81 		if ((TERM = getenv("TERM"))) {
82 			tidbit (TERM, "bufsz", &bufsz);
83 			tidbit (TERM, "cps", &cps);
84 			if (cps > 0 && bufsz > 0)
85 				sleep_time = LONG_ENOUGH(bufsz, cps);
86 		} else
87 			sleep_time = 2;
88 
89 	/*
90 	 * Wait ``long enough'' for the printer to finish
91 	 * printing what's in its buffer.
92 	 */
93 	if (sleep_time)
94 		sleep (sleep_time);
95 
96 	exit (0);
97 	/*NOTREACHED*/
98 }
99