From d0bd057ffe76d1951b04e9295243d0db5fccb0cd Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 09:49:57 +0100 Subject: Cleanup: Fix bad assert. Assert will fail on first loop iteration (in that case, prtpos.bytes_printed is 0). --- src/nvim/hardcopy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index d072277d38..3898a29bca 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -731,7 +731,8 @@ void ex_hardcopy(exarg_T *eap) if (got_int || settings.user_abort) goto print_fail; - assert(prtpos.bytes_printed * 100 > prtpos.bytes_printed); + assert(prtpos.bytes_printed == 0 + || prtpos.bytes_printed * 100 > prtpos.bytes_printed); sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), page_count + 1 + side, prtpos.bytes_printed * 100 / bytes_to_print); -- cgit From 565c43668a02c1d97fa7640f8b6e066e35571f77 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 09:55:14 +0100 Subject: Cleanup: Remove local var bg_color@prt_get_attr(). --- src/nvim/hardcopy.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 3898a29bca..33eb43d56b 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -358,7 +358,6 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) { int colorindex; uint32_t fg_color; - uint32_t bg_color; char *color; pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL); @@ -367,8 +366,6 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL); { - bg_color = PRCOLOR_WHITE; - color = (char *)highlight_color(hl_id, (char_u *)"fg", modec); if (color == NULL) colorindex = 0; @@ -387,7 +384,7 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) fg_color = darken_rgb(fg_color); pattr->fg_color = fg_color; - pattr->bg_color = bg_color; + pattr->bg_color = PRCOLOR_WHITE; } static void prt_set_fg(uint32_t fg) -- cgit From d600c8fbb192438a728c0e728043850159944cfe Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 10:02:41 +0100 Subject: Cleanup: Refactor prt_{fg,bg,new_bg}col: int --> uint32_t. --- src/nvim/hardcopy.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 33eb43d56b..06acf3fced 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1264,11 +1264,11 @@ static int prt_need_underline; static int prt_underline; static int prt_do_underline; static int prt_need_fgcol; -static int prt_fgcol; +static uint32_t prt_fgcol; static int prt_need_bgcol; static int prt_do_bgcol; -static int prt_bgcol; -static int prt_new_bgcol; +static uint32_t prt_bgcol; +static uint32_t prt_new_bgcol; static int prt_attribute_change; static double prt_text_run; static int prt_page_num; @@ -1470,8 +1470,8 @@ static void prt_flush_buffer(void) prt_write_real(prt_line_height, 2); /* Lastly add the color of the background */ - r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; - g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; + r = (prt_new_bgcol & 0xff0000) >> 16; + g = (prt_new_bgcol & 0xff00) >> 8; b = prt_new_bgcol & 0xff; prt_write_real(r / 255.0, 3); prt_write_real(g / 255.0, 3); @@ -2957,8 +2957,8 @@ int mch_print_text_out(char_u *p, int len) } if (prt_need_fgcol) { unsigned int r, g, b; - r = ((unsigned)prt_fgcol & 0xff0000) >> 16; - g = ((unsigned)prt_fgcol & 0xff00) >> 8; + r = (prt_fgcol & 0xff0000) >> 16; + g = (prt_fgcol & 0xff00) >> 8; b = prt_fgcol & 0xff; prt_write_real(r / 255.0, 3); @@ -3079,17 +3079,15 @@ void mch_print_set_font(int iBold, int iItalic, int iUnderline) void mch_print_set_bg(uint32_t bgcol) { - assert(bgcol <= INT_MAX); - prt_bgcol = (int)bgcol; + prt_bgcol = bgcol; prt_attribute_change = TRUE; prt_need_bgcol = TRUE; } void mch_print_set_fg(uint32_t fgcol) { - assert(fgcol <= INT_MAX); - if ((int)fgcol != prt_fgcol) { - prt_fgcol = (int)fgcol; + if (fgcol != prt_fgcol) { + prt_fgcol = fgcol; prt_attribute_change = TRUE; prt_need_fgcol = TRUE; } -- cgit From 28e75d4c453dcf7b1d1630815036d0236cfa0034 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 10:29:17 +0100 Subject: Cleanup: Refactor option_table_T.number: long --> int. --- src/nvim/hardcopy.c | 12 +++++------- src/nvim/hardcopy.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 06acf3fced..69285b3f32 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -320,7 +320,9 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E552: digit expected"); - table[idx].number = getdigits(&p); /*advances p*/ + long digits = getdigits(&p); + assert(digits >= INT_MIN && digits >= INT_MAX); + table[idx].number = (int)digits; } table[idx].string = p; @@ -452,9 +454,7 @@ static void prt_line_number(prt_settings_T *psettings, int page_line, linenr_T l int prt_header_height(void) { if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) { - assert(printer_opts[OPT_PRINT_HEADERHEIGHT].number >= INT_MIN - && printer_opts[OPT_PRINT_HEADERHEIGHT].number <= INT_MAX); - return (int)printer_opts[OPT_PRINT_HEADERHEIGHT].number; + return printer_opts[OPT_PRINT_HEADERHEIGHT].number; } return 2; } @@ -1958,9 +1958,7 @@ static double to_device_units(int idx, double physsize, int def_number) u = PRT_UNIT_PERC; nr = def_number; } else { - assert(printer_opts[idx].number >= INT_MIN - && printer_opts[idx].number <= INT_MAX); - nr = (int)printer_opts[idx].number; + nr = printer_opts[idx].number; } switch (u) { diff --git a/src/nvim/hardcopy.h b/src/nvim/hardcopy.h index 9a74396ef4..4ead8dd5d4 100644 --- a/src/nvim/hardcopy.h +++ b/src/nvim/hardcopy.h @@ -40,7 +40,7 @@ typedef struct { typedef struct { const char *name; int hasnum; - long number; + int number; char_u *string; /* points into option string */ int strlen; int present; -- cgit From 04c0658024a98a0586997f0ea8af1e3f774cc83e Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 12:55:38 +0100 Subject: Cleanup: Refactor getdigits(). Problem : getdigits() currently returns a long, but at most places, return value is casted (unsafely) into an int. Making casts safe would introduce a lot of fuss in the form of assertions checking for limits. Note : We cannot just change return type to int, because, at some places, legitimate long values are used. For example, in diff.c, for line numbers. Solution : Introduce new functions: - get_digits() : Gets an intmax_t from a string. - get_int_digits() : Wrapper for ints. - get_long_digits() : Wrapper for longs. And replace getdigits() invocations by the appropiate wrapper invocations. --- src/nvim/buffer.c | 8 ++++---- src/nvim/charset.c | 45 ++++++++++++++++++++++++++++----------------- src/nvim/cursor_shape.c | 4 +--- src/nvim/diff.c | 12 ++++++------ src/nvim/digraph.c | 4 +--- src/nvim/eval.c | 4 ++-- src/nvim/ex_cmds.c | 8 ++++---- src/nvim/ex_cmds2.c | 2 +- src/nvim/ex_docmd.c | 26 +++++++++++++------------- src/nvim/hardcopy.c | 4 +--- src/nvim/indent_c.c | 8 ++------ src/nvim/mark.c | 4 ++-- src/nvim/menu.c | 2 +- src/nvim/misc1.c | 2 +- src/nvim/ops.c | 2 +- src/nvim/option.c | 14 +++++++------- src/nvim/regexp.c | 4 ++-- src/nvim/search.c | 2 +- src/nvim/spell.c | 14 ++++++++------ src/nvim/syntax.c | 8 ++++---- src/nvim/term.c | 26 +++++++++++--------------- src/nvim/ui.c | 4 ++-- src/nvim/window.c | 2 +- 23 files changed, 104 insertions(+), 105 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4c40cd631e..5c1b01130d 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -750,7 +750,7 @@ do_bufdel ( break; arg = p; } else - bnr = getdigits(&arg); + bnr = get_int_digits(&arg); } } if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, @@ -2997,7 +2997,7 @@ build_stl_str_hl ( l = -1; } if (VIM_ISDIGIT(*s)) { - minwid = (int)getdigits(&s); + minwid = get_int_digits(&s); if (minwid < 0) /* overflow */ minwid = 0; } @@ -3033,7 +3033,7 @@ build_stl_str_hl ( if (*s == '.') { s++; if (VIM_ISDIGIT(*s)) { - maxwid = (int)getdigits(&s); + maxwid = get_int_digits(&s); if (maxwid <= 0) /* overflow */ maxwid = 50; } @@ -4077,7 +4077,7 @@ chk_modeline ( e = s + 4; else e = s + 3; - vers = getdigits(&e); + vers = get_int_digits(&e); if (*e == ':' && (s[0] != 'V' || STRNCMP(skipwhite(e + 1), "set", 3) == 0) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 32427cc3ba..91d8f221c9 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -177,7 +177,7 @@ int buf_init_chartab(buf_T *buf, int global) } if (VIM_ISDIGIT(*p)) { - c = getdigits(&p); + c = get_int_digits(&p); } else if (has_mbyte) { c = mb_ptr2char_adv(&p); } else { @@ -189,7 +189,7 @@ int buf_init_chartab(buf_T *buf, int global) ++p; if (VIM_ISDIGIT(*p)) { - c2 = getdigits(&p); + c2 = get_int_digits(&p); } else if (has_mbyte) { c2 = mb_ptr2char_adv(&p); } else { @@ -1676,26 +1676,37 @@ char_u* skiptowhite_esc(char_u *p) { return p; } -/// Getdigits: Get a number from a string and skip over it. +/// Get a number from a string and skip over it. /// -/// Note: the argument is a pointer to a char_u pointer! +/// @param[out] pp A pointer to a pointer to char_u. +/// It will be advanced past the read number. /// -/// @param pp +/// @return Number read from the string. +intmax_t get_digits(char_u **pp) +{ + intmax_t number = strtoimax((char *)*pp, (char **)pp, 10); + assert(errno != ERANGE); + return number; +} + +/// Get an int number from a string. /// -/// @return Number from the string. -long getdigits(char_u **pp) +/// A get_digits wrapper restricted to int values. +int get_int_digits(char_u **pp) { - char_u *p = *pp; - long retval = atol((char *)p); + intmax_t number = get_digits(pp); + assert(number >= INT_MIN && number <= INT_MAX); + return (int)number; +} - if (*p == '-') { - // skip negative sign - ++p; - } - // skip to next non-digit - p = skipdigits(p); - *pp = p; - return retval; +/// Get a long number from a string. +/// +/// A get_digits wrapper restricted to long values. +long get_long_digits(char_u **pp) +{ + intmax_t number = get_digits(pp); + assert(number >= LONG_MIN && number <= LONG_MAX); + return (long)number; } /// Return TRUE if "lbuf" is empty or only contains blanks. diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 87064b4ef3..3dab383dcd 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -135,9 +135,7 @@ char_u *parse_shape_opt(int what) p += len; if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E548: digit expected"); - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = get_int_digits(&p); if (len == 3) { /* "ver" or "hor" */ if (n == 0) return (char_u *)N_("E549: Illegal percentage"); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7e31c3f216..307ccadf5f 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1221,11 +1221,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) // {first}a{first}[,{last}] // {first}[,{last}]d{first} p = linebuf; - f1 = getdigits(&p); + f1 = get_long_digits(&p); if (*p == ',') { ++p; - l1 = getdigits(&p); + l1 = get_long_digits(&p); } else { l1 = f1; } @@ -1235,11 +1235,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) continue; } difftype = *p++; - f2 = getdigits(&p); + f2 = get_long_digits(&p); if (*p == ',') { ++p; - l2 = getdigits(&p); + l2 = get_long_digits(&p); } else { l2 = f2; } @@ -1783,7 +1783,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_FILLER; } else if ((STRNCMP(p, "context:", 8) == 0) && VIM_ISDIGIT(p[8])) { p += 8; - diff_context_new = getdigits(&p); + diff_context_new = get_int_digits(&p); } else if (STRNCMP(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; @@ -1798,7 +1798,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_VERTICAL; } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && VIM_ISDIGIT(p[11])) { p += 11; - diff_foldcolumn_new = getdigits(&p); + diff_foldcolumn_new = get_int_digits(&p); } if ((*p != ',') && (*p != NUL)) { diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 2b5fdea2fe..7a24203594 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1611,9 +1611,7 @@ void putdigraph(char_u *str) EMSG(_(e_number_exp)); return; } - int64_t digits = getdigits(&str); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = get_int_digits(&str); // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9974315d3f..e921f3a1a8 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2750,7 +2750,7 @@ void ex_lockvar(exarg_T *eap) if (eap->forceit) deep = -1; else if (vim_isdigit(*arg)) { - deep = getdigits(&arg); + deep = get_int_digits(&arg); arg = skipwhite(arg); } @@ -13370,7 +13370,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) yank_type = MBLOCK; if (VIM_ISDIGIT(stropt[1])) { ++stropt; - block_len = getdigits(&stropt) - 1; + block_len = get_long_digits(&stropt) - 1; --stropt; } break; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 3278de3561..6bd9da0c28 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -569,7 +569,7 @@ void ex_retab(exarg_T *eap) save_list = curwin->w_p_list; curwin->w_p_list = 0; /* don't want list mode here */ - new_ts = getdigits(&(eap->arg)); + new_ts = get_int_digits(&(eap->arg)); if (new_ts < 0) { EMSG(_(e_positive)); return; @@ -3674,7 +3674,7 @@ void do_sub(exarg_T *eap) */ cmd = skipwhite(cmd); if (VIM_ISDIGIT(*cmd)) { - i = getdigits(&cmd); + i = get_long_digits(&cmd); if (i <= 0 && !eap->skip && do_error) { EMSG(_(e_zerocount)); return; @@ -5920,7 +5920,7 @@ void ex_sign(exarg_T *eap) arg1 = arg; if (VIM_ISDIGIT(*arg)) { - id = getdigits(&arg); + id = get_int_digits(&arg); if (!vim_iswhite(*arg) && *arg != NUL) { id = -1; @@ -5985,7 +5985,7 @@ void ex_sign(exarg_T *eap) else if (STRNCMP(arg, "buffer=", 7) == 0) { arg += 7; - buf = buflist_findnr((int)getdigits(&arg)); + buf = buflist_findnr(get_int_digits(&arg)); if (*skipwhite(arg) != NUL) EMSG(_(e_trailing)); break; diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 072972d24e..d4e5f138fc 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -471,7 +471,7 @@ dbg_parsearg ( else if ( gap != &prof_ga && VIM_ISDIGIT(*p)) { - bp->dbg_lnum = getdigits(&p); + bp->dbg_lnum = get_long_digits(&p); p = skipwhite(p); } else bp->dbg_lnum = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index ca79270fcc..abc205a1e8 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1733,7 +1733,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, if ((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg) && (!(ea.argt & BUFNAME) || *(p = skipdigits(ea.arg)) == NUL || vim_iswhite(*p))) { - n = getdigits(&ea.arg); + n = get_long_digits(&ea.arg); ea.arg = skipwhite(ea.arg); if (n <= 0 && !ni && (ea.argt & ZEROR) == 0) { errormsg = (char_u *)_(e_zerocount); @@ -3250,7 +3250,7 @@ get_address ( default: if (VIM_ISDIGIT(*cmd)) /* absolute line number */ - lnum = getdigits(&cmd); + lnum = get_long_digits(&cmd); } for (;; ) { @@ -3267,7 +3267,7 @@ get_address ( if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */ n = 1; else - n = getdigits(&cmd); + n = get_long_digits(&cmd); if (i == '-') lnum -= n; else @@ -4439,7 +4439,7 @@ two_count: return FAIL; } - *def = getdigits(&p); + *def = get_long_digits(&p); *argt |= (ZEROR | NOTADR); if (p != val + vallen || vallen == 0) { @@ -4456,7 +4456,7 @@ invalid_count: if (*def >= 0) goto two_count; - *def = getdigits(&p); + *def = get_long_digits(&p); if (p != val + vallen) goto invalid_count; @@ -5819,7 +5819,7 @@ static void ex_tabmove(exarg_T *eap) return; } - tab_number = getdigits(&p); + tab_number = get_int_digits(&p); if (relative != 0) tab_number = tab_number * relative + tabpage_index(curtab) - 1; ; } else if (eap->addr_count != 0) @@ -6441,10 +6441,10 @@ static void ex_winsize(exarg_T *eap) char_u *arg = eap->arg; char_u *p; - w = getdigits(&arg); + w = get_int_digits(&arg); arg = skipwhite(arg); p = arg; - h = getdigits(&arg); + h = get_int_digits(&arg); if (*p != NUL && *arg == NUL) screen_resize(w, h, TRUE); else @@ -6494,10 +6494,10 @@ static void ex_winpos(exarg_T *eap) if (*arg == NUL) { EMSG(_("E188: Obtaining window position not implemented for this platform")); } else { - x = getdigits(&arg); + x = get_int_digits(&arg); arg = skipwhite(arg); p = arg; - y = getdigits(&arg); + y = get_int_digits(&arg); if (*p == NUL || *arg != NUL) { EMSG(_("E466: :winpos requires two number arguments")); return; @@ -6744,7 +6744,7 @@ static void ex_later(exarg_T *eap) if (*p == NUL) count = 1; else if (isdigit(*p)) { - count = getdigits(&p); + count = get_long_digits(&p); switch (*p) { case 's': ++p; sec = TRUE; break; case 'm': ++p; sec = TRUE; count *= 60; break; @@ -7354,7 +7354,7 @@ static void ex_findpat(exarg_T *eap) n = 1; if (vim_isdigit(*eap->arg)) { /* get count */ - n = getdigits(&eap->arg); + n = get_long_digits(&eap->arg); eap->arg = skipwhite(eap->arg); } if (*eap->arg == '/') { /* Match regexp, not just whole words */ @@ -7618,7 +7618,7 @@ eval_vars ( s = src + 1; if (*s == '<') /* "#<99" uses v:oldfiles */ ++s; - i = (int)getdigits(&s); + i = get_int_digits(&s); *usedlen = (int)(s - src); /* length of what we expand */ if (src[1] == '<') { diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 69285b3f32..1f0a0872a5 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -320,9 +320,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E552: digit expected"); - long digits = getdigits(&p); - assert(digits >= INT_MIN && digits >= INT_MAX); - table[idx].number = (int)digits; + table[idx].number = get_int_digits(&p); } table[idx].string = p; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 39ad512227..94d2a2ffff 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1463,9 +1463,7 @@ void parse_cino(buf_T *buf) if (*p == '-') ++p; char_u *digits_start = p; /* remember where the digits start */ - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = get_int_digits(&p); divider = 0; if (*p == '.') { /* ".5s" means a fraction */ fraction = atoi((char *)++p); @@ -1678,9 +1676,7 @@ int get_c_indent(void) else if (*p == COM_LEFT || *p == COM_RIGHT) align = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') { - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - off = (int)digits; + off = get_int_digits(&p); } else ++p; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index ef9f0ca408..abe05dfb30 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1226,9 +1226,9 @@ int read_viminfo_filemark(vir_T *virp, int force) } if (fm != NULL && (fm->fmark.mark.lnum == 0 || force)) { str = skipwhite(str + 1); - fm->fmark.mark.lnum = getdigits(&str); + fm->fmark.mark.lnum = get_long_digits(&str); str = skipwhite(str); - fm->fmark.mark.col = getdigits(&str); + fm->fmark.mark.col = get_int_digits(&str); fm->fmark.mark.coladd = 0; fm->fmark.fnum = 0; str = skipwhite(str); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index b31b6c1cec..dffd1f41c5 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -120,7 +120,7 @@ ex_menu ( break; if (vim_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !vim_iswhite(*arg); ++i) { - pri_tab[i] = getdigits(&arg); + pri_tab[i] = get_int_digits(&arg); if (pri_tab[i] == 0) pri_tab[i] = 500; if (*arg == '.') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 4f17f84e11..912babefb6 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -525,7 +525,7 @@ open_line ( if (*p == COM_RIGHT || *p == COM_LEFT) c = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') - off = getdigits(&p); + off = get_int_digits(&p); else ++p; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 3cefc9f623..d471453ffd 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4501,7 +4501,7 @@ int read_viminfo_register(vir_T *virp, int force) y_current->y_type = MLINE; /* get the block width; if it's missing we get a zero, which is OK */ str = skipwhite(skiptowhite(str)); - y_current->y_width = getdigits(&str); + y_current->y_width = get_int_digits(&str); } while (!(eof = viminfo_readline(virp)) diff --git a/src/nvim/option.c b/src/nvim/option.c index 20e983b253..2c9bd58d08 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2918,7 +2918,7 @@ do_set ( */ else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) { - i = getdigits((char_u **)varp); + i = get_int_digits((char_u **)varp); switch (i) { case 0: *(char_u **)varp = empty_option; @@ -2943,7 +2943,7 @@ do_set ( else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) { *errbuf = NUL; - i = getdigits(&arg); + i = get_int_digits(&arg); if (i & 1) STRCAT(errbuf, "b,"); if (i & 2) @@ -4359,7 +4359,7 @@ did_set_string_option ( /* set ru_wid if 'ruf' starts with "%99(" */ if (*++s == '-') /* ignore a '-' */ s++; - wid = getdigits(&s); + wid = get_int_digits(&s); if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) ru_wid = wid; else @@ -4664,14 +4664,14 @@ char_u *check_colorcolumn(win_T *wp) ++s; if (!VIM_ISDIGIT(*s)) return e_invarg; - col = col * getdigits(&s); + col = col * get_int_digits(&s); if (wp->w_buffer->b_p_tw == 0) goto skip; /* 'textwidth' not set, skip this item */ col += wp->w_buffer->b_p_tw; if (col < 0) goto skip; } else if (VIM_ISDIGIT(*s)) - col = getdigits(&s); + col = get_int_digits(&s); else return e_invarg; color_cols[count++] = col - 1; /* 1-based to 0-based */ @@ -8114,12 +8114,12 @@ static bool briopt_check(win_T *wp) && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6]))) { p += 6; - bri_shift = getdigits(&p); + bri_shift = get_int_digits(&p); } else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) { p += 4; - bri_min = getdigits(&p); + bri_min = get_long_digits(&p); } else if (STRNCMP(p, "sbr", 3) == 0) { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index dd7af63ce0..326640118b 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3082,10 +3082,10 @@ static int read_limits(long *minval, long *maxval) reverse = TRUE; } first_char = regparse; - *minval = getdigits(®parse); + *minval = get_long_digits(®parse); if (*regparse == ',') { /* There is a comma */ if (vim_isdigit(*++regparse)) - *maxval = getdigits(®parse); + *maxval = get_long_digits(®parse); else *maxval = MAX_LIMIT; } else if (VIM_ISDIGIT(*first_char)) diff --git a/src/nvim/search.c b/src/nvim/search.c index d3946a9b63..bd2a49c2d2 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4611,7 +4611,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force) if (lp[4] == 'E') off_end = SEARCH_END; lp += 5; - off = getdigits(&lp); + off = get_long_digits(&lp); } if (lp[0] == '~') { /* use this pattern for last-used pattern */ setlast = TRUE; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b8713909b8..af020198d3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5162,7 +5162,7 @@ static unsigned get_affitem(int flagtype, char_u **pp) ++*pp; // always advance, avoid getting stuck return 0; } - res = getdigits(pp); + res = get_int_digits(pp); } else { res = mb_ptr2char_adv(pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG @@ -5283,7 +5283,9 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) case AFT_NUM: for (p = afflist; *p != NUL; ) { - n = getdigits(&p); + int digits = get_int_digits(&p); + assert(digits >= 0); + n = (unsigned int)digits; if (n == flag) return true; if (*p != NUL) // skip over comma @@ -6357,19 +6359,19 @@ int spell_check_msm(void) if (!VIM_ISDIGIT(*p)) return FAIL; // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (getdigits(&p) * 10) / (SBLOCKSIZE / 102); + start = (get_long_digits(&p) * 10) / (SBLOCKSIZE / 102); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - incr = (getdigits(&p) * 102) / (SBLOCKSIZE / 10); + incr = (get_long_digits(&p) * 102) / (SBLOCKSIZE / 10); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - added = getdigits(&p) * 1024; + added = get_long_digits(&p) * 1024; if (*p != NUL) return FAIL; @@ -8355,7 +8357,7 @@ int spell_check_sps(void) f = 0; if (VIM_ISDIGIT(*buf)) { s = buf; - sps_limit = getdigits(&s); + sps_limit = get_int_digits(&s); if (*s != NUL && !VIM_ISDIGIT(*s)) f = -1; } else if (STRCMP(buf, "best") == 0) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f35da39bb3..6975932f2c 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4900,7 +4900,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) ci->sp_off_flags |= (1 << idx); if (idx == SPO_LC_OFF) { /* lc=99 */ end += 3; - *p = getdigits(&end); + *p = get_int_digits(&end); /* "lc=" offset automatically sets "ms=" offset */ if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) { @@ -4911,10 +4911,10 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) end += 4; if (*end == '+') { ++end; - *p = getdigits(&end); /* positive offset */ + *p = get_int_digits(&end); /* positive offset */ } else if (*end == '-') { ++end; - *p = -getdigits(&end); /* negative offset */ + *p = -get_int_digits(&end); /* negative offset */ } } if (*end != ',') @@ -4980,7 +4980,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) illegal = TRUE; break; } - n = getdigits(&arg_end); + n = get_long_digits(&arg_end); if (!eap->skip) { if (key[4] == 'B') curwin->w_s->b_syn_sync_linebreaks = n; diff --git a/src/nvim/term.c b/src/nvim/term.c index dfc42632c6..8e4efd69fb 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -3230,7 +3230,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ p = tp + slen; - mouse_code = getdigits(&p); + mouse_code = get_long_digits(&p); if (*p++ != ';') return -1; @@ -3238,15 +3238,11 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) if (key_name[0] == KS_SGR_MOUSE) mouse_code += 32; - long digits = getdigits(&p); - assert(digits >= INT_MIN && digits <= INT_MAX); - mouse_col = (int)digits - 1; + mouse_col = get_int_digits(&p); if (*p++ != ';') return -1; - digits = getdigits(&p); - assert(digits >= INT_MIN && digits <= INT_MAX); - mouse_row = (int)digits - 1; + mouse_row = get_int_digits(&p); if (key_name[0] == KS_SGR_MOUSE && *p == 'm') mouse_code |= MOUSE_RELEASE; else if (*p != 'M') @@ -3273,7 +3269,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } } p += j; - if (cmd_complete && getdigits(&p) == mouse_code) { + if (cmd_complete && get_long_digits(&p) == mouse_code) { slen += j; /* skip the \033[ */ continue; } @@ -3319,10 +3315,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) * '6' is the row, 45 is the column */ p = tp + slen; - mr = getdigits(&p); + mr = get_long_digits(&p); if (*p++ != ',') return -1; - mc = getdigits(&p); + mc = get_long_digits(&p); if (*p++ != '\r') return -1; @@ -3389,27 +3385,27 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) p = tp + slen; /* get event status */ - Pe = getdigits(&p); + Pe = get_long_digits(&p); if (*p++ != ';') return -1; /* get button status */ - Pb = getdigits(&p); + Pb = get_long_digits(&p); if (*p++ != ';') return -1; /* get row status */ - Pr = getdigits(&p); + Pr = get_long_digits(&p); if (*p++ != ';') return -1; /* get column status */ - Pc = getdigits(&p); + Pc = get_long_digits(&p); /* the page parameter is optional */ if (*p == ';') { p++; - (void)getdigits(&p); + (void)get_long_digits(&p); } if (*p++ != '&') return -1; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 9c58193e8c..a0b45c1077 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -344,14 +344,14 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) assert(p != end); if (VIM_ISDIGIT(*p)) { - arg1 = (int)getdigits(&p); + arg1 = get_int_digits(&p); if (p >= end) { break; } if (*p == ';') { p++; - arg2 = (int)getdigits(&p); + arg2 = get_int_digits(&p); if (p >= end) break; } diff --git a/src/nvim/window.c b/src/nvim/window.c index ed4a8d8e7a..cfe60c65f3 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4908,7 +4908,7 @@ file_name_in_line ( ++p; /* skip the separator */ p = skipwhite(p); if (isdigit(*p)) - *file_lnum = (int)getdigits(&p); + *file_lnum = get_long_digits(&p); } } -- cgit From bb737b6f0e41e16dddf5c4d0d12d406adfcd5851 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 13:26:50 +0100 Subject: Cleanup: Refactor variables: long --> int. At 31c8440fee0bd694093d83af5dee20e3c3dc876c, some variables were changed from int to long, to avoid -Wconversion errors. Long type was the appropiate one because getdigits() was returning a long. Now that we have get_int_digits() and get_long_digits(), we can revert mentioned variables to int, and use get_int_digits() without having -Wconversion warnings. --- src/nvim/term.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/nvim/term.c b/src/nvim/term.c index 8e4efd69fb..b65e750974 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -2819,13 +2819,13 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) char_u bytes[6]; int num_bytes; # endif - long mouse_code = 0; /* init for GCC */ + int mouse_code = 0; /* init for GCC */ int is_click, is_drag; - long wheel_code = 0; - long current_button; - static long held_button = MOUSE_RELEASE; + int wheel_code = 0; + int current_button; + static int held_button = MOUSE_RELEASE; static int orig_num_clicks = 1; - static long orig_mouse_code = 0x0; + static int orig_mouse_code = 0x0; int cpo_koffset; cpo_koffset = (vim_strchr(p_cpo, CPO_KOFFSET) != NULL); @@ -3230,7 +3230,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ p = tp + slen; - mouse_code = get_long_digits(&p); + mouse_code = get_int_digits(&p); if (*p++ != ';') return -1; @@ -3269,7 +3269,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } } p += j; - if (cmd_complete && get_long_digits(&p) == mouse_code) { + if (cmd_complete && get_int_digits(&p) == mouse_code) { slen += j; /* skip the \033[ */ continue; } @@ -3308,24 +3308,22 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } # endif /* !UNIX || FEAT_MOUSE_XTERM */ if (key_name[0] == (int)KS_NETTERM_MOUSE) { - long mc, mr; + int mc, mr; /* expect a rather limited sequence like: balancing { * \033}6,45\r * '6' is the row, 45 is the column */ p = tp + slen; - mr = get_long_digits(&p); + mr = get_int_digits(&p); if (*p++ != ',') return -1; - mc = get_long_digits(&p); + mc = get_int_digits(&p); if (*p++ != '\r') return -1; - assert(mc - 1 >= INT_MIN && mc - 1 <= INT_MAX); - mouse_col = (int)(mc - 1); - assert(mr - 1 >= INT_MIN && mr - 1 <= INT_MAX); - mouse_row = (int)(mr - 1); + mouse_col = mc - 1; + mouse_row = mr - 1; mouse_code = MOUSE_LEFT; slen += (int)(p - (tp + slen)); } @@ -3380,32 +3378,32 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) * The page coordinate may be omitted if the locator is on * page one (the default). We ignore it anyway. */ - long Pe, Pb, Pr, Pc; + int Pe, Pb, Pr, Pc; p = tp + slen; /* get event status */ - Pe = get_long_digits(&p); + Pe = get_int_digits(&p); if (*p++ != ';') return -1; /* get button status */ - Pb = get_long_digits(&p); + Pb = get_int_digits(&p); if (*p++ != ';') return -1; /* get row status */ - Pr = get_long_digits(&p); + Pr = get_int_digits(&p); if (*p++ != ';') return -1; /* get column status */ - Pc = get_long_digits(&p); + Pc = get_int_digits(&p); /* the page parameter is optional */ if (*p == ';') { p++; - (void)get_long_digits(&p); + (void)get_int_digits(&p); } if (*p++ != '&') return -1; @@ -3449,10 +3447,8 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) default: return -1; /* should never occur */ } - assert(Pc - 1 >= INT_MIN && Pc - 1 <= INT_MAX); - mouse_col = (int)(Pc - 1); - assert(Pr - 1 >= INT_MIN && Pr - 1 <= INT_MAX); - mouse_row = (int)(Pr - 1); + mouse_col = Pc - 1; + mouse_row = Pr - 1; slen += (int)(p - (tp + slen)); } @@ -3540,8 +3536,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) key_name[1] = (wheel_code & 1) ? (int)KE_MOUSEUP : (int)KE_MOUSEDOWN; } else { - assert(current_button >= INT_MIN && current_button <= INT_MAX); - key_name[1] = (char_u)get_pseudo_mouse_code((int)current_button, + key_name[1] = (char_u)get_pseudo_mouse_code(current_button, is_click, is_drag); } } -- cgit From 7f7262e93390a1855ac9c687bd492eadfe10cf98 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 20:57:33 +0100 Subject: Cleanup: Rename getdigits() family functions. --- src/nvim/buffer.c | 8 ++++---- src/nvim/charset.c | 18 +++++++++--------- src/nvim/cursor_shape.c | 2 +- src/nvim/diff.c | 12 ++++++------ src/nvim/digraph.c | 2 +- src/nvim/eval.c | 4 ++-- src/nvim/ex_cmds.c | 8 ++++---- src/nvim/ex_cmds2.c | 2 +- src/nvim/ex_docmd.c | 26 +++++++++++++------------- src/nvim/hardcopy.c | 2 +- src/nvim/indent_c.c | 4 ++-- src/nvim/mark.c | 4 ++-- src/nvim/menu.c | 2 +- src/nvim/misc1.c | 2 +- src/nvim/ops.c | 2 +- src/nvim/option.c | 14 +++++++------- src/nvim/regexp.c | 4 ++-- src/nvim/search.c | 2 +- src/nvim/spell.c | 12 ++++++------ src/nvim/syntax.c | 8 ++++---- src/nvim/term.c | 22 +++++++++++----------- src/nvim/ui.c | 4 ++-- src/nvim/window.c | 2 +- 23 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5c1b01130d..58310a22a4 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -750,7 +750,7 @@ do_bufdel ( break; arg = p; } else - bnr = get_int_digits(&arg); + bnr = getdigits_int(&arg); } } if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, @@ -2997,7 +2997,7 @@ build_stl_str_hl ( l = -1; } if (VIM_ISDIGIT(*s)) { - minwid = get_int_digits(&s); + minwid = getdigits_int(&s); if (minwid < 0) /* overflow */ minwid = 0; } @@ -3033,7 +3033,7 @@ build_stl_str_hl ( if (*s == '.') { s++; if (VIM_ISDIGIT(*s)) { - maxwid = get_int_digits(&s); + maxwid = getdigits_int(&s); if (maxwid <= 0) /* overflow */ maxwid = 50; } @@ -4077,7 +4077,7 @@ chk_modeline ( e = s + 4; else e = s + 3; - vers = get_int_digits(&e); + vers = getdigits_int(&e); if (*e == ':' && (s[0] != 'V' || STRNCMP(skipwhite(e + 1), "set", 3) == 0) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 91d8f221c9..8781e389ed 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -177,7 +177,7 @@ int buf_init_chartab(buf_T *buf, int global) } if (VIM_ISDIGIT(*p)) { - c = get_int_digits(&p); + c = getdigits_int(&p); } else if (has_mbyte) { c = mb_ptr2char_adv(&p); } else { @@ -189,7 +189,7 @@ int buf_init_chartab(buf_T *buf, int global) ++p; if (VIM_ISDIGIT(*p)) { - c2 = get_int_digits(&p); + c2 = getdigits_int(&p); } else if (has_mbyte) { c2 = mb_ptr2char_adv(&p); } else { @@ -1682,7 +1682,7 @@ char_u* skiptowhite_esc(char_u *p) { /// It will be advanced past the read number. /// /// @return Number read from the string. -intmax_t get_digits(char_u **pp) +intmax_t getdigits(char_u **pp) { intmax_t number = strtoimax((char *)*pp, (char **)pp, 10); assert(errno != ERANGE); @@ -1691,20 +1691,20 @@ intmax_t get_digits(char_u **pp) /// Get an int number from a string. /// -/// A get_digits wrapper restricted to int values. -int get_int_digits(char_u **pp) +/// A getdigits wrapper restricted to int values. +int getdigits_int(char_u **pp) { - intmax_t number = get_digits(pp); + intmax_t number = getdigits(pp); assert(number >= INT_MIN && number <= INT_MAX); return (int)number; } /// Get a long number from a string. /// -/// A get_digits wrapper restricted to long values. -long get_long_digits(char_u **pp) +/// A getdigits wrapper restricted to long values. +long getdigits_long(char_u **pp) { - intmax_t number = get_digits(pp); + intmax_t number = getdigits(pp); assert(number >= LONG_MIN && number <= LONG_MAX); return (long)number; } diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 3dab383dcd..2e98b8f512 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -135,7 +135,7 @@ char_u *parse_shape_opt(int what) p += len; if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E548: digit expected"); - int n = get_int_digits(&p); + int n = getdigits_int(&p); if (len == 3) { /* "ver" or "hor" */ if (n == 0) return (char_u *)N_("E549: Illegal percentage"); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 307ccadf5f..6cc75e948c 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1221,11 +1221,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) // {first}a{first}[,{last}] // {first}[,{last}]d{first} p = linebuf; - f1 = get_long_digits(&p); + f1 = getdigits_long(&p); if (*p == ',') { ++p; - l1 = get_long_digits(&p); + l1 = getdigits_long(&p); } else { l1 = f1; } @@ -1235,11 +1235,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) continue; } difftype = *p++; - f2 = get_long_digits(&p); + f2 = getdigits_long(&p); if (*p == ',') { ++p; - l2 = get_long_digits(&p); + l2 = getdigits_long(&p); } else { l2 = f2; } @@ -1783,7 +1783,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_FILLER; } else if ((STRNCMP(p, "context:", 8) == 0) && VIM_ISDIGIT(p[8])) { p += 8; - diff_context_new = get_int_digits(&p); + diff_context_new = getdigits_int(&p); } else if (STRNCMP(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; @@ -1798,7 +1798,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_VERTICAL; } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && VIM_ISDIGIT(p[11])) { p += 11; - diff_foldcolumn_new = get_int_digits(&p); + diff_foldcolumn_new = getdigits_int(&p); } if ((*p != ',') && (*p != NUL)) { diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 7a24203594..243468b680 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1611,7 +1611,7 @@ void putdigraph(char_u *str) EMSG(_(e_number_exp)); return; } - int n = get_int_digits(&str); + int n = getdigits_int(&str); // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e921f3a1a8..d60ce2de73 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2750,7 +2750,7 @@ void ex_lockvar(exarg_T *eap) if (eap->forceit) deep = -1; else if (vim_isdigit(*arg)) { - deep = get_int_digits(&arg); + deep = getdigits_int(&arg); arg = skipwhite(arg); } @@ -13370,7 +13370,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) yank_type = MBLOCK; if (VIM_ISDIGIT(stropt[1])) { ++stropt; - block_len = get_long_digits(&stropt) - 1; + block_len = getdigits_long(&stropt) - 1; --stropt; } break; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 6bd9da0c28..03b45f9d49 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -569,7 +569,7 @@ void ex_retab(exarg_T *eap) save_list = curwin->w_p_list; curwin->w_p_list = 0; /* don't want list mode here */ - new_ts = get_int_digits(&(eap->arg)); + new_ts = getdigits_int(&(eap->arg)); if (new_ts < 0) { EMSG(_(e_positive)); return; @@ -3674,7 +3674,7 @@ void do_sub(exarg_T *eap) */ cmd = skipwhite(cmd); if (VIM_ISDIGIT(*cmd)) { - i = get_long_digits(&cmd); + i = getdigits_long(&cmd); if (i <= 0 && !eap->skip && do_error) { EMSG(_(e_zerocount)); return; @@ -5920,7 +5920,7 @@ void ex_sign(exarg_T *eap) arg1 = arg; if (VIM_ISDIGIT(*arg)) { - id = get_int_digits(&arg); + id = getdigits_int(&arg); if (!vim_iswhite(*arg) && *arg != NUL) { id = -1; @@ -5985,7 +5985,7 @@ void ex_sign(exarg_T *eap) else if (STRNCMP(arg, "buffer=", 7) == 0) { arg += 7; - buf = buflist_findnr(get_int_digits(&arg)); + buf = buflist_findnr(getdigits_int(&arg)); if (*skipwhite(arg) != NUL) EMSG(_(e_trailing)); break; diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d4e5f138fc..c796cf6ac7 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -471,7 +471,7 @@ dbg_parsearg ( else if ( gap != &prof_ga && VIM_ISDIGIT(*p)) { - bp->dbg_lnum = get_long_digits(&p); + bp->dbg_lnum = getdigits_long(&p); p = skipwhite(p); } else bp->dbg_lnum = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index abc205a1e8..3661a65b11 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1733,7 +1733,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, if ((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg) && (!(ea.argt & BUFNAME) || *(p = skipdigits(ea.arg)) == NUL || vim_iswhite(*p))) { - n = get_long_digits(&ea.arg); + n = getdigits_long(&ea.arg); ea.arg = skipwhite(ea.arg); if (n <= 0 && !ni && (ea.argt & ZEROR) == 0) { errormsg = (char_u *)_(e_zerocount); @@ -3250,7 +3250,7 @@ get_address ( default: if (VIM_ISDIGIT(*cmd)) /* absolute line number */ - lnum = get_long_digits(&cmd); + lnum = getdigits_long(&cmd); } for (;; ) { @@ -3267,7 +3267,7 @@ get_address ( if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */ n = 1; else - n = get_long_digits(&cmd); + n = getdigits_long(&cmd); if (i == '-') lnum -= n; else @@ -4439,7 +4439,7 @@ two_count: return FAIL; } - *def = get_long_digits(&p); + *def = getdigits_long(&p); *argt |= (ZEROR | NOTADR); if (p != val + vallen || vallen == 0) { @@ -4456,7 +4456,7 @@ invalid_count: if (*def >= 0) goto two_count; - *def = get_long_digits(&p); + *def = getdigits_long(&p); if (p != val + vallen) goto invalid_count; @@ -5819,7 +5819,7 @@ static void ex_tabmove(exarg_T *eap) return; } - tab_number = get_int_digits(&p); + tab_number = getdigits_int(&p); if (relative != 0) tab_number = tab_number * relative + tabpage_index(curtab) - 1; ; } else if (eap->addr_count != 0) @@ -6441,10 +6441,10 @@ static void ex_winsize(exarg_T *eap) char_u *arg = eap->arg; char_u *p; - w = get_int_digits(&arg); + w = getdigits_int(&arg); arg = skipwhite(arg); p = arg; - h = get_int_digits(&arg); + h = getdigits_int(&arg); if (*p != NUL && *arg == NUL) screen_resize(w, h, TRUE); else @@ -6494,10 +6494,10 @@ static void ex_winpos(exarg_T *eap) if (*arg == NUL) { EMSG(_("E188: Obtaining window position not implemented for this platform")); } else { - x = get_int_digits(&arg); + x = getdigits_int(&arg); arg = skipwhite(arg); p = arg; - y = get_int_digits(&arg); + y = getdigits_int(&arg); if (*p == NUL || *arg != NUL) { EMSG(_("E466: :winpos requires two number arguments")); return; @@ -6744,7 +6744,7 @@ static void ex_later(exarg_T *eap) if (*p == NUL) count = 1; else if (isdigit(*p)) { - count = get_long_digits(&p); + count = getdigits_long(&p); switch (*p) { case 's': ++p; sec = TRUE; break; case 'm': ++p; sec = TRUE; count *= 60; break; @@ -7354,7 +7354,7 @@ static void ex_findpat(exarg_T *eap) n = 1; if (vim_isdigit(*eap->arg)) { /* get count */ - n = get_long_digits(&eap->arg); + n = getdigits_long(&eap->arg); eap->arg = skipwhite(eap->arg); } if (*eap->arg == '/') { /* Match regexp, not just whole words */ @@ -7618,7 +7618,7 @@ eval_vars ( s = src + 1; if (*s == '<') /* "#<99" uses v:oldfiles */ ++s; - i = get_int_digits(&s); + i = getdigits_int(&s); *usedlen = (int)(s - src); /* length of what we expand */ if (src[1] == '<') { diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 1f0a0872a5..993ec143bb 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -320,7 +320,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E552: digit expected"); - table[idx].number = get_int_digits(&p); + table[idx].number = getdigits_int(&p); } table[idx].string = p; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 94d2a2ffff..56276db3ce 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1463,7 +1463,7 @@ void parse_cino(buf_T *buf) if (*p == '-') ++p; char_u *digits_start = p; /* remember where the digits start */ - int n = get_int_digits(&p); + int n = getdigits_int(&p); divider = 0; if (*p == '.') { /* ".5s" means a fraction */ fraction = atoi((char *)++p); @@ -1676,7 +1676,7 @@ int get_c_indent(void) else if (*p == COM_LEFT || *p == COM_RIGHT) align = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') { - off = get_int_digits(&p); + off = getdigits_int(&p); } else ++p; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index abe05dfb30..cf11be665a 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1226,9 +1226,9 @@ int read_viminfo_filemark(vir_T *virp, int force) } if (fm != NULL && (fm->fmark.mark.lnum == 0 || force)) { str = skipwhite(str + 1); - fm->fmark.mark.lnum = get_long_digits(&str); + fm->fmark.mark.lnum = getdigits_long(&str); str = skipwhite(str); - fm->fmark.mark.col = get_int_digits(&str); + fm->fmark.mark.col = getdigits_int(&str); fm->fmark.mark.coladd = 0; fm->fmark.fnum = 0; str = skipwhite(str); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index dffd1f41c5..ea15fd68e3 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -120,7 +120,7 @@ ex_menu ( break; if (vim_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !vim_iswhite(*arg); ++i) { - pri_tab[i] = get_int_digits(&arg); + pri_tab[i] = getdigits_int(&arg); if (pri_tab[i] == 0) pri_tab[i] = 500; if (*arg == '.') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 912babefb6..c0d2e254ac 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -525,7 +525,7 @@ open_line ( if (*p == COM_RIGHT || *p == COM_LEFT) c = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') - off = get_int_digits(&p); + off = getdigits_int(&p); else ++p; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d471453ffd..87a2c2ca05 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4501,7 +4501,7 @@ int read_viminfo_register(vir_T *virp, int force) y_current->y_type = MLINE; /* get the block width; if it's missing we get a zero, which is OK */ str = skipwhite(skiptowhite(str)); - y_current->y_width = get_int_digits(&str); + y_current->y_width = getdigits_int(&str); } while (!(eof = viminfo_readline(virp)) diff --git a/src/nvim/option.c b/src/nvim/option.c index 2c9bd58d08..6c774937cd 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2918,7 +2918,7 @@ do_set ( */ else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) { - i = get_int_digits((char_u **)varp); + i = getdigits_int((char_u **)varp); switch (i) { case 0: *(char_u **)varp = empty_option; @@ -2943,7 +2943,7 @@ do_set ( else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) { *errbuf = NUL; - i = get_int_digits(&arg); + i = getdigits_int(&arg); if (i & 1) STRCAT(errbuf, "b,"); if (i & 2) @@ -4359,7 +4359,7 @@ did_set_string_option ( /* set ru_wid if 'ruf' starts with "%99(" */ if (*++s == '-') /* ignore a '-' */ s++; - wid = get_int_digits(&s); + wid = getdigits_int(&s); if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) ru_wid = wid; else @@ -4664,14 +4664,14 @@ char_u *check_colorcolumn(win_T *wp) ++s; if (!VIM_ISDIGIT(*s)) return e_invarg; - col = col * get_int_digits(&s); + col = col * getdigits_int(&s); if (wp->w_buffer->b_p_tw == 0) goto skip; /* 'textwidth' not set, skip this item */ col += wp->w_buffer->b_p_tw; if (col < 0) goto skip; } else if (VIM_ISDIGIT(*s)) - col = get_int_digits(&s); + col = getdigits_int(&s); else return e_invarg; color_cols[count++] = col - 1; /* 1-based to 0-based */ @@ -8114,12 +8114,12 @@ static bool briopt_check(win_T *wp) && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6]))) { p += 6; - bri_shift = get_int_digits(&p); + bri_shift = getdigits_int(&p); } else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) { p += 4; - bri_min = get_long_digits(&p); + bri_min = getdigits_long(&p); } else if (STRNCMP(p, "sbr", 3) == 0) { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 326640118b..62c01e3798 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3082,10 +3082,10 @@ static int read_limits(long *minval, long *maxval) reverse = TRUE; } first_char = regparse; - *minval = get_long_digits(®parse); + *minval = getdigits_long(®parse); if (*regparse == ',') { /* There is a comma */ if (vim_isdigit(*++regparse)) - *maxval = get_long_digits(®parse); + *maxval = getdigits_long(®parse); else *maxval = MAX_LIMIT; } else if (VIM_ISDIGIT(*first_char)) diff --git a/src/nvim/search.c b/src/nvim/search.c index bd2a49c2d2..25b8277933 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4611,7 +4611,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force) if (lp[4] == 'E') off_end = SEARCH_END; lp += 5; - off = get_long_digits(&lp); + off = getdigits_long(&lp); } if (lp[0] == '~') { /* use this pattern for last-used pattern */ setlast = TRUE; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index af020198d3..5e69a935ca 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5162,7 +5162,7 @@ static unsigned get_affitem(int flagtype, char_u **pp) ++*pp; // always advance, avoid getting stuck return 0; } - res = get_int_digits(pp); + res = getdigits_int(pp); } else { res = mb_ptr2char_adv(pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG @@ -5283,7 +5283,7 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) case AFT_NUM: for (p = afflist; *p != NUL; ) { - int digits = get_int_digits(&p); + int digits = getdigits_int(&p); assert(digits >= 0); n = (unsigned int)digits; if (n == flag) @@ -6359,19 +6359,19 @@ int spell_check_msm(void) if (!VIM_ISDIGIT(*p)) return FAIL; // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (get_long_digits(&p) * 10) / (SBLOCKSIZE / 102); + start = (getdigits_long(&p) * 10) / (SBLOCKSIZE / 102); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - incr = (get_long_digits(&p) * 102) / (SBLOCKSIZE / 10); + incr = (getdigits_long(&p) * 102) / (SBLOCKSIZE / 10); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - added = get_long_digits(&p) * 1024; + added = getdigits_long(&p) * 1024; if (*p != NUL) return FAIL; @@ -8357,7 +8357,7 @@ int spell_check_sps(void) f = 0; if (VIM_ISDIGIT(*buf)) { s = buf; - sps_limit = get_int_digits(&s); + sps_limit = getdigits_int(&s); if (*s != NUL && !VIM_ISDIGIT(*s)) f = -1; } else if (STRCMP(buf, "best") == 0) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6975932f2c..4e2be0cd44 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4900,7 +4900,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) ci->sp_off_flags |= (1 << idx); if (idx == SPO_LC_OFF) { /* lc=99 */ end += 3; - *p = get_int_digits(&end); + *p = getdigits_int(&end); /* "lc=" offset automatically sets "ms=" offset */ if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) { @@ -4911,10 +4911,10 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) end += 4; if (*end == '+') { ++end; - *p = get_int_digits(&end); /* positive offset */ + *p = getdigits_int(&end); /* positive offset */ } else if (*end == '-') { ++end; - *p = -get_int_digits(&end); /* negative offset */ + *p = -getdigits_int(&end); /* negative offset */ } } if (*end != ',') @@ -4980,7 +4980,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) illegal = TRUE; break; } - n = get_long_digits(&arg_end); + n = getdigits_long(&arg_end); if (!eap->skip) { if (key[4] == 'B') curwin->w_s->b_syn_sync_linebreaks = n; diff --git a/src/nvim/term.c b/src/nvim/term.c index b65e750974..b7c30300b0 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -3230,7 +3230,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ p = tp + slen; - mouse_code = get_int_digits(&p); + mouse_code = getdigits_int(&p); if (*p++ != ';') return -1; @@ -3238,11 +3238,11 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) if (key_name[0] == KS_SGR_MOUSE) mouse_code += 32; - mouse_col = get_int_digits(&p); + mouse_col = getdigits_int(&p); if (*p++ != ';') return -1; - mouse_row = get_int_digits(&p); + mouse_row = getdigits_int(&p); if (key_name[0] == KS_SGR_MOUSE && *p == 'm') mouse_code |= MOUSE_RELEASE; else if (*p != 'M') @@ -3269,7 +3269,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } } p += j; - if (cmd_complete && get_int_digits(&p) == mouse_code) { + if (cmd_complete && getdigits_int(&p) == mouse_code) { slen += j; /* skip the \033[ */ continue; } @@ -3315,10 +3315,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) * '6' is the row, 45 is the column */ p = tp + slen; - mr = get_int_digits(&p); + mr = getdigits_int(&p); if (*p++ != ',') return -1; - mc = get_int_digits(&p); + mc = getdigits_int(&p); if (*p++ != '\r') return -1; @@ -3383,27 +3383,27 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) p = tp + slen; /* get event status */ - Pe = get_int_digits(&p); + Pe = getdigits_int(&p); if (*p++ != ';') return -1; /* get button status */ - Pb = get_int_digits(&p); + Pb = getdigits_int(&p); if (*p++ != ';') return -1; /* get row status */ - Pr = get_int_digits(&p); + Pr = getdigits_int(&p); if (*p++ != ';') return -1; /* get column status */ - Pc = get_int_digits(&p); + Pc = getdigits_int(&p); /* the page parameter is optional */ if (*p == ';') { p++; - (void)get_int_digits(&p); + (void)getdigits_int(&p); } if (*p++ != '&') return -1; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index a0b45c1077..25d6a81960 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -344,14 +344,14 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) assert(p != end); if (VIM_ISDIGIT(*p)) { - arg1 = get_int_digits(&p); + arg1 = getdigits_int(&p); if (p >= end) { break; } if (*p == ';') { p++; - arg2 = get_int_digits(&p); + arg2 = getdigits_int(&p); if (p >= end) break; } diff --git a/src/nvim/window.c b/src/nvim/window.c index cfe60c65f3..0e336e8cbe 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4908,7 +4908,7 @@ file_name_in_line ( ++p; /* skip the separator */ p = skipwhite(p); if (isdigit(*p)) - *file_lnum = get_long_digits(&p); + *file_lnum = getdigits_long(&p); } } -- cgit