Dan Karron@UCBVAX.BERKELEY.EDU (04/17/91)
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@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> |
msc@ramoth.esd.sgi.com (Mark Callow) (04/19/91)
In article <9104170341.AA13470@karron.med.nyu.edu>, Dan Karron@UCBVAX.BERKELEY.EDU writes: |> What about cases when you are 1) not connected to a terminal, |> 2) piped to the printer, or How can the "window size" be relevant in these cases. You aren't talking to a window. I can see some need to know how wide the printer's lines are. Make a terminfo entry for the printer and see 3 below. |> 3) using termio Do you mean terminfo? The ioctl works just fine with termio. Terminfo uses the ioctl to get the value of lines and columns. If the ioctl fails then it falls back to the LINES and COLUMNS environment variables. If those don't exist it falls back to the value given in the terminal database. |> 4) using termcap Ditto with terminfo. |> 4) completely lost and need to make a best guess ! Use terminfo or curses which fall back on the value in the terminal data base. I will admit that the TIOCGETWINSZ ioctl is not clearly documented. However most of the rest of this stuff is documented in the terminfo/curses man pages. -- From the TARDIS of Mark Callow msc@ramoth.sgi.com, ...{ames,decwrl}!sgi!msc "Spirits of genius are always opposed by mediocre minds" - Albert Einstein
pkr@sgi.com (Phil Ronzone) (04/19/91)
In article <1991Apr18.183945.21088@odin.corp.sgi.com> msc@sgi.com writes: >I will admit that the TIOCGETWINSZ ioctl is not clearly documented. However >most of the rest of this stuff is documented in the terminfo/curses man pages. > >-- >From the TARDIS of Mark Callow >msc@ramoth.sgi.com, ...{ames,decwrl}!sgi!msc >"Spirits of genius are always opposed by mediocre minds" - Albert Einstein int lines; int columns; status = ioctl(fileno(stdin),TIOCGWINSZ,&ws); if (status != 0) { rpterr(1,1,fn,"Bad return from ioctl(,TIOCGWINSZ,) of %d",status); return(1); } columns = ws.ws_col; lines = ws.ws_row; -- Philip K. Ronzone pkr@sgi.com Silicon Graphics, Inc. MS 9U-500 work (415) 335-1511 2011 N. Shoreline Blvd., Mountain View, CA 94039 fax (415) 969-2314 ...................................."Why, you little ........", Homer Simpson