refactor: use int for Columns and Rows

This commit is contained in:
Björn Linse 2019-07-19 09:12:58 +02:00
parent 75928101f8
commit aa28e070e9
20 changed files with 94 additions and 92 deletions

View File

@ -1230,7 +1230,7 @@ static void do_filter(
/* Create the shell command in allocated memory. */
cmd_buf = make_filter_cmd(cmd, itmp, otmp);
ui_cursor_goto((int)Rows - 1, 0);
ui_cursor_goto(Rows - 1, 0);
if (do_out) {
if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) {

View File

@ -6417,7 +6417,7 @@ static void ex_stop(exarg_T *eap)
apply_autocmds(EVENT_VIMSUSPEND, NULL, NULL, false, NULL);
// TODO(bfredl): the TUI should do this on suspend
ui_cursor_goto((int)Rows - 1, 0);
ui_cursor_goto(Rows - 1, 0);
ui_call_grid_scroll(1, 0, Rows, 0, Columns, 1, 0);
ui_flush();
ui_call_suspend(); // call machine specific function

View File

@ -3499,15 +3499,17 @@ static void cursorcmd(void)
}
if (cmdmsg_rl) {
msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1));
msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1;
if (msg_row <= 0)
msg_row = cmdline_row + (ccline.cmdspos / (Columns - 1));
msg_col = Columns - (ccline.cmdspos % (Columns - 1)) - 1;
if (msg_row <= 0) {
msg_row = Rows - 1;
}
} else {
msg_row = cmdline_row + (ccline.cmdspos / (int)Columns);
msg_col = ccline.cmdspos % (int)Columns;
if (msg_row >= Rows)
msg_row = cmdline_row + (ccline.cmdspos / Columns);
msg_col = ccline.cmdspos % Columns;
if (msg_row >= Rows) {
msg_row = Rows - 1;
}
}
ui_cursor_goto(msg_row, msg_col);
@ -4168,14 +4170,15 @@ static int showmatches(expand_T *xp, int wildmenu)
maxlen = j;
}
if (xp->xp_context == EXPAND_TAGS_LISTFILES)
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
lines = num_files;
else {
/* compute the number of columns and lines for the listing */
maxlen += 2; /* two spaces between file names */
columns = ((int)Columns + 2) / maxlen;
if (columns < 1)
} else {
// compute the number of columns and lines for the listing
maxlen += 2; // two spaces between file names
columns = (Columns + 2) / maxlen;
if (columns < 1) {
columns = 1;
}
lines = (num_files + columns - 1) / columns;
}
@ -5964,13 +5967,14 @@ void ex_history(exarg_T *eap)
if (hist[i].hisstr != NULL
&& hist[i].hisnum >= j && hist[i].hisnum <= k) {
msg_putchar('\n');
sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ',
hist[i].hisnum);
if (vim_strsize(hist[i].hisstr) > (int)Columns - 10)
snprintf((char *)IObuff, IOSIZE, "%c%6d ", i == idx ? '>' : ' ',
hist[i].hisnum);
if (vim_strsize(hist[i].hisstr) > Columns - 10) {
trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff),
(int)Columns - 10, IOSIZE - (int)STRLEN(IObuff));
else
Columns - 10, IOSIZE - (int)STRLEN(IObuff));
} else {
STRCAT(IObuff, hist[i].hisstr);
}
msg_outtrans(IObuff);
ui_flush();
}

View File

@ -1928,7 +1928,7 @@ static int vgetorpeek(int advance)
set_option_value("paste", !p_paste, NULL, 0);
if (!(State & INSERT)) {
msg_col = 0;
msg_row = (int)Rows - 1;
msg_row = Rows - 1;
msg_clr_eos(); // clear ruler
}
status_redraw_all();

View File

