typo
[apps/madmutt.git] / resize.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #if HAVE_CONFIG_H
11 # include "config.h"
12 #endif
13
14 #include "mutt.h"
15 #include "mutt_curses.h"
16
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include <termios.h>
21
22 #ifdef HAVE_SYS_IOCTL_H
23 #include <sys/ioctl.h>
24 #else
25 # ifdef HAVE_IOCTL_H
26 # include <ioctl.h>
27 # endif
28 #endif
29
30 /* this routine should be called after receiving SIGWINCH */
31 void mutt_resize_screen (void)
32 {
33   char *cp;
34   int fd;
35   struct winsize w;
36
37 #ifdef HAVE_RESIZETERM
38   int SLtt_Screen_Rows, SLtt_Screen_Cols;
39 #endif
40
41   SLtt_Screen_Rows = -1;
42   SLtt_Screen_Cols = -1;
43   if ((fd = open ("/dev/tty", O_RDONLY)) != -1) {
44     if (ioctl (fd, TIOCGWINSZ, &w) != -1) {
45       SLtt_Screen_Rows = w.ws_row;
46       SLtt_Screen_Cols = w.ws_col;
47     }
48     close (fd);
49   }
50   if (SLtt_Screen_Rows <= 0) {
51     if ((cp = getenv ("LINES")) != NULL) {
52       SLtt_Screen_Rows = atoi (cp);
53     }
54     else
55       SLtt_Screen_Rows = 24;
56   }
57   if (SLtt_Screen_Cols <= 0) {
58     if ((cp = getenv ("COLUMNS")) != NULL)
59       SLtt_Screen_Cols = atoi (cp);
60     else
61       SLtt_Screen_Cols = 80;
62   }
63 #ifdef USE_SLANG_CURSES
64   delwin (stdscr);
65   SLsmg_reset_smg ();
66   SLsmg_init_smg ();
67   stdscr = newwin (0, 0, 0, 0);
68   keypad (stdscr, TRUE);
69 #else
70   resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
71 #endif
72 }