1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2007 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 <libpspp/compiler.h>
29 #define _(msgid) gettext (msgid)
31 static int view_width = -1;
32 static int view_length = -1;
34 /* Initializes the terminal interface by determining the size of
35 the user's terminal. Stores a pointer to the size variables
36 in *VIEW_WIDTH_P and *VIEW_LENGTH_P. */
38 terminal_init (int **view_width_p, int **view_length_p)
40 *view_width_p = &view_width;
41 *view_length_p = &view_length;
42 terminal_check_size ();
45 /* Code that interfaces to ncurses. This must be at the very end
46 of this file because curses.h redefines "bool" on some systems
47 (e.g. OpenBSD), causing declaration mismatches with functions
48 that have parameters or return values of type "bool". */
54 /* Determines the size of the terminal, if possible, or at least
55 takes an educated guess. */
57 terminal_check_size (void)
60 if (getenv ("TERM") != NULL)
62 char term_buffer [16384];
64 if (tgetent (term_buffer, getenv ("TERM")) > 0)
66 if (tgetnum ("li") > 0)
67 view_length = tgetnum ("li");
68 if (tgetnum ("co") > 1)
69 view_width = tgetnum ("co") - 1;
72 error (0, 0, _("could not access definition for terminal `%s'"),
79 if (getenv ("COLUMNS") != NULL)
80 view_width = atoi (getenv ("COLUMNS"));
87 if (getenv ("LINES") != NULL)
88 view_length = atoi (getenv ("LINES"));