From 83c6b327b0334a3b1aff9f2a0d2633041fa32ce3 Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 5 Apr 1994 23:35:16 +0000 Subject: TIOCGWINSZ --- rain/rain.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'rain/rain.c') diff --git a/rain/rain.c b/rain/rain.c index dd7b075c..8ad61be2 100644 --- a/rain/rain.c +++ b/rain/rain.c @@ -39,7 +39,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)rain.c 5.6 (Berkeley) 2/28/91";*/ -static char rcsid[] = "$Id: rain.c,v 1.3 1993/12/08 08:18:22 mycroft Exp $"; +static char rcsid[] = "$Id: rain.c,v 1.4 1994/04/05 23:35:16 deraadt Exp $"; #endif /* not lint */ /* @@ -80,6 +80,9 @@ main(argc, argv) long cols, lines, random(); int xpos[5], ypos[5]; static void onsig(); +#ifdef TIOCGWINSZ + struct winsize ws; +#endif if (!(term = getenv("TERM"))) { fprintf(stderr, "%s: TERM: parameter not set\n", *argv); @@ -104,10 +107,19 @@ main(argc, argv) DN = "\n"; if (!(ND = tgetstr("nd", &tcp))) ND = " "; - if ((cols = tgetnum("co")) == -1) - cols = 80; - if ((lines = tgetnum("li")) == -1) - lines = 24; +#ifdef TIOCGWINSZ + if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) != -1 && + ws.ws_col && ws.ws_row) { + cols = ws.ws_col; + lines = ws.ws_row; + } else +#endif + { + if ((cols = tgetnum("co")) == -1) + cols = 80; + if ((lines = tgetnum("li")) == -1) + lines = 24; + } cols -= 4; lines -= 4; TE = tgetstr("te", &tcp); -- cgit v1.2.3-56-ge451