Remove globals 'li' and 'co' in term.c

These globals were used to store the original terminal dimesions from the terminal database (or
in the case of reattaching, supplied by scr-bx) to be applied if the current terminal dimensions
could not be determined.

Instead, we leave the original terminal dimensions in current_term->TI_lines and current_term->TI_cols,
and create current_term->li and current_term->co to store the current terminal dimensions (as eg.
supplied by scr-bx).
This commit is contained in:
Kevin Easton
2017-09-15 17:15:24 +10:00
parent c9b0e654b5
commit 70ac43ce77
8 changed files with 67 additions and 64 deletions

View File

@@ -639,6 +639,8 @@ struct term_struct {
char *TI_memu; /* mu / memu memory unlock */ char *TI_memu; /* mu / memu memory unlock */
char *TI_box1; /* bx / box1 box characters primary set */ char *TI_box1; /* bx / box1 box characters primary set */
/* non termcap/terminfo terminal info (generated by epic) */ /* non termcap/terminfo terminal info (generated by epic) */
int co; /* current actual number of columns */
int li; /* current actual number of lines */
char TI_normal[256]; char TI_normal[256];
char *TI_sgrstrs[TERM_SGR_MAXVAL]; char *TI_sgrstrs[TERM_SGR_MAXVAL];
char *TI_forecolors[16]; char *TI_forecolors[16];

View File

@@ -4209,7 +4209,7 @@ BUILT_IN_FUNCTION(function_channelmode, word)
BUILT_IN_FUNCTION(function_geom, words) BUILT_IN_FUNCTION(function_geom, words)
{ {
/* Erf. CO and LI are ints. (crowman) */ /* Erf. CO and LI are ints. (crowman) */
return m_sprintf("%d %d", current_term->TI_cols, current_term->TI_lines); return m_sprintf("%d %d", current_term->co, current_term->li);
} }
BUILT_IN_FUNCTION(function_pass, words) BUILT_IN_FUNCTION(function_pass, words)

View File

@@ -532,7 +532,7 @@ void gtk_label_set_color(GtkWidget *label, int color)
/* This may be going away, it replaces code which is currently elsewhere in BitchX */ /* This may be going away, it replaces code which is currently elsewhere in BitchX */
void gtk_resize(Screen *this_screen) void gtk_resize(Screen *this_screen)
{ {
co = this_screen->co; li = this_screen->li; current_term->co = this_screen->co; current_term->li = this_screen->li;
/* Recalculate some stuff that was done in input.c previously */ /* Recalculate some stuff that was done in input.c previously */
this_screen->input_line = this_screen->li-1; this_screen->input_line = this_screen->li-1;
@@ -2179,8 +2179,8 @@ void gui_init(void)
{ {
current_term->TI_cols = 80; current_term->TI_cols = 80;
current_term->TI_lines = 25; current_term->TI_lines = 25;
li = current_term->TI_lines; current_term->li = current_term->TI_lines;
co = current_term->TI_cols; current_temr->co = current_term->TI_cols;
pthread_mutex_init(&evmutex, NULL); pthread_mutex_init(&evmutex, NULL);
pthread_cond_init(&evcond, NULL); pthread_cond_init(&evcond, NULL);
@@ -2544,7 +2544,7 @@ void gtk_new_window(Screen *gtknew, Window *win)
else else
zvt_load_font("fixed", gtknew); zvt_load_font("fixed", gtknew);
gtknew->co = co; gtknew->li = li; gtknew->co = current_term->co; gtknew->li = current_term->li;
zvt_term_set_scrollback((ZvtTerm *)gtknew->viewport, 0); zvt_term_set_scrollback((ZvtTerm *)gtknew->viewport, 0);
zvt_term_set_blink((ZvtTerm *)gtknew->viewport, TRUE); zvt_term_set_blink((ZvtTerm *)gtknew->viewport, TRUE);
zvt_term_set_bell((ZvtTerm *)gtknew->viewport, TRUE); zvt_term_set_bell((ZvtTerm *)gtknew->viewport, TRUE);

View File

@@ -447,11 +447,11 @@ MRESULT EXPENTRY FontDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
changescreen->VIO_font_width = fonts[i].lAveCharWidth; changescreen->VIO_font_width = fonts[i].lAveCharWidth;
changescreen->VIO_font_height = fonts[i].lMaxBaselineExt; changescreen->VIO_font_height = fonts[i].lMaxBaselineExt;
co = changescreen->co; current_term->co = changescreen->co;
li = changescreen->li; current_term->li = changescreen->li;
cx = (co - 1) * changescreen->VIO_font_width; cx = (changescreen->co - 1) * changescreen->VIO_font_width;
cy = li * changescreen->VIO_font_height; cy = changescreen->li * changescreen->VIO_font_height;
maxX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); maxX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
maxY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); maxY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
@@ -464,8 +464,8 @@ MRESULT EXPENTRY FontDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
changescreen->li = (maxY / changescreen->VIO_font_height) -1; changescreen->li = (maxY / changescreen->VIO_font_height) -1;
/* Recalculate in case we modified the values */ /* Recalculate in case we modified the values */
cx = (co - 1) * changescreen->VIO_font_width; cx = (changescreen->co - 1) * changescreen->VIO_font_width;
cy = li * changescreen->VIO_font_height; cy = changescreen->li * changescreen->VIO_font_height;
if(changescreen->nicklist) if(changescreen->nicklist)
cx += (changescreen->VIO_font_width * changescreen->nicklist) + cxvs; cx += (changescreen->VIO_font_width * changescreen->nicklist) + cxvs;
@@ -937,7 +937,7 @@ void pm_resize(Screen *this_screen)
cx = this_screen->co * this_screen->VIO_font_width; cx = this_screen->co * this_screen->VIO_font_width;
cy = this_screen->li * this_screen->VIO_font_height; cy = this_screen->li * this_screen->VIO_font_height;
co = this_screen->co; li = this_screen->li; current_term->co = this_screen->co; current_term->li = this_screen->li;
/* Recalculate some stuff that was done in input.c previously */ /* Recalculate some stuff that was done in input.c previously */
this_screen->input_line = this_screen->li-1; this_screen->input_line = this_screen->li-1;
@@ -1765,10 +1765,10 @@ void avio_init() {
NULL); NULL);
hwndMenu=(HWND)NULL; hwndMenu=(HWND)NULL;
current_term->TI_cols = co = 81; current_term->co = current_term->TI_cols = 81;
current_term->TI_lines = li = 25; current_term->li = current_term->TI_lines = 25;
cx = (co+14) * VIO_font_width; cx = (current_term->co+14) * VIO_font_width;
cy = li * VIO_font_height; cy = current_term->li * VIO_font_height;
WinSetParent(MDIFrame, HWND_OBJECT, FALSE); WinSetParent(MDIFrame, HWND_OBJECT, FALSE);
/* Setup main window */ /* Setup main window */
@@ -1811,8 +1811,8 @@ void avio_init() {
WinSubclassWindow(hwndLeft, FrameWndProc); WinSubclassWindow(hwndLeft, FrameWndProc);
WinSubclassWindow(hwndRight, FrameWndProc); WinSubclassWindow(hwndRight, FrameWndProc);
WinSendMsg(hwndnickscroll, SBM_SETSCROLLBAR, (MPARAM)0, MPFROM2SHORT(0, li)); WinSendMsg(hwndnickscroll, SBM_SETSCROLLBAR, (MPARAM)0, MPFROM2SHORT(0, current_term->li));
WinSendMsg(hwndnickscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(li, 0), (MPARAM)NULL); WinSendMsg(hwndnickscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(current_term->li, 0), (MPARAM)NULL);
setmode(guiipc[0], O_BINARY); setmode(guiipc[0], O_BINARY);
setmode(guiipc[1], O_BINARY); setmode(guiipc[1], O_BINARY);
@@ -2662,8 +2662,8 @@ void gui_init(void)
DC_SEM_SHARED, DC_SEM_SHARED,
FALSE); FALSE);
li = 25; current_term->li = 25;
co = 80; current_term->co = 80;
#ifdef SOUND #ifdef SOUND
if(DosLoadModule(NULL, 0, "MCIAPI", &hmod) == NO_ERROR) if(DosLoadModule(NULL, 0, "MCIAPI", &hmod) == NO_ERROR)

View File

@@ -1500,8 +1500,8 @@ Screen * BX_create_new_screen(void)
new->fdin = fileno(stdin); new->fdin = fileno(stdin);
new->alive = 1; new->alive = 1;
new->li = current_term->TI_lines; new->li = current_term->li;
new->co = current_term->TI_cols; new->co = current_term->co;
new->old_li = 0; new->old_li = 0;
new->old_co = 0; new->old_co = 0;
new->buffer_pos = new->buffer_min_pos = 0; new->buffer_pos = new->buffer_min_pos = 0;
@@ -1651,7 +1651,7 @@ extern Window *BX_create_additional_screen (void)
} }
else if (screen_type == ST_XTERM) else if (screen_type == ST_XTERM)
{ {
snprintf(geom, sizeof geom, "%dx%d", current_term->TI_cols, current_term->TI_lines); snprintf(geom, sizeof geom, "%dx%d", current_term->co, current_term->li);
opts = LOCAL_COPY(get_string_var(XTERM_OPTIONS_VAR)); opts = LOCAL_COPY(get_string_var(XTERM_OPTIONS_VAR));
if (!(xterm = getenv("XTERM"))) if (!(xterm = getenv("XTERM")))
if (!(xterm = get_string_var(XTERM_VAR))) if (!(xterm = get_string_var(XTERM_VAR)))

View File

@@ -623,8 +623,6 @@ static const int numcaps = sizeof tcaps / sizeof tcaps[0];
int can_color = 0; int can_color = 0;
int need_redraw = 0; int need_redraw = 0;
static int term_echo_flag = 1; static int term_echo_flag = 1;
static int li;
static int co;
#if !defined(__EMX__) && !defined(WINNT) && !defined(GUI) #if !defined(__EMX__) && !defined(WINNT) && !defined(GUI)
#ifndef HAVE_TERMINFO #ifndef HAVE_TERMINFO
@@ -872,12 +870,13 @@ int term_init (char *term)
} }
} }
li = current_term->TI_lines; if (!current_term->TI_cols)
co = current_term->TI_cols; current_term->TI_cols = 79;
if (!co) if (!current_term->TI_lines)
co = 79; current_term->TI_lines = 24;
if (!li)
li = 24; current_term->li = current_term->TI_lines;
current_term->co = current_term->TI_cols;
if (!current_term->TI_nel) if (!current_term->TI_nel)
current_term->TI_nel = "\n"; current_term->TI_nel = "\n";
@@ -901,7 +900,7 @@ int term_init (char *term)
} }
#else #else /* !defined(__EMX__) && !defined(WINNT) && !defined(GUI) */
#if defined(WINNT) && !defined(GUI) #if defined(WINNT) && !defined(GUI)
CONSOLE_SCREEN_BUFFER_INFO scrbuf; CONSOLE_SCREEN_BUFFER_INFO scrbuf;
@@ -929,13 +928,13 @@ int term_init (char *term)
GetConsoleCursorInfo(hinput, &gcursbuf); GetConsoleCursorInfo(hinput, &gcursbuf);
GetConsoleScreenBufferInfo(ghstdout, &scrbuf); GetConsoleScreenBufferInfo(ghstdout, &scrbuf);
li = scrbuf.srWindow.Bottom - scrbuf.srWindow.Top + 1; current_term->TI_lines = scrbuf.srWindow.Bottom - scrbuf.srWindow.Top + 1;
co = scrbuf.srWindow.Right - scrbuf.srWindow.Left + 1; current_term->TI_cols = scrbuf.srWindow.Right - scrbuf.srWindow.Left + 1;
memset(current_term, 0, sizeof(struct term_struct)); memset(current_term, 0, sizeof(struct term_struct));
current_term->TI_lines = li; current_term->li = current_term->TI_lines;
current_term->TI_cols = co - 1; current_term->co = current_term->TI_cols - 1;
#elif defined(GUI) #elif defined(GUI)
memset(current_term, 0, sizeof(struct term_struct)); memset(current_term, 0, sizeof(struct term_struct));
@@ -950,8 +949,8 @@ int term_init (char *term)
current_term->TI_lines = vmode.row; current_term->TI_lines = vmode.row;
current_term->TI_cols = vmode.col; current_term->TI_cols = vmode.col;
li = current_term->TI_lines; current_term->li = current_term->TI_lines;
co = current_term->TI_cols; current_term->co = current_term->TI_cols;
#endif #endif
current_term->TI_cup = strdup("\e[%i%d;%dH"); current_term->TI_cup = strdup("\e[%i%d;%dH");
@@ -1248,14 +1247,16 @@ void tty_dup(int tty)
dup2(tty, tty_des); dup2(tty, tty_des);
} }
/* These force the default terminal size, and are used when reattached by scr-bx.
They are then used as the fallback by term_resize(). */
void reset_lines(int nlines) void reset_lines(int nlines)
{ {
li = nlines; current_term->TI_lines = nlines;
} }
void reset_cols(int cols) void reset_cols(int cols)
{ {
co = cols; current_term->TI_cols = cols;
} }
/* /*
@@ -1275,40 +1276,40 @@ int term_resize (void)
if (ioctl(tty_des, TIOCGWINSZ, &window) < 0) if (ioctl(tty_des, TIOCGWINSZ, &window) < 0)
{ {
current_term->TI_lines = li; current_term->li = current_term->TI_lines;
current_term->TI_cols = co; current_term->co = current_term->TI_cols;
} }
else else
{ {
if ((current_term->TI_lines = window.ws_row) == 0) if ((current_term->li = window.ws_row) == 0)
current_term->TI_lines = li; current_term->li = current_term->TI_lines;
if ((current_term->TI_cols = (window.ws_col)) == 0) if ((current_term->co = window.ws_col) == 0)
current_term->TI_cols = co; current_term->co = current_term->TI_cols;
} }
} }
# else # else
{ {
current_term->TI_lines = li; current_term->li = current_term->TI_lines;
current_term->TI_cols = co; current_term->co = current_term->TI_cols;
} }
# endif # endif
#if use_automargins #if use_automargins
if (!current_term->TI_am || !current_term->TI_rmam) if (!current_term->TI_am || !current_term->TI_rmam)
{ {
current_term->TI_cols--; current_term->co--;
} }
#else #else
current_term->TI_cols--; current_term->co--;
#endif #endif
if ((old_li != current_term->TI_lines) || (old_co != current_term->TI_cols)) if ((old_li != current_term->li) || (old_co != current_term->co))
{ {
old_li = current_term->TI_lines; old_li = current_term->li;
old_co = current_term->TI_cols; old_co = current_term->co;
if (main_screen) if (main_screen)
{ {
main_screen->li = current_term->TI_lines; main_screen->li = current_term->li;
main_screen->co = current_term->TI_cols; main_screen->co = current_term->co;
} }
return (1); return (1);
} }

View File

@@ -3174,8 +3174,8 @@ void winbx_init(void)
ShowWindow(HVTWin, SW_SHOWDEFAULT); ShowWindow(HVTWin, SW_SHOWDEFAULT);
ChangeCaret(); ChangeCaret();
current_term->TI_cols = co = 81; current_term->co = current_term->TI_cols = 81;
current_term->TI_lines = li = 25; current_term->li = current_term->TI_lines = 25;
#if 0 #if 0
while (GetMessage(&msg,NULL,0,0)) { while (GetMessage(&msg,NULL,0,0)) {
@@ -3325,7 +3325,7 @@ void gui_resize(Screen *this_screen)
/*cx = this_screen->co * this_screen->VIO_font_width; /*cx = this_screen->co * this_screen->VIO_font_width;
cy = this_screen->li * this_screen->VIO_font_height;*/ cy = this_screen->li * this_screen->VIO_font_height;*/
co = this_screen->co; li = this_screen->li; current_term->co = this_screen->co; current_term->li = this_screen->li;
/* Recalculate some stuff that was done in input.c previously */ /* Recalculate some stuff that was done in input.c previously */
this_screen->input_line = this_screen->li-1; this_screen->input_line = this_screen->li-1;

