1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1992-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * David Korn
1N/A * AT&T Bell Laboratories
1N/A *
1N/A * tty
1N/A */
1N/A
1N/Astatic const char usage[] =
1N/A"[-?\n@(#)$Id: tty (AT&T Research) 2008-03-13 $\n]"
1N/AUSAGE_LICENSE
1N/A"[+NAME?tty - write the name of the terminal to standard output]"
1N/A"[+DESCRIPTION?\btty\b writes the name of the terminal that is connected "
1N/A "to standard input onto standard output. If the standard input is not "
1N/A "a terminal, \"\bnot a tty\b\" will be written to standard output.]"
1N/A"[l:line-number?Write the synchronous line number of the terminal on a "
1N/A "separate line following the terminal name line. If the standard "
1N/A "input is not a synchronous terminal then "
1N/A "\"\bnot on an active synchronous line\b\" is written.]"
1N/A"[s:silent|quiet?Disable the terminal name line. Use \b[[ -t 0 ]]]]\b instead.]"
1N/A"[+EXIT STATUS?]{"
1N/A "[+0?Standard input is a tty.]"
1N/A "[+1?Standard input is not a tty.]"
1N/A "[+2?Invalid arguments.]"
1N/A "[+3?A an error occurred.]"
1N/A"}"
1N/A;
1N/A
1N/A
1N/A#include <cmd.h>
1N/A
1N/A#if _mac_STWLINE
1N/A#include <sys/stermio.h>
1N/A#endif
1N/A
1N/Aint
1N/Ab_tty(int argc, char *argv[], void* context)
1N/A{
1N/A register int n,sflag=0,lflag=0;
1N/A register char *tty;
1N/A
1N/A cmdinit(argc, argv, context, ERROR_CATALOG, 0);
1N/A for (;;)
1N/A {
1N/A switch (optget(argv, usage))
1N/A {
1N/A case 'l':
1N/A lflag++;
1N/A continue;
1N/A case 's':
1N/A sflag++;
1N/A continue;
1N/A case ':':
1N/A error(2, "%s", opt_info.arg);
1N/A break;
1N/A case '?':
1N/A error(ERROR_usage(2), "%s", opt_info.arg);
1N/A break;
1N/A }
1N/A break;
1N/A }
1N/A if(error_info.errors)
1N/A error(ERROR_usage(2), "%s", optusage(NiL));
1N/A if(!(tty=ttyname(0)))
1N/A {
1N/A tty = ERROR_translate(0, 0, 0, "not a tty");
1N/A error_info.errors++;
1N/A }
1N/A if(!sflag)
1N/A sfputr(sfstdout,tty,'\n');
1N/A if(lflag)
1N/A {
1N/A#if _mac_STWLINE
1N/A if (n = ioctl(0, STWLINE, 0)) >= 0)
1N/A error(ERROR_OUTPUT, 1, "synchronous line %d", n);
1N/A else
1N/A#endif
1N/A error(ERROR_OUTPUT, 1, "not on an active synchronous line");
1N/A }
1N/A return(error_info.errors);
1N/A}