@ -88,18 +88,15 @@ EXTERN struct nvim_stats_s {
#define NO_BUFFERS 1 // not all buffers loaded yet
// 0 not starting anymore
/*
* Number of Rows and Columns in the screen.
* Must be long to be able to use them as options in option.c.
* Note: Use default_grid.Rows and default_grid.Columns to access items in
* default_grid.chars[]. They may have different values when the screen
* wasn't (re)allocated yet after setting Rows or Columns (e.g., when starting
* up).
*/
// Number of Rows and Columns in the screen.
// Note: Use default_grid.Rows and default_grid.Columns to access items in
// default_grid.chars[]. They may have different values when the screen
// wasn't (re)allocated yet after setting Rows or Columns (e.g., when starting
// up).
#define DFLT_COLS 80 // default value for 'columns'
#define DFLT_ROWS 24 // default value for 'lines'
EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows in the screen
EXTERN long Columns INIT(= DFLT_COLS); // nr of columns in the screen
EXTERN int Rows INIT(= DFLT_ROWS); // nr of rows in the screen
EXTERN int Columns INIT(= DFLT_COLS); // nr of columns in the screen
// We use 64-bit file functions here, if available. E.g. ftello() returns
// off_t instead of long, which helps if long is 32 bit and off_t is 64 bit.

View File

@ -582,9 +582,9 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum,
*/
static void prt_message(char_u *s)
{
grid_fill(&default_grid, (int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ',
0);
grid_puts(&default_grid, s, (int)Rows - 1, 0, HL_ATTR(HLF_R));
// TODO(bfredl): delete this
grid_fill(&default_grid, Rows - 1, Rows, 0, Columns, ' ', ' ', 0);
grid_puts(&default_grid, s, Rows - 1, 0, HL_ATTR(HLF_R));
ui_flush();
}

View File

@ -1648,7 +1648,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts,
assert(buf_len >= 0);
// Print the context only if it fits on the same line.
if (msg_col + buf_len >= (int)Columns) {
if (msg_col + buf_len >= Columns) {
msg_putchar('\n');
}
msg_advance(12);

View File

@ -589,8 +589,8 @@ void getout(int exitval)
set_vim_var_nr(VV_EXITING, exitval);
/* Position the cursor on the last screen line, below all the text */
ui_cursor_goto((int)Rows - 1, 0);
// Position the cursor on the last screen line, below all the text
ui_cursor_goto(Rows - 1, 0);
/* Optionally print hashtable efficiency. */
hash_debug_results();
@ -656,8 +656,8 @@ void getout(int exitval)
wait_return(FALSE);
}
/* Position the cursor again, the autocommands may have moved it */
ui_cursor_goto((int)Rows - 1, 0);
// Position the cursor again, the autocommands may have moved it
ui_cursor_goto(Rows - 1, 0);
// Apply 'titleold'.
if (p_title && *p_titleold != NUL) {

View File

@ -846,11 +846,11 @@ void curs_columns(
prev_skipcol = curwin->w_skipcol;
int p_lines = 0;
int plines = 0;
if ((curwin->w_wrow >= curwin->w_height_inner
|| ((prev_skipcol > 0
|| curwin->w_wrow + p_so >= curwin->w_height_inner)
&& (p_lines =
&& (plines =
plines_win_nofill(curwin, curwin->w_cursor.lnum, false)) - 1
>= curwin->w_height_inner))
&& curwin->w_height_inner != 0
@ -869,20 +869,21 @@ void curs_columns(
extra = 1;
/* Compute last display line of the buffer line that we want at the
* bottom of the window. */
if (p_lines == 0)
p_lines = plines_win(curwin, curwin->w_cursor.lnum, false);
--p_lines;
if (p_lines > curwin->w_wrow + p_so) {
if (plines == 0) {
plines = plines_win(curwin, curwin->w_cursor.lnum, false);
}
plines--;
if (plines > curwin->w_wrow + p_so) {
assert(p_so <= INT_MAX);
n = curwin->w_wrow + (int)p_so;
} else {
n = plines;
}
else
n = p_lines;
if ((colnr_T)n >= curwin->w_height_inner + curwin->w_skipcol / width) {
extra += 2;
}
if (extra == 3 || p_lines < p_so * 2) {
if (extra == 3 || plines < p_so * 2) {
// not enough room for 'scrolloff', put cursor in the middle
n = curwin->w_virtcol / width;
if (n > curwin->w_height_inner / 2) {
@ -891,8 +892,8 @@ void curs_columns(
n = 0;
}
// don't skip more than necessary
if (n > p_lines - curwin->w_height_inner + 1) {
n = p_lines - curwin->w_height_inner + 1;
if (n > plines - curwin->w_height_inner + 1) {
n = plines - curwin->w_height_inner + 1;
}
curwin->w_skipcol = n * width;
} else if (extra == 1) {

View File

@ -3451,7 +3451,7 @@ static void display_showcmd(void)
return;
}
int showcmd_row = (int)Rows - 1;
int showcmd_row = Rows - 1;
grid_puts_line_start(&default_grid, showcmd_row);
if (!showcmd_is_clear) {

View File

@ -3433,7 +3433,7 @@ void ex_display(exarg_T *eap)
msg_putchar(name);
MSG_PUTS(" ");
int n = (int)Columns - 6;
int n = Columns - 6;
for (size_t j = 0; j < yb->y_size && n > 1; j++) {
if (j) {
MSG_PUTS_ATTR("^J", attr);
@ -3525,7 +3525,7 @@ dis_msg (
int n;
int l;
n = (int)Columns - 6;
n = Columns - 6;
while (*p != NUL
&& !(*p == ESC && skip_esc && *(p + 1) == NUL)
&& (n -= ptr2cells(p)) >= 0) {

View File

@ -4165,7 +4165,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
char_u *errmsg = NULL;
long old_value = *(long *)varp;
long old_Rows = Rows; // remember old Rows
long old_Columns = Columns; // remember old Columns
long *pp = (long *)varp;
// Disallow changing some options from secure mode.
@ -4432,36 +4431,41 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
// Check the (new) bounds for Rows and Columns here.
if (Rows < min_rows() && full_screen) {
if (p_lines < min_rows() && full_screen) {
if (errbuf != NULL) {
vim_snprintf((char *)errbuf, errbuflen,
_("E593: Need at least %d lines"), min_rows());
errmsg = errbuf;
}
Rows = min_rows();
p_lines = min_rows();
}
if (Columns < MIN_COLUMNS && full_screen) {
if (p_columns < MIN_COLUMNS && full_screen) {
if (errbuf != NULL) {
vim_snprintf((char *)errbuf, errbuflen,
_("E594: Need at least %d columns"), MIN_COLUMNS);
errmsg = errbuf;
}
Columns = MIN_COLUMNS;
p_columns = MIN_COLUMNS;
}
limit_screen_size();
// True max size is defined by check_shellsize()
p_lines = MIN(p_lines, INT_MAX);
p_columns = MIN(p_columns, INT_MAX);
// If the screen (shell) height has been changed, assume it is the
// physical screenheight.
if (old_Rows != Rows || old_Columns != Columns) {
if (p_lines != Rows || p_columns != Columns) {
// Changing the screen size is not allowed while updating the screen.
if (updating_screen) {
*pp = old_value;
} else if (full_screen) {
screen_resize((int)Columns, (int)Rows);
screen_resize((int)p_columns, (int)p_lines);
} else {
// TODO(bfredl): is this branch ever needed?
// Postpone the resizing; check the size and cmdline position for
// messages.
Rows = (int)p_lines;
Columns = (int)p_columns;
check_shellsize();
if (cmdline_row > Rows - p_ch && Rows > p_ch) {
assert(p_ch >= 0 && Rows - p_ch <= INT_MAX);
@ -5079,8 +5083,8 @@ showoptions(
* display the items
*/
if (run == 1) {
assert(Columns <= LONG_MAX - GAP
&& Columns + GAP >= LONG_MIN + 3
assert(Columns <= INT_MAX - GAP
&& Columns + GAP >= INT_MIN + 3
&& (Columns + GAP - 3) / INC >= INT_MIN
&& (Columns + GAP - 3) / INC <= INT_MAX);
cols = (int)((Columns + GAP - 3) / INC);

View File

@ -366,6 +366,7 @@ static char *(p_cb_values[]) = {"unnamed", "unnamedplus", NULL};
# define CB_UNNAMEDMASK (CB_UNNAMED | CB_UNNAMEDPLUS)
EXTERN long p_cwh; // 'cmdwinheight'
EXTERN long p_ch; // 'cmdheight'
EXTERN long p_columns; // 'columns'
EXTERN int p_confirm; // 'confirm'
EXTERN int p_cp; // 'compatible'
EXTERN char_u *p_cot; // 'completeopt'
@ -476,6 +477,7 @@ EXTERN char_u *p_langmap; // 'langmap'
EXTERN int p_lnr; // 'langnoremap'
EXTERN int p_lrm; // 'langremap'
EXTERN char_u *p_lm; // 'langmenu'
EXTERN long p_lines; // 'lines'
EXTERN long p_linespace; // 'linespace'
EXTERN char_u *p_lispwords; // 'lispwords'
EXTERN long p_ls; // 'laststatus'

View File

@ -379,10 +379,9 @@ return {
full_name='columns', abbreviation='co',
type='number', scope={'global'},
no_mkrc=true,
nodefault=true,
vi_def=true,
redraw={'everything'},
varname='Columns',
varname='p_columns',
defaults={if_true={vi=macros('DFLT_COLS')}}
},
{
@ -1384,10 +1383,9 @@ return {
full_name='lines',
type='number', scope={'global'},
no_mkrc=true,
nodefault=true,
vi_def=true,
redraw={'everything'},
varname='Rows',
varname='p_lines',
defaults={if_true={vi=macros('DFLT_ROWS')}}
},
{

View File

@ -321,10 +321,10 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf,
// Make sure the mouse position is valid. Some terminals may
// return weird values.
if (col >= Columns) {
col = (int)Columns - 1;
col = Columns - 1;
}
if (row >= Rows) {
row = (int)Rows - 1;
row = Rows - 1;
}
mouse_grid = 0;
mouse_row = row;

View File

@ -369,10 +369,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
// With interactive completion, the error message is not printed.
if (!(flags & EW_SILENT)) {
msg_putchar('\n'); // clear bottom line quickly
#if SIZEOF_LONG > SIZEOF_INT
assert(Rows <= (long)INT_MAX + 1);
#endif
cmdline_row = (int)(Rows - 1); // continue on last line
cmdline_row = Rows - 1; // continue on last line
MSG(_(e_wildexpand));
msg_start(); // don't overwrite this message
}

View File

@ -2654,7 +2654,7 @@ static void qf_msg(qf_info_T *qi, int which, char *lead)
}
xstrlcat((char *)buf, title, IOSIZE);
}
trunc_string(buf, buf, (int)Columns - 1, IOSIZE);
trunc_string(buf, buf, Columns - 1, IOSIZE);
msg(buf);
}

View File

@ -341,8 +341,7 @@ int update_screen(int type)
type = CLEAR;
} else if (type != CLEAR) {
check_for_delay(false);
grid_ins_lines(&default_grid, 0, msg_scrolled, (int)Rows,
0, (int)Columns);
grid_ins_lines(&default_grid, 0, msg_scrolled, Rows, 0, Columns);
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_floating) {
continue;
@ -1463,7 +1462,7 @@ static void win_update(win_T *wp)
// Last line isn't finished: Display "@@@" in the last screen line.
grid_puts_len(&wp->w_grid, (char_u *)"@@", 2, scr_row, 0, at_attr);
grid_fill(&wp->w_grid, scr_row, scr_row + 1, 2, (int)wp->w_grid.Columns,
grid_fill(&wp->w_grid, scr_row, scr_row + 1, 2, wp->w_grid.Columns,
'@', ' ', at_attr);
set_empty_rows(wp, srow);
wp->w_botline = lnum;
@ -4823,7 +4822,7 @@ win_redr_status_matches (
grid_puts(&default_grid, selstart, row, selstart_col, HL_ATTR(HLF_WM));
}
grid_fill(&default_grid, row, row + 1, clen, (int)Columns,
grid_fill(&default_grid, row, row + 1, clen, Columns,
fillchar, fillchar, attr);
}
@ -6808,13 +6807,11 @@ static void draw_tabline(void)
c = '_';
else
c = ' ';
grid_fill(&default_grid, 0, 1, col, (int)Columns, c, c,
attr_fill);
grid_fill(&default_grid, 0, 1, col, Columns, c, c, attr_fill);
/* Put an "X" for closing the current tab if there are several. */
if (first_tabpage->tp_next != NULL) {
grid_putchar(&default_grid, 'X', 0, (int)Columns - 1,
attr_nosel);
grid_putchar(&default_grid, 'X', 0, Columns - 1, attr_nosel);
tab_page_click_defs[Columns - 1] = (StlClickDefinition) {
.type = kStlClickTabClose,
.tabnr = 999,
@ -7177,6 +7174,8 @@ void screen_resize(int width, int height)
check_shellsize();
height = Rows;
width = Columns;
p_lines = Rows;
p_columns = Columns;
ui_call_grid_resize(1, width, height);
send_grid_resize = true;

View File

@ -2130,8 +2130,8 @@ static void version_msg(char *s)
int len = (int)STRLEN(s);
if (!got_int
&& (len < (int)Columns)
&& (msg_col + len >= (int)Columns)
&& (len < Columns)
&& (msg_col + len >= Columns)
&& (*s != '\n')) {
msg_putchar('\n');
}

View File

@ -1892,8 +1892,8 @@ void win_equal(
if (dir == 0)
dir = *p_ead;
win_equal_rec(next_curwin == NULL ? curwin : next_curwin, current,
topframe, dir, 0, tabline_height(),
(int)Columns, topframe->fr_height);
topframe, dir, 0, tabline_height(),
Columns, topframe->fr_height);
}
/*
@ -4742,9 +4742,10 @@ void shell_new_columns(void)
/* First try setting the widths of windows with 'winfixwidth'. If that
* doesn't result in the right width, forget about that option. */
frame_new_width(topframe, (int)Columns, FALSE, TRUE);
if (!frame_check_width(topframe, Columns))
frame_new_width(topframe, (int)Columns, FALSE, FALSE);
frame_new_width(topframe, Columns, false, true);
if (!frame_check_width(topframe, Columns)) {
frame_new_width(topframe, Columns, false, false);
}
(void)win_comp_pos(); /* recompute w_winrow and w_wincol */
}
@ -4890,7 +4891,7 @@ void win_setheight_win(int height, win_T *win)
// If there is extra space created between the last window and the command
// line, clear it.
if (full_screen && msg_scrolled == 0 && row < cmdline_row) {
grid_fill(&default_grid, row, cmdline_row, 0, (int)Columns, ' ', ' ', 0);
grid_fill(&default_grid, row, cmdline_row, 0, Columns, ' ', ' ', 0);
}
cmdline_row = row;
msg_row = row;
@ -5352,7 +5353,7 @@ void win_drag_status_line(win_T *dragwin, int offset)
fr = fr->fr_next;
}
row = win_comp_pos();
grid_fill(&default_grid, row, cmdline_row, 0, (int)Columns, ' ', ' ', 0);
grid_fill(&default_grid, row, cmdline_row, 0, Columns, ' ', ' ', 0);
cmdline_row = row;
p_ch = Rows - cmdline_row;
if (p_ch < 1)
@ -5721,8 +5722,7 @@ void command_height(void)
// clear the lines added to cmdline
if (full_screen) {
grid_fill(&default_grid, cmdline_row, (int)Rows, 0, (int)Columns, ' ',
' ', 0);
grid_fill(&default_grid, cmdline_row, Rows, 0, Columns, ' ', ' ', 0);
}
msg_row = cmdline_row;
redraw_cmdline = TRUE;