View File

@@ -940,8 +940,8 @@ void BX_recalculate_windows (Screen *screen)
if (dumb_mode) if (dumb_mode)
return; return;
#ifdef GUI #ifdef GUI
current_term->TI_lines = screen->li; current_term->li = screen->li;
current_term->TI_cols = screen->co; current_term->co = screen->co;
#endif #endif
if (!screen) /* it's a hidden window. ignore this */ if (!screen) /* it's a hidden window. ignore this */
@@ -951,10 +951,10 @@ void BX_recalculate_windows (Screen *screen)
*/ */
if (screen && !screen->current_window) if (screen && !screen->current_window)
{ {
int display_size = current_term->li - 2 - screen->window_list->double_status;
screen->window_list->top = 0; screen->window_list->top = 0;
screen->window_list->display_size = current_term->TI_lines - 2 - screen->window_list->double_status; screen->window_list->display_size = display_size;
screen->window_list->bottom = current_term->TI_lines - 2 - screen->window_list->double_status; screen->window_list->bottom = display_size;
old_li = current_term->TI_lines;
return; return;
} }
@@ -974,7 +974,7 @@ void BX_recalculate_windows (Screen *screen)
split += tmp->status_lines; split += tmp->status_lines;
} }
excess_li = current_term->TI_lines - old_li - split; excess_li = current_term->li - old_li - split;
for (tmp = screen->window_list; tmp; tmp = tmp->next) for (tmp = screen->window_list; tmp; tmp = tmp->next)
{ {