home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume23
/
sps2
/
part03
/
termwidth.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
978b
|
52 lines
# ifndef lint
static char SccsId[] = "@(#)termwidth.c 1.3\t8/6/90" ;
# endif
# include <sys/ioctl.h>
/*
** TERMWIDTH - Sets the external variable `Termwidth' to the # of columns
** on the terminal.
*/
termwidth ()
{
register char *termtype ;
register int twidth ;
# ifdef TIOCGWINSZ
struct winsize w ;
# else
# ifdef TIOCGSIZE
struct ttysize w ;
# endif
# endif
char buf[ 1025 ] ;
extern unsigned Termwidth ;
char *getenv() ;
# ifdef TIOCGWINSZ
w.ws_col = 0 ;
if ( !ioctl( 0, TIOCGWINSZ, &w ) && w.ws_col )
{
Termwidth = w.ws_col ;
return ;
}
# else
# ifdef TIOCGSIZE
w.ts_cols = 0 ;
if ( !ioctl( 0, TIOCGSIZE, &w ) && w.ts_cols )
{
Termwidth = w.ts_cols ;
return ;
}
# endif
# endif
Termwidth = 80 ;
if ( !(termtype = getenv( "TERM" )) )
return ;
if ( tgetent( buf, termtype ) != 1 )
return ;
twidth = tgetnum( "co" ) ;
if ( twidth > 40 )
Termwidth = twidth ;
}