Fix lint issues

This commit is contained in:
Jason Schulz
2016-01-14 22:33:51 -08:00
parent 7ad3f077dc
commit f82e982bda
11 changed files with 600 additions and 544 deletions

View File

@@ -85,10 +85,25 @@
# define PATHSEPSTR "/" # define PATHSEPSTR "/"
#endif #endif
static inline bool ascii_iswhite(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; static inline bool ascii_iswhite(int)
static inline bool ascii_isdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; REAL_FATTR_CONST
static inline bool ascii_isxdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; REAL_FATTR_ALWAYS_INLINE;
static inline bool ascii_isspace(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
static inline bool ascii_isdigit(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
static inline bool ascii_isxdigit(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
static inline bool ascii_isbdigit(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
static inline bool ascii_isspace(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a space or tab character. /// Checks if `c` is a space or tab character.
/// ///

View File

@@ -1456,16 +1456,20 @@ char_u* skipdigits(char_u *q)
/// skip over binary digits /// skip over binary digits
/// ///
/// @param q /// @param q pointer to string
/// ///
/// @return Pointer to the character after the skipped digits. /// @return Pointer to the character after the skipped digits.
char_u* skipbin(char_u *q) const char* skipbin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
{ {
char_u *p = q; const char *p = q;
while (ascii_isbdigit(*p)) {
while (ascii_isbdigit(*p)) /* skip to next non-digit */ // skip to next non-digit
++p; p++;
return p; }
return p;
} }
/// skip over digits and hex characters /// skip over digits and hex characters
@@ -1501,16 +1505,20 @@ char_u* skiptodigit(char_u *q)
/// skip to binary character (or NUL after the string) /// skip to binary character (or NUL after the string)
/// ///
/// @param q /// @param q pointer to string
/// ///
/// @return Pointer to the binary character or (NUL after the string). /// @return Pointer to the binary character or (NUL after the string).
char_u* skiptobin(char_u *q) const char* skiptobin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
{ {
char_u *p = q; const char *p = q;
while (*p != NUL && !ascii_isbdigit(*p)) {
while (*p != NUL && !ascii_isbdigit(*p)) /* skip to next digit */ // skip to next digit
++p; p++;
return p; }
return p;
} }
/// skip to hex character (or NUL after the string) /// skip to hex character (or NUL after the string)
@@ -1752,8 +1760,8 @@ int vim_isblankline(char_u *lbuf)
/// If "prep" is not NULL, returns a flag to indicate the type of the number: /// If "prep" is not NULL, returns a flag to indicate the type of the number:
/// 0 decimal /// 0 decimal
/// '0' octal /// '0' octal
/// 'B' bin /// 'B' bin
/// 'b' bin /// 'b' bin
/// 'X' hex /// 'X' hex
/// 'x' hex /// 'x' hex
/// If "len" is not NULL, the length of the number in characters is returned. /// If "len" is not NULL, the length of the number in characters is returned.
@@ -1775,18 +1783,19 @@ int vim_isblankline(char_u *lbuf)
/// @param dohex recognize hex number /// @param dohex recognize hex number
/// @param nptr Returns the signed result. /// @param nptr Returns the signed result.
/// @param unptr Returns the unsigned result. /// @param unptr Returns the unsigned result.
void vim_str2nr(char_u *start, int *prep, int *len, int dobin, int dooct, int dohex, void vim_str2nr(char_u *start, int *prep, int *len,
int dobin, int dooct, int dohex,
long *nptr, unsigned long *unptr) long *nptr, unsigned long *unptr)
{ {
char_u *ptr = start; char_u *ptr = start;
int pre = 0; // default is decimal int pre = 0; // default is decimal
int negative = FALSE; int negative = false;
unsigned long un = 0; unsigned long un = 0;
int n; int n;
if (ptr[0] == '-') { if (ptr[0] == '-') {
negative = TRUE; negative = true;
++ptr; ptr++;
} }
// Recognize hex, octal, and bin. // Recognize hex, octal, and bin.
@@ -1827,11 +1836,12 @@ void vim_str2nr(char_u *start, int *prep, int *len, int dobin, int dooct, int do
// Do the string-to-numeric conversion "manually" to avoid sscanf quirks. // Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
if ((pre == 'B') || (pre == 'b') || (dobin > 1)) { if ((pre == 'B') || (pre == 'b') || (dobin > 1)) {
// bin // bin
if (pre != 0) if (pre != 0) {
n += 2; // skip over "0b" n += 2; // skip over "0b"
}
while ('0' <= *ptr && *ptr <= '1') { while ('0' <= *ptr && *ptr <= '1') {
un = 2 * un + (unsigned long)(*ptr - '0'); un = 2 * un + (unsigned long)(*ptr - '0');
++ptr; ptr++;
} }
} else if ((pre == '0') || (dooct > 1)) { } else if ((pre == '0') || (dooct > 1)) {
// octal // octal
@@ -1841,17 +1851,18 @@ void vim_str2nr(char_u *start, int *prep, int *len, int dobin, int dooct, int do
} }
} else if (pre != 0 || dohex > 1) { } else if (pre != 0 || dohex > 1) {
// hex // hex
if (pre != 0) if (pre != 0) {
n += 2; // skip over "0x" n += 2; // skip over "0x"
}
while (ascii_isxdigit(*ptr)) { while (ascii_isxdigit(*ptr)) {
un = 16 * un + (unsigned long)hex2nr(*ptr); un = 16 * un + (unsigned long)hex2nr(*ptr);
++ptr; ptr++;
} }
} else { } else {
// decimal // decimal
while (ascii_isdigit(*ptr)) { while (ascii_isdigit(*ptr)) {
un = 10 * un + (unsigned long)(*ptr - '0'); un = 10 * un + (unsigned long)(*ptr - '0');
++ptr; ptr++;
} }
} }

View File

@@ -1113,19 +1113,17 @@ typval_T *eval_expr(char_u *arg, char_u **nextcmd)
} }
/* // Call some vimL function and return the result in "*rettv".
* Call some vimL function and return the result in "*rettv". // Uses argv[argc] for the function arguments. Only Number and String
* Uses argv[argc] for the function arguments. Only Number and String // arguments are currently supported.
* arguments are currently supported. //
* Returns OK or FAIL. // Return OK or FAIL.
*/ int call_vim_function(
int
call_vim_function (
char_u *func, char_u *func,
int argc, int argc,
char_u **argv, char_u **argv,
int safe, /* use the sandbox */ int safe, // use the sandbox
int str_arg_only, /* all arguments are strings */ int str_arg_only, // all arguments are strings
typval_T *rettv typval_T *rettv
) )
{ {
@@ -1138,18 +1136,19 @@ call_vim_function (
typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T)); typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T));
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
/* Pass a NULL or empty argument as an empty string */ // Pass a NULL or empty argument as an empty string
if (argv[i] == NULL || *argv[i] == NUL) { if (argv[i] == NULL || *argv[i] == NUL) {
argvars[i].v_type = VAR_STRING; argvars[i].v_type = VAR_STRING;
argvars[i].vval.v_string = (char_u *)""; argvars[i].vval.v_string = (char_u *)"";
continue; continue;
} }
if (str_arg_only) if (str_arg_only) {
len = 0; len = 0;
else } else {
/* Recognize a number argument, the others must be strings. */ // Recognize a number argument, the others must be strings.
vim_str2nr(argv[i], NULL, &len, TRUE, TRUE, TRUE, &n, NULL); vim_str2nr(argv[i], NULL, &len, true, true, true, &n, NULL);
}
if (len != 0 && len == (int)STRLEN(argv[i])) { if (len != 0 && len == (int)STRLEN(argv[i])) {
argvars[i].v_type = VAR_NUMBER; argvars[i].v_type = VAR_NUMBER;
argvars[i].vval.v_number = n; argvars[i].vval.v_number = n;
@@ -1166,16 +1165,17 @@ call_vim_function (
rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */
ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars, ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars,
curwin->w_cursor.lnum, curwin->w_cursor.lnum, curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&doesrange, TRUE, NULL); &doesrange, true, NULL);
if (safe) { if (safe) {
--sandbox; --sandbox;
restore_funccal(save_funccalp); restore_funccal(save_funccalp);
} }
xfree(argvars); xfree(argvars);
if (ret == FAIL) if (ret == FAIL) {
clear_tv(rettv); clear_tv(rettv);
}
return ret; return ret;
} }
@@ -4025,38 +4025,35 @@ eval6 (
return OK; return OK;
} }
/* // Handle sixth level expression:
* Handle sixth level expression: // number number constant
* number number constant // "string" string constant
* "string" string constant // 'string' literal string constant
* 'string' literal string constant // &option-name option value
* &option-name option value // @r register contents
* @r register contents // identifier variable value
* identifier variable value // function() function call
* function() function call // $VAR environment variable
* $VAR environment variable // (expression) nested expression
* (expression) nested expression // [expr, expr] List
* [expr, expr] List // {key: val, key: val} Dictionary
* {key: val, key: val} Dictionary //
* // Also handle:
* Also handle: // ! in front logical NOT
* ! in front logical NOT // - in front unary minus
* - in front unary minus // + in front unary plus (ignored)
* + in front unary plus (ignored) // trailing [] subscript in String or List
* trailing [] subscript in String or List // trailing .name entry in Dictionary
* trailing .name entry in Dictionary //
* // "arg" must point to the first non-white of the expression.
* "arg" must point to the first non-white of the expression. // "arg" is advanced to the next non-white after the recognized expression.
* "arg" is advanced to the next non-white after the recognized expression. //
* // Return OK or FAIL.
* Return OK or FAIL. static int eval7(
*/
static int
eval7 (
char_u **arg, char_u **arg,
typval_T *rettv, typval_T *rettv,
int evaluate, int evaluate,
int want_string /* after "." operator */ int want_string // after "." operator
) )
{ {
long n; long n;
@@ -4066,24 +4063,19 @@ eval7 (
int ret = OK; int ret = OK;
char_u *alias; char_u *alias;
/* // Initialise variable so that clear_tv() can't mistake this for a
* Initialise variable so that clear_tv() can't mistake this for a // string and free a string that isn't there.
* string and free a string that isn't there.
*/
rettv->v_type = VAR_UNKNOWN; rettv->v_type = VAR_UNKNOWN;
/* // Skip '!' and '-' characters. They are handled later.
* Skip '!' and '-' characters. They are handled later.
*/
start_leader = *arg; start_leader = *arg;
while (**arg == '!' || **arg == '-' || **arg == '+') while (**arg == '!' || **arg == '-' || **arg == '+') {
*arg = skipwhite(*arg + 1); *arg = skipwhite(*arg + 1);
}
end_leader = *arg; end_leader = *arg;
switch (**arg) { switch (**arg) {
/* // Number constant.
* Number constant.
*/
case '0': case '0':
case '1': case '1':
case '2': case '2':
@@ -4096,27 +4088,30 @@ eval7 (
case '9': case '9':
{ {
char_u *p = skipdigits(*arg + 1); char_u *p = skipdigits(*arg + 1);
int get_float = FALSE; int get_float = false;
/* We accept a float when the format matches // We accept a float when the format matches
* "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very
* strict to avoid backwards compatibility problems. // strict to avoid backwards compatibility problems.
* Don't look for a float after the "." operator, so that // Don't look for a float after the "." operator, so that
* ":let vers = 1.2.3" doesn't fail. */ // ":let vers = 1.2.3" doesn't fail.
if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) { if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) {
get_float = TRUE; get_float = true;
p = skipdigits(p + 2); p = skipdigits(p + 2);
if (*p == 'e' || *p == 'E') { if (*p == 'e' || *p == 'E') {
++p; ++p;
if (*p == '-' || *p == '+') if (*p == '-' || *p == '+') {
++p; ++p;
if (!ascii_isdigit(*p)) }
get_float = FALSE; if (!ascii_isdigit(*p)) {
else get_float = false;
} else {
p = skipdigits(p + 1); p = skipdigits(p + 1);
}
}
if (ASCII_ISALPHA(*p) || *p == '.') {
get_float = false;
} }
if (ASCII_ISALPHA(*p) || *p == '.')
get_float = FALSE;
} }
if (get_float) { if (get_float) {
float_T f; float_T f;
@@ -4127,7 +4122,7 @@ eval7 (
rettv->vval.v_float = f; rettv->vval.v_float = f;
} }
} else { } else {
vim_str2nr(*arg, NULL, &len, TRUE, TRUE, TRUE, &n, NULL); vim_str2nr(*arg, NULL, &len, true, true, true, &n, NULL);
*arg += len; *arg += len;
if (evaluate) { if (evaluate) {
rettv->v_type = VAR_NUMBER; rettv->v_type = VAR_NUMBER;
@@ -4137,62 +4132,47 @@ eval7 (
break; break;
} }
/* // String constant: "string".
* String constant: "string".
*/
case '"': ret = get_string_tv(arg, rettv, evaluate); case '"': ret = get_string_tv(arg, rettv, evaluate);
break; break;
/* // Literal string constant: 'str''ing'.
* Literal string constant: 'str''ing'.
*/
case '\'': ret = get_lit_string_tv(arg, rettv, evaluate); case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
break; break;
/* // List: [expr, expr]
* List: [expr, expr]
*/
case '[': ret = get_list_tv(arg, rettv, evaluate); case '[': ret = get_list_tv(arg, rettv, evaluate);
break; break;
/* // Dictionary: {key: val, key: val}
* Dictionary: {key: val, key: val}
*/
case '{': ret = get_dict_tv(arg, rettv, evaluate); case '{': ret = get_dict_tv(arg, rettv, evaluate);
break; break;
/* // Option value: &name
* Option value: &name
*/
case '&': ret = get_option_tv(arg, rettv, evaluate); case '&': ret = get_option_tv(arg, rettv, evaluate);
break; break;
/* // Environment variable: $VAR.
* Environment variable: $VAR.
*/
case '$': ret = get_env_tv(arg, rettv, evaluate); case '$': ret = get_env_tv(arg, rettv, evaluate);
break; break;
/* // Register contents: @r.
* Register contents: @r.
*/
case '@': ++*arg; case '@': ++*arg;
if (evaluate) { if (evaluate) {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc); rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc);
} }
if (**arg != NUL) if (**arg != NUL) {
++*arg; ++*arg;
}
break; break;
/* // nested expression: (expression).
* nested expression: (expression).
*/
case '(': *arg = skipwhite(*arg + 1); case '(': *arg = skipwhite(*arg + 1);
ret = eval1(arg, rettv, evaluate); /* recursive! */ ret = eval1(arg, rettv, evaluate); // recursive!
if (**arg == ')') if (**arg == ')') {
++*arg; ++*arg;
else if (ret == OK) { } else if (ret == OK) {
EMSG(_("E110: Missing ')'")); EMSG(_("E110: Missing ')'"));
clear_tv(rettv); clear_tv(rettv);
ret = FAIL; ret = FAIL;
@@ -4204,71 +4184,72 @@ eval7 (
} }
if (ret == NOTDONE) { if (ret == NOTDONE) {
/* // Must be a variable or function name.
* Must be a variable or function name. // Can also be a curly-braces kind of name: {expr}.
* Can also be a curly-braces kind of name: {expr}.
*/
s = *arg; s = *arg;
len = get_name_len(arg, &alias, evaluate, TRUE); len = get_name_len(arg, &alias, evaluate, true);
if (alias != NULL) if (alias != NULL) {
s = alias; s = alias;
}
if (len <= 0) if (len <= 0) {
ret = FAIL; ret = FAIL;
else { } else {
if (**arg == '(') { /* recursive! */ if (**arg == '(') { // recursive!
/* If "s" is the name of a variable of type VAR_FUNC // If "s" is the name of a variable of type VAR_FUNC
* use its contents. */ // use its contents.
s = deref_func_name(s, &len, !evaluate); s = deref_func_name(s, &len, !evaluate);
/* Invoke the function. */ // Invoke the function.
ret = get_func_tv(s, len, rettv, arg, ret = get_func_tv(s, len, rettv, arg,
curwin->w_cursor.lnum, curwin->w_cursor.lnum, curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&len, evaluate, NULL); &len, evaluate, NULL);
/* If evaluate is FALSE rettv->v_type was not set in // If evaluate is false rettv->v_type was not set in
* get_func_tv, but it's needed in handle_subscript() to parse // get_func_tv, but it's needed in handle_subscript() to parse
* what follows. So set it here. */ // what follows. So set it here.
if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') { if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') {
rettv->vval.v_string = empty_string; rettv->vval.v_string = empty_string;
rettv->v_type = VAR_FUNC; rettv->v_type = VAR_FUNC;
} }
/* Stop the expression evaluation when immediately // Stop the expression evaluation when immediately
* aborting on error, or when an interrupt occurred or // aborting on error, or when an interrupt occurred or
* an exception was thrown but not caught. */ // an exception was thrown but not caught.
if (aborting()) { if (aborting()) {
if (ret == OK) if (ret == OK) {
clear_tv(rettv); clear_tv(rettv);
}
ret = FAIL; ret = FAIL;
} }
} else if (evaluate) } else if (evaluate) {
ret = get_var_tv(s, len, rettv, TRUE, FALSE); ret = get_var_tv(s, len, rettv, true, false);
else } else {
ret = OK; ret = OK;
}
} }
xfree(alias); xfree(alias);
} }
*arg = skipwhite(*arg); *arg = skipwhite(*arg);
/* Handle following '[', '(' and '.' for expr[expr], expr.name, // Handle following '[', '(' and '.' for expr[expr], expr.name,
* expr(expr). */ // expr(expr).
if (ret == OK) if (ret == OK) {
ret = handle_subscript(arg, rettv, evaluate, TRUE); ret = handle_subscript(arg, rettv, evaluate, true);
}
/* // Apply logical NOT and unary '-', from right to left, ignore '+'.
* Apply logical NOT and unary '-', from right to left, ignore '+'.
*/
if (ret == OK && evaluate && end_leader > start_leader) { if (ret == OK && evaluate && end_leader > start_leader) {
int error = FALSE; int error = false;
int val = 0; int val = 0;
float_T f = 0.0; float_T f = 0.0;
if (rettv->v_type == VAR_FLOAT) if (rettv->v_type == VAR_FLOAT) {
f = rettv->vval.v_float; f = rettv->vval.v_float;
else } else {
val = get_tv_number_chk(rettv, &error); val = get_tv_number_chk(rettv, &error);
}
if (error) { if (error) {
clear_tv(rettv); clear_tv(rettv);
ret = FAIL; ret = FAIL;
@@ -4276,15 +4257,17 @@ eval7 (
while (end_leader > start_leader) { while (end_leader > start_leader) {
--end_leader; --end_leader;
if (*end_leader == '!') { if (*end_leader == '!') {
if (rettv->v_type == VAR_FLOAT) if (rettv->v_type == VAR_FLOAT) {
f = !f; f = !f;
else } else {
val = !val; val = !val;
}
} else if (*end_leader == '-') { } else if (*end_leader == '-') {
if (rettv->v_type == VAR_FLOAT) if (rettv->v_type == VAR_FLOAT) {
f = -f; f = -f;
else } else {
val = -val; val = -val;
}
} }
} }
if (rettv->v_type == VAR_FLOAT) { if (rettv->v_type == VAR_FLOAT) {
@@ -15971,9 +15954,7 @@ static void f_str2float(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_FLOAT; rettv->v_type = VAR_FLOAT;
} }
/* // "str2nr()" function
* "str2nr()" function
*/
static void f_str2nr(typval_T *argvars, typval_T *rettv) static void f_str2nr(typval_T *argvars, typval_T *rettv)
{ {
int base = 10; int base = 10;
@@ -15989,9 +15970,14 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv)
} }
p = skipwhite(get_tv_string(&argvars[0])); p = skipwhite(get_tv_string(&argvars[0]));
if (*p == '+') if (*p == '+') {
p = skipwhite(p + 1); p = skipwhite(p + 1);
vim_str2nr(p, NULL, NULL, base == 2 ? 2 : 0, base == 8 ? 2 : 0, base == 16 ? 2 : 0, &n, NULL); }
vim_str2nr(p, NULL, NULL,
base == 2 ? 2 : 0,
base == 8 ? 2 : 0,
base == 16 ? 2 : 0,
&n, NULL);
rettv->vval.v_number = n; rettv->vval.v_number = n;
} }
@@ -18271,9 +18257,10 @@ long get_tv_number_chk(typval_T *varp, int *denote)
EMSG(_("E703: Using a Funcref as a Number")); EMSG(_("E703: Using a Funcref as a Number"));
break; break;
case VAR_STRING: case VAR_STRING:
if (varp->vval.v_string != NULL) if (varp->vval.v_string != NULL) {
vim_str2nr(varp->vval.v_string, NULL, NULL, vim_str2nr(varp->vval.v_string, NULL, NULL,
TRUE, TRUE, TRUE, &n, NULL); true, true, true, &n, NULL);
}
return n; return n;
case VAR_LIST: case VAR_LIST:
EMSG(_("E745: Using a List as a Number")); EMSG(_("E745: Using a List as a Number"));
@@ -18285,10 +18272,12 @@ long get_tv_number_chk(typval_T *varp, int *denote)
EMSG2(_(e_intern2), "get_tv_number()"); EMSG2(_(e_intern2), "get_tv_number()");
break; break;
} }
if (denote == NULL) /* useful for values that must be unsigned */ if (denote == NULL) {
// useful for values that must be unsigned
n = -1; n = -1;
else } else {
*denote = TRUE; *denote = true;
}
return n; return n;
} }

View File

@@ -329,9 +329,7 @@ static int sort_compare(const void *s1, const void *s2)
return result; return result;
} }
/* // ":sort".
* ":sort".
*/
void ex_sort(exarg_T *eap) void ex_sort(exarg_T *eap)
{ {
regmatch_T regmatch; regmatch_T regmatch;
@@ -343,18 +341,19 @@ void ex_sort(exarg_T *eap)
char_u *p; char_u *p;
char_u *s; char_u *s;
char_u *s2; char_u *s2;
char_u c; /* temporary character storage */ char_u c; // temporary character storage
int unique = FALSE; int unique = false;
long deleted; long deleted;
colnr_T start_col; colnr_T start_col;
colnr_T end_col; colnr_T end_col;
int sort_bin; /* sort on bin number */ int sort_bin; // sort on bin number
int sort_oct; /* sort on octal number */ int sort_oct; // sort on octal number
int sort_hex; /* sort on hex number */ int sort_hex; // sort on hex number
/* Sorting one line is really quick! */ // Sorting one line is really quick!
if (count <= 1) if (count <= 1) {
return; return;
}
if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL)
return; return;
@@ -366,46 +365,48 @@ void ex_sort(exarg_T *eap)
sort_abort = sort_ic = sort_rx = sort_nr = sort_bin = sort_oct = sort_hex = 0; sort_abort = sort_ic = sort_rx = sort_nr = sort_bin = sort_oct = sort_hex = 0;
for (p = eap->arg; *p != NUL; ++p) { for (p = eap->arg; *p != NUL; ++p) {
if (ascii_iswhite(*p)) if (ascii_iswhite(*p)) {
; } else if (*p == 'i') {
else if (*p == 'i') sort_ic = true;
sort_ic = TRUE; } else if (*p == 'r') {
else if (*p == 'r') sort_rx = true;
sort_rx = TRUE; } else if (*p == 'n') {
else if (*p == 'n')
sort_nr = 2; sort_nr = 2;
else if (*p == 'b') } else if (*p == 'b') {
sort_bin = 2; sort_bin = 2;
else if (*p == 'o') } else if (*p == 'o') {
sort_oct = 2; sort_oct = 2;
else if (*p == 'x') } else if (*p == 'x') {
sort_hex = 2; sort_hex = 2;
else if (*p == 'u') } else if (*p == 'u') {
unique = TRUE; unique = true;
else if (*p == '"') /* comment start */ } else if (*p == '"') {
// comment start
break; break;
else if (check_nextcmd(p) != NULL) { } else if (check_nextcmd(p) != NULL) {
eap->nextcmd = check_nextcmd(p); eap->nextcmd = check_nextcmd(p);
break; break;
} else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) {
s = skip_regexp(p + 1, *p, TRUE, NULL); s = skip_regexp(p + 1, *p, true, NULL);
if (*s != *p) { if (*s != *p) {
EMSG(_(e_invalpat)); EMSG(_(e_invalpat));
goto sortend; goto sortend;
} }
*s = NUL; *s = NUL;
/* Use last search pattern if sort pattern is empty. */ // Use last search pattern if sort pattern is empty.
if (s == p + 1) { if (s == p + 1) {
if (last_search_pat() == NULL) { if (last_search_pat() == NULL) {
EMSG(_(e_noprevre)); EMSG(_(e_noprevre));
goto sortend; goto sortend;
} }
regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC);
} else } else {
regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC);
if (regmatch.regprog == NULL) }
if (regmatch.regprog == NULL) {
goto sortend; goto sortend;
p = s; /* continue after the regexp */ }
p = s; // continue after the regexp
regmatch.rm_ic = p_ic; regmatch.rm_ic = p_ic;
} else { } else {
EMSG2(_(e_invarg2), p); EMSG2(_(e_invarg2), p);
@@ -413,28 +414,27 @@ void ex_sort(exarg_T *eap)
} }
} }
/* Can only have one of 'n', 'b', 'o' and 'x'. */ // Can only have one of 'n', 'b', 'o' and 'x'.
if (sort_nr + sort_bin + sort_oct + sort_hex > 2) { if (sort_nr + sort_bin + sort_oct + sort_hex > 2) {
EMSG(_(e_invarg)); EMSG(_(e_invarg));
goto sortend; goto sortend;
} }
/* From here on "sort_nr" is used as a flag for any number sorting. */ // From here on "sort_nr" is used as a flag for any number sorting.
sort_nr += sort_bin + sort_oct + sort_hex; sort_nr += sort_bin + sort_oct + sort_hex;
/* // Make an array with all line numbers. This avoids having to copy all
* Make an array with all line numbers. This avoids having to copy all // the lines into allocated memory.
* the lines into allocated memory. // When sorting on strings "start_col_nr" is the offset in the line, for
* When sorting on strings "start_col_nr" is the offset in the line, for // numbers sorting it's the number to sort on. This means the pattern
* numbers sorting it's the number to sort on. This means the pattern // matching and number conversion only has to be done once per line.
* matching and number conversion only has to be done once per line. // Also get the longest line length for allocating "sortbuf".
* Also get the longest line length for allocating "sortbuf".
*/
for (lnum = eap->line1; lnum <= eap->line2; ++lnum) { for (lnum = eap->line1; lnum <= eap->line2; ++lnum) {
s = ml_get(lnum); s = ml_get(lnum);
len = (int)STRLEN(s); len = (int)STRLEN(s);
if (maxlen < len) if (maxlen < len) {
maxlen = len; maxlen = len;
}
start_col = 0; start_col = 0;
end_col = len; end_col = len;
@@ -442,36 +442,41 @@ void ex_sort(exarg_T *eap)
if (sort_rx) { if (sort_rx) {
start_col = (colnr_T)(regmatch.startp[0] - s); start_col = (colnr_T)(regmatch.startp[0] - s);
end_col = (colnr_T)(regmatch.endp[0] - s); end_col = (colnr_T)(regmatch.endp[0] - s);
} else } else {
start_col = (colnr_T)(regmatch.endp[0] - s); start_col = (colnr_T)(regmatch.endp[0] - s);
} else if (regmatch.regprog != NULL) }
} else if (regmatch.regprog != NULL) {
end_col = 0; end_col = 0;
}
if (sort_nr) { if (sort_nr) {
/* Make sure vim_str2nr doesn't read any digits past the end // Make sure vim_str2nr doesn't read any digits past the end
* of the match, by temporarily terminating the string there */ // of the match, by temporarily terminating the string there
s2 = s + end_col; s2 = s + end_col;
c = *s2; c = *s2;
*s2 = NUL; *s2 = NUL;
/* Sorting on number: Store the number itself. */ // Sorting on number: Store the number itself.
p = s + start_col; p = s + start_col;
if (sort_hex) if (sort_hex) {
s = skiptohex(p); s = skiptohex(p);
else if (sort_bin) } else if (sort_bin) {
s = skiptobin(p); s = (char_u*) skiptobin((char*) p);
else } else {
s = skiptodigit(p); s = skiptodigit(p);
if (s > p && s[-1] == '-') }
--s; /* include preceding negative sign */ if (s > p && s[-1] == '-') {
if (*s == NUL) --s; // include preceding negative sign
/* empty line should sort before any number */ }
if (*s == NUL) {
// empty line should sort before any number
nrs[lnum - eap->line1].start_col_nr = -MAXLNUM; nrs[lnum - eap->line1].start_col_nr = -MAXLNUM;
else } else {
vim_str2nr(s, NULL, NULL, sort_bin, sort_oct, sort_hex, vim_str2nr(s, NULL, NULL, sort_bin, sort_oct, sort_hex,
&nrs[lnum - eap->line1].start_col_nr, NULL); &nrs[lnum - eap->line1].start_col_nr, NULL);
}
*s2 = c; *s2 = c;
} else { } else {
/* Store the column to sort at. */ // Store the column to sort at.
nrs[lnum - eap->line1].start_col_nr = start_col; nrs[lnum - eap->line1].start_col_nr = start_col;
nrs[lnum - eap->line1].end_col_nr = end_col; nrs[lnum - eap->line1].end_col_nr = end_col;
} }
@@ -484,17 +489,17 @@ void ex_sort(exarg_T *eap)
goto sortend; goto sortend;
} }
/* Allocate a buffer that can hold the longest line. */ // Allocate a buffer that can hold the longest line.
sortbuf1 = xmalloc(maxlen + 1); sortbuf1 = xmalloc(maxlen + 1);
sortbuf2 = xmalloc(maxlen + 1); sortbuf2 = xmalloc(maxlen + 1);
/* Sort the array of line numbers. Note: can't be interrupted! */ // Sort the array of line numbers. Note: can't be interrupted!
qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); qsort((void *)nrs, count, sizeof(sorti_T), sort_compare);
if (sort_abort) if (sort_abort)
goto sortend; goto sortend;
/* Insert the lines in the sorted order below the last one. */ // Insert the lines in the sorted order below the last one.
lnum = eap->line2; lnum = eap->line2;
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum);
@@ -512,19 +517,22 @@ void ex_sort(exarg_T *eap)
goto sortend; goto sortend;
} }
/* delete the original lines if appending worked */ // delete the original lines if appending worked
if (i == count) if (i == count) {
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i) {
ml_delete(eap->line1, FALSE); ml_delete(eap->line1, false);
else }
} else {
count = 0; count = 0;
}
/* Adjust marks for deleted (or added) lines and prepare for displaying. */ // Adjust marks for deleted (or added) lines and prepare for displaying.
deleted = (long)(count - (lnum - eap->line2)); deleted = (long)(count - (lnum - eap->line2));
if (deleted > 0) if (deleted > 0) {
mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted);
else if (deleted < 0) } else if (deleted < 0) {
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); mark_adjust(eap->line2, MAXLNUM, -deleted, 0L);
}
changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); changed_lines(eap->line1, 0, eap->line2 + 1, -deleted);
curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.lnum = eap->line1;
@@ -535,8 +543,9 @@ sortend:
xfree(sortbuf1); xfree(sortbuf1);
xfree(sortbuf2); xfree(sortbuf2);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
if (got_int) if (got_int) {
EMSG(_(e_interr)); EMSG(_(e_interr));
}
} }
/* /*

View File

@@ -4767,35 +4767,40 @@ int del_history_idx(int histype, int idx)
return TRUE; return TRUE;
} }
/* /// Get indices that specify a range within a list (not a range of text lines
* Get indices "num1,num2" that specify a range within a list (not a range of /// in a buffer!) from a string. Used for ":history" and ":clist".
* text lines in a buffer!) from a string. Used for ":history" and ":clist". ///
* Returns OK if parsed successfully, otherwise FAIL. /// @param str string to parse range from
*/ /// @param num1 from
/// @param num2 to
///
/// @return OK if parsed successfully, otherwise FAIL.
int get_list_range(char_u **str, int *num1, int *num2) int get_list_range(char_u **str, int *num1, int *num2)
{ {
int len; int len;
int first = FALSE; int first = false;
long num; long num;
*str = skipwhite(*str); *str = skipwhite(*str);
if (**str == '-' || ascii_isdigit(**str)) { /* parse "from" part of range */ if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range
vim_str2nr(*str, NULL, &len, FALSE, FALSE, FALSE, &num, NULL); vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL);
*str += len; *str += len;
*num1 = (int)num; *num1 = (int)num;
first = TRUE; first = true;
} }
*str = skipwhite(*str); *str = skipwhite(*str);
if (**str == ',') { /* parse "to" part of range */ if (**str == ',') { // parse "to" part of range
*str = skipwhite(*str + 1); *str = skipwhite(*str + 1);
vim_str2nr(*str, NULL, &len, FALSE, FALSE, FALSE, &num, NULL); vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL);
if (len > 0) { if (len > 0) {
*num2 = (int)num; *num2 = (int)num;
*str = skipwhite(*str + len); *str = skipwhite(*str + len);
} else if (!first) /* no number given at all */ } else if (!first) { // no number given at all
return FAIL; return FAIL;
} else if (first) /* only one number given */ }
} else if (first) { // only one number given
*num2 = *num1; *num2 = *num1;
}
return OK; return OK;
} }

