1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1992-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
20 ***********************************************************************/
24 * AT&T Bell Laboratories
29 static const char usage
[] =
30 "[-?\n@(#)$Id: tty (AT&T Research) 2008-03-13 $\n]"
32 "[+NAME?tty - write the name of the terminal to standard output]"
33 "[+DESCRIPTION?\btty\b writes the name of the terminal that is connected "
34 "to standard input onto standard output. If the standard input is not "
35 "a terminal, \"\bnot a tty\b\" will be written to standard output.]"
36 "[l:line-number?Write the synchronous line number of the terminal on a "
37 "separate line following the terminal name line. If the standard "
38 "input is not a synchronous terminal then "
39 "\"\bnot on an active synchronous line\b\" is written.]"
40 "[s:silent|quiet?Disable the terminal name line. Use \b[[ -t 0 ]]]]\b instead.]"
42 "[+0?Standard input is a tty.]"
43 "[+1?Standard input is not a tty.]"
44 "[+2?Invalid arguments.]"
45 "[+3?A an error occurred.]"
53 #include <sys/stermio.h>
57 b_tty(int argc
, char *argv
[], void* context
)
59 register int n
,sflag
=0,lflag
=0;
62 cmdinit(argc
, argv
, context
, ERROR_CATALOG
, 0);
63 while (n
= optget(argv
, usage
)) switch (n
)
72 error(2, "%s", opt_info
.arg
);
75 error(ERROR_usage(2), "%s", opt_info
.arg
);
79 error(ERROR_usage(2), "%s", optusage(NiL
));
82 tty
= ERROR_translate(0, 0, 0, "not a tty");
86 sfputr(sfstdout
,tty
,'\n');
90 if (n
= ioctl(0, STWLINE
, 0)) >= 0)
91 error(ERROR_OUTPUT
, 1, "synchronous line %d", n
);
94 error(ERROR_OUTPUT
, 1, "not on an active synchronous line");
96 return(error_info
.errors
);