From: Ben Pfaff Date: Tue, 25 Sep 2007 04:19:11 +0000 (+0000) Subject: (set_fallback_viewport): Make code easier to understand. X-Git-Tag: v0.6.0~248 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54058c1e5c66b976ec7ddab606fd7740f0c61a6e;p=pspp-builds.git (set_fallback_viewport): Make code easier to understand. (get_termcap_viewport): Ditto. Reviewed by John Darrington. --- diff --git a/src/ui/terminal/ChangeLog b/src/ui/terminal/ChangeLog index f7983110..59c94918 100644 --- a/src/ui/terminal/ChangeLog +++ b/src/ui/terminal/ChangeLog @@ -1,3 +1,9 @@ +2007-09-24 Ben Pfaff + + * main.c (set_fallback_viewport): Make code easier to understand. + (get_termcap_viewport): Ditto. + Reviewed by John Darrington. + 2007-09-19 John Darrington * main.c: Moved get_termcap_viewport from src/data/settings.c diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index b25350b9..ad76cb1a 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -233,26 +233,31 @@ terminate (bool success) } - #include "error.h" #include "gettext.h" #define _(msgid) gettext (msgid) +/* If view_width or view_length has not yet been set to a + reasonable value, takes a guess. */ static void set_fallback_viewport (void) { - if (view_width < 0 && getenv ("COLUMNS") != NULL) - view_width = atoi (getenv ("COLUMNS")); - - if (view_length < 0 && getenv ("LINES") != NULL) - view_length = atoi (getenv ("LINES")); - - if (view_width < 0) - view_width = 79; + if (view_width <= 0) + { + if (getenv ("COLUMNS") != NULL) + view_width = atoi (getenv ("COLUMNS")); + if (view_width <= 0) + view_width = 79; + } - if (view_length < 0) - view_length = 24; + if (view_length <= 0) + { + if (getenv ("LINES") != NULL) + view_length = atoi (getenv ("LINES")); + if (view_length <= 0) + view_length = 24; + } } /* Code that interfaces to ncurses. This must be at the very end @@ -268,23 +273,20 @@ get_termcap_viewport (int sig UNUSED) { char term_buffer [16384]; - if (getenv ("TERM") == NULL) - goto fallback; - - else if (tgetent (term_buffer, getenv ("TERM")) <= 0) + if (getenv ("TERM") != NULL) { - error (0,0, _("could not access definition for terminal `%s'"), - getenv ("TERM")); - goto fallback; + if (tgetent (term_buffer, getenv ("TERM")) > 0) + { + if (tgetnum ("li") > 0) + view_length = tgetnum ("li"); + if (tgetnum ("co") > 1) + view_width = tgetnum ("co") - 1; + } + else + error (0, 0, _("could not access definition for terminal `%s'"), + getenv ("TERM")); } - if (tgetnum ("li") > 0) - view_length = tgetnum ("li"); - - if (tgetnum ("co") > 1) - view_width = tgetnum ("co") - 1; - - fallback: set_fallback_viewport (); }