View File

@@ -531,17 +531,14 @@ trans_special (
return dlen; return dlen;
} }
/* // Try translating a <> name at (*srcp)[], return the key and modifiers.
* Try translating a <> name at (*srcp)[], return the key and modifiers. // srcp is advanced to after the <> name.
* srcp is advanced to after the <> name. // returns 0 if there is no match.
* returns 0 if there is no match. int find_special_key(
*/
int
find_special_key (
char_u **srcp, char_u **srcp,
int *modp, int *modp,
int keycode, /* prefer key code, e.g. K_DEL instead of DEL */ int keycode, // prefer key code, e.g. K_DEL instead of DEL
int keep_x_key /* don't translate xHome to Home key */ int keep_x_key // don't translate xHome to Home key
) )
{ {
char_u *last_dash; char_u *last_dash;
@@ -558,24 +555,26 @@ find_special_key (
if (src[0] != '<') if (src[0] != '<')
return 0; return 0;
/* Find end of modifier list */ // Find end of modifier list
last_dash = src; last_dash = src;
for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) { for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) {
if (*bp == '-') { if (*bp == '-') {
last_dash = bp; last_dash = bp;
if (bp[1] != NUL) { if (bp[1] != NUL) {
if (has_mbyte) if (has_mbyte) {
l = mb_ptr2len(bp + 1); l = mb_ptr2len(bp + 1);
else } else {
l = 1; l = 1;
if (bp[l + 1] == '>') }
bp += l; /* anything accepted, like <C-?> */ if (bp[l + 1] == '>') {
bp += l; // anything accepted, like <C-?>
}
} }
} }
if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) {
bp += 3; /* skip t_xx, xx may be '-' or '>' */ bp += 3; // skip t_xx, xx may be '-' or '>'
else if (STRNICMP(bp, "char-", 5) == 0) { } else if (STRNICMP(bp, "char-", 5) == 0) {
vim_str2nr(bp + 5, NULL, &l, TRUE, TRUE, TRUE, NULL, NULL); vim_str2nr(bp + 5, NULL, &l, true, true, true, NULL, NULL);
bp += l + 5; bp += l + 5;
break; break;
} }
@@ -589,55 +588,53 @@ find_special_key (
for (bp = src + 1; bp < last_dash; bp++) { for (bp = src + 1; bp < last_dash; bp++) {
if (*bp != '-') { if (*bp != '-') {
bit = name_to_mod_mask(*bp); bit = name_to_mod_mask(*bp);
if (bit == 0x0) if (bit == 0x0) {
break; /* Illegal modifier name */ break; // Illegal modifier name
}
modifiers |= bit; modifiers |= bit;
} }
} }
/* // Legal modifier name.
* Legal modifier name.
*/
if (bp >= last_dash) { if (bp >= last_dash) {
if (STRNICMP(last_dash + 1, "char-", 5) == 0 if (STRNICMP(last_dash + 1, "char-", 5) == 0
&& ascii_isdigit(last_dash[6])) { && ascii_isdigit(last_dash[6])) {
/* <Char-123> or <Char-033> or <Char-0x33> */ // <Char-123> or <Char-033> or <Char-0x33>
vim_str2nr(last_dash + 6, NULL, NULL, TRUE, TRUE, TRUE, NULL, &n); vim_str2nr(last_dash + 6, NULL, NULL, true, true, true, NULL, &n);
key = (int)n; key = (int)n;
} else { } else {
/* /*
* Modifier with single letter, or special key name. * Modifier with single letter, or special key name.
*/ */
if (has_mbyte) if (has_mbyte) {
l = mb_ptr2len(last_dash + 1); l = mb_ptr2len(last_dash + 1);
else } else {
l = 1; l = 1;
if (modifiers != 0 && last_dash[l + 1] == '>') }
if (modifiers != 0 && last_dash[l + 1] == '>') {
key = PTR2CHAR(last_dash + 1); key = PTR2CHAR(last_dash + 1);
else { } else {
key = get_special_key_code(last_dash + 1); key = get_special_key_code(last_dash + 1);
if (!keep_x_key) if (!keep_x_key) {
key = handle_x_keys(key); key = handle_x_keys(key);
}
} }
} }
/* // get_special_key_code() may return NUL for invalid
* get_special_key_code() may return NUL for invalid // special key name.
* special key name.
*/
if (key != NUL) { if (key != NUL) {
/* // Only use a modifier when there is no special key code that
* Only use a modifier when there is no special key code that // includes the modifier.
* includes the modifier.
*/
key = simplify_key(key, &modifiers); key = simplify_key(key, &modifiers);
if (!keycode) { if (!keycode) {
/* don't want keycode, use single byte code */ // don't want keycode, use single byte code
if (key == K_BS) if (key == K_BS) {
key = BS; key = BS;
else if (key == K_DEL || key == K_KDEL) } else if (key == K_DEL || key == K_KDEL) {
key = DEL; key = DEL;
}
} }
// Normal Key with modifier: // Normal Key with modifier:

View File

@@ -3103,8 +3103,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
char *p = fmt; char *p = fmt;
int arg_idx = 1; int arg_idx = 1;
if (!p) if (!p) {
p = ""; p = "";
}
while (*p) { while (*p) {
if (*p != '%') { if (*p != '%') {
// copy up to the next '%' or NUL without any changes // copy up to the next '%' or NUL without any changes
@@ -3176,9 +3177,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
if (*p == '*') { if (*p == '*') {
p++; p++;
int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int);
if (j >= 0) if (j >= 0) {
min_field_width = j; min_field_width = j;
else { } else {
min_field_width = -j; min_field_width = -j;
justify_left = 1; justify_left = 1;
} }
@@ -3187,8 +3188,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
// argument like common implementations do // argument like common implementations do
unsigned int uj = *p++ - '0'; unsigned int uj = *p++ - '0';
while (ascii_isdigit((int)(*p))) while (ascii_isdigit((int)(*p))) {
uj = 10 * uj + (unsigned int)(*p++ - '0'); uj = 10 * uj + (unsigned int)(*p++ - '0');
}
min_field_width = uj; min_field_width = uj;
} }
@@ -3199,9 +3201,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
if (*p == '*') { if (*p == '*') {
int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int);
p++; p++;
if (j >= 0) if (j >= 0) {
precision = j; precision = j;
else { } else {
precision_specified = 0; precision_specified = 0;
precision = 0; precision = 0;
} }
@@ -3210,8 +3212,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
// treat argument like common implementations do // treat argument like common implementations do
unsigned int uj = *p++ - '0'; unsigned int uj = *p++ - '0';
while (ascii_isdigit((int)(*p))) while (ascii_isdigit((int)(*p))) {
uj = 10 * uj + (unsigned int)(*p++ - '0'); uj = 10 * uj + (unsigned int)(*p++ - '0');
}
precision = uj; precision = uj;
} }
} }
@@ -3262,14 +3265,13 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
if (!str_arg) { if (!str_arg) {
str_arg = "[NULL]"; str_arg = "[NULL]";
str_arg_l = 6; str_arg_l = 6;
} } else if (!precision_specified) {
// make sure not to address string beyond the specified precision // make sure not to address string beyond the specified precision
else if (!precision_specified)
str_arg_l = strlen(str_arg); str_arg_l = strlen(str_arg);
// truncate string if necessary as requested by precision } else if (precision == 0) {
else if (precision == 0) // truncate string if necessary as requested by precision
str_arg_l = 0; str_arg_l = 0;
else { } else {
// memchr on HP does not like n > 2^31 // memchr on HP does not like n > 2^31
// TODO(elmart): check if this still holds / is relevant // TODO(elmart): check if this still holds / is relevant
str_arg_l = (size_t)((char *)xmemscan(str_arg, str_arg_l = (size_t)((char *)xmemscan(str_arg,
@@ -3283,8 +3285,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
- mb_string2cells((char_u *) str_arg); - mb_string2cells((char_u *) str_arg);
if (precision) { if (precision) {
char_u *p1 = (char_u *)str_arg; char_u *p1 = (char_u *)str_arg;
for (size_t i = 0; i < precision && *p1; i++) for (size_t i = 0; i < precision && *p1; i++) {
p1 += mb_ptr2len(p1); p1 += mb_ptr2len(p1);
}
str_arg_l = precision = p1 - (char_u *)str_arg; str_arg_l = precision = p1 - (char_u *)str_arg;
} }
} }
@@ -3295,9 +3298,14 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
} }
break; break;
case 'd': case 'u': case 'b': case 'B': case 'o': case 'x': case 'X': case 'p': { case 'd':
// u, b, B, o, x, X and p conversion specifiers imply the value is unsigned; case 'u':
// d implies a signed value case 'b': case 'B':
case 'o':
case 'x': case 'X':
case 'p': {
// u, b, B, o, x, X and p conversion specifiers imply
// the value is unsigned; d implies a signed value
// 0 if numeric argument is zero (or if pointer is NULL for 'p'), // 0 if numeric argument is zero (or if pointer is NULL for 'p'),
// +1 if greater than zero (or non NULL for 'p'), // +1 if greater than zero (or non NULL for 'p'),
@@ -3325,8 +3333,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
if (fmt_spec == 'p') { if (fmt_spec == 'p') {
length_modifier = '\0'; length_modifier = '\0';
ptr_arg = tvs ? (void *)tv_str(tvs, &arg_idx) : va_arg(ap, void *); ptr_arg = tvs ? (void *)tv_str(tvs, &arg_idx) : va_arg(ap, void *);
if (ptr_arg) if (ptr_arg) {
arg_sign = 1; arg_sign = 1;
}
} else if (fmt_spec == 'd') { } else if (fmt_spec == 'd') {
// signed // signed
switch (length_modifier) { switch (length_modifier) {
@@ -3334,25 +3343,28 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
case 'h': case 'h':
// char and short arguments are passed as int // char and short arguments are passed as int
int_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); int_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int);
if (int_arg > 0) if (int_arg > 0) {
arg_sign = 1; arg_sign = 1;
else if (int_arg < 0) } else if (int_arg < 0) {
arg_sign = -1; arg_sign = -1;
}
break; break;
case 'l': case 'l':
long_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, long int); long_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, long int);
if (long_arg > 0) if (long_arg > 0) {
arg_sign = 1; arg_sign = 1;
else if (long_arg < 0) } else if (long_arg < 0) {
arg_sign = -1; arg_sign = -1;
}
break; break;
case '2': case '2':
long_long_arg = tvs ? tv_nr(tvs, &arg_idx) long_long_arg = tvs ? tv_nr(tvs, &arg_idx)
: va_arg(ap, long long int); : va_arg(ap, long long int); // NOLINT (runtime/int)
if (long_long_arg > 0) if (long_long_arg > 0) {
arg_sign = 1; arg_sign = 1;
else if (long_long_arg < 0) } else if (long_long_arg < 0) {
arg_sign = -1; arg_sign = -1;
}
break; break;
} }
} else { } else {
@@ -3362,24 +3374,23 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
case 'h': case 'h':
uint_arg = tvs ? (unsigned)tv_nr(tvs, &arg_idx) uint_arg = tvs ? (unsigned)tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned int); : va_arg(ap, unsigned int);
if (uint_arg != 0) if (uint_arg != 0) { arg_sign = 1; }
arg_sign = 1;
break; break;
case 'l': case 'l':
ulong_arg = tvs ? (unsigned long)tv_nr(tvs, &arg_idx) ulong_arg = tvs ? (unsigned long)tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned long int); : va_arg(ap, unsigned long int);
if (ulong_arg != 0) if (ulong_arg != 0) { arg_sign = 1; }
arg_sign = 1;
break; break;
case '2': case '2':
ulong_long_arg = tvs ? (unsigned long long)tv_nr(tvs, &arg_idx) ulong_long_arg = tvs
: va_arg(ap, unsigned long long int); ? (unsigned long long)tv_nr(tvs, &arg_idx) // NOLINT (runtime/int)
if (ulong_long_arg) arg_sign = 1; : va_arg(ap, unsigned long long int); // NOLINT (runtime/int)
if (ulong_long_arg) { arg_sign = 1; }
break; break;
case 'z': case 'z':
size_t_arg = tvs ? (size_t)tv_nr(tvs, &arg_idx) size_t_arg = tvs ? (size_t)tv_nr(tvs, &arg_idx)
: va_arg(ap, size_t); : va_arg(ap, size_t);
if (size_t_arg) arg_sign = 1; if (size_t_arg) { arg_sign = 1; }
break; break;
} }
} }
@@ -3390,12 +3401,14 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
// For d, i, u, o, x, and X conversions, if precision is specified, // For d, i, u, o, x, and X conversions, if precision is specified,
// '0' flag should be ignored. This is so with Solaris 2.6, Digital UNIX // '0' flag should be ignored. This is so with Solaris 2.6, Digital UNIX
// 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl. // 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl.
if (precision_specified) if (precision_specified) {
zero_padding = 0; zero_padding = 0;
}
if (fmt_spec == 'd') { if (fmt_spec == 'd') {
if (force_sign && arg_sign >= 0) if (force_sign && arg_sign >= 0) {
tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
}
// leave negative numbers for sprintf to handle, to // leave negative numbers for sprintf to handle, to
// avoid handling tricky cases like (short int)-32768 // avoid handling tricky cases like (short int)-32768
} else if (alternate_form) { } else if (alternate_form) {
@@ -3408,8 +3421,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
} }
zero_padding_insertion_ind = str_arg_l; zero_padding_insertion_ind = str_arg_l;
if (!precision_specified) if (!precision_specified) {
precision = 1; // default precision is 1 precision = 1; // default precision is 1
}
if (precision == 0 && arg_sign == 0) { if (precision == 0 && arg_sign == 0) {
// when zero value is formatted with an explicit precision 0, // when zero value is formatted with an explicit precision 0,
// resulting formatted string is empty (d, i, u, b, B, o, x, X, p) // resulting formatted string is empty (d, i, u, b, B, o, x, X, p)
@@ -3419,9 +3433,8 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
// construct a simple format string for sprintf // construct a simple format string for sprintf
f[f_l++] = '%'; f[f_l++] = '%';
if (!length_modifier) if (!length_modifier) {
; } else if (length_modifier == '2') {
else if (length_modifier == '2') {
f[f_l++] = 'l'; f[f_l++] = 'l';
f[f_l++] = 'l'; f[f_l++] = 'l';
} else } else
@@ -3443,33 +3456,38 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
break; break;
} }
} else if (fmt_spec == 'b' || fmt_spec == 'B') { } else if (fmt_spec == 'b' || fmt_spec == 'B') {
//binary // binary
size_t bits = 0; size_t bits = 0;
switch (length_modifier) { switch (length_modifier) {
case '\0': case '\0':
case 'h': for (bits = sizeof(unsigned) * 8; bits > 0; bits--) case 'h': for (bits = sizeof(unsigned) * 8; bits > 0; bits--) {
if ((uint_arg >> (bits - 1)) & 0x1) break; if ((uint_arg >> (bits - 1)) & 0x1) { break; } }
while (bits > 0) while (bits > 0) {
tmp[str_arg_l++] = ((uint_arg >> --bits) & 0x1) ? '1' : '0'; tmp[str_arg_l++] =
((uint_arg >> --bits) & 0x1) ? '1' : '0'; }
break; break;
case 'l': for (bits = sizeof(unsigned long) * 8; bits > 0; bits--) case 'l': for (bits = sizeof(unsigned long) * 8; bits > 0; bits--) {
if ((ulong_arg >> (bits - 1)) & 0x1) break; if ((ulong_arg >> (bits - 1)) & 0x1) { break; } }
while (bits > 0) while (bits > 0) {
tmp[str_arg_l++] = ((ulong_arg >> --bits) & 0x1) ? '1' : '0'; tmp[str_arg_l++] =
((ulong_arg >> --bits) & 0x1) ? '1' : '0'; }
break; break;
case '2': for (bits = sizeof(unsigned long long) * 8; bits > 0; bits--) case '2': for (bits = sizeof(unsigned long long) * 8; // NOLINT (runtime/int)
if ((ulong_long_arg >> (bits - 1)) & 0x1) break; bits > 0; bits--) {
if ((ulong_long_arg >> (bits - 1)) & 0x1) { break; } }
while (bits > 0)
tmp[str_arg_l++] = ((ulong_long_arg >> --bits) & 0x1) ? '1' : '0'; while (bits > 0) {
tmp[str_arg_l++] =
((ulong_long_arg >> --bits) & 0x1) ? '1' : '0'; }
break; break;
case 'z': for (bits = sizeof(size_t) * 8; bits > 0; bits--) case 'z': for (bits = sizeof(size_t) * 8; bits > 0; bits--) {
if ((size_t_arg >> (bits - 1)) & 0x1) break; if ((size_t_arg >> (bits - 1)) & 0x1) { break; } }
while (bits > 0) while (bits > 0) {
tmp[str_arg_l++] = ((size_t_arg >> --bits) & 0x1) ? '1' : '0'; tmp[str_arg_l++] =
((size_t_arg >> --bits) & 0x1) ? '1' : '0'; }
break; break;
} }
} else { } else {
@@ -3540,7 +3558,7 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
// floating point // floating point
char format[40]; char format[40];
int l; int l;
int remove_trailing_zeroes = FALSE; int remove_trailing_zeroes = false;
double f = tvs ? tv_float(tvs, &arg_idx) : va_arg(ap, double); double f = tvs ? tv_float(tvs, &arg_idx) : va_arg(ap, double);
double abs_f = f < 0 ? -f : f; double abs_f = f < 0 ? -f : f;
@@ -3551,7 +3569,7 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
fmt_spec = 'f'; fmt_spec = 'f';
else else
fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; fmt_spec = fmt_spec == 'g' ? 'e' : 'E';
remove_trailing_zeroes = TRUE; remove_trailing_zeroes = true;
} }
if (fmt_spec == 'f' && abs_f > 1.0e307) { if (fmt_spec == 'f' && abs_f > 1.0e307) {

View File

@@ -4186,23 +4186,23 @@ static void reverse_line(char_u *s)
# define RLADDSUBFIX(ptr) if (curwin->w_p_rl) reverse_line(ptr); # define RLADDSUBFIX(ptr) if (curwin->w_p_rl) reverse_line(ptr);
/* /// Add or subtract from a number in a line.
* add or subtract 'Prenum1' from a number in a line ///
* 'command' is CTRL-A for add, CTRL-X for subtract /// @param command CTRL-A for add, CTRL-X for subtract
* // @param Prenum1 number to add or subtract
* return FAIL for failure, OK otherwise ///
*/ /// @return FAIL for failure, OK otherwise
int do_addsub(int command, linenr_T Prenum1) int do_addsub(int command, linenr_T Prenum1)
{ {
int col; int col;
char_u *buf1; char_u *buf1;
char_u buf2[NUMBUFLEN]; char_u buf2[NUMBUFLEN];
int pre; /* 'X' or 'x': hex; '0': octal; 'B' or 'b': bin */ int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin
static int hexupper = FALSE; /* 0xABC */ static int hexupper = false; // 0xABC
unsigned long n, oldn; unsigned long n, oldn;
char_u *ptr; char_u *ptr;
int c; int c;
int length = 0; /* character length of the number */ int length = 0; // character length of the number
int todel; int todel;
int dohex; int dohex;
int dooct; int dooct;
@@ -4212,76 +4212,76 @@ int do_addsub(int command, linenr_T Prenum1)
int negative; int negative;
int subtract; int subtract;
dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX"
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal"
dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin"
doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha"
ptr = get_cursor_line_ptr(); ptr = get_cursor_line_ptr();
RLADDSUBFIX(ptr); RLADDSUBFIX(ptr);
/* // First check if we are on a hexadecimal number, after the "0x".
* First check if we are on a hexadecimal number, after the "0x".
*/
col = curwin->w_cursor.col; col = curwin->w_cursor.col;
if (dobin) if (dobin) {
while (col > 0 && ascii_isbdigit(ptr[col])) while (col > 0 && ascii_isbdigit(ptr[col])) {
--col; col--;
}
}
if (dohex) if (dohex) {
while (col > 0 && ascii_isxdigit(ptr[col])) while (col > 0 && ascii_isxdigit(ptr[col])) {
--col; col--;
if ( dobin }
&& dohex }
&& ! ((col > 0 if (dobin
&& (ptr[col] == 'X' && dohex
|| ptr[col] == 'x') && !((col > 0
&& ptr[col - 1] == '0' && (ptr[col] == 'X' ||
&& ascii_isxdigit(ptr[col + 1])))) { ptr[col] == 'x')
&& ptr[col - 1] == '0'
/* In case of binary/hexadecimal pattern overlap match, rescan */ && ascii_isxdigit(ptr[col + 1])))) {
// In case of binary/hexadecimal pattern overlap match, rescan
col = curwin->w_cursor.col; col = curwin->w_cursor.col;
while (col > 0 && ascii_isdigit(ptr[col])) while (col > 0 && ascii_isdigit(ptr[col])) {
col--; col--;
}
} }
if (( dohex if ((dohex
&& col > 0 && col > 0
&& (ptr[col] == 'X' && (ptr[col] == 'X'
|| ptr[col] == 'x') || ptr[col] == 'x')
&& ptr[col - 1] == '0' && ptr[col - 1] == '0'
&& ascii_isxdigit(ptr[col + 1])) || && ascii_isxdigit(ptr[col + 1])) ||
( dobin (dobin
&& col > 0 && col > 0
&& (ptr[col] == 'B' && (ptr[col] == 'B'
|| ptr[col] == 'b') || ptr[col] == 'b')
&& ptr[col - 1] == '0' && ptr[col - 1] == '0'
&& ascii_isbdigit(ptr[col + 1]))) { && ascii_isbdigit(ptr[col + 1]))) {
/* Found hexadecimal or binary number, move to its start. */ // Found hexadecimal or binary number, move to its start.
--col; col--;
} else { } else {
/* // Search forward and then backward to find the start of number.
* Search forward and then backward to find the start of number.
*/
col = curwin->w_cursor.col; col = curwin->w_cursor.col;
while (ptr[col] != NUL while (ptr[col] != NUL
&& !ascii_isdigit(ptr[col]) && !ascii_isdigit(ptr[col])
&& !(doalp && ASCII_ISALPHA(ptr[col]))) && !(doalp && ASCII_ISALPHA(ptr[col]))) {
++col; col++;
}
while (col > 0 while (col > 0
&& ascii_isdigit(ptr[col - 1]) && ascii_isdigit(ptr[col - 1])
&& !(doalp && ASCII_ISALPHA(ptr[col]))) && !(doalp && ASCII_ISALPHA(ptr[col]))) {
--col; col--;
}
} }
/* // If a number was found, and saving for undo works, replace the number.
* If a number was found, and saving for undo works, replace the number.
*/
firstdigit = ptr[col]; firstdigit = ptr[col];
RLADDSUBFIX(ptr); RLADDSUBFIX(ptr);
if ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) if ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit)))
@@ -4290,108 +4290,111 @@ int do_addsub(int command, linenr_T Prenum1)
return FAIL; return FAIL;
} }
/* get ptr again, because u_save() may have changed it */ // get ptr again, because u_save() may have changed it
ptr = get_cursor_line_ptr(); ptr = get_cursor_line_ptr();
RLADDSUBFIX(ptr); RLADDSUBFIX(ptr);
if (doalp && ASCII_ISALPHA(firstdigit)) { if (doalp && ASCII_ISALPHA(firstdigit)) {
/* decrement or increment alphabetic character */ // decrement or increment alphabetic character
if (command == Ctrl_X) { if (command == Ctrl_X) {
if (CharOrd(firstdigit) < Prenum1) { if (CharOrd(firstdigit) < Prenum1) {
if (isupper(firstdigit)) if (isupper(firstdigit)) {
firstdigit = 'A'; firstdigit = 'A';
else } else {
firstdigit = 'a'; firstdigit = 'a';
} else }
} else {
firstdigit -= Prenum1; firstdigit -= Prenum1;
}
} else { } else {
if (26 - CharOrd(firstdigit) - 1 < Prenum1) { if (26 - CharOrd(firstdigit) - 1 < Prenum1) {
if (isupper(firstdigit)) if (isupper(firstdigit)) {
firstdigit = 'Z'; firstdigit = 'Z';
else } else {
firstdigit = 'z'; firstdigit = 'z';
} else }
} else {
firstdigit += Prenum1; firstdigit += Prenum1;
}
} }
curwin->w_cursor.col = col; curwin->w_cursor.col = col;
(void)del_char(FALSE); (void)del_char(false);
ins_char(firstdigit); ins_char(firstdigit);
} else { } else {
negative = FALSE; negative = false;
if (col > 0 && ptr[col - 1] == '-') { /* negative number */ if (col > 0 && ptr[col - 1] == '-') { // negative number
--col; --col;
negative = TRUE; negative = true;
} }
/* get the number value (unsigned) */ // get the number value (unsigned)
vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, NULL, &n); vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, NULL, &n);
/* ignore leading '-' for hex, octal and bin numbers */ // ignore leading '-' for hex, octal and bin numbers
if (pre && negative) { if (pre && negative) {
++col; ++col;
--length; --length;
negative = FALSE; negative = false;
} }
/* add or subtract */ // add or subtract
subtract = FALSE; subtract = false;
if (command == Ctrl_X) if (command == Ctrl_X) {
subtract ^= TRUE; subtract ^= true;
if (negative) }
subtract ^= TRUE; if (negative) {
subtract ^= true;
}
oldn = n; oldn = n;
if (subtract)
n -= (unsigned long)Prenum1;
else
n += (unsigned long)Prenum1;
/* handle wraparound for decimal numbers */ n = subtract ? n - (unsigned long) Prenum1
: n + (unsigned long) Prenum1;
// handle wraparound for decimal numbers
if (!pre) { if (!pre) {
if (subtract) { if (subtract) {
if (n > oldn) { if (n > oldn) {
n = 1 + (n ^ (unsigned long)-1); n = 1 + (n ^ (unsigned long)-1);
negative ^= TRUE; negative ^= true;
} }
} else { /* add */ } else { /* add */
if (n < oldn) { if (n < oldn) {
n = (n ^ (unsigned long)-1); n = (n ^ (unsigned long)-1);
negative ^= TRUE; negative ^= true;
} }
} }
if (n == 0) if (n == 0) {
negative = FALSE; negative = false;
}
} }
/* // Delete the old number.
* Delete the old number.
*/
curwin->w_cursor.col = col; curwin->w_cursor.col = col;
todel = length; todel = length;
c = gchar_cursor(); c = gchar_cursor();
/*
* Don't include the '-' in the length, only the length of the part // Don't include the '-' in the length, only the length of the part
* after it is kept the same. // after it is kept the same.
*/ if (c == '-') {
if (c == '-')
--length; --length;
}
while (todel-- > 0) { while (todel-- > 0) {
if (c < 0x100 && isalpha(c)) { if (c < 0x100 && isalpha(c)) {
if (isupper(c)) if (isupper(c)) {
hexupper = TRUE; hexupper = true;
else } else {
hexupper = FALSE; hexupper = false;
}
} }
/* del_char() will mark line needing displaying */ // del_char() will mark line needing displaying
(void)del_char(FALSE); (void)del_char(false);
c = gchar_cursor(); c = gchar_cursor();
} }
/* // Prepare the leading characters in buf1[].
* Prepare the leading characters in buf1[]. // When there are many leading zeros it could be very long. Allocate
* When there are many leading zeros it could be very long. Allocate // a bit too much.
* a bit too much.
*/
buf1 = xmalloc(length + NUMBUFLEN); buf1 = xmalloc(length + NUMBUFLEN);
ptr = buf1; ptr = buf1;
if (negative) { if (negative) {
@@ -4401,56 +4404,56 @@ int do_addsub(int command, linenr_T Prenum1)
*ptr++ = '0'; *ptr++ = '0';
--length; --length;
} }
if (pre == 'b' || pre == 'B' if (pre == 'b' || pre == 'B' ||
|| pre == 'x' || pre == 'X') { pre == 'x' || pre == 'X') {
*ptr++ = pre; *ptr++ = pre;
--length; --length;
} }
/* // Put the number characters in buf2[].
* Put the number characters in buf2[].
*/
if (pre == 'b' || pre == 'B') { if (pre == 'b' || pre == 'B') {
size_t bits = 0; size_t bits = 0;
size_t pos = 0; size_t pos = 0;
/* leading zeros */ // leading zeros
for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) {
if ((n >> (bits - 1)) & 0x1) break; if ((n >> (bits - 1)) & 0x1) { break; }
}
while (bits > 0) while (bits > 0) {
buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0'; buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0';
}
buf2[pos] = '\0'; buf2[pos] = '\0';
} else if (pre == 0) } else if (pre == 0) {
sprintf((char *)buf2, "%" PRIu64, (uint64_t)n); snprintf((char *)buf2, NUMBUFLEN, "%" PRIu64, (uint64_t)n);
else if (pre == '0') } else if (pre == '0') {
sprintf((char *)buf2, "%" PRIo64, (uint64_t)n); snprintf((char *)buf2, NUMBUFLEN, "%" PRIo64, (uint64_t)n);
else if (pre && hexupper) } else if (pre && hexupper) {
sprintf((char *)buf2, "%" PRIX64, (uint64_t)n); snprintf((char *)buf2, NUMBUFLEN, "%" PRIX64, (uint64_t)n);
else } else {
sprintf((char *)buf2, "%" PRIx64, (uint64_t)n); snprintf((char *)buf2, NUMBUFLEN, "%" PRIx64, (uint64_t)n);
}
length -= (int)STRLEN(buf2); length -= (int)STRLEN(buf2);
/* // Adjust number of zeros to the new number of digits, so the
* Adjust number of zeros to the new number of digits, so the // total length of the number remains the same.
* total length of the number remains the same. // Don't do this when
* Don't do this when // the result may look like an octal number.
* the result may look like an octal number. if (firstdigit == '0' && !(dooct && pre == 0)) {
*/ while (length-- > 0) {
if (firstdigit == '0' && !(dooct && pre == 0))
while (length-- > 0)
*ptr++ = '0'; *ptr++ = '0';
}
}
*ptr = NUL; *ptr = NUL;
STRCAT(buf1, buf2); STRCAT(buf1, buf2);
ins_str(buf1); /* insert the new number */ ins_str(buf1); /* insert the new number */
xfree(buf1); xfree(buf1);
} }
--curwin->w_cursor.col; --curwin->w_cursor.col;
curwin->w_set_curswant = TRUE; curwin->w_set_curswant = true;
ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true);
RLADDSUBFIX(ptr); RLADDSUBFIX(ptr);
return OK; return OK;
} }

