home *** CD-ROM | disk | FTP | other *** search
- # 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 ;
- }
-