Mercurial > vim
comparison src/evalfunc.c @ 18777:3a68dc2a1bc1 v8.1.2378
patch 8.1.2378: using old C style comments
Commit: https://github.com/vim/vim/commit/5d18efecfd6c45d69f55268948a22cd0465bb955
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 21:11:22 2019 +0100
patch 8.1.2378: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 21:15:03 +0100 |
parents | 49b78d6465e5 |
children | bf8eb950df61 |
comparison
equal
deleted
inserted
replaced
18776:90a6831d6cd7 | 18777:3a68dc2a1bc1 |
---|---|
1288 { | 1288 { |
1289 pumitem_T *array; | 1289 pumitem_T *array; |
1290 int size = split_message(msg, &array); | 1290 int size = split_message(msg, &array); |
1291 int i; | 1291 int i; |
1292 | 1292 |
1293 /* Skip the first and last item, they are always empty. */ | 1293 // Skip the first and last item, they are always empty. |
1294 for (i = 1; i < size - 1; ++i) | 1294 for (i = 1; i < size - 1; ++i) |
1295 list_append_string(rettv->vval.v_list, array[i].pum_text, -1); | 1295 list_append_string(rettv->vval.v_list, array[i].pum_text, -1); |
1296 while (size > 0) | 1296 while (size > 0) |
1297 vim_free(array[--size].pum_text); | 1297 vim_free(array[--size].pum_text); |
1298 vim_free(array); | 1298 vim_free(array); |
1320 if (name[0] == '$' && name[1] == NUL) | 1320 if (name[0] == '$' && name[1] == NUL) |
1321 return lastbuf; | 1321 return lastbuf; |
1322 | 1322 |
1323 buf = buflist_find_by_name(name, curtab_only); | 1323 buf = buflist_find_by_name(name, curtab_only); |
1324 | 1324 |
1325 /* If not found, try expanding the name, like done for bufexists(). */ | 1325 // If not found, try expanding the name, like done for bufexists(). |
1326 if (buf == NULL) | 1326 if (buf == NULL) |
1327 buf = find_buffer(tv); | 1327 buf = find_buffer(tv); |
1328 | 1328 |
1329 return buf; | 1329 return buf; |
1330 } | 1330 } |
1355 #ifndef FEAT_BYTEOFF | 1355 #ifndef FEAT_BYTEOFF |
1356 rettv->vval.v_number = -1; | 1356 rettv->vval.v_number = -1; |
1357 #else | 1357 #else |
1358 long boff = 0; | 1358 long boff = 0; |
1359 | 1359 |
1360 boff = tv_get_number(&argvars[0]) - 1; /* boff gets -1 on type error */ | 1360 boff = tv_get_number(&argvars[0]) - 1; // boff gets -1 on type error |
1361 if (boff < 0) | 1361 if (boff < 0) |
1362 rettv->vval.v_number = -1; | 1362 rettv->vval.v_number = -1; |
1363 else | 1363 else |
1364 rettv->vval.v_number = ml_find_line_or_offset(curbuf, | 1364 rettv->vval.v_number = ml_find_line_or_offset(curbuf, |
1365 (linenr_T)0, &boff); | 1365 (linenr_T)0, &boff); |
1380 return; | 1380 return; |
1381 | 1381 |
1382 t = str; | 1382 t = str; |
1383 for ( ; idx > 0; idx--) | 1383 for ( ; idx > 0; idx--) |
1384 { | 1384 { |
1385 if (*t == NUL) /* EOL reached */ | 1385 if (*t == NUL) // EOL reached |
1386 return; | 1386 return; |
1387 if (enc_utf8 && comp) | 1387 if (enc_utf8 && comp) |
1388 t += utf_ptr2len(t); | 1388 t += utf_ptr2len(t); |
1389 else | 1389 else |
1390 t += (*mb_ptr2len)(t); | 1390 t += (*mb_ptr2len)(t); |
1436 func = partial_name(partial); | 1436 func = partial_name(partial); |
1437 } | 1437 } |
1438 else | 1438 else |
1439 func = tv_get_string(&argvars[0]); | 1439 func = tv_get_string(&argvars[0]); |
1440 if (*func == NUL) | 1440 if (*func == NUL) |
1441 return; /* type error or empty name */ | 1441 return; // type error or empty name |
1442 | 1442 |
1443 if (argvars[2].v_type != VAR_UNKNOWN) | 1443 if (argvars[2].v_type != VAR_UNKNOWN) |
1444 { | 1444 { |
1445 if (argvars[2].v_type != VAR_DICT) | 1445 if (argvars[2].v_type != VAR_DICT) |
1446 { | 1446 { |
1531 fp = var2fpos(&argvars[0], FALSE, &fnum); | 1531 fp = var2fpos(&argvars[0], FALSE, &fnum); |
1532 if (fp != NULL && fnum == curbuf->b_fnum) | 1532 if (fp != NULL && fnum == curbuf->b_fnum) |
1533 { | 1533 { |
1534 if (fp->col == MAXCOL) | 1534 if (fp->col == MAXCOL) |
1535 { | 1535 { |
1536 /* '> can be MAXCOL, get the length of the line then */ | 1536 // '> can be MAXCOL, get the length of the line then |
1537 if (fp->lnum <= curbuf->b_ml.ml_line_count) | 1537 if (fp->lnum <= curbuf->b_ml.ml_line_count) |
1538 col = (colnr_T)STRLEN(ml_get(fp->lnum)) + 1; | 1538 col = (colnr_T)STRLEN(ml_get(fp->lnum)) + 1; |
1539 else | 1539 else |
1540 col = MAXCOL; | 1540 col = MAXCOL; |
1541 } | 1541 } |
1542 else | 1542 else |
1543 { | 1543 { |
1544 col = fp->col + 1; | 1544 col = fp->col + 1; |
1545 /* col(".") when the cursor is on the NUL at the end of the line | 1545 // col(".") when the cursor is on the NUL at the end of the line |
1546 * because of "coladd" can be seen as an extra column. */ | 1546 // because of "coladd" can be seen as an extra column. |
1547 if (virtual_active() && fp == &curwin->w_cursor) | 1547 if (virtual_active() && fp == &curwin->w_cursor) |
1548 { | 1548 { |
1549 char_u *p = ml_get_cursor(); | 1549 char_u *p = ml_get_cursor(); |
1550 | 1550 |
1551 if (curwin->w_cursor.coladd >= (colnr_T)chartabsize(p, | 1551 if (curwin->w_cursor.coladd >= (colnr_T)chartabsize(p, |
1699 col = (long)tv_get_number_chk(&argvars[1], NULL); | 1699 col = (long)tv_get_number_chk(&argvars[1], NULL); |
1700 if (argvars[2].v_type != VAR_UNKNOWN) | 1700 if (argvars[2].v_type != VAR_UNKNOWN) |
1701 coladd = (long)tv_get_number_chk(&argvars[2], NULL); | 1701 coladd = (long)tv_get_number_chk(&argvars[2], NULL); |
1702 } | 1702 } |
1703 if (line < 0 || col < 0 || coladd < 0) | 1703 if (line < 0 || col < 0 || coladd < 0) |
1704 return; /* type error; errmsg already given */ | 1704 return; // type error; errmsg already given |
1705 if (line > 0) | 1705 if (line > 0) |
1706 curwin->w_cursor.lnum = line; | 1706 curwin->w_cursor.lnum = line; |
1707 if (col > 0) | 1707 if (col > 0) |
1708 curwin->w_cursor.col = col - 1; | 1708 curwin->w_cursor.col = col - 1; |
1709 curwin->w_cursor.coladd = coladd; | 1709 curwin->w_cursor.coladd = coladd; |
1710 | 1710 |
1711 /* Make sure the cursor is in a valid position. */ | 1711 // Make sure the cursor is in a valid position. |
1712 check_cursor(); | 1712 check_cursor(); |
1713 /* Correct cursor for multi-byte character. */ | 1713 // Correct cursor for multi-byte character. |
1714 if (has_mbyte) | 1714 if (has_mbyte) |
1715 mb_adjust_cursor(); | 1715 mb_adjust_cursor(); |
1716 | 1716 |
1717 curwin->w_set_curswant = set_curswant; | 1717 curwin->w_set_curswant = set_curswant; |
1718 rettv->vval.v_number = 0; | 1718 rettv->vval.v_number = 0; |
1947 execute_redir_str(char_u *value, int value_len) | 1947 execute_redir_str(char_u *value, int value_len) |
1948 { | 1948 { |
1949 int len; | 1949 int len; |
1950 | 1950 |
1951 if (value_len == -1) | 1951 if (value_len == -1) |
1952 len = (int)STRLEN(value); /* Append the entire string */ | 1952 len = (int)STRLEN(value); // Append the entire string |
1953 else | 1953 else |
1954 len = value_len; /* Append only "value_len" characters */ | 1954 len = value_len; // Append only "value_len" characters |
1955 if (ga_grow(&redir_execute_ga, len) == OK) | 1955 if (ga_grow(&redir_execute_ga, len) == OK) |
1956 { | 1956 { |
1957 mch_memmove((char *)redir_execute_ga.ga_data | 1957 mch_memmove((char *)redir_execute_ga.ga_data |
1958 + redir_execute_ga.ga_len, value, len); | 1958 + redir_execute_ga.ga_len, value, len); |
1959 redir_execute_ga.ga_len += len; | 1959 redir_execute_ga.ga_len += len; |
2007 | 2007 |
2008 if (argvars[arg_off].v_type == VAR_LIST) | 2008 if (argvars[arg_off].v_type == VAR_LIST) |
2009 { | 2009 { |
2010 list = argvars[arg_off].vval.v_list; | 2010 list = argvars[arg_off].vval.v_list; |
2011 if (list == NULL || list->lv_first == NULL) | 2011 if (list == NULL || list->lv_first == NULL) |
2012 /* empty list, no commands, empty output */ | 2012 // empty list, no commands, empty output |
2013 return; | 2013 return; |
2014 ++list->lv_refcount; | 2014 ++list->lv_refcount; |
2015 } | 2015 } |
2016 else | 2016 else |
2017 { | 2017 { |
2057 do_cmdline(NULL, get_list_line, (void *)&item, | 2057 do_cmdline(NULL, get_list_line, (void *)&item, |
2058 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED); | 2058 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED); |
2059 --list->lv_refcount; | 2059 --list->lv_refcount; |
2060 } | 2060 } |
2061 | 2061 |
2062 /* Need to append a NUL to the result. */ | 2062 // Need to append a NUL to the result. |
2063 if (ga_grow(&redir_execute_ga, 1) == OK) | 2063 if (ga_grow(&redir_execute_ga, 1) == OK) |
2064 { | 2064 { |
2065 ((char *)redir_execute_ga.ga_data)[redir_execute_ga.ga_len] = NUL; | 2065 ((char *)redir_execute_ga.ga_data)[redir_execute_ga.ga_len] = NUL; |
2066 rettv->vval.v_string = redir_execute_ga.ga_data; | 2066 rettv->vval.v_string = redir_execute_ga.ga_data; |
2067 } | 2067 } |
2107 { | 2107 { |
2108 char_u *p; | 2108 char_u *p; |
2109 int n = FALSE; | 2109 int n = FALSE; |
2110 | 2110 |
2111 p = tv_get_string(&argvars[0]); | 2111 p = tv_get_string(&argvars[0]); |
2112 if (*p == '$') /* environment variable */ | 2112 if (*p == '$') // environment variable |
2113 { | 2113 { |
2114 /* first try "normal" environment variables (fast) */ | 2114 // first try "normal" environment variables (fast) |
2115 if (mch_getenv(p + 1) != NULL) | 2115 if (mch_getenv(p + 1) != NULL) |
2116 n = TRUE; | 2116 n = TRUE; |
2117 else | 2117 else |
2118 { | 2118 { |
2119 /* try expanding things like $VIM and ${HOME} */ | 2119 // try expanding things like $VIM and ${HOME} |
2120 p = expand_env_save(p); | 2120 p = expand_env_save(p); |
2121 if (p != NULL && *p != '$') | 2121 if (p != NULL && *p != '$') |
2122 n = TRUE; | 2122 n = TRUE; |
2123 vim_free(p); | 2123 vim_free(p); |
2124 } | 2124 } |
2125 } | 2125 } |
2126 else if (*p == '&' || *p == '+') /* option */ | 2126 else if (*p == '&' || *p == '+') // option |
2127 { | 2127 { |
2128 n = (get_option_tv(&p, NULL, TRUE) == OK); | 2128 n = (get_option_tv(&p, NULL, TRUE) == OK); |
2129 if (*skipwhite(p) != NUL) | 2129 if (*skipwhite(p) != NUL) |
2130 n = FALSE; /* trailing garbage */ | 2130 n = FALSE; // trailing garbage |
2131 } | 2131 } |
2132 else if (*p == '*') /* internal or user defined function */ | 2132 else if (*p == '*') // internal or user defined function |
2133 { | 2133 { |
2134 n = function_exists(p + 1, FALSE); | 2134 n = function_exists(p + 1, FALSE); |
2135 } | 2135 } |
2136 else if (*p == ':') | 2136 else if (*p == ':') |
2137 { | 2137 { |
2142 if (p[1] == '#') | 2142 if (p[1] == '#') |
2143 n = autocmd_supported(p + 2); | 2143 n = autocmd_supported(p + 2); |
2144 else | 2144 else |
2145 n = au_exists(p + 1); | 2145 n = au_exists(p + 1); |
2146 } | 2146 } |
2147 else /* internal variable */ | 2147 else // internal variable |
2148 { | 2148 { |
2149 n = var_exists(p); | 2149 n = var_exists(p); |
2150 } | 2150 } |
2151 | 2151 |
2152 rettv->vval.v_number = n; | 2152 rettv->vval.v_number = n; |
2205 else | 2205 else |
2206 rettv->vval.v_string = result; | 2206 rettv->vval.v_string = result; |
2207 } | 2207 } |
2208 else | 2208 else |
2209 { | 2209 { |
2210 /* When the optional second argument is non-zero, don't remove matches | 2210 // When the optional second argument is non-zero, don't remove matches |
2211 * for 'wildignore' and don't put matches for 'suffixes' at the end. */ | 2211 // for 'wildignore' and don't put matches for 'suffixes' at the end. |
2212 if (argvars[1].v_type != VAR_UNKNOWN | 2212 if (argvars[1].v_type != VAR_UNKNOWN |
2213 && tv_get_number_chk(&argvars[1], &error)) | 2213 && tv_get_number_chk(&argvars[1], &error)) |
2214 options |= WILD_KEEP_ALL; | 2214 options |= WILD_KEEP_ALL; |
2215 if (!error) | 2215 if (!error) |
2216 { | 2216 { |
2279 int execute = FALSE; | 2279 int execute = FALSE; |
2280 int dangerous = FALSE; | 2280 int dangerous = FALSE; |
2281 int lowlevel = FALSE; | 2281 int lowlevel = FALSE; |
2282 char_u *keys_esc; | 2282 char_u *keys_esc; |
2283 | 2283 |
2284 /* This is not allowed in the sandbox. If the commands would still be | 2284 // This is not allowed in the sandbox. If the commands would still be |
2285 * executed in the sandbox it would be OK, but it probably happens later, | 2285 // executed in the sandbox it would be OK, but it probably happens later, |
2286 * when "sandbox" is no longer set. */ | 2286 // when "sandbox" is no longer set. |
2287 if (check_secure()) | 2287 if (check_secure()) |
2288 return; | 2288 return; |
2289 | 2289 |
2290 keys = tv_get_string(&argvars[0]); | 2290 keys = tv_get_string(&argvars[0]); |
2291 | 2291 |
2307 } | 2307 } |
2308 } | 2308 } |
2309 | 2309 |
2310 if (*keys != NUL || execute) | 2310 if (*keys != NUL || execute) |
2311 { | 2311 { |
2312 /* Need to escape K_SPECIAL and CSI before putting the string in the | 2312 // Need to escape K_SPECIAL and CSI before putting the string in the |
2313 * typeahead buffer. */ | 2313 // typeahead buffer. |
2314 keys_esc = vim_strsave_escape_csi(keys); | 2314 keys_esc = vim_strsave_escape_csi(keys); |
2315 if (keys_esc != NULL) | 2315 if (keys_esc != NULL) |
2316 { | 2316 { |
2317 if (lowlevel) | 2317 if (lowlevel) |
2318 { | 2318 { |
2337 | 2337 |
2338 if (execute) | 2338 if (execute) |
2339 { | 2339 { |
2340 int save_msg_scroll = msg_scroll; | 2340 int save_msg_scroll = msg_scroll; |
2341 | 2341 |
2342 /* Avoid a 1 second delay when the keys start Insert mode. */ | 2342 // Avoid a 1 second delay when the keys start Insert mode. |
2343 msg_scroll = FALSE; | 2343 msg_scroll = FALSE; |
2344 | 2344 |
2345 if (!dangerous) | 2345 if (!dangerous) |
2346 ++ex_normal_busy; | 2346 ++ex_normal_busy; |
2347 exec_normal(TRUE, lowlevel, TRUE); | 2347 exec_normal(TRUE, lowlevel, TRUE); |
2444 partial_T *arg_pt = NULL; | 2444 partial_T *arg_pt = NULL; |
2445 char_u *trans_name = NULL; | 2445 char_u *trans_name = NULL; |
2446 | 2446 |
2447 if (argvars[0].v_type == VAR_FUNC) | 2447 if (argvars[0].v_type == VAR_FUNC) |
2448 { | 2448 { |
2449 /* function(MyFunc, [arg], dict) */ | 2449 // function(MyFunc, [arg], dict) |
2450 s = argvars[0].vval.v_string; | 2450 s = argvars[0].vval.v_string; |
2451 } | 2451 } |
2452 else if (argvars[0].v_type == VAR_PARTIAL | 2452 else if (argvars[0].v_type == VAR_PARTIAL |
2453 && argvars[0].vval.v_partial != NULL) | 2453 && argvars[0].vval.v_partial != NULL) |
2454 { | 2454 { |
2455 /* function(dict.MyFunc, [arg]) */ | 2455 // function(dict.MyFunc, [arg]) |
2456 arg_pt = argvars[0].vval.v_partial; | 2456 arg_pt = argvars[0].vval.v_partial; |
2457 s = partial_name(arg_pt); | 2457 s = partial_name(arg_pt); |
2458 } | 2458 } |
2459 else | 2459 else |
2460 { | 2460 { |
2461 /* function('MyFunc', [arg], dict) */ | 2461 // function('MyFunc', [arg], dict) |
2462 s = tv_get_string(&argvars[0]); | 2462 s = tv_get_string(&argvars[0]); |
2463 use_string = TRUE; | 2463 use_string = TRUE; |
2464 } | 2464 } |
2465 | 2465 |
2466 if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) | 2466 if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) |
2473 } | 2473 } |
2474 | 2474 |
2475 if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) | 2475 if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) |
2476 || (is_funcref && trans_name == NULL)) | 2476 || (is_funcref && trans_name == NULL)) |
2477 semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); | 2477 semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); |
2478 /* Don't check an autoload name for existence here. */ | 2478 // Don't check an autoload name for existence here. |
2479 else if (trans_name != NULL && (is_funcref | 2479 else if (trans_name != NULL && (is_funcref |
2480 ? find_func(trans_name) == NULL | 2480 ? find_func(trans_name) == NULL |
2481 : !translated_function_exists(trans_name))) | 2481 : !translated_function_exists(trans_name))) |
2482 semsg(_("E700: Unknown function: %s"), s); | 2482 semsg(_("E700: Unknown function: %s"), s); |
2483 else | 2483 else |
2489 if (STRNCMP(s, "s:", 2) == 0 || STRNCMP(s, "<SID>", 5) == 0) | 2489 if (STRNCMP(s, "s:", 2) == 0 || STRNCMP(s, "<SID>", 5) == 0) |
2490 { | 2490 { |
2491 char sid_buf[25]; | 2491 char sid_buf[25]; |
2492 int off = *s == 's' ? 2 : 5; | 2492 int off = *s == 's' ? 2 : 5; |
2493 | 2493 |
2494 /* Expand s: and <SID> into <SNR>nr_, so that the function can | 2494 // Expand s: and <SID> into <SNR>nr_, so that the function can |
2495 * also be called from another script. Using trans_function_name() | 2495 // also be called from another script. Using trans_function_name() |
2496 * would also work, but some plugins depend on the name being | 2496 // would also work, but some plugins depend on the name being |
2497 * printable text. */ | 2497 // printable text. |
2498 sprintf(sid_buf, "<SNR>%ld_", (long)current_sctx.sc_sid); | 2498 sprintf(sid_buf, "<SNR>%ld_", (long)current_sctx.sc_sid); |
2499 name = alloc(STRLEN(sid_buf) + STRLEN(s + off) + 1); | 2499 name = alloc(STRLEN(sid_buf) + STRLEN(s + off) + 1); |
2500 if (name != NULL) | 2500 if (name != NULL) |
2501 { | 2501 { |
2502 STRCPY(name, sid_buf); | 2502 STRCPY(name, sid_buf); |
2508 | 2508 |
2509 if (argvars[1].v_type != VAR_UNKNOWN) | 2509 if (argvars[1].v_type != VAR_UNKNOWN) |
2510 { | 2510 { |
2511 if (argvars[2].v_type != VAR_UNKNOWN) | 2511 if (argvars[2].v_type != VAR_UNKNOWN) |
2512 { | 2512 { |
2513 /* function(name, [args], dict) */ | 2513 // function(name, [args], dict) |
2514 arg_idx = 1; | 2514 arg_idx = 1; |
2515 dict_idx = 2; | 2515 dict_idx = 2; |
2516 } | 2516 } |
2517 else if (argvars[1].v_type == VAR_DICT) | 2517 else if (argvars[1].v_type == VAR_DICT) |
2518 /* function(name, dict) */ | 2518 // function(name, dict) |
2519 dict_idx = 1; | 2519 dict_idx = 1; |
2520 else | 2520 else |
2521 /* function(name, [args]) */ | 2521 // function(name, [args]) |
2522 arg_idx = 1; | 2522 arg_idx = 1; |
2523 if (dict_idx > 0) | 2523 if (dict_idx > 0) |
2524 { | 2524 { |
2525 if (argvars[dict_idx].v_type != VAR_DICT) | 2525 if (argvars[dict_idx].v_type != VAR_DICT) |
2526 { | 2526 { |
2552 } | 2552 } |
2553 if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL || is_funcref) | 2553 if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL || is_funcref) |
2554 { | 2554 { |
2555 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); | 2555 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
2556 | 2556 |
2557 /* result is a VAR_PARTIAL */ | 2557 // result is a VAR_PARTIAL |
2558 if (pt == NULL) | 2558 if (pt == NULL) |
2559 vim_free(name); | 2559 vim_free(name); |
2560 else | 2560 else |
2561 { | 2561 { |
2562 if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0)) | 2562 if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0)) |
2584 for (li = list->lv_first; li != NULL; | 2584 for (li = list->lv_first; li != NULL; |
2585 li = li->li_next) | 2585 li = li->li_next) |
2586 copy_tv(&li->li_tv, &pt->pt_argv[i++]); | 2586 copy_tv(&li->li_tv, &pt->pt_argv[i++]); |
2587 } | 2587 } |
2588 | 2588 |
2589 /* For "function(dict.func, [], dict)" and "func" is a partial | 2589 // For "function(dict.func, [], dict)" and "func" is a partial |
2590 * use "dict". That is backwards compatible. */ | 2590 // use "dict". That is backwards compatible. |
2591 if (dict_idx > 0) | 2591 if (dict_idx > 0) |
2592 { | 2592 { |
2593 /* The dict is bound explicitly, pt_auto is FALSE. */ | 2593 // The dict is bound explicitly, pt_auto is FALSE. |
2594 pt->pt_dict = argvars[dict_idx].vval.v_dict; | 2594 pt->pt_dict = argvars[dict_idx].vval.v_dict; |
2595 ++pt->pt_dict->dv_refcount; | 2595 ++pt->pt_dict->dv_refcount; |
2596 } | 2596 } |
2597 else if (arg_pt != NULL) | 2597 else if (arg_pt != NULL) |
2598 { | 2598 { |
2599 /* If the dict was bound automatically the result is also | 2599 // If the dict was bound automatically the result is also |
2600 * bound automatically. */ | 2600 // bound automatically. |
2601 pt->pt_dict = arg_pt->pt_dict; | 2601 pt->pt_dict = arg_pt->pt_dict; |
2602 pt->pt_auto = arg_pt->pt_auto; | 2602 pt->pt_auto = arg_pt->pt_auto; |
2603 if (pt->pt_dict != NULL) | 2603 if (pt->pt_dict != NULL) |
2604 ++pt->pt_dict->dv_refcount; | 2604 ++pt->pt_dict->dv_refcount; |
2605 } | 2605 } |
2626 rettv->v_type = VAR_PARTIAL; | 2626 rettv->v_type = VAR_PARTIAL; |
2627 rettv->vval.v_partial = pt; | 2627 rettv->vval.v_partial = pt; |
2628 } | 2628 } |
2629 else | 2629 else |
2630 { | 2630 { |
2631 /* result is a VAR_FUNC */ | 2631 // result is a VAR_FUNC |
2632 rettv->v_type = VAR_FUNC; | 2632 rettv->v_type = VAR_FUNC; |
2633 rettv->vval.v_string = name; | 2633 rettv->vval.v_string = name; |
2634 func_ref(name); | 2634 func_ref(name); |
2635 } | 2635 } |
2636 } | 2636 } |
2660 * "garbagecollect()" function | 2660 * "garbagecollect()" function |
2661 */ | 2661 */ |
2662 static void | 2662 static void |
2663 f_garbagecollect(typval_T *argvars, typval_T *rettv UNUSED) | 2663 f_garbagecollect(typval_T *argvars, typval_T *rettv UNUSED) |
2664 { | 2664 { |
2665 /* This is postponed until we are back at the toplevel, because we may be | 2665 // This is postponed until we are back at the toplevel, because we may be |
2666 * using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */ | 2666 // using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". |
2667 want_garbage_collect = TRUE; | 2667 want_garbage_collect = TRUE; |
2668 | 2668 |
2669 if (argvars[0].v_type != VAR_UNKNOWN && tv_get_number(&argvars[0]) == 1) | 2669 if (argvars[0].v_type != VAR_UNKNOWN && tv_get_number(&argvars[0]) == 1) |
2670 garbage_collect_at_exit = TRUE; | 2670 garbage_collect_at_exit = TRUE; |
2671 } | 2671 } |
2920 GuiFont font; | 2920 GuiFont font; |
2921 char_u *name = NULL; | 2921 char_u *name = NULL; |
2922 | 2922 |
2923 if (argvars[0].v_type == VAR_UNKNOWN) | 2923 if (argvars[0].v_type == VAR_UNKNOWN) |
2924 { | 2924 { |
2925 /* Get the "Normal" font. Either the name saved by | 2925 // Get the "Normal" font. Either the name saved by |
2926 * hl_set_font_name() or from the font ID. */ | 2926 // hl_set_font_name() or from the font ID. |
2927 font = gui.norm_font; | 2927 font = gui.norm_font; |
2928 name = hl_get_font_name(); | 2928 name = hl_get_font_name(); |
2929 } | 2929 } |
2930 else | 2930 else |
2931 { | 2931 { |
2932 name = tv_get_string(&argvars[0]); | 2932 name = tv_get_string(&argvars[0]); |
2933 if (STRCMP(name, "*") == 0) /* don't use font dialog */ | 2933 if (STRCMP(name, "*") == 0) // don't use font dialog |
2934 return; | 2934 return; |
2935 font = gui_mch_get_font(name, FALSE); | 2935 font = gui_mch_get_font(name, FALSE); |
2936 if (font == NOFONT) | 2936 if (font == NOFONT) |
2937 return; /* Invalid font name, return empty string. */ | 2937 return; // Invalid font name, return empty string. |
2938 } | 2938 } |
2939 rettv->vval.v_string = gui_mch_get_fontname(font, name); | 2939 rettv->vval.v_string = gui_mch_get_fontname(font, name); |
2940 if (argvars[0].v_type != VAR_UNKNOWN) | 2940 if (argvars[0].v_type != VAR_UNKNOWN) |
2941 gui_mch_free_font(font); | 2941 gui_mch_free_font(font); |
2942 } | 2942 } |
3135 long reglen = 0; | 3135 long reglen = 0; |
3136 | 3136 |
3137 if (argvars[0].v_type != VAR_UNKNOWN) | 3137 if (argvars[0].v_type != VAR_UNKNOWN) |
3138 { | 3138 { |
3139 strregname = tv_get_string_chk(&argvars[0]); | 3139 strregname = tv_get_string_chk(&argvars[0]); |
3140 if (strregname == NULL) /* type error; errmsg already given */ | 3140 if (strregname == NULL) // type error; errmsg already given |
3141 { | 3141 { |
3142 rettv->v_type = VAR_STRING; | 3142 rettv->v_type = VAR_STRING; |
3143 rettv->vval.v_string = NULL; | 3143 rettv->vval.v_string = NULL; |
3144 return; | 3144 return; |
3145 } | 3145 } |
3146 } | 3146 } |
3147 else | 3147 else |
3148 /* Default to v:register */ | 3148 // Default to v:register |
3149 strregname = get_vim_var_str(VV_REG); | 3149 strregname = get_vim_var_str(VV_REG); |
3150 | 3150 |
3151 regname = (strregname == NULL ? '"' : *strregname); | 3151 regname = (strregname == NULL ? '"' : *strregname); |
3152 if (regname == 0) | 3152 if (regname == 0) |
3153 regname = '"'; | 3153 regname = '"'; |
3186 } | 3186 } |
3187 | 3187 |
3188 get_tagstack(wp, rettv->vval.v_dict); | 3188 get_tagstack(wp, rettv->vval.v_dict); |
3189 } | 3189 } |
3190 | 3190 |
3191 /* for VIM_VERSION_ defines */ | 3191 // for VIM_VERSION_ defines |
3192 #include "version.h" | 3192 #include "version.h" |
3193 | 3193 |
3194 /* | 3194 /* |
3195 * "has()" function | 3195 * "has()" function |
3196 */ | 3196 */ |
3219 #endif | 3219 #endif |
3220 #ifdef __linux__ | 3220 #ifdef __linux__ |
3221 "linux", | 3221 "linux", |
3222 #endif | 3222 #endif |
3223 #ifdef MACOS_X | 3223 #ifdef MACOS_X |
3224 "mac", /* Mac OS X (and, once, Mac OS Classic) */ | 3224 "mac", // Mac OS X (and, once, Mac OS Classic) |
3225 "osx", /* Mac OS X */ | 3225 "osx", // Mac OS X |
3226 # ifdef MACOS_X_DARWIN | 3226 # ifdef MACOS_X_DARWIN |
3227 "macunix", /* Mac OS X, with the darwin feature */ | 3227 "macunix", // Mac OS X, with the darwin feature |
3228 "osxdarwin", /* synonym for macunix */ | 3228 "osxdarwin", // synonym for macunix |
3229 # endif | 3229 # endif |
3230 #endif | 3230 #endif |
3231 #ifdef __QNX__ | 3231 #ifdef __QNX__ |
3232 "qnx", | 3232 "qnx", |
3233 #endif | 3233 #endif |
3270 #ifdef FEAT_AUTOSERVERNAME | 3270 #ifdef FEAT_AUTOSERVERNAME |
3271 "autoservername", | 3271 "autoservername", |
3272 #endif | 3272 #endif |
3273 #ifdef FEAT_BEVAL_GUI | 3273 #ifdef FEAT_BEVAL_GUI |
3274 "balloon_eval", | 3274 "balloon_eval", |
3275 # ifndef FEAT_GUI_MSWIN /* other GUIs always have multiline balloons */ | 3275 # ifndef FEAT_GUI_MSWIN // other GUIs always have multiline balloons |
3276 "balloon_multiline", | 3276 "balloon_multiline", |
3277 # endif | 3277 # endif |
3278 #endif | 3278 #endif |
3279 #ifdef FEAT_BEVAL_TERM | 3279 #ifdef FEAT_BEVAL_TERM |
3280 "balloon_eval_term", | 3280 "balloon_eval_term", |
3345 "dnd", | 3345 "dnd", |
3346 #endif | 3346 #endif |
3347 #ifdef FEAT_EMACS_TAGS | 3347 #ifdef FEAT_EMACS_TAGS |
3348 "emacs_tags", | 3348 "emacs_tags", |
3349 #endif | 3349 #endif |
3350 "eval", /* always present, of course! */ | 3350 "eval", // always present, of course! |
3351 "ex_extra", /* graduated feature */ | 3351 "ex_extra", // graduated feature |
3352 #ifdef FEAT_SEARCH_EXTRA | 3352 #ifdef FEAT_SEARCH_EXTRA |
3353 "extra_search", | 3353 "extra_search", |
3354 #endif | 3354 #endif |
3355 #ifdef FEAT_SEARCHPATH | 3355 #ifdef FEAT_SEARCHPATH |
3356 "file_in_path", | 3356 "file_in_path", |
3420 "jumplist", | 3420 "jumplist", |
3421 #endif | 3421 #endif |
3422 #ifdef FEAT_KEYMAP | 3422 #ifdef FEAT_KEYMAP |
3423 "keymap", | 3423 "keymap", |
3424 #endif | 3424 #endif |
3425 "lambda", /* always with FEAT_EVAL, since 7.4.2120 with closure */ | 3425 "lambda", // always with FEAT_EVAL, since 7.4.2120 with closure |
3426 #ifdef FEAT_LANGMAP | 3426 #ifdef FEAT_LANGMAP |
3427 "langmap", | 3427 "langmap", |
3428 #endif | 3428 #endif |
3429 #ifdef FEAT_LIBCALL | 3429 #ifdef FEAT_LIBCALL |
3430 "libcall", | 3430 "libcall", |
3627 "toolbar", | 3627 "toolbar", |
3628 #endif | 3628 #endif |
3629 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | 3629 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3630 "unnamedplus", | 3630 "unnamedplus", |
3631 #endif | 3631 #endif |
3632 "user-commands", /* was accidentally included in 5.4 */ | 3632 "user-commands", // was accidentally included in 5.4 |
3633 "user_commands", | 3633 "user_commands", |
3634 #ifdef FEAT_VARTABS | 3634 #ifdef FEAT_VARTABS |
3635 "vartabs", | 3635 "vartabs", |
3636 #endif | 3636 #endif |
3637 "vertsplit", | 3637 "vertsplit", |
3668 #ifdef FEAT_XFONTSET | 3668 #ifdef FEAT_XFONTSET |
3669 "xfontset", | 3669 "xfontset", |
3670 #endif | 3670 #endif |
3671 #ifdef FEAT_XPM_W32 | 3671 #ifdef FEAT_XPM_W32 |
3672 "xpm", | 3672 "xpm", |
3673 "xpm_w32", /* for backward compatibility */ | 3673 "xpm_w32", // for backward compatibility |
3674 #else | 3674 #else |
3675 # if defined(HAVE_XPM) | 3675 # if defined(HAVE_XPM) |
3676 "xpm", | 3676 "xpm", |
3677 # endif | 3677 # endif |
3678 #endif | 3678 #endif |
3713 && vim_isdigit(name[10])) | 3713 && vim_isdigit(name[10])) |
3714 { | 3714 { |
3715 int major = atoi((char *)name + 6); | 3715 int major = atoi((char *)name + 6); |
3716 int minor = atoi((char *)name + 8); | 3716 int minor = atoi((char *)name + 8); |
3717 | 3717 |
3718 /* Expect "patch-9.9.01234". */ | 3718 // Expect "patch-9.9.01234". |
3719 n = (major < VIM_VERSION_MAJOR | 3719 n = (major < VIM_VERSION_MAJOR |
3720 || (major == VIM_VERSION_MAJOR | 3720 || (major == VIM_VERSION_MAJOR |
3721 && (minor < VIM_VERSION_MINOR | 3721 && (minor < VIM_VERSION_MINOR |
3722 || (minor == VIM_VERSION_MINOR | 3722 || (minor == VIM_VERSION_MINOR |
3723 && has_patch(atoi((char *)name + 10)))))); | 3723 && has_patch(atoi((char *)name + 10)))))); |
3789 #ifdef FEAT_GUI | 3789 #ifdef FEAT_GUI |
3790 else if (STRICMP(name, "gui_running") == 0) | 3790 else if (STRICMP(name, "gui_running") == 0) |
3791 n = (gui.in_use || gui.starting); | 3791 n = (gui.in_use || gui.starting); |
3792 # ifdef FEAT_BROWSE | 3792 # ifdef FEAT_BROWSE |
3793 else if (STRICMP(name, "browse") == 0) | 3793 else if (STRICMP(name, "browse") == 0) |
3794 n = gui.in_use; /* gui_mch_browse() works when GUI is running */ | 3794 n = gui.in_use; // gui_mch_browse() works when GUI is running |
3795 # endif | 3795 # endif |
3796 #endif | 3796 #endif |
3797 #ifdef FEAT_SYN_HL | 3797 #ifdef FEAT_SYN_HL |
3798 else if (STRICMP(name, "syntax_items") == 0) | 3798 else if (STRICMP(name, "syntax_items") == 0) |
3799 n = syntax_present(curwin); | 3799 n = syntax_present(curwin); |
3927 from = enc_canonize(enc_skip(tv_get_string_buf(&argvars[1], buf1))); | 3927 from = enc_canonize(enc_skip(tv_get_string_buf(&argvars[1], buf1))); |
3928 to = enc_canonize(enc_skip(tv_get_string_buf(&argvars[2], buf2))); | 3928 to = enc_canonize(enc_skip(tv_get_string_buf(&argvars[2], buf2))); |
3929 vimconv.vc_type = CONV_NONE; | 3929 vimconv.vc_type = CONV_NONE; |
3930 convert_setup(&vimconv, from, to); | 3930 convert_setup(&vimconv, from, to); |
3931 | 3931 |
3932 /* If the encodings are equal, no conversion needed. */ | 3932 // If the encodings are equal, no conversion needed. |
3933 if (vimconv.vc_type == CONV_NONE) | 3933 if (vimconv.vc_type == CONV_NONE) |
3934 rettv->vval.v_string = vim_strsave(str); | 3934 rettv->vval.v_string = vim_strsave(str); |
3935 else | 3935 else |
3936 rettv->vval.v_string = string_convert(&vimconv, str, NULL); | 3936 rettv->vval.v_string = string_convert(&vimconv, str, NULL); |
3937 | 3937 |
3997 if (l != NULL) | 3997 if (l != NULL) |
3998 { | 3998 { |
3999 item = l->lv_first; | 3999 item = l->lv_first; |
4000 if (argvars[2].v_type != VAR_UNKNOWN) | 4000 if (argvars[2].v_type != VAR_UNKNOWN) |
4001 { | 4001 { |
4002 /* Start at specified item. Use the cached index that list_find() | 4002 // Start at specified item. Use the cached index that list_find() |
4003 * sets, so that a negative number also works. */ | 4003 // sets, so that a negative number also works. |
4004 item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error)); | 4004 item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error)); |
4005 idx = l->lv_idx; | 4005 idx = l->lv_idx; |
4006 if (argvars[3].v_type != VAR_UNKNOWN) | 4006 if (argvars[3].v_type != VAR_UNKNOWN) |
4007 ic = (int)tv_get_number_chk(&argvars[3], &error); | 4007 ic = (int)tv_get_number_chk(&argvars[3], &error); |
4008 if (error) | 4008 if (error) |
4035 */ | 4035 */ |
4036 static void | 4036 static void |
4037 f_inputdialog(typval_T *argvars, typval_T *rettv) | 4037 f_inputdialog(typval_T *argvars, typval_T *rettv) |
4038 { | 4038 { |
4039 #if defined(FEAT_GUI_TEXTDIALOG) | 4039 #if defined(FEAT_GUI_TEXTDIALOG) |
4040 /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ | 4040 // Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' |
4041 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) | 4041 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) |
4042 { | 4042 { |
4043 char_u *message; | 4043 char_u *message; |
4044 char_u buf[NUMBUFLEN]; | 4044 char_u buf[NUMBUFLEN]; |
4045 char_u *defstr = (char_u *)""; | 4045 char_u *defstr = (char_u *)""; |
4080 listitem_T *li; | 4080 listitem_T *li; |
4081 int selected; | 4081 int selected; |
4082 int mouse_used; | 4082 int mouse_used; |
4083 | 4083 |
4084 #ifdef NO_CONSOLE_INPUT | 4084 #ifdef NO_CONSOLE_INPUT |
4085 /* While starting up, there is no place to enter text. When running tests | 4085 // While starting up, there is no place to enter text. When running tests |
4086 * with --not-a-term we assume feedkeys() will be used. */ | 4086 // with --not-a-term we assume feedkeys() will be used. |
4087 if (no_console_input() && !is_not_a_term()) | 4087 if (no_console_input() && !is_not_a_term()) |
4088 return; | 4088 return; |
4089 #endif | 4089 #endif |
4090 if (argvars[0].v_type != VAR_LIST || argvars[0].vval.v_list == NULL) | 4090 if (argvars[0].v_type != VAR_LIST || argvars[0].vval.v_list == NULL) |
4091 { | 4091 { |
4092 semsg(_(e_listarg), "inputlist()"); | 4092 semsg(_(e_listarg), "inputlist()"); |
4093 return; | 4093 return; |
4094 } | 4094 } |
4095 | 4095 |
4096 msg_start(); | 4096 msg_start(); |
4097 msg_row = Rows - 1; /* for when 'cmdheight' > 1 */ | 4097 msg_row = Rows - 1; // for when 'cmdheight' > 1 |
4098 lines_left = Rows; /* avoid more prompt */ | 4098 lines_left = Rows; // avoid more prompt |
4099 msg_scroll = TRUE; | 4099 msg_scroll = TRUE; |
4100 msg_clr_eos(); | 4100 msg_clr_eos(); |
4101 | 4101 |
4102 for (li = argvars[0].vval.v_list->lv_first; li != NULL; li = li->li_next) | 4102 for (li = argvars[0].vval.v_list->lv_first; li != NULL; li = li->li_next) |
4103 { | 4103 { |
4104 msg_puts((char *)tv_get_string(&li->li_tv)); | 4104 msg_puts((char *)tv_get_string(&li->li_tv)); |
4105 msg_putchar('\n'); | 4105 msg_putchar('\n'); |
4106 } | 4106 } |
4107 | 4107 |
4108 /* Ask for choice. */ | 4108 // Ask for choice. |
4109 selected = prompt_for_number(&mouse_used); | 4109 selected = prompt_for_number(&mouse_used); |
4110 if (mouse_used) | 4110 if (mouse_used) |
4111 selected -= lines_left; | 4111 selected -= lines_left; |
4112 | 4112 |
4113 rettv->vval.v_number = selected; | 4113 rettv->vval.v_number = selected; |
4124 if (ga_userinput.ga_len > 0) | 4124 if (ga_userinput.ga_len > 0) |
4125 { | 4125 { |
4126 --ga_userinput.ga_len; | 4126 --ga_userinput.ga_len; |
4127 restore_typeahead((tasave_T *)(ga_userinput.ga_data) | 4127 restore_typeahead((tasave_T *)(ga_userinput.ga_data) |
4128 + ga_userinput.ga_len); | 4128 + ga_userinput.ga_len); |
4129 /* default return is zero == OK */ | 4129 // default return is zero == OK |
4130 } | 4130 } |
4131 else if (p_verbose > 1) | 4131 else if (p_verbose > 1) |
4132 { | 4132 { |
4133 verb_msg(_("called inputrestore() more often than inputsave()")); | 4133 verb_msg(_("called inputrestore() more often than inputsave()")); |
4134 rettv->vval.v_number = 1; /* Failed */ | 4134 rettv->vval.v_number = 1; // Failed |
4135 } | 4135 } |
4136 } | 4136 } |
4137 | 4137 |
4138 /* | 4138 /* |
4139 * "inputsave()" function | 4139 * "inputsave()" function |
4140 */ | 4140 */ |
4141 static void | 4141 static void |
4142 f_inputsave(typval_T *argvars UNUSED, typval_T *rettv) | 4142 f_inputsave(typval_T *argvars UNUSED, typval_T *rettv) |
4143 { | 4143 { |
4144 /* Add an entry to the stack of typeahead storage. */ | 4144 // Add an entry to the stack of typeahead storage. |
4145 if (ga_grow(&ga_userinput, 1) == OK) | 4145 if (ga_grow(&ga_userinput, 1) == OK) |
4146 { | 4146 { |
4147 save_typeahead((tasave_T *)(ga_userinput.ga_data) | 4147 save_typeahead((tasave_T *)(ga_userinput.ga_data) |
4148 + ga_userinput.ga_len); | 4148 + ga_userinput.ga_len); |
4149 ++ga_userinput.ga_len; | 4149 ++ga_userinput.ga_len; |
4150 /* default return is zero == OK */ | 4150 // default return is zero == OK |
4151 } | 4151 } |
4152 else | 4152 else |
4153 rettv->vval.v_number = 1; /* Failed */ | 4153 rettv->vval.v_number = 1; // Failed |
4154 } | 4154 } |
4155 | 4155 |
4156 /* | 4156 /* |
4157 * "inputsecret()" function | 4157 * "inputsecret()" function |
4158 */ | 4158 */ |
4222 if (lv.ll_tv == NULL) | 4222 if (lv.ll_tv == NULL) |
4223 { | 4223 { |
4224 di = find_var(lv.ll_name, NULL, TRUE); | 4224 di = find_var(lv.ll_name, NULL, TRUE); |
4225 if (di != NULL) | 4225 if (di != NULL) |
4226 { | 4226 { |
4227 /* Consider a variable locked when: | 4227 // Consider a variable locked when: |
4228 * 1. the variable itself is locked | 4228 // 1. the variable itself is locked |
4229 * 2. the value of the variable is locked. | 4229 // 2. the value of the variable is locked. |
4230 * 3. the List or Dict value is locked. | 4230 // 3. the List or Dict value is locked. |
4231 */ | |
4232 rettv->vval.v_number = ((di->di_flags & DI_FLAGS_LOCK) | 4231 rettv->vval.v_number = ((di->di_flags & DI_FLAGS_LOCK) |
4233 || tv_islocked(&di->di_tv)); | 4232 || tv_islocked(&di->di_tv)); |
4234 } | 4233 } |
4235 } | 4234 } |
4236 else if (lv.ll_range) | 4235 else if (lv.ll_range) |
4237 emsg(_("E786: Range not allowed")); | 4236 emsg(_("E786: Range not allowed")); |
4238 else if (lv.ll_newkey != NULL) | 4237 else if (lv.ll_newkey != NULL) |
4239 semsg(_(e_dictkey), lv.ll_newkey); | 4238 semsg(_(e_dictkey), lv.ll_newkey); |
4240 else if (lv.ll_list != NULL) | 4239 else if (lv.ll_list != NULL) |
4241 /* List item. */ | 4240 // List item. |
4242 rettv->vval.v_number = tv_islocked(&lv.ll_li->li_tv); | 4241 rettv->vval.v_number = tv_islocked(&lv.ll_li->li_tv); |
4243 else | 4242 else |
4244 /* Dictionary item. */ | 4243 // Dictionary item. |
4245 rettv->vval.v_number = tv_islocked(&lv.ll_di->di_tv); | 4244 rettv->vval.v_number = tv_islocked(&lv.ll_di->di_tv); |
4246 } | 4245 } |
4247 } | 4246 } |
4248 | 4247 |
4249 clear_lval(&lv); | 4248 clear_lval(&lv); |
4336 | 4335 |
4337 if (check_restricted() || check_secure()) | 4336 if (check_restricted() || check_secure()) |
4338 return; | 4337 return; |
4339 | 4338 |
4340 #ifdef FEAT_LIBCALL | 4339 #ifdef FEAT_LIBCALL |
4341 /* The first two args must be strings, otherwise it's meaningless */ | 4340 // The first two args must be strings, otherwise it's meaningless |
4342 if (argvars[0].v_type == VAR_STRING && argvars[1].v_type == VAR_STRING) | 4341 if (argvars[0].v_type == VAR_STRING && argvars[1].v_type == VAR_STRING) |
4343 { | 4342 { |
4344 string_in = NULL; | 4343 string_in = NULL; |
4345 if (argvars[2].v_type == VAR_STRING) | 4344 if (argvars[2].v_type == VAR_STRING) |
4346 string_in = argvars[2].vval.v_string; | 4345 string_in = argvars[2].vval.v_string; |
4516 get_maparg(argvars, rettv, FALSE); | 4515 get_maparg(argvars, rettv, FALSE); |
4517 } | 4516 } |
4518 | 4517 |
4519 typedef enum | 4518 typedef enum |
4520 { | 4519 { |
4521 MATCH_END, /* matchend() */ | 4520 MATCH_END, // matchend() |
4522 MATCH_MATCH, /* match() */ | 4521 MATCH_MATCH, // match() |
4523 MATCH_STR, /* matchstr() */ | 4522 MATCH_STR, // matchstr() |
4524 MATCH_LIST, /* matchlist() */ | 4523 MATCH_LIST, // matchlist() |
4525 MATCH_POS /* matchstrpos() */ | 4524 MATCH_POS // matchstrpos() |
4526 } matchtype_T; | 4525 } matchtype_T; |
4527 | 4526 |
4528 static void | 4527 static void |
4529 find_some_match(typval_T *argvars, typval_T *rettv, matchtype_T type) | 4528 find_some_match(typval_T *argvars, typval_T *rettv, matchtype_T type) |
4530 { | 4529 { |
4543 list_T *l = NULL; | 4542 list_T *l = NULL; |
4544 listitem_T *li = NULL; | 4543 listitem_T *li = NULL; |
4545 long idx = 0; | 4544 long idx = 0; |
4546 char_u *tofree = NULL; | 4545 char_u *tofree = NULL; |
4547 | 4546 |
4548 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 4547 // Make 'cpoptions' empty, the 'l' flag should not be used here. |
4549 save_cpo = p_cpo; | 4548 save_cpo = p_cpo; |
4550 p_cpo = (char_u *)""; | 4549 p_cpo = (char_u *)""; |
4551 | 4550 |
4552 rettv->vval.v_number = -1; | 4551 rettv->vval.v_number = -1; |
4553 if (type == MATCH_LIST || type == MATCH_POS) | 4552 if (type == MATCH_LIST || type == MATCH_POS) |
4554 { | 4553 { |
4555 /* type MATCH_LIST: return empty list when there are no matches. | 4554 // type MATCH_LIST: return empty list when there are no matches. |
4556 * type MATCH_POS: return ["", -1, -1, -1] */ | 4555 // type MATCH_POS: return ["", -1, -1, -1] |
4557 if (rettv_list_alloc(rettv) == FAIL) | 4556 if (rettv_list_alloc(rettv) == FAIL) |
4558 goto theend; | 4557 goto theend; |
4559 if (type == MATCH_POS | 4558 if (type == MATCH_POS |
4560 && (list_append_string(rettv->vval.v_list, | 4559 && (list_append_string(rettv->vval.v_list, |
4561 (char_u *)"", 0) == FAIL | 4560 (char_u *)"", 0) == FAIL |
4603 if (l != NULL) | 4602 if (l != NULL) |
4604 { | 4603 { |
4605 li = list_find(l, start); | 4604 li = list_find(l, start); |
4606 if (li == NULL) | 4605 if (li == NULL) |
4607 goto theend; | 4606 goto theend; |
4608 idx = l->lv_idx; /* use the cached index */ | 4607 idx = l->lv_idx; // use the cached index |
4609 } | 4608 } |
4610 else | 4609 else |
4611 { | 4610 { |
4612 if (start < 0) | 4611 if (start < 0) |
4613 start = 0; | 4612 start = 0; |
4614 if (start > len) | 4613 if (start > len) |
4615 goto theend; | 4614 goto theend; |
4616 /* When "count" argument is there ignore matches before "start", | 4615 // When "count" argument is there ignore matches before "start", |
4617 * otherwise skip part of the string. Differs when pattern is "^" | 4616 // otherwise skip part of the string. Differs when pattern is "^" |
4618 * or "\<". */ | 4617 // or "\<". |
4619 if (argvars[3].v_type != VAR_UNKNOWN) | 4618 if (argvars[3].v_type != VAR_UNKNOWN) |
4620 startcol = start; | 4619 startcol = start; |
4621 else | 4620 else |
4622 { | 4621 { |
4623 str += start; | 4622 str += start; |
4656 if (match && --nth <= 0) | 4655 if (match && --nth <= 0) |
4657 break; | 4656 break; |
4658 if (l == NULL && !match) | 4657 if (l == NULL && !match) |
4659 break; | 4658 break; |
4660 | 4659 |
4661 /* Advance to just after the match. */ | 4660 // Advance to just after the match. |
4662 if (l != NULL) | 4661 if (l != NULL) |
4663 { | 4662 { |
4664 li = li->li_next; | 4663 li = li->li_next; |
4665 ++idx; | 4664 ++idx; |
4666 } | 4665 } |
4698 } | 4697 } |
4699 else if (type == MATCH_LIST) | 4698 else if (type == MATCH_LIST) |
4700 { | 4699 { |
4701 int i; | 4700 int i; |
4702 | 4701 |
4703 /* return list with matched string and submatches */ | 4702 // return list with matched string and submatches |
4704 for (i = 0; i < NSUBEXP; ++i) | 4703 for (i = 0; i < NSUBEXP; ++i) |
4705 { | 4704 { |
4706 if (regmatch.endp[i] == NULL) | 4705 if (regmatch.endp[i] == NULL) |
4707 { | 4706 { |
4708 if (list_append_string(rettv->vval.v_list, | 4707 if (list_append_string(rettv->vval.v_list, |
4716 break; | 4715 break; |
4717 } | 4716 } |
4718 } | 4717 } |
4719 else if (type == MATCH_STR) | 4718 else if (type == MATCH_STR) |
4720 { | 4719 { |
4721 /* return matched string */ | 4720 // return matched string |
4722 if (l != NULL) | 4721 if (l != NULL) |
4723 copy_tv(&li->li_tv, rettv); | 4722 copy_tv(&li->li_tv, rettv); |
4724 else | 4723 else |
4725 rettv->vval.v_string = vim_strnsave(regmatch.startp[0], | 4724 rettv->vval.v_string = vim_strnsave(regmatch.startp[0], |
4726 (int)(regmatch.endp[0] - regmatch.startp[0])); | 4725 (int)(regmatch.endp[0] - regmatch.startp[0])); |
4741 vim_regfree(regmatch.regprog); | 4740 vim_regfree(regmatch.regprog); |
4742 } | 4741 } |
4743 | 4742 |
4744 theend: | 4743 theend: |
4745 if (type == MATCH_POS && l == NULL && rettv->vval.v_list != NULL) | 4744 if (type == MATCH_POS && l == NULL && rettv->vval.v_list != NULL) |
4746 /* matchstrpos() without a list: drop the second item. */ | 4745 // matchstrpos() without a list: drop the second item. |
4747 listitem_remove(rettv->vval.v_list, | 4746 listitem_remove(rettv->vval.v_list, |
4748 rettv->vval.v_list->lv_first->li_next); | 4747 rettv->vval.v_list->lv_first->li_next); |
4749 vim_free(tofree); | 4748 vim_free(tofree); |
4750 p_cpo = save_cpo; | 4749 p_cpo = save_cpo; |
4751 } | 4750 } |
5014 while (lnum >= 1 && *skipwhite(ml_get(lnum)) == NUL) | 5013 while (lnum >= 1 && *skipwhite(ml_get(lnum)) == NUL) |
5015 --lnum; | 5014 --lnum; |
5016 rettv->vval.v_number = lnum; | 5015 rettv->vval.v_number = lnum; |
5017 } | 5016 } |
5018 | 5017 |
5019 /* This dummy va_list is here because: | 5018 // This dummy va_list is here because: |
5020 * - passing a NULL pointer doesn't work when va_list isn't a pointer | 5019 // - passing a NULL pointer doesn't work when va_list isn't a pointer |
5021 * - locally in the function results in a "used before set" warning | 5020 // - locally in the function results in a "used before set" warning |
5022 * - using va_start() to initialize it gives "function with fixed args" error */ | 5021 // - using va_start() to initialize it gives "function with fixed args" error |
5023 static va_list ap; | 5022 static va_list ap; |
5024 | 5023 |
5025 /* | 5024 /* |
5026 * "printf()" function | 5025 * "printf()" function |
5027 */ | 5026 */ |
5035 char *fmt; | 5034 char *fmt; |
5036 | 5035 |
5037 rettv->v_type = VAR_STRING; | 5036 rettv->v_type = VAR_STRING; |
5038 rettv->vval.v_string = NULL; | 5037 rettv->vval.v_string = NULL; |
5039 | 5038 |
5040 /* Get the required length, allocate the buffer and do it for real. */ | 5039 // Get the required length, allocate the buffer and do it for real. |
5041 did_emsg = FALSE; | 5040 did_emsg = FALSE; |
5042 fmt = (char *)tv_get_string_buf(&argvars[0], buf); | 5041 fmt = (char *)tv_get_string_buf(&argvars[0], buf); |
5043 len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1); | 5042 len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1); |
5044 if (!did_emsg) | 5043 if (!did_emsg) |
5045 { | 5044 { |
5242 if (argvars[2].v_type != VAR_UNKNOWN) | 5241 if (argvars[2].v_type != VAR_UNKNOWN) |
5243 stride = tv_get_number_chk(&argvars[2], &error); | 5242 stride = tv_get_number_chk(&argvars[2], &error); |
5244 } | 5243 } |
5245 | 5244 |
5246 if (error) | 5245 if (error) |
5247 return; /* type error; errmsg already given */ | 5246 return; // type error; errmsg already given |
5248 if (stride == 0) | 5247 if (stride == 0) |
5249 emsg(_("E726: Stride is zero")); | 5248 emsg(_("E726: Stride is zero")); |
5250 else if (stride > 0 ? end + 1 < start : end - 1 > start) | 5249 else if (stride > 0 ? end + 1 < start : end - 1 > start) |
5251 emsg(_("E727: Start past end")); | 5250 emsg(_("E727: Start past end")); |
5252 else | 5251 else |
5310 tm->tv_sec = n1; | 5309 tm->tv_sec = n1; |
5311 tm->tv_usec = n2; | 5310 tm->tv_usec = n2; |
5312 # endif | 5311 # endif |
5313 return error ? FAIL : OK; | 5312 return error ? FAIL : OK; |
5314 } | 5313 } |
5315 #endif /* FEAT_RELTIME */ | 5314 #endif // FEAT_RELTIME |
5316 | 5315 |
5317 /* | 5316 /* |
5318 * "reltime()" function | 5317 * "reltime()" function |
5319 */ | 5318 */ |
5320 static void | 5319 static void |
5324 proftime_T res; | 5323 proftime_T res; |
5325 proftime_T start; | 5324 proftime_T start; |
5326 | 5325 |
5327 if (argvars[0].v_type == VAR_UNKNOWN) | 5326 if (argvars[0].v_type == VAR_UNKNOWN) |
5328 { | 5327 { |
5329 /* No arguments: get current time. */ | 5328 // No arguments: get current time. |
5330 profile_start(&res); | 5329 profile_start(&res); |
5331 } | 5330 } |
5332 else if (argvars[1].v_type == VAR_UNKNOWN) | 5331 else if (argvars[1].v_type == VAR_UNKNOWN) |
5333 { | 5332 { |
5334 if (list2proftime(&argvars[0], &res) == FAIL) | 5333 if (list2proftime(&argvars[0], &res) == FAIL) |
5335 return; | 5334 return; |
5336 profile_end(&res); | 5335 profile_end(&res); |
5337 } | 5336 } |
5338 else | 5337 else |
5339 { | 5338 { |
5340 /* Two arguments: compute the difference. */ | 5339 // Two arguments: compute the difference. |
5341 if (list2proftime(&argvars[0], &start) == FAIL | 5340 if (list2proftime(&argvars[0], &start) == FAIL |
5342 || list2proftime(&argvars[1], &res) == FAIL) | 5341 || list2proftime(&argvars[1], &res) == FAIL) |
5343 return; | 5342 return; |
5344 profile_sub(&res, &start); | 5343 profile_sub(&res, &start); |
5345 } | 5344 } |
5454 && argvars[3].v_type != VAR_UNKNOWN) | 5453 && argvars[3].v_type != VAR_UNKNOWN) |
5455 timeout = tv_get_number(&argvars[3]); | 5454 timeout = tv_get_number(&argvars[3]); |
5456 | 5455 |
5457 server_name = tv_get_string_chk(&argvars[0]); | 5456 server_name = tv_get_string_chk(&argvars[0]); |
5458 if (server_name == NULL) | 5457 if (server_name == NULL) |
5459 return; /* type error; errmsg already given */ | 5458 return; // type error; errmsg already given |
5460 keys = tv_get_string_buf(&argvars[1], buf); | 5459 keys = tv_get_string_buf(&argvars[1], buf); |
5461 # ifdef MSWIN | 5460 # ifdef MSWIN |
5462 if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0) | 5461 if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0) |
5463 # else | 5462 # else |
5464 if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, timeout, | 5463 if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, timeout, |
5515 static void | 5514 static void |
5516 f_remote_foreground(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | 5515 f_remote_foreground(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
5517 { | 5516 { |
5518 #ifdef FEAT_CLIENTSERVER | 5517 #ifdef FEAT_CLIENTSERVER |
5519 # ifdef MSWIN | 5518 # ifdef MSWIN |
5520 /* On Win32 it's done in this application. */ | 5519 // On Win32 it's done in this application. |
5521 { | 5520 { |
5522 char_u *server_name = tv_get_string_chk(&argvars[0]); | 5521 char_u *server_name = tv_get_string_chk(&argvars[0]); |
5523 | 5522 |
5524 if (server_name != NULL) | 5523 if (server_name != NULL) |
5525 serverForeground(server_name); | 5524 serverForeground(server_name); |
5526 } | 5525 } |
5527 # else | 5526 # else |
5528 /* Send a foreground() expression to the server. */ | 5527 // Send a foreground() expression to the server. |
5529 argvars[1].v_type = VAR_STRING; | 5528 argvars[1].v_type = VAR_STRING; |
5530 argvars[1].vval.v_string = vim_strsave((char_u *)"foreground()"); | 5529 argvars[1].vval.v_string = vim_strsave((char_u *)"foreground()"); |
5531 argvars[2].v_type = VAR_UNKNOWN; | 5530 argvars[2].v_type = VAR_UNKNOWN; |
5532 rettv->v_type = VAR_STRING; | 5531 rettv->v_type = VAR_STRING; |
5533 rettv->vval.v_string = NULL; | 5532 rettv->vval.v_string = NULL; |
5555 } | 5554 } |
5556 serverid = tv_get_string_chk(&argvars[0]); | 5555 serverid = tv_get_string_chk(&argvars[0]); |
5557 if (serverid == NULL) | 5556 if (serverid == NULL) |
5558 { | 5557 { |
5559 rettv->vval.v_number = -1; | 5558 rettv->vval.v_number = -1; |
5560 return; /* type error; errmsg already given */ | 5559 return; // type error; errmsg already given |
5561 } | 5560 } |
5562 # ifdef MSWIN | 5561 # ifdef MSWIN |
5563 sscanf((const char *)serverid, SCANF_HEX_LONG_U, &n); | 5562 sscanf((const char *)serverid, SCANF_HEX_LONG_U, &n); |
5564 if (n == 0) | 5563 if (n == 0) |
5565 rettv->vval.v_number = -1; | 5564 rettv->vval.v_number = -1; |
5602 | 5601 |
5603 if (serverid != NULL && !check_restricted() && !check_secure()) | 5602 if (serverid != NULL && !check_restricted() && !check_secure()) |
5604 { | 5603 { |
5605 int timeout = 0; | 5604 int timeout = 0; |
5606 # ifdef MSWIN | 5605 # ifdef MSWIN |
5607 /* The server's HWND is encoded in the 'id' parameter */ | 5606 // The server's HWND is encoded in the 'id' parameter |
5608 long_u n = 0; | 5607 long_u n = 0; |
5609 # endif | 5608 # endif |
5610 | 5609 |
5611 if (argvars[1].v_type != VAR_UNKNOWN) | 5610 if (argvars[1].v_type != VAR_UNKNOWN) |
5612 timeout = tv_get_number(&argvars[1]); | 5611 timeout = tv_get_number(&argvars[1]); |
5649 { | 5648 { |
5650 #ifdef FEAT_CLIENTSERVER | 5649 #ifdef FEAT_CLIENTSERVER |
5651 char_u *server = tv_get_string_chk(&argvars[0]); | 5650 char_u *server = tv_get_string_chk(&argvars[0]); |
5652 | 5651 |
5653 if (server == NULL) | 5652 if (server == NULL) |
5654 return; /* type error; errmsg already given */ | 5653 return; // type error; errmsg already given |
5655 if (serverName != NULL) | 5654 if (serverName != NULL) |
5656 emsg(_("E941: already started a server")); | 5655 emsg(_("E941: already started a server")); |
5657 else | 5656 else |
5658 { | 5657 { |
5659 # ifdef FEAT_X11 | 5658 # ifdef FEAT_X11 |
5726 | 5725 |
5727 rettv->vval.v_string = r; | 5726 rettv->vval.v_string = r; |
5728 } | 5727 } |
5729 } | 5728 } |
5730 | 5729 |
5731 #define SP_NOMOVE 0x01 /* don't move cursor */ | 5730 #define SP_NOMOVE 0x01 // don't move cursor |
5732 #define SP_REPEAT 0x02 /* repeat to find outer pair */ | 5731 #define SP_REPEAT 0x02 // repeat to find outer pair |
5733 #define SP_RETCOUNT 0x04 /* return matchcount */ | 5732 #define SP_RETCOUNT 0x04 // return matchcount |
5734 #define SP_SETPCMARK 0x08 /* set previous context mark */ | 5733 #define SP_SETPCMARK 0x08 // set previous context mark |
5735 #define SP_START 0x10 /* accept match at start position */ | 5734 #define SP_START 0x10 // accept match at start position |
5736 #define SP_SUBPAT 0x20 /* return nr of matching sub-pattern */ | 5735 #define SP_SUBPAT 0x20 // return nr of matching sub-pattern |
5737 #define SP_END 0x40 /* leave cursor at end of match */ | 5736 #define SP_END 0x40 // leave cursor at end of match |
5738 #define SP_COLUMN 0x80 /* start at cursor column */ | 5737 #define SP_COLUMN 0x80 // start at cursor column |
5739 | 5738 |
5740 /* | 5739 /* |
5741 * Get flags for a search function. | 5740 * Get flags for a search function. |
5742 * Possibly sets "p_ws". | 5741 * Possibly sets "p_ws". |
5743 * Returns BACKWARD, FORWARD or zero (for an error). | 5742 * Returns BACKWARD, FORWARD or zero (for an error). |
5752 | 5751 |
5753 if (varp->v_type != VAR_UNKNOWN) | 5752 if (varp->v_type != VAR_UNKNOWN) |
5754 { | 5753 { |
5755 flags = tv_get_string_buf_chk(varp, nbuf); | 5754 flags = tv_get_string_buf_chk(varp, nbuf); |
5756 if (flags == NULL) | 5755 if (flags == NULL) |
5757 return 0; /* type error; errmsg already given */ | 5756 return 0; // type error; errmsg already given |
5758 while (*flags != NUL) | 5757 while (*flags != NUL) |
5759 { | 5758 { |
5760 switch (*flags) | 5759 switch (*flags) |
5761 { | 5760 { |
5762 case 'b': dir = BACKWARD; break; | 5761 case 'b': dir = BACKWARD; break; |
5801 char_u *pat; | 5800 char_u *pat; |
5802 pos_T pos; | 5801 pos_T pos; |
5803 pos_T save_cursor; | 5802 pos_T save_cursor; |
5804 int save_p_ws = p_ws; | 5803 int save_p_ws = p_ws; |
5805 int dir; | 5804 int dir; |
5806 int retval = 0; /* default: FAIL */ | 5805 int retval = 0; // default: FAIL |
5807 long lnum_stop = 0; | 5806 long lnum_stop = 0; |
5808 #ifdef FEAT_RELTIME | 5807 #ifdef FEAT_RELTIME |
5809 proftime_T tm; | 5808 proftime_T tm; |
5810 long time_limit = 0; | 5809 long time_limit = 0; |
5811 #endif | 5810 #endif |
5812 int options = SEARCH_KEEP; | 5811 int options = SEARCH_KEEP; |
5813 int subpatnum; | 5812 int subpatnum; |
5814 searchit_arg_T sia; | 5813 searchit_arg_T sia; |
5815 | 5814 |
5816 pat = tv_get_string(&argvars[0]); | 5815 pat = tv_get_string(&argvars[0]); |
5817 dir = get_search_arg(&argvars[1], flagsp); /* may set p_ws */ | 5816 dir = get_search_arg(&argvars[1], flagsp); // may set p_ws |
5818 if (dir == 0) | 5817 if (dir == 0) |
5819 goto theend; | 5818 goto theend; |
5820 flags = *flagsp; | 5819 flags = *flagsp; |
5821 if (flags & SP_START) | 5820 if (flags & SP_START) |
5822 options |= SEARCH_START; | 5821 options |= SEARCH_START; |
5823 if (flags & SP_END) | 5822 if (flags & SP_END) |
5824 options |= SEARCH_END; | 5823 options |= SEARCH_END; |
5825 if (flags & SP_COLUMN) | 5824 if (flags & SP_COLUMN) |
5826 options |= SEARCH_COL; | 5825 options |= SEARCH_COL; |
5827 | 5826 |
5828 /* Optional arguments: line number to stop searching and timeout. */ | 5827 // Optional arguments: line number to stop searching and timeout. |
5829 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) | 5828 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) |
5830 { | 5829 { |
5831 lnum_stop = (long)tv_get_number_chk(&argvars[2], NULL); | 5830 lnum_stop = (long)tv_get_number_chk(&argvars[2], NULL); |
5832 if (lnum_stop < 0) | 5831 if (lnum_stop < 0) |
5833 goto theend; | 5832 goto theend; |
5840 } | 5839 } |
5841 #endif | 5840 #endif |
5842 } | 5841 } |
5843 | 5842 |
5844 #ifdef FEAT_RELTIME | 5843 #ifdef FEAT_RELTIME |
5845 /* Set the time limit, if there is one. */ | 5844 // Set the time limit, if there is one. |
5846 profile_setlimit(time_limit, &tm); | 5845 profile_setlimit(time_limit, &tm); |
5847 #endif | 5846 #endif |
5848 | 5847 |
5849 /* | 5848 /* |
5850 * This function does not accept SP_REPEAT and SP_RETCOUNT flags. | 5849 * This function does not accept SP_REPEAT and SP_RETCOUNT flags. |
5876 if (flags & SP_SETPCMARK) | 5875 if (flags & SP_SETPCMARK) |
5877 setpcmark(); | 5876 setpcmark(); |
5878 curwin->w_cursor = pos; | 5877 curwin->w_cursor = pos; |
5879 if (match_pos != NULL) | 5878 if (match_pos != NULL) |
5880 { | 5879 { |
5881 /* Store the match cursor position */ | 5880 // Store the match cursor position |
5882 match_pos->lnum = pos.lnum; | 5881 match_pos->lnum = pos.lnum; |
5883 match_pos->col = pos.col + 1; | 5882 match_pos->col = pos.col + 1; |
5884 } | 5883 } |
5885 /* "/$" will put the cursor after the end of the line, may need to | 5884 // "/$" will put the cursor after the end of the line, may need to |
5886 * correct that here */ | 5885 // correct that here |
5887 check_cursor(); | 5886 check_cursor(); |
5888 } | 5887 } |
5889 | 5888 |
5890 /* If 'n' flag is used: restore cursor position. */ | 5889 // If 'n' flag is used: restore cursor position. |
5891 if (flags & SP_NOMOVE) | 5890 if (flags & SP_NOMOVE) |
5892 curwin->w_cursor = save_cursor; | 5891 curwin->w_cursor = save_cursor; |
5893 else | 5892 else |
5894 curwin->w_set_curswant = TRUE; | 5893 curwin->w_set_curswant = TRUE; |
5895 theend: | 5894 theend: |
6096 int locally = 1; | 6095 int locally = 1; |
6097 int thisblock = 0; | 6096 int thisblock = 0; |
6098 int error = FALSE; | 6097 int error = FALSE; |
6099 char_u *name; | 6098 char_u *name; |
6100 | 6099 |
6101 rettv->vval.v_number = 1; /* default: FAIL */ | 6100 rettv->vval.v_number = 1; // default: FAIL |
6102 | 6101 |
6103 name = tv_get_string_chk(&argvars[0]); | 6102 name = tv_get_string_chk(&argvars[0]); |
6104 if (argvars[1].v_type != VAR_UNKNOWN) | 6103 if (argvars[1].v_type != VAR_UNKNOWN) |
6105 { | 6104 { |
6106 locally = (int)tv_get_number_chk(&argvars[1], &error) == 0; | 6105 locally = (int)tv_get_number_chk(&argvars[1], &error) == 0; |
6123 int save_p_ws = p_ws; | 6122 int save_p_ws = p_ws; |
6124 int dir; | 6123 int dir; |
6125 int flags = 0; | 6124 int flags = 0; |
6126 char_u nbuf1[NUMBUFLEN]; | 6125 char_u nbuf1[NUMBUFLEN]; |
6127 char_u nbuf2[NUMBUFLEN]; | 6126 char_u nbuf2[NUMBUFLEN]; |
6128 int retval = 0; /* default: FAIL */ | 6127 int retval = 0; // default: FAIL |
6129 long lnum_stop = 0; | 6128 long lnum_stop = 0; |
6130 long time_limit = 0; | 6129 long time_limit = 0; |
6131 | 6130 |
6132 /* Get the three pattern arguments: start, middle, end. Will result in an | 6131 // Get the three pattern arguments: start, middle, end. Will result in an |
6133 * error if not a valid argument. */ | 6132 // error if not a valid argument. |
6134 spat = tv_get_string_chk(&argvars[0]); | 6133 spat = tv_get_string_chk(&argvars[0]); |
6135 mpat = tv_get_string_buf_chk(&argvars[1], nbuf1); | 6134 mpat = tv_get_string_buf_chk(&argvars[1], nbuf1); |
6136 epat = tv_get_string_buf_chk(&argvars[2], nbuf2); | 6135 epat = tv_get_string_buf_chk(&argvars[2], nbuf2); |
6137 if (spat == NULL || mpat == NULL || epat == NULL) | 6136 if (spat == NULL || mpat == NULL || epat == NULL) |
6138 goto theend; /* type error */ | 6137 goto theend; // type error |
6139 | 6138 |
6140 /* Handle the optional fourth argument: flags */ | 6139 // Handle the optional fourth argument: flags |
6141 dir = get_search_arg(&argvars[3], &flags); /* may set p_ws */ | 6140 dir = get_search_arg(&argvars[3], &flags); // may set p_ws |
6142 if (dir == 0) | 6141 if (dir == 0) |
6143 goto theend; | 6142 goto theend; |
6144 | 6143 |
6145 /* Don't accept SP_END or SP_SUBPAT. | 6144 // Don't accept SP_END or SP_SUBPAT. |
6146 * Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set. | 6145 // Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set. |
6147 */ | |
6148 if ((flags & (SP_END | SP_SUBPAT)) != 0 | 6146 if ((flags & (SP_END | SP_SUBPAT)) != 0 |
6149 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK))) | 6147 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK))) |
6150 { | 6148 { |
6151 semsg(_(e_invarg2), tv_get_string(&argvars[3])); | 6149 semsg(_(e_invarg2), tv_get_string(&argvars[3])); |
6152 goto theend; | 6150 goto theend; |
6153 } | 6151 } |
6154 | 6152 |
6155 /* Using 'r' implies 'W', otherwise it doesn't work. */ | 6153 // Using 'r' implies 'W', otherwise it doesn't work. |
6156 if (flags & SP_REPEAT) | 6154 if (flags & SP_REPEAT) |
6157 p_ws = FALSE; | 6155 p_ws = FALSE; |
6158 | 6156 |
6159 /* Optional fifth argument: skip expression */ | 6157 // Optional fifth argument: skip expression |
6160 if (argvars[3].v_type == VAR_UNKNOWN | 6158 if (argvars[3].v_type == VAR_UNKNOWN |
6161 || argvars[4].v_type == VAR_UNKNOWN) | 6159 || argvars[4].v_type == VAR_UNKNOWN) |
6162 skip = NULL; | 6160 skip = NULL; |
6163 else | 6161 else |
6164 { | 6162 { |
6165 skip = &argvars[4]; | 6163 skip = &argvars[4]; |
6166 if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL | 6164 if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL |
6167 && skip->v_type != VAR_STRING) | 6165 && skip->v_type != VAR_STRING) |
6168 { | 6166 { |
6169 /* Type error */ | 6167 // Type error |
6170 semsg(_(e_invarg2), tv_get_string(&argvars[4])); | 6168 semsg(_(e_invarg2), tv_get_string(&argvars[4])); |
6171 goto theend; | 6169 goto theend; |
6172 } | 6170 } |
6173 if (argvars[5].v_type != VAR_UNKNOWN) | 6171 if (argvars[5].v_type != VAR_UNKNOWN) |
6174 { | 6172 { |
6238 * Used by searchpair(), see its documentation for the details. | 6236 * Used by searchpair(), see its documentation for the details. |
6239 * Returns 0 or -1 for no match, | 6237 * Returns 0 or -1 for no match, |
6240 */ | 6238 */ |
6241 long | 6239 long |
6242 do_searchpair( | 6240 do_searchpair( |
6243 char_u *spat, /* start pattern */ | 6241 char_u *spat, // start pattern |
6244 char_u *mpat, /* middle pattern */ | 6242 char_u *mpat, // middle pattern |
6245 char_u *epat, /* end pattern */ | 6243 char_u *epat, // end pattern |
6246 int dir, /* BACKWARD or FORWARD */ | 6244 int dir, // BACKWARD or FORWARD |
6247 typval_T *skip, /* skip expression */ | 6245 typval_T *skip, // skip expression |
6248 int flags, /* SP_SETPCMARK and other SP_ values */ | 6246 int flags, // SP_SETPCMARK and other SP_ values |
6249 pos_T *match_pos, | 6247 pos_T *match_pos, |
6250 linenr_T lnum_stop, /* stop at this line if not zero */ | 6248 linenr_T lnum_stop, // stop at this line if not zero |
6251 long time_limit UNUSED) /* stop after this many msec */ | 6249 long time_limit UNUSED) // stop after this many msec |
6252 { | 6250 { |
6253 char_u *save_cpo; | 6251 char_u *save_cpo; |
6254 char_u *pat, *pat2 = NULL, *pat3 = NULL; | 6252 char_u *pat, *pat2 = NULL, *pat3 = NULL; |
6255 long retval = 0; | 6253 long retval = 0; |
6256 pos_T pos; | 6254 pos_T pos; |
6266 int options = SEARCH_KEEP; | 6264 int options = SEARCH_KEEP; |
6267 #ifdef FEAT_RELTIME | 6265 #ifdef FEAT_RELTIME |
6268 proftime_T tm; | 6266 proftime_T tm; |
6269 #endif | 6267 #endif |
6270 | 6268 |
6271 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 6269 // Make 'cpoptions' empty, the 'l' flag should not be used here. |
6272 save_cpo = p_cpo; | 6270 save_cpo = p_cpo; |
6273 p_cpo = empty_option; | 6271 p_cpo = empty_option; |
6274 | 6272 |
6275 #ifdef FEAT_RELTIME | 6273 #ifdef FEAT_RELTIME |
6276 /* Set the time limit, if there is one. */ | 6274 // Set the time limit, if there is one. |
6277 profile_setlimit(time_limit, &tm); | 6275 profile_setlimit(time_limit, &tm); |
6278 #endif | 6276 #endif |
6279 | 6277 |
6280 /* Make two search patterns: start/end (pat2, for in nested pairs) and | 6278 // Make two search patterns: start/end (pat2, for in nested pairs) and |
6281 * start/middle/end (pat3, for the top pair). */ | 6279 // start/middle/end (pat3, for the top pair). |
6282 pat2 = alloc(STRLEN(spat) + STRLEN(epat) + 17); | 6280 pat2 = alloc(STRLEN(spat) + STRLEN(epat) + 17); |
6283 pat3 = alloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25); | 6281 pat3 = alloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25); |
6284 if (pat2 == NULL || pat3 == NULL) | 6282 if (pat2 == NULL || pat3 == NULL) |
6285 goto theend; | 6283 goto theend; |
6286 sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); | 6284 sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); |
6292 if (flags & SP_START) | 6290 if (flags & SP_START) |
6293 options |= SEARCH_START; | 6291 options |= SEARCH_START; |
6294 | 6292 |
6295 if (skip != NULL) | 6293 if (skip != NULL) |
6296 { | 6294 { |
6297 /* Empty string means to not use the skip expression. */ | 6295 // Empty string means to not use the skip expression. |
6298 if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC) | 6296 if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC) |
6299 use_skip = skip->vval.v_string != NULL | 6297 use_skip = skip->vval.v_string != NULL |
6300 && *skip->vval.v_string != NUL; | 6298 && *skip->vval.v_string != NUL; |
6301 } | 6299 } |
6302 | 6300 |
6315 sia.sa_tm = &tm; | 6313 sia.sa_tm = &tm; |
6316 #endif | 6314 #endif |
6317 n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, | 6315 n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, |
6318 options, RE_SEARCH, &sia); | 6316 options, RE_SEARCH, &sia); |
6319 if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))) | 6317 if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))) |
6320 /* didn't find it or found the first match again: FAIL */ | 6318 // didn't find it or found the first match again: FAIL |
6321 break; | 6319 break; |
6322 | 6320 |
6323 if (firstpos.lnum == 0) | 6321 if (firstpos.lnum == 0) |
6324 firstpos = pos; | 6322 firstpos = pos; |
6325 if (EQUAL_POS(pos, foundpos)) | 6323 if (EQUAL_POS(pos, foundpos)) |
6326 { | 6324 { |
6327 /* Found the same position again. Can happen with a pattern that | 6325 // Found the same position again. Can happen with a pattern that |
6328 * has "\zs" at the end and searching backwards. Advance one | 6326 // has "\zs" at the end and searching backwards. Advance one |
6329 * character and try again. */ | 6327 // character and try again. |
6330 if (dir == BACKWARD) | 6328 if (dir == BACKWARD) |
6331 decl(&pos); | 6329 decl(&pos); |
6332 else | 6330 else |
6333 incl(&pos); | 6331 incl(&pos); |
6334 } | 6332 } |
6335 foundpos = pos; | 6333 foundpos = pos; |
6336 | 6334 |
6337 /* clear the start flag to avoid getting stuck here */ | 6335 // clear the start flag to avoid getting stuck here |
6338 options &= ~SEARCH_START; | 6336 options &= ~SEARCH_START; |
6339 | 6337 |
6340 /* If the skip pattern matches, ignore this match. */ | 6338 // If the skip pattern matches, ignore this match. |
6341 if (use_skip) | 6339 if (use_skip) |
6342 { | 6340 { |
6343 save_pos = curwin->w_cursor; | 6341 save_pos = curwin->w_cursor; |
6344 curwin->w_cursor = pos; | 6342 curwin->w_cursor = pos; |
6345 err = FALSE; | 6343 err = FALSE; |
6346 r = eval_expr_to_bool(skip, &err); | 6344 r = eval_expr_to_bool(skip, &err); |
6347 curwin->w_cursor = save_pos; | 6345 curwin->w_cursor = save_pos; |
6348 if (err) | 6346 if (err) |
6349 { | 6347 { |
6350 /* Evaluating {skip} caused an error, break here. */ | 6348 // Evaluating {skip} caused an error, break here. |
6351 curwin->w_cursor = save_cursor; | 6349 curwin->w_cursor = save_cursor; |
6352 retval = -1; | 6350 retval = -1; |
6353 break; | 6351 break; |
6354 } | 6352 } |
6355 if (r) | 6353 if (r) |
6356 continue; | 6354 continue; |
6357 } | 6355 } |
6358 | 6356 |
6359 if ((dir == BACKWARD && n == 3) || (dir == FORWARD && n == 2)) | 6357 if ((dir == BACKWARD && n == 3) || (dir == FORWARD && n == 2)) |
6360 { | 6358 { |
6361 /* Found end when searching backwards or start when searching | 6359 // Found end when searching backwards or start when searching |
6362 * forward: nested pair. */ | 6360 // forward: nested pair. |
6363 ++nest; | 6361 ++nest; |
6364 pat = pat2; /* nested, don't search for middle */ | 6362 pat = pat2; // nested, don't search for middle |
6365 } | 6363 } |
6366 else | 6364 else |
6367 { | 6365 { |
6368 /* Found end when searching forward or start when searching | 6366 // Found end when searching forward or start when searching |
6369 * backward: end of (nested) pair; or found middle in outer pair. */ | 6367 // backward: end of (nested) pair; or found middle in outer pair. |
6370 if (--nest == 1) | 6368 if (--nest == 1) |
6371 pat = pat3; /* outer level, search for middle */ | 6369 pat = pat3; // outer level, search for middle |
6372 } | 6370 } |
6373 | 6371 |
6374 if (nest == 0) | 6372 if (nest == 0) |
6375 { | 6373 { |
6376 /* Found the match: return matchcount or line number. */ | 6374 // Found the match: return matchcount or line number. |
6377 if (flags & SP_RETCOUNT) | 6375 if (flags & SP_RETCOUNT) |
6378 ++retval; | 6376 ++retval; |
6379 else | 6377 else |
6380 retval = pos.lnum; | 6378 retval = pos.lnum; |
6381 if (flags & SP_SETPCMARK) | 6379 if (flags & SP_SETPCMARK) |
6382 setpcmark(); | 6380 setpcmark(); |
6383 curwin->w_cursor = pos; | 6381 curwin->w_cursor = pos; |
6384 if (!(flags & SP_REPEAT)) | 6382 if (!(flags & SP_REPEAT)) |
6385 break; | 6383 break; |
6386 nest = 1; /* search for next unmatched */ | 6384 nest = 1; // search for next unmatched |
6387 } | 6385 } |
6388 } | 6386 } |
6389 | 6387 |
6390 if (match_pos != NULL) | 6388 if (match_pos != NULL) |
6391 { | 6389 { |
6392 /* Store the match cursor position */ | 6390 // Store the match cursor position |
6393 match_pos->lnum = curwin->w_cursor.lnum; | 6391 match_pos->lnum = curwin->w_cursor.lnum; |
6394 match_pos->col = curwin->w_cursor.col + 1; | 6392 match_pos->col = curwin->w_cursor.col + 1; |
6395 } | 6393 } |
6396 | 6394 |
6397 /* If 'n' flag is used or search failed: restore cursor position. */ | 6395 // If 'n' flag is used or search failed: restore cursor position. |
6398 if ((flags & SP_NOMOVE) || retval == 0) | 6396 if ((flags & SP_NOMOVE) || retval == 0) |
6399 curwin->w_cursor = save_cursor; | 6397 curwin->w_cursor = save_cursor; |
6400 | 6398 |
6401 theend: | 6399 theend: |
6402 vim_free(pat2); | 6400 vim_free(pat2); |
6403 vim_free(pat3); | 6401 vim_free(pat3); |
6404 if (p_cpo == empty_option) | 6402 if (p_cpo == empty_option) |
6405 p_cpo = save_cpo; | 6403 p_cpo = save_cpo; |
6406 else | 6404 else |
6407 /* Darn, evaluating the {skip} expression changed the value. */ | 6405 // Darn, evaluating the {skip} expression changed the value. |
6408 free_string_option(save_cpo); | 6406 free_string_option(save_cpo); |
6409 | 6407 |
6410 return retval; | 6408 return retval; |
6411 } | 6409 } |
6412 | 6410 |
6598 { | 6596 { |
6599 if (--pos.col < 0) | 6597 if (--pos.col < 0) |
6600 pos.col = 0; | 6598 pos.col = 0; |
6601 if (name[0] == '.' && name[1] == NUL) | 6599 if (name[0] == '.' && name[1] == NUL) |
6602 { | 6600 { |
6603 /* set cursor; "fnum" is ignored */ | 6601 // set cursor; "fnum" is ignored |
6604 curwin->w_cursor = pos; | 6602 curwin->w_cursor = pos; |
6605 if (curswant >= 0) | 6603 if (curswant >= 0) |
6606 { | 6604 { |
6607 curwin->w_curswant = curswant - 1; | 6605 curwin->w_curswant = curswant - 1; |
6608 curwin->w_set_curswant = FALSE; | 6606 curwin->w_set_curswant = FALSE; |
6610 check_cursor(); | 6608 check_cursor(); |
6611 rettv->vval.v_number = 0; | 6609 rettv->vval.v_number = 0; |
6612 } | 6610 } |
6613 else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) | 6611 else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) |
6614 { | 6612 { |
6615 /* set mark */ | 6613 // set mark |
6616 if (setmark_pos(name[1], &pos, fnum) == OK) | 6614 if (setmark_pos(name[1], &pos, fnum) == OK) |
6617 rettv->vval.v_number = 0; | 6615 rettv->vval.v_number = 0; |
6618 } | 6616 } |
6619 else | 6617 else |
6620 emsg(_(e_invarg)); | 6618 emsg(_(e_invarg)); |
6639 block_len = -1; | 6637 block_len = -1; |
6640 yank_type = MAUTO; | 6638 yank_type = MAUTO; |
6641 append = FALSE; | 6639 append = FALSE; |
6642 | 6640 |
6643 strregname = tv_get_string_chk(argvars); | 6641 strregname = tv_get_string_chk(argvars); |
6644 rettv->vval.v_number = 1; /* FAIL is default */ | 6642 rettv->vval.v_number = 1; // FAIL is default |
6645 | 6643 |
6646 if (strregname == NULL) | 6644 if (strregname == NULL) |
6647 return; /* type error; errmsg already given */ | 6645 return; // type error; errmsg already given |
6648 regname = *strregname; | 6646 regname = *strregname; |
6649 if (regname == 0 || regname == '@') | 6647 if (regname == 0 || regname == '@') |
6650 regname = '"'; | 6648 regname = '"'; |
6651 | 6649 |
6652 if (argvars[2].v_type != VAR_UNKNOWN) | 6650 if (argvars[2].v_type != VAR_UNKNOWN) |
6653 { | 6651 { |
6654 stropt = tv_get_string_chk(&argvars[2]); | 6652 stropt = tv_get_string_chk(&argvars[2]); |
6655 if (stropt == NULL) | 6653 if (stropt == NULL) |
6656 return; /* type error */ | 6654 return; // type error |
6657 for (; *stropt != NUL; ++stropt) | 6655 for (; *stropt != NUL; ++stropt) |
6658 switch (*stropt) | 6656 switch (*stropt) |
6659 { | 6657 { |
6660 case 'a': case 'A': /* append */ | 6658 case 'a': case 'A': // append |
6661 append = TRUE; | 6659 append = TRUE; |
6662 break; | 6660 break; |
6663 case 'v': case 'c': /* character-wise selection */ | 6661 case 'v': case 'c': // character-wise selection |
6664 yank_type = MCHAR; | 6662 yank_type = MCHAR; |
6665 break; | 6663 break; |
6666 case 'V': case 'l': /* line-wise selection */ | 6664 case 'V': case 'l': // line-wise selection |
6667 yank_type = MLINE; | 6665 yank_type = MLINE; |
6668 break; | 6666 break; |
6669 case 'b': case Ctrl_V: /* block-wise selection */ | 6667 case 'b': case Ctrl_V: // block-wise selection |
6670 yank_type = MBLOCK; | 6668 yank_type = MBLOCK; |
6671 if (VIM_ISDIGIT(stropt[1])) | 6669 if (VIM_ISDIGIT(stropt[1])) |
6672 { | 6670 { |
6673 ++stropt; | 6671 ++stropt; |
6674 block_len = getdigits(&stropt) - 1; | 6672 block_len = getdigits(&stropt) - 1; |
6687 char_u **curallocval; | 6685 char_u **curallocval; |
6688 list_T *ll = argvars[1].vval.v_list; | 6686 list_T *ll = argvars[1].vval.v_list; |
6689 listitem_T *li; | 6687 listitem_T *li; |
6690 int len; | 6688 int len; |
6691 | 6689 |
6692 /* If the list is NULL handle like an empty list. */ | 6690 // If the list is NULL handle like an empty list. |
6693 len = ll == NULL ? 0 : ll->lv_len; | 6691 len = ll == NULL ? 0 : ll->lv_len; |
6694 | 6692 |
6695 /* First half: use for pointers to result lines; second half: use for | 6693 // First half: use for pointers to result lines; second half: use for |
6696 * pointers to allocated copies. */ | 6694 // pointers to allocated copies. |
6697 lstval = ALLOC_MULT(char_u *, (len + 1) * 2); | 6695 lstval = ALLOC_MULT(char_u *, (len + 1) * 2); |
6698 if (lstval == NULL) | 6696 if (lstval == NULL) |
6699 return; | 6697 return; |
6700 curval = lstval; | 6698 curval = lstval; |
6701 allocval = lstval + len + 2; | 6699 allocval = lstval + len + 2; |
6707 strval = tv_get_string_buf_chk(&li->li_tv, buf); | 6705 strval = tv_get_string_buf_chk(&li->li_tv, buf); |
6708 if (strval == NULL) | 6706 if (strval == NULL) |
6709 goto free_lstval; | 6707 goto free_lstval; |
6710 if (strval == buf) | 6708 if (strval == buf) |
6711 { | 6709 { |
6712 /* Need to make a copy, next tv_get_string_buf_chk() will | 6710 // Need to make a copy, next tv_get_string_buf_chk() will |
6713 * overwrite the string. */ | 6711 // overwrite the string. |
6714 strval = vim_strsave(buf); | 6712 strval = vim_strsave(buf); |
6715 if (strval == NULL) | 6713 if (strval == NULL) |
6716 goto free_lstval; | 6714 goto free_lstval; |
6717 *curallocval++ = strval; | 6715 *curallocval++ = strval; |
6718 } | 6716 } |
6806 p = tv_get_string(&argvars[0]); | 6804 p = tv_get_string(&argvars[0]); |
6807 rettv->vval.v_string = vim_strsave( | 6805 rettv->vval.v_string = vim_strsave( |
6808 sha256_bytes(p, (int)STRLEN(p), NULL, 0)); | 6806 sha256_bytes(p, (int)STRLEN(p), NULL, 0)); |
6809 rettv->v_type = VAR_STRING; | 6807 rettv->v_type = VAR_STRING; |
6810 } | 6808 } |
6811 #endif /* FEAT_CRYPT */ | 6809 #endif // FEAT_CRYPT |
6812 | 6810 |
6813 /* | 6811 /* |
6814 * "shellescape({string})" function | 6812 * "shellescape({string})" function |
6815 */ | 6813 */ |
6816 static void | 6814 static void |
6910 return; | 6908 return; |
6911 | 6909 |
6912 #ifdef FEAT_SPELL | 6910 #ifdef FEAT_SPELL |
6913 if (argvars[0].v_type == VAR_UNKNOWN) | 6911 if (argvars[0].v_type == VAR_UNKNOWN) |
6914 { | 6912 { |
6915 /* Find the start and length of the badly spelled word. */ | 6913 // Find the start and length of the badly spelled word. |
6916 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr); | 6914 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr); |
6917 if (len != 0) | 6915 if (len != 0) |
6918 { | 6916 { |
6919 word = ml_get_cursor(); | 6917 word = ml_get_cursor(); |
6920 curwin->w_set_curswant = TRUE; | 6918 curwin->w_set_curswant = TRUE; |
6925 char_u *str = tv_get_string_chk(&argvars[0]); | 6923 char_u *str = tv_get_string_chk(&argvars[0]); |
6926 int capcol = -1; | 6924 int capcol = -1; |
6927 | 6925 |
6928 if (str != NULL) | 6926 if (str != NULL) |
6929 { | 6927 { |
6930 /* Check the argument for spelling. */ | 6928 // Check the argument for spelling. |
6931 while (*str != NUL) | 6929 while (*str != NUL) |
6932 { | 6930 { |
6933 len = spell_check(curwin, str, &attr, &capcol, FALSE); | 6931 len = spell_check(curwin, str, &attr, &capcol, FALSE); |
6934 if (attr != HLF_COUNT) | 6932 if (attr != HLF_COUNT) |
6935 { | 6933 { |
7025 int match; | 7023 int match; |
7026 colnr_T col = 0; | 7024 colnr_T col = 0; |
7027 int keepempty = FALSE; | 7025 int keepempty = FALSE; |
7028 int typeerr = FALSE; | 7026 int typeerr = FALSE; |
7029 | 7027 |
7030 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 7028 // Make 'cpoptions' empty, the 'l' flag should not be used here. |
7031 save_cpo = p_cpo; | 7029 save_cpo = p_cpo; |
7032 p_cpo = (char_u *)""; | 7030 p_cpo = (char_u *)""; |
7033 | 7031 |
7034 str = tv_get_string(&argvars[0]); | 7032 str = tv_get_string(&argvars[0]); |
7035 if (argvars[1].v_type != VAR_UNKNOWN) | 7033 if (argvars[1].v_type != VAR_UNKNOWN) |
7053 { | 7051 { |
7054 regmatch.rm_ic = FALSE; | 7052 regmatch.rm_ic = FALSE; |
7055 while (*str != NUL || keepempty) | 7053 while (*str != NUL || keepempty) |
7056 { | 7054 { |
7057 if (*str == NUL) | 7055 if (*str == NUL) |
7058 match = FALSE; /* empty item at the end */ | 7056 match = FALSE; // empty item at the end |
7059 else | 7057 else |
7060 match = vim_regexec_nl(®match, str, col); | 7058 match = vim_regexec_nl(®match, str, col); |
7061 if (match) | 7059 if (match) |
7062 end = regmatch.startp[0]; | 7060 end = regmatch.startp[0]; |
7063 else | 7061 else |
7292 if (argvars[1].v_type == VAR_UNKNOWN) | 7290 if (argvars[1].v_type == VAR_UNKNOWN) |
7293 seconds = time(NULL); | 7291 seconds = time(NULL); |
7294 else | 7292 else |
7295 seconds = (time_t)tv_get_number(&argvars[1]); | 7293 seconds = (time_t)tv_get_number(&argvars[1]); |
7296 curtime = vim_localtime(&seconds, &tmval); | 7294 curtime = vim_localtime(&seconds, &tmval); |
7297 /* MSVC returns NULL for an invalid value of seconds. */ | 7295 // MSVC returns NULL for an invalid value of seconds. |
7298 if (curtime == NULL) | 7296 if (curtime == NULL) |
7299 rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); | 7297 rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); |
7300 else | 7298 else |
7301 { | 7299 { |
7302 vimconv_T conv; | 7300 vimconv_T conv; |
7319 if (conv.vc_type != CONV_NONE) | 7317 if (conv.vc_type != CONV_NONE) |
7320 rettv->vval.v_string = string_convert(&conv, result_buf, NULL); | 7318 rettv->vval.v_string = string_convert(&conv, result_buf, NULL); |
7321 else | 7319 else |
7322 rettv->vval.v_string = vim_strsave(result_buf); | 7320 rettv->vval.v_string = vim_strsave(result_buf); |
7323 | 7321 |
7324 /* Release conversion descriptors */ | 7322 // Release conversion descriptors |
7325 convert_setup(&conv, NULL, NULL); | 7323 convert_setup(&conv, NULL, NULL); |
7326 vim_free(enc); | 7324 vim_free(enc); |
7327 } | 7325 } |
7328 } | 7326 } |
7329 #endif | 7327 #endif |
7376 | 7374 |
7377 needle = tv_get_string_chk(&argvars[1]); | 7375 needle = tv_get_string_chk(&argvars[1]); |
7378 save_haystack = haystack = tv_get_string_buf_chk(&argvars[0], buf); | 7376 save_haystack = haystack = tv_get_string_buf_chk(&argvars[0], buf); |
7379 rettv->vval.v_number = -1; | 7377 rettv->vval.v_number = -1; |
7380 if (needle == NULL || haystack == NULL) | 7378 if (needle == NULL || haystack == NULL) |
7381 return; /* type error; errmsg already given */ | 7379 return; // type error; errmsg already given |
7382 | 7380 |
7383 if (argvars[2].v_type != VAR_UNKNOWN) | 7381 if (argvars[2].v_type != VAR_UNKNOWN) |
7384 { | 7382 { |
7385 int error = FALSE; | 7383 int error = FALSE; |
7386 | 7384 |
7406 char_u numbuf[NUMBUFLEN]; | 7404 char_u numbuf[NUMBUFLEN]; |
7407 | 7405 |
7408 rettv->v_type = VAR_STRING; | 7406 rettv->v_type = VAR_STRING; |
7409 rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, | 7407 rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, |
7410 get_copyID()); | 7408 get_copyID()); |
7411 /* Make a copy if we have a value but it's not in allocated memory. */ | 7409 // Make a copy if we have a value but it's not in allocated memory. |
7412 if (rettv->vval.v_string != NULL && tofree == NULL) | 7410 if (rettv->vval.v_string != NULL && tofree == NULL) |
7413 rettv->vval.v_string = vim_strsave(rettv->vval.v_string); | 7411 rettv->vval.v_string = vim_strsave(rettv->vval.v_string); |
7414 } | 7412 } |
7415 | 7413 |
7416 /* | 7414 /* |
7517 len += MB_CPTR2LEN(p + off); | 7515 len += MB_CPTR2LEN(p + off); |
7518 --charlen; | 7516 --charlen; |
7519 } | 7517 } |
7520 } | 7518 } |
7521 else | 7519 else |
7522 len = slen - nbyte; /* default: all bytes that are available. */ | 7520 len = slen - nbyte; // default: all bytes that are available. |
7523 } | 7521 } |
7524 | 7522 |
7525 /* | 7523 /* |
7526 * Only return the overlap between the specified part and the actual | 7524 * Only return the overlap between the specified part and the actual |
7527 * string. | 7525 * string. |
7561 if (error) | 7559 if (error) |
7562 len = 0; | 7560 len = 0; |
7563 else if (argvars[2].v_type != VAR_UNKNOWN) | 7561 else if (argvars[2].v_type != VAR_UNKNOWN) |
7564 len = (int)tv_get_number(&argvars[2]); | 7562 len = (int)tv_get_number(&argvars[2]); |
7565 else | 7563 else |
7566 len = slen - n; /* default len: all bytes that are available. */ | 7564 len = slen - n; // default len: all bytes that are available. |
7567 | 7565 |
7568 /* | 7566 /* |
7569 * Only return the overlap between the specified part and the actual | 7567 * Only return the overlap between the specified part and the actual |
7570 * string. | 7568 * string. |
7571 */ | 7569 */ |
7635 needle = tv_get_string_chk(&argvars[1]); | 7633 needle = tv_get_string_chk(&argvars[1]); |
7636 haystack = tv_get_string_buf_chk(&argvars[0], buf); | 7634 haystack = tv_get_string_buf_chk(&argvars[0], buf); |
7637 | 7635 |
7638 rettv->vval.v_number = -1; | 7636 rettv->vval.v_number = -1; |
7639 if (needle == NULL || haystack == NULL) | 7637 if (needle == NULL || haystack == NULL) |
7640 return; /* type error; errmsg already given */ | 7638 return; // type error; errmsg already given |
7641 | 7639 |
7642 haystack_len = (int)STRLEN(haystack); | 7640 haystack_len = (int)STRLEN(haystack); |
7643 if (argvars[2].v_type != VAR_UNKNOWN) | 7641 if (argvars[2].v_type != VAR_UNKNOWN) |
7644 { | 7642 { |
7645 /* Third argument: upper limit for index */ | 7643 // Third argument: upper limit for index |
7646 end_idx = (int)tv_get_number_chk(&argvars[2], NULL); | 7644 end_idx = (int)tv_get_number_chk(&argvars[2], NULL); |
7647 if (end_idx < 0) | 7645 if (end_idx < 0) |
7648 return; /* can never find a match */ | 7646 return; // can never find a match |
7649 } | 7647 } |
7650 else | 7648 else |
7651 end_idx = haystack_len; | 7649 end_idx = haystack_len; |
7652 | 7650 |
7653 if (*needle == NUL) | 7651 if (*needle == NUL) |
7654 { | 7652 { |
7655 /* Empty string matches past the end. */ | 7653 // Empty string matches past the end. |
7656 lastmatch = haystack + end_idx; | 7654 lastmatch = haystack + end_idx; |
7657 } | 7655 } |
7658 else | 7656 else |
7659 { | 7657 { |
7660 for (rest = haystack; *rest != '\0'; ++rest) | 7658 for (rest = haystack; *rest != '\0'; ++rest) |
7784 linenr_T lnum; | 7782 linenr_T lnum; |
7785 colnr_T col; | 7783 colnr_T col; |
7786 int trans; | 7784 int trans; |
7787 int transerr = FALSE; | 7785 int transerr = FALSE; |
7788 | 7786 |
7789 lnum = tv_get_lnum(argvars); /* -1 on type error */ | 7787 lnum = tv_get_lnum(argvars); // -1 on type error |
7790 col = (linenr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ | 7788 col = (linenr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error |
7791 trans = (int)tv_get_number_chk(&argvars[2], &transerr); | 7789 trans = (int)tv_get_number_chk(&argvars[2], &transerr); |
7792 | 7790 |
7793 if (!transerr && lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count | 7791 if (!transerr && lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count |
7794 && col >= 0 && col < (long)STRLEN(ml_get(lnum))) | 7792 && col >= 0 && col < (long)STRLEN(ml_get(lnum))) |
7795 id = syn_get_id(curwin, lnum, (colnr_T)col, trans, NULL, FALSE); | 7793 id = syn_get_id(curwin, lnum, (colnr_T)col, trans, NULL, FALSE); |
7817 if (argvars[2].v_type != VAR_UNKNOWN) | 7815 if (argvars[2].v_type != VAR_UNKNOWN) |
7818 { | 7816 { |
7819 mode = tv_get_string_buf(&argvars[2], modebuf); | 7817 mode = tv_get_string_buf(&argvars[2], modebuf); |
7820 modec = TOLOWER_ASC(mode[0]); | 7818 modec = TOLOWER_ASC(mode[0]); |
7821 if (modec != 't' && modec != 'c' && modec != 'g') | 7819 if (modec != 't' && modec != 'c' && modec != 'g') |
7822 modec = 0; /* replace invalid with current */ | 7820 modec = 0; // replace invalid with current |
7823 } | 7821 } |
7824 else | 7822 else |
7825 { | 7823 { |
7826 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) | 7824 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7827 if (USE_24BIT) | 7825 if (USE_24BIT) |
7835 } | 7833 } |
7836 | 7834 |
7837 switch (TOLOWER_ASC(what[0])) | 7835 switch (TOLOWER_ASC(what[0])) |
7838 { | 7836 { |
7839 case 'b': | 7837 case 'b': |
7840 if (TOLOWER_ASC(what[1]) == 'g') /* bg[#] */ | 7838 if (TOLOWER_ASC(what[1]) == 'g') // bg[#] |
7841 p = highlight_color(id, what, modec); | 7839 p = highlight_color(id, what, modec); |
7842 else /* bold */ | 7840 else // bold |
7843 p = highlight_has_attr(id, HL_BOLD, modec); | 7841 p = highlight_has_attr(id, HL_BOLD, modec); |
7844 break; | 7842 break; |
7845 | 7843 |
7846 case 'f': /* fg[#] or font */ | 7844 case 'f': // fg[#] or font |
7847 p = highlight_color(id, what, modec); | 7845 p = highlight_color(id, what, modec); |
7848 break; | 7846 break; |
7849 | 7847 |
7850 case 'i': | 7848 case 'i': |
7851 if (TOLOWER_ASC(what[1]) == 'n') /* inverse */ | 7849 if (TOLOWER_ASC(what[1]) == 'n') // inverse |
7852 p = highlight_has_attr(id, HL_INVERSE, modec); | 7850 p = highlight_has_attr(id, HL_INVERSE, modec); |
7853 else /* italic */ | 7851 else // italic |
7854 p = highlight_has_attr(id, HL_ITALIC, modec); | 7852 p = highlight_has_attr(id, HL_ITALIC, modec); |
7855 break; | 7853 break; |
7856 | 7854 |
7857 case 'n': /* name */ | 7855 case 'n': // name |
7858 p = get_highlight_name_ext(NULL, id - 1, FALSE); | 7856 p = get_highlight_name_ext(NULL, id - 1, FALSE); |
7859 break; | 7857 break; |
7860 | 7858 |
7861 case 'r': /* reverse */ | 7859 case 'r': // reverse |
7862 p = highlight_has_attr(id, HL_INVERSE, modec); | 7860 p = highlight_has_attr(id, HL_INVERSE, modec); |
7863 break; | 7861 break; |
7864 | 7862 |
7865 case 's': | 7863 case 's': |
7866 if (TOLOWER_ASC(what[1]) == 'p') /* sp[#] */ | 7864 if (TOLOWER_ASC(what[1]) == 'p') // sp[#] |
7867 p = highlight_color(id, what, modec); | 7865 p = highlight_color(id, what, modec); |
7868 /* strikeout */ | 7866 // strikeout |
7869 else if (TOLOWER_ASC(what[1]) == 't' && | 7867 else if (TOLOWER_ASC(what[1]) == 't' && |
7870 TOLOWER_ASC(what[2]) == 'r') | 7868 TOLOWER_ASC(what[2]) == 'r') |
7871 p = highlight_has_attr(id, HL_STRIKETHROUGH, modec); | 7869 p = highlight_has_attr(id, HL_STRIKETHROUGH, modec); |
7872 else /* standout */ | 7870 else // standout |
7873 p = highlight_has_attr(id, HL_STANDOUT, modec); | 7871 p = highlight_has_attr(id, HL_STANDOUT, modec); |
7874 break; | 7872 break; |
7875 | 7873 |
7876 case 'u': | 7874 case 'u': |
7877 if (STRLEN(what) <= 5 || TOLOWER_ASC(what[5]) != 'c') | 7875 if (STRLEN(what) <= 5 || TOLOWER_ASC(what[5]) != 'c') |
7878 /* underline */ | 7876 // underline |
7879 p = highlight_has_attr(id, HL_UNDERLINE, modec); | 7877 p = highlight_has_attr(id, HL_UNDERLINE, modec); |
7880 else | 7878 else |
7881 /* undercurl */ | 7879 // undercurl |
7882 p = highlight_has_attr(id, HL_UNDERCURL, modec); | 7880 p = highlight_has_attr(id, HL_UNDERCURL, modec); |
7883 break; | 7881 break; |
7884 } | 7882 } |
7885 | 7883 |
7886 if (p != NULL) | 7884 if (p != NULL) |
7926 #endif | 7924 #endif |
7927 | 7925 |
7928 rettv_list_set(rettv, NULL); | 7926 rettv_list_set(rettv, NULL); |
7929 | 7927 |
7930 #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) | 7928 #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) |
7931 lnum = tv_get_lnum(argvars); /* -1 on type error */ | 7929 lnum = tv_get_lnum(argvars); // -1 on type error |
7932 col = (colnr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ | 7930 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error |
7933 | 7931 |
7934 vim_memset(str, NUL, sizeof(str)); | 7932 vim_memset(str, NUL, sizeof(str)); |
7935 | 7933 |
7936 if (rettv_list_alloc(rettv) != FAIL) | 7934 if (rettv_list_alloc(rettv) != FAIL) |
7937 { | 7935 { |
7940 && curwin->w_p_cole > 0) | 7938 && curwin->w_p_cole > 0) |
7941 { | 7939 { |
7942 (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); | 7940 (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); |
7943 syntax_flags = get_syntax_info(&matchid); | 7941 syntax_flags = get_syntax_info(&matchid); |
7944 | 7942 |
7945 /* get the conceal character */ | 7943 // get the conceal character |
7946 if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) | 7944 if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) |
7947 { | 7945 { |
7948 cchar = syn_get_sub_char(); | 7946 cchar = syn_get_sub_char(); |
7949 if (cchar == NUL && curwin->w_p_cole == 1) | 7947 if (cchar == NUL && curwin->w_p_cole == 1) |
7950 cchar = (lcs_conceal == NUL) ? ' ' : lcs_conceal; | 7948 cchar = (lcs_conceal == NUL) ? ' ' : lcs_conceal; |
7958 } | 7956 } |
7959 } | 7957 } |
7960 | 7958 |
7961 list_append_number(rettv->vval.v_list, | 7959 list_append_number(rettv->vval.v_list, |
7962 (syntax_flags & HL_CONCEAL) != 0); | 7960 (syntax_flags & HL_CONCEAL) != 0); |
7963 /* -1 to auto-determine strlen */ | 7961 // -1 to auto-determine strlen |
7964 list_append_string(rettv->vval.v_list, str, -1); | 7962 list_append_string(rettv->vval.v_list, str, -1); |
7965 list_append_number(rettv->vval.v_list, matchid); | 7963 list_append_number(rettv->vval.v_list, matchid); |
7966 } | 7964 } |
7967 #endif | 7965 #endif |
7968 } | 7966 } |
7981 #endif | 7979 #endif |
7982 | 7980 |
7983 rettv_list_set(rettv, NULL); | 7981 rettv_list_set(rettv, NULL); |
7984 | 7982 |
7985 #ifdef FEAT_SYN_HL | 7983 #ifdef FEAT_SYN_HL |
7986 lnum = tv_get_lnum(argvars); /* -1 on type error */ | 7984 lnum = tv_get_lnum(argvars); // -1 on type error |
7987 col = (colnr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ | 7985 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error |
7988 | 7986 |
7989 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count | 7987 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count |
7990 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) | 7988 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) |
7991 && rettv_list_alloc(rettv) != FAIL) | 7989 && rettv_list_alloc(rettv) != FAIL) |
7992 { | 7990 { |
8149 | 8147 |
8150 in_str = tv_get_string(&argvars[0]); | 8148 in_str = tv_get_string(&argvars[0]); |
8151 fromstr = tv_get_string_buf_chk(&argvars[1], buf); | 8149 fromstr = tv_get_string_buf_chk(&argvars[1], buf); |
8152 tostr = tv_get_string_buf_chk(&argvars[2], buf2); | 8150 tostr = tv_get_string_buf_chk(&argvars[2], buf2); |
8153 | 8151 |
8154 /* Default return value: empty string. */ | 8152 // Default return value: empty string. |
8155 rettv->v_type = VAR_STRING; | 8153 rettv->v_type = VAR_STRING; |
8156 rettv->vval.v_string = NULL; | 8154 rettv->vval.v_string = NULL; |
8157 if (fromstr == NULL || tostr == NULL) | 8155 if (fromstr == NULL || tostr == NULL) |
8158 return; /* type error; errmsg already given */ | 8156 return; // type error; errmsg already given |
8159 ga_init2(&ga, (int)sizeof(char), 80); | 8157 ga_init2(&ga, (int)sizeof(char), 80); |
8160 | 8158 |
8161 if (!has_mbyte) | 8159 if (!has_mbyte) |
8162 /* not multi-byte: fromstr and tostr must be the same length */ | 8160 // not multi-byte: fromstr and tostr must be the same length |
8163 if (STRLEN(fromstr) != STRLEN(tostr)) | 8161 if (STRLEN(fromstr) != STRLEN(tostr)) |
8164 { | 8162 { |
8165 error: | 8163 error: |
8166 semsg(_(e_invarg2), fromstr); | 8164 semsg(_(e_invarg2), fromstr); |
8167 ga_clear(&ga); | 8165 ga_clear(&ga); |
8168 return; | 8166 return; |
8169 } | 8167 } |
8170 | 8168 |
8171 /* fromstr and tostr have to contain the same number of chars */ | 8169 // fromstr and tostr have to contain the same number of chars |
8172 while (*in_str != NUL) | 8170 while (*in_str != NUL) |
8173 { | 8171 { |
8174 if (has_mbyte) | 8172 if (has_mbyte) |
8175 { | 8173 { |
8176 inlen = (*mb_ptr2len)(in_str); | 8174 inlen = (*mb_ptr2len)(in_str); |
8190 cplen = tolen; | 8188 cplen = tolen; |
8191 cpstr = p; | 8189 cpstr = p; |
8192 break; | 8190 break; |
8193 } | 8191 } |
8194 } | 8192 } |
8195 if (*p == NUL) /* tostr is shorter than fromstr */ | 8193 if (*p == NUL) // tostr is shorter than fromstr |
8196 goto error; | 8194 goto error; |
8197 break; | 8195 break; |
8198 } | 8196 } |
8199 ++idx; | 8197 ++idx; |
8200 } | 8198 } |
8201 | 8199 |
8202 if (first && cpstr == in_str) | 8200 if (first && cpstr == in_str) |
8203 { | 8201 { |
8204 /* Check that fromstr and tostr have the same number of | 8202 // Check that fromstr and tostr have the same number of |
8205 * (multi-byte) characters. Done only once when a character | 8203 // (multi-byte) characters. Done only once when a character |
8206 * of in_str doesn't appear in fromstr. */ | 8204 // of in_str doesn't appear in fromstr. |
8207 first = FALSE; | 8205 first = FALSE; |
8208 for (p = tostr; *p != NUL; p += tolen) | 8206 for (p = tostr; *p != NUL; p += tolen) |
8209 { | 8207 { |
8210 tolen = (*mb_ptr2len)(p); | 8208 tolen = (*mb_ptr2len)(p); |
8211 --idx; | 8209 --idx; |
8220 | 8218 |
8221 in_str += inlen; | 8219 in_str += inlen; |
8222 } | 8220 } |
8223 else | 8221 else |
8224 { | 8222 { |
8225 /* When not using multi-byte chars we can do it faster. */ | 8223 // When not using multi-byte chars we can do it faster. |
8226 p = vim_strchr(fromstr, *in_str); | 8224 p = vim_strchr(fromstr, *in_str); |
8227 if (p != NULL) | 8225 if (p != NULL) |
8228 ga_append(&ga, tostr[p - fromstr]); | 8226 ga_append(&ga, tostr[p - fromstr]); |
8229 else | 8227 else |
8230 ga_append(&ga, *in_str); | 8228 ga_append(&ga, *in_str); |
8231 ++in_str; | 8229 ++in_str; |
8232 } | 8230 } |
8233 } | 8231 } |
8234 | 8232 |
8235 /* add a terminating NUL */ | 8233 // add a terminating NUL |
8236 (void)ga_grow(&ga, 1); | 8234 (void)ga_grow(&ga, 1); |
8237 ga_append(&ga, NUL); | 8235 ga_append(&ga, NUL); |
8238 | 8236 |
8239 rettv->vval.v_string = ga.ga_data; | 8237 rettv->vval.v_string = ga.ga_data; |
8240 } | 8238 } |
8314 { | 8312 { |
8315 float_T f = 0.0; | 8313 float_T f = 0.0; |
8316 | 8314 |
8317 rettv->v_type = VAR_FLOAT; | 8315 rettv->v_type = VAR_FLOAT; |
8318 if (get_float_arg(argvars, &f) == OK) | 8316 if (get_float_arg(argvars, &f) == OK) |
8319 /* trunc() is not in C90, use floor() or ceil() instead. */ | 8317 // trunc() is not in C90, use floor() or ceil() instead. |
8320 rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); | 8318 rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); |
8321 else | 8319 else |
8322 rettv->vval.v_float = 0.0; | 8320 rettv->vval.v_float = 0.0; |
8323 } | 8321 } |
8324 #endif | 8322 #endif |
8390 rettv->v_type = VAR_STRING; | 8388 rettv->v_type = VAR_STRING; |
8391 str[0] = curbuf->b_visual_mode_eval; | 8389 str[0] = curbuf->b_visual_mode_eval; |
8392 str[1] = NUL; | 8390 str[1] = NUL; |
8393 rettv->vval.v_string = vim_strsave(str); | 8391 rettv->vval.v_string = vim_strsave(str); |
8394 | 8392 |
8395 /* A non-zero number or non-empty string argument: reset mode. */ | 8393 // A non-zero number or non-empty string argument: reset mode. |
8396 if (non_zero_arg(&argvars[0])) | 8394 if (non_zero_arg(&argvars[0])) |
8397 curbuf->b_visual_mode_eval = NUL; | 8395 curbuf->b_visual_mode_eval = NUL; |
8398 } | 8396 } |
8399 | 8397 |
8400 /* | 8398 /* |
8428 { | 8426 { |
8429 rettv->vval.v_number = tv_get_number_chk(&argvars[0], NULL) | 8427 rettv->vval.v_number = tv_get_number_chk(&argvars[0], NULL) |
8430 ^ tv_get_number_chk(&argvars[1], NULL); | 8428 ^ tv_get_number_chk(&argvars[1], NULL); |
8431 } | 8429 } |
8432 | 8430 |
8433 #endif /* FEAT_EVAL */ | 8431 #endif // FEAT_EVAL |