#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: resizeterm.c,v 1.21 2007/03/10 23:45:14 tom Exp $")
+MODULE_ID("$Id: resizeterm.c,v 1.23 2007/10/13 20:12:13 tom Exp $")
#define stolen_lines (screen_lines - SP->_lines_avail)
resize_term(int ToLines, int ToCols)
{
int result = OK EXTRA_ARGS;
- int was_stolen = (screen_lines - SP->_lines_avail);
+ int was_stolen;
T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
ToLines, ToCols,
screen_lines, screen_columns));
+ if (SP == 0) {
+ returnCode(ERR);
+ }
+ was_stolen = (screen_lines - SP->_lines_avail);
if (is_term_resized(ToLines, ToCols)) {
int myLines = CurLines = screen_lines;
int myCols = CurCols = screen_columns;
#ifdef TRACE
- if (_nc_tracing & TRACE_UPDATE)
+ if (USE_TRACEF(TRACE_UPDATE)) {
show_window_sizes("before");
+ _nc_unlock_global(tracef);
+ }
#endif
if (ToLines > screen_lines) {
increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
FreeAndNull(SP->newhash);
}
#ifdef TRACE
- if (_nc_tracing & TRACE_UPDATE) {
+ if (USE_TRACEF(TRACE_UPDATE)) {
SET_LINES(ToLines - was_stolen);
SET_COLS(ToCols);
show_window_sizes("after");
+ _nc_unlock_global(tracef);
}
#endif
}
NCURSES_EXPORT(int)
resizeterm(int ToLines, int ToCols)
{
- int result = OK;
-
- SP->_sig_winch = FALSE;
+ int result = ERR;
T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
ToLines, ToCols,
screen_lines, screen_columns));
- if (is_term_resized(ToLines, ToCols)) {
+ if (SP != 0) {
+ result = OK;
+ SP->_sig_winch = FALSE;
+
+ if (is_term_resized(ToLines, ToCols)) {
#if USE_SIGWINCH
- ungetch(KEY_RESIZE); /* so application can know this */
- clearok(curscr, TRUE); /* screen contents are unknown */
+ ungetch(KEY_RESIZE); /* so application can know this */
+ clearok(curscr, TRUE); /* screen contents are unknown */
#endif
- result = resize_term(ToLines, ToCols);
+ result = resize_term(ToLines, ToCols);
+ }
}
returnCode(result);