From 2981ebc0eeb14a4e0c91a39c454bfe3c4dfce1a4 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 23 Mar 2004 00:07:36 +0000 Subject: [PATCH] Added missing call to close_temp_file and improved the way the viewport is set --- src/ChangeLog | 8 ++++++++ src/set.q | 46 +++++++++++++++++++++++++++++----------------- src/sort.c | 5 +++-- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index edc5c34d..a027c8d4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +Tue Mar 23 08:00:42 WAST 2004 John Darrington + + * sort.c: Added missing call to temp_file_close. Changed error + messages to warnings. + + * set.q: Improved setting of set_view{length,width} to be more tolerant + of buggy OSes. + Sun Mar 21 10:11:14 WST 2004 John Darrington * val-labs.c: Fixed a bug where PSPP would crash, if VALUE LABELS was diff --git a/src/set.q b/src/set.q index 2d1a1699..b42786a6 100644 --- a/src/set.q +++ b/src/set.q @@ -84,6 +84,7 @@ #else /* !HAVE_TERMCAP_H */ int tgetent (char *, const char *); int tgetnum (const char *); +int tgetflag (const char *); #endif /* !HAVE_TERMCAP_H */ #endif /* !HAVE_LIBTERMCAP */ @@ -985,11 +986,8 @@ set_viewport(int sig_num UNUSED) static char term_buffer[16384]; #endif - /* Workable defaults before we determine the real terminal size. */ - set_viewwidth = 79; - set_viewlength = 24; - - + set_viewwidth = -1; + set_viewlength = -1; #if __DJGPP__ || __BORLANDC__ { @@ -1007,7 +1005,7 @@ set_viewport(int sig_num UNUSED) /* This code stolen from termcap.info, though modified. */ termtype = getenv ("TERM"); if (!termtype) - msg (FE, _("Specify a terminal type with `setenv TERM '.")); + msg (FE, _("Specify a terminal type with the TERM environment variable.")); success = tgetent (term_buffer, termtype); if (success <= 0) @@ -1019,22 +1017,36 @@ set_viewport(int sig_num UNUSED) } else { - set_viewlength = tgetnum ("li"); - set_viewwidth = tgetnum ("co") - 1; + /* NOTE: Do not rely upon tgetnum returning -1 if the value is + not available. It's supposed to do it, but not all platforms + do (eg Cygwin) . + */ + if ( tgetflag("li")) + set_viewlength = tgetnum ("li"); + + if ( tgetflag("co")) + set_viewwidth = tgetnum ("co") - 1; } } -#else - { - char *s; +#endif /* HAVE_LIBTERMCAP */ /* Try the environment variables */ - s = getenv("COLUMNS"); - if ( s ) set_viewwidth = atoi(s); + if ( -1 == set_viewwidth ) + { + char *s = getenv("COLUMNS"); + if ( s ) set_viewwidth = atoi(s); + } - s = getenv("LINES"); - if ( s ) set_viewlength = atoi(s); - } -#endif /* !HAVE_LIBTERMCAP */ + if ( -1 == set_viewwidth ) + { + char *s = getenv("LINES"); + if ( s ) set_viewlength = atoi(s); + } + + + /* Last resort. Use hard coded values */ + if ( 0 > set_viewwidth ) set_viewwidth = 79; + if ( 0 > set_viewlength ) set_viewlength = 24; } diff --git a/src/sort.c b/src/sort.c index fd636ac8..ec90b558 100644 --- a/src/sort.c +++ b/src/sort.c @@ -507,7 +507,7 @@ rmdir_temp_dir (struct external_sort *xsrt) { if (xsrt->temp_dir != NULL && rmdir (xsrt->temp_dir) == -1) { - msg (SE, _("%s: Error removing directory for temporary files: %s."), + msg (SW, _("%s: Error removing directory for temporary files: %s."), xsrt->temp_dir, strerror (errno)); xsrt->temp_dir = NULL; } @@ -569,7 +569,7 @@ remove_temp_file (struct external_sort *xsrt, int file_idx) { char *temp_file = get_temp_file_name (xsrt, file_idx); if (simulate_error () || remove (temp_file) != 0) - msg (SE, _("%s: Error removing temporary file: %s."), + msg (SW, _("%s: Error removing temporary file: %s."), temp_file, strerror (errno)); } } @@ -1383,6 +1383,7 @@ read_external_sort_output (struct external_sort *xsrt, break; } free (c); + close_temp_file (xsrt, file_idx, file); } static void -- 2.30.2