View File

@@ -258,30 +258,31 @@ typedef struct vimoption {
#define PARAM_COUNT ARRAY_SIZE(options) #define PARAM_COUNT ARRAY_SIZE(options)
static char *(p_ambw_values[]) = {"single", "double", NULL}; static char *(p_ambw_values[]) = { "single", "double", NULL };
static char *(p_bg_values[]) = {"light", "dark", NULL}; static char *(p_bg_values[]) = { "light", "dark", NULL };
static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL}; static char *(p_nf_values[]) = { "bin", "octal", "hex", "alpha", NULL };
static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; static char *(p_ff_values[]) = { FF_UNIX, FF_DOS, FF_MAC, NULL };
static char *(p_wop_values[]) = {"tagfile", NULL}; static char *(p_wop_values[]) = { "tagfile", NULL };
static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; static char *(p_wak_values[]) = { "yes", "menu", "no", NULL };
static char *(p_mousem_values[]) = static char *(p_mousem_values[]) = { "extend", "popup", "popup_setpos",
{"extend", "popup", "popup_setpos", "mac", NULL}; "mac", NULL };
static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; static char *(p_sel_values[]) = { "inclusive", "exclusive", "old", NULL };
static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; static char *(p_slm_values[]) = { "mouse", "key", "cmd", NULL };
static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; static char *(p_km_values[]) = { "startsel", "stopsel", NULL };
static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; static char *(p_scbopt_values[]) = { "ver", "hor", "jump", NULL };
static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; static char *(p_debug_values[]) = { "msg", "throw", "beep", NULL };
static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; static char *(p_ead_values[]) = { "both", "ver", "hor", NULL };
static char *(p_buftype_values[]) = static char *(p_buftype_values[]) = { "nofile", "nowrite", "quickfix",
{"nofile", "nowrite", "quickfix", "help", "acwrite", "terminal", NULL}; "help", "acwrite", "terminal", NULL };
static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; static char *(p_bufhidden_values[]) = { "hide", "unload", "delete",
static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", "wipe", NULL };
"diff", static char *(p_bs_values[]) = { "indent", "eol", "start", NULL };
NULL}; static char *(p_fdm_values[]) = { "manual", "expr", "marker", "indent",
static char *(p_fcl_values[]) = {"all", NULL}; "syntax", "diff", NULL };
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", static char *(p_fcl_values[]) = { "all", NULL };
"noinsert", "noselect", NULL}; static char *(p_cot_values[]) = { "menu", "menuone", "longest", "preview",
"noinsert", "noselect", NULL };
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "option.c.generated.h" # include "option.c.generated.h"

