1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2007, 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "ui/terminal/terminal.h"
24 #include "data/settings.h"
25 #include "libpspp/compiler.h"
30 #define _(msgid) gettext (msgid)
32 /* Code that interfaces to ncurses. This must be at the very end
33 of this file because curses.h redefines "bool" on some systems
34 (e.g. OpenBSD), causing declaration mismatches with functions
35 that have parameters or return values of type "bool". */
41 /* Determines the size of the terminal, if possible, or at least
42 takes an educated guess. */
44 terminal_check_size (void)
50 if (getenv ("TERM") != NULL)
52 char term_buffer [16384];
54 if (tgetent (term_buffer, getenv ("TERM")) > 0)
56 if (tgetnum ("li") > 0)
57 view_length = tgetnum ("li");
58 if (tgetnum ("co") > 1)
59 view_width = tgetnum ("co") - 1;
62 error (0, 0, _("could not access definition for terminal `%s'"),
67 if (view_width <= 0 && getenv ("COLUMNS") != NULL)
68 view_width = atoi (getenv ("COLUMNS"));
70 settings_set_viewwidth (view_width);
72 if (view_length <= 0 && getenv ("LINES") != NULL)
73 view_length = atoi (getenv ("LINES"));
75 settings_set_viewlength (view_length);