wsh window size code
DanKarron at UCBVAX.BERKELEY.EDU
DanKarron at UCBVAX.BERKELEY.EDU
Wed Apr 17 13:41:05 AEST 1991
Here is the answer to my previous question. Thans to
Mike Sweet for clueing me to the place to look.
This code is adapted from the tcsh editor code. Thanks Christos !
Now for the hard part, that I don't want to do:
What about cases when you are 1) not connected to a terminal,
2) piped to the printer, or
3) using termio
4) using termcap
4) completely lost and need to make a best guess !
Anyway, here is the simple way:
---------snip---------------------------------------------------
#include "stdio.h"
#include "termio.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int GetSize(int *lins, int *cols)
{
struct winsize ws;
if (ioctl(0, TIOCGWINSZ,&ws) < 0)
return(0);
if (ws.ws_col)
*cols = ws.ws_col;
if (ws.ws_row)
*lins = ws.ws_row;
return(*cols);
}
main()
{
int i,j;
int lines,cols;
struct winsize *t;
system("clear");
sleep(4);
GetSize(&lines,&cols);
for(j=0;j<lines-3;j++)
{
for(i=0;i<cols;i++)
putchar('x');
}
printf("lines=%d,cols=%d. If correct, blank line at bottom\n",lines,cols);
exit(0);
}
------------------snip----------------------------------------------------
| karron at nyu.edu (e-mail alias ) Dan Karron, Research Associate |
| Phone: 212 263 5210 Fax: 212 263 7190 New York University Medical Center |
| 560 First Avenue Digital Pager <1> (212) 397 9330 |
| New York, New York 10016 <2> 10896 <3> <your-number-here> |
More information about the Comp.sys.sgi
mailing list