8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / model / drain.output.c
blob6a11c4713c32f100befdbf6e7d7fc3fcd5814270
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include "termio.h"
35 * The following macro computes the number of seconds to sleep
36 * AFTER waiting for the system buffers to be drained.
38 * Various choices:
40 * - A percentage (perhaps even >100%) of the time it would
41 * take to print the printer's buffer. Use this if it appears
42 * the printers are affected if the port is closed before they
43 * finish printing.
45 * - 0. Use this to avoid any extra sleep after waiting for the
46 * system buffers to be flushed.
48 * - N > 0. Use this to have a fixed sleep after flushing the
49 * system buffers.
51 * The sleep period can be overridden by a single command line argument.
53 /* 25% of the print-full-buffer time, plus 1 */
54 #define LONG_ENOUGH(BUFSZ,CPS) (1 + ((250 * BUFSZ) / CPS) / 1000)
56 extern int tidbit();
58 /**
59 ** main()
60 **/
62 int
63 main(int argc, char *argv[])
65 extern char *getenv();
67 short bufsz = -1,
68 cps = -1;
70 char *TERM;
72 int sleep_time = 0;
76 * Wait for the output to drain.
78 ioctl (1, TCSBRK, (struct termio *)1);
81 * Decide how long to sleep.
83 if (argc != 2 || (sleep_time = atoi(argv[1])) < 0)
84 if ((TERM = getenv("TERM"))) {
85 tidbit (TERM, "bufsz", &bufsz);
86 tidbit (TERM, "cps", &cps);
87 if (cps > 0 && bufsz > 0)
88 sleep_time = LONG_ENOUGH(bufsz, cps);
89 } else
90 sleep_time = 2;
93 * Wait ``long enough'' for the printer to finish
94 * printing what's in its buffer.
96 if (sleep_time)
97 sleep (sleep_time);
99 return (0);