View File

@@ -1063,8 +1063,7 @@ static char_u *repl_to = NULL;
// //
// Returns the length of the word in bytes, also when it's OK, so that the // Returns the length of the word in bytes, also when it's OK, so that the
// caller can skip over the word. // caller can skip over the word.
size_t size_t spell_check(
spell_check (
win_T *wp, // current window win_T *wp, // current window
char_u *ptr, char_u *ptr,
hlf_T *attrp, hlf_T *attrp,
@@ -1082,12 +1081,14 @@ spell_check (
// A word never starts at a space or a control character. Return quickly // A word never starts at a space or a control character. Return quickly
// then, skipping over the character. // then, skipping over the character.
if (*ptr <= ' ') if (*ptr <= ' ') {
return 1; return 1;
}
// Return here when loading language files failed. // Return here when loading language files failed.
if (GA_EMPTY(&wp->w_s->b_langp)) if (GA_EMPTY(&wp->w_s->b_langp)) {
return 1; return 1;
}
memset(&mi, 0, sizeof(matchinf_T)); memset(&mi, 0, sizeof(matchinf_T));
@@ -1095,12 +1096,13 @@ spell_check (
// 0X99FF. But always do check spelling to find "3GPP" and "11 // 0X99FF. But always do check spelling to find "3GPP" and "11
// julifeest". // julifeest".
if (*ptr >= '0' && *ptr <= '9') { if (*ptr >= '0' && *ptr <= '9') {
if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) {
mi.mi_end = skipbin(ptr + 2); mi.mi_end = (char_u*) skipbin((char*) ptr + 2);
else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) {
mi.mi_end = skiphex(ptr + 2); mi.mi_end = skiphex(ptr + 2);
else } else {
mi.mi_end = skipdigits(ptr); mi.mi_end = skipdigits(ptr);
}
nrlen = (size_t)(mi.mi_end - ptr); nrlen = (size_t)(mi.mi_end - ptr);
} }
@@ -1115,12 +1117,14 @@ spell_check (
if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) { if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) {
// Check word starting with capital letter. // Check word starting with capital letter.
c = PTR2CHAR(ptr); c = PTR2CHAR(ptr);
if (!SPELL_ISUPPER(c)) if (!SPELL_ISUPPER(c)) {
wrongcaplen = (size_t)(mi.mi_fend - ptr); wrongcaplen = (size_t)(mi.mi_fend - ptr);
}
} }
} }
if (capcol != NULL) if (capcol != NULL) {
*capcol = -1; *capcol = -1;
}
// We always use the characters up to the next non-word character, // We always use the characters up to the next non-word character,
// also for bad words. // also for bad words.
@@ -1133,8 +1137,9 @@ spell_check (
// case-fold the word with one non-word character, so that we can check // case-fold the word with one non-word character, so that we can check
// for the word end. // for the word end.
if (*mi.mi_fend != NUL) if (*mi.mi_fend != NUL) {
mb_ptr_adv(mi.mi_fend); mb_ptr_adv(mi.mi_fend);
}
(void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1); (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1);
mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); mi.mi_fwordlen = (int)STRLEN(mi.mi_fword);
@@ -1151,8 +1156,9 @@ spell_check (
// If reloading fails the language is still in the list but everything // If reloading fails the language is still in the list but everything
// has been cleared. // has been cleared.
if (mi.mi_lp->lp_slang->sl_fidxs == NULL) if (mi.mi_lp->lp_slang->sl_fidxs == NULL) {
continue; continue;
}
// Check for a matching word in case-folded words. // Check for a matching word in case-folded words.
find_word(&mi, FIND_FOLDWORD); find_word(&mi, FIND_FOLDWORD);
@@ -1183,18 +1189,18 @@ spell_check (
// If we found a number skip over it. Allows for "42nd". Do flag // If we found a number skip over it. Allows for "42nd". Do flag
// rare and local words, e.g., "3GPP". // rare and local words, e.g., "3GPP".
if (nrlen > 0) { if (nrlen > 0) {
if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) {
return nrlen; return nrlen;
} }
} else if (!spell_iswordp_nmw(ptr, wp)) {
// When we are at a non-word character there is no error, just // When we are at a non-word character there is no error, just
// skip over the character (try looking for a word after it). // skip over the character (try looking for a word after it).
else if (!spell_iswordp_nmw(ptr, wp)) {
if (capcol != NULL && wp->w_s->b_cap_prog != NULL) { if (capcol != NULL && wp->w_s->b_cap_prog != NULL) {
regmatch_T regmatch; regmatch_T regmatch;
// Check for end of sentence. // Check for end of sentence.
regmatch.regprog = wp->w_s->b_cap_prog; regmatch.regprog = wp->w_s->b_cap_prog;
regmatch.rm_ic = FALSE; regmatch.rm_ic = false;
int r = vim_regexec(&regmatch, ptr, 0); int r = vim_regexec(&regmatch, ptr, 0);
wp->w_s->b_cap_prog = regmatch.regprog; wp->w_s->b_cap_prog = regmatch.regprog;
if (r) { if (r) {
@@ -1206,12 +1212,12 @@ spell_check (
return (size_t)(*mb_ptr2len)(ptr); return (size_t)(*mb_ptr2len)(ptr);
} }
return 1; return 1;
} else if (mi.mi_end == ptr) } else if (mi.mi_end == ptr) {
// Always include at least one character. Required for when there // Always include at least one character. Required for when there
// is a mixup in "midword". // is a mixup in "midword".
mb_ptr_adv(mi.mi_end); mb_ptr_adv(mi.mi_end);
else if (mi.mi_result == SP_BAD } else if (mi.mi_result == SP_BAD
&& LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) {
char_u *p, *fp; char_u *p, *fp;
int save_result = mi.mi_result; int save_result = mi.mi_result;
@@ -1221,11 +1227,12 @@ spell_check (
if (mi.mi_lp->lp_slang->sl_fidxs != NULL) { if (mi.mi_lp->lp_slang->sl_fidxs != NULL) {
p = mi.mi_word; p = mi.mi_word;
fp = mi.mi_fword; fp = mi.mi_fword;
for (;; ) { for (;;) {
mb_ptr_adv(p); mb_ptr_adv(p);
mb_ptr_adv(fp); mb_ptr_adv(fp);
if (p >= mi.mi_end) if (p >= mi.mi_end) {
break; break;
}
mi.mi_compoff = (int)(fp - mi.mi_fword); mi.mi_compoff = (int)(fp - mi.mi_fword);
find_word(&mi, FIND_COMPOUND); find_word(&mi, FIND_COMPOUND);
if (mi.mi_result != SP_BAD) { if (mi.mi_result != SP_BAD) {
@@ -1237,12 +1244,13 @@ spell_check (
} }
} }
if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) {
*attrp = HLF_SPB; *attrp = HLF_SPB;
else if (mi.mi_result == SP_RARE) } else if (mi.mi_result == SP_RARE) {
*attrp = HLF_SPR; *attrp = HLF_SPR;
else } else {
*attrp = HLF_SPL; *attrp = HLF_SPL;
}
} }
if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) { if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) {

View File

@@ -35,7 +35,7 @@ Error: configure did not run properly.Check auto/config.log.
#include "nvim/os/os_defs.h" /* bring lots of system header files */ #include "nvim/os/os_defs.h" /* bring lots of system header files */
#define NUMBUFLEN 65 /* length of a buffer to store a number in ASCII */ #define NUMBUFLEN 65 // length of a buffer to store a number in ASCII
#define MAX_TYPENR 65535 #define MAX_TYPENR 65535