comparison src/evalfunc.c @ 20587:f502455965c0 v8.2.0847

patch 8.2.0847: typval related code is spread out Commit: https://github.com/vim/vim/commit/367d59e6ba65cf554d167933775fa17e40dcc6a7 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 30 17:06:14 2020 +0200 patch 8.2.0847: typval related code is spread out Problem: Typval related code is spread out. Solution: Move code to new typval.c file. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6093)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 May 2020 17:15:03 +0200
parents 70986f70880a
children 4411c2b96af9
comparison
equal deleted inserted replaced
20586:fed0050be1a1 20587:f502455965c0
1267 || (argvars[0].v_type == VAR_STRING 1267 || (argvars[0].v_type == VAR_STRING
1268 && argvars[0].vval.v_string != NULL 1268 && argvars[0].vval.v_string != NULL
1269 && *argvars[0].vval.v_string != NUL)); 1269 && *argvars[0].vval.v_string != NUL));
1270 } 1270 }
1271 1271
1272 /*
1273 * Get the lnum from the first argument.
1274 * Also accepts ".", "$", etc., but that only works for the current buffer.
1275 * Returns -1 on error.
1276 */
1277 linenr_T
1278 tv_get_lnum(typval_T *argvars)
1279 {
1280 linenr_T lnum;
1281
1282 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL);
1283 if (lnum == 0) // no valid number, try using arg like line()
1284 {
1285 int fnum;
1286 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum);
1287
1288 if (fp != NULL)
1289 lnum = fp->lnum;
1290 }
1291 return lnum;
1292 }
1293
1294 /*
1295 * Get the lnum from the first argument.
1296 * Also accepts "$", then "buf" is used.
1297 * Returns 0 on error.
1298 */
1299 linenr_T
1300 tv_get_lnum_buf(typval_T *argvars, buf_T *buf)
1301 {
1302 if (argvars[0].v_type == VAR_STRING
1303 && argvars[0].vval.v_string != NULL
1304 && argvars[0].vval.v_string[0] == '$'
1305 && buf != NULL)
1306 return buf->b_ml.ml_line_count;
1307 return (linenr_T)tv_get_number_chk(&argvars[0], NULL);
1308 }
1309
1310 #ifdef FEAT_FLOAT 1272 #ifdef FEAT_FLOAT
1311 /* 1273 /*
1312 * Get the float value of "argvars[0]" into "f". 1274 * Get the float value of "argvars[0]" into "f".
1313 * Returns FAIL when the argument is not a Number or Float. 1275 * Returns FAIL when the argument is not a Number or Float.
1314 */ 1276 */
1497 } 1459 }
1498 } 1460 }
1499 } 1461 }
1500 # endif 1462 # endif
1501 #endif 1463 #endif
1502
1503 /*
1504 * Get buffer by number or pattern.
1505 */
1506 buf_T *
1507 tv_get_buf(typval_T *tv, int curtab_only)
1508 {
1509 char_u *name = tv->vval.v_string;
1510 buf_T *buf;
1511
1512 if (tv->v_type == VAR_NUMBER)
1513 return buflist_findnr((int)tv->vval.v_number);
1514 if (tv->v_type != VAR_STRING)
1515 return NULL;
1516 if (name == NULL || *name == NUL)
1517 return curbuf;
1518 if (name[0] == '$' && name[1] == NUL)
1519 return lastbuf;
1520
1521 buf = buflist_find_by_name(name, curtab_only);
1522
1523 // If not found, try expanding the name, like done for bufexists().
1524 if (buf == NULL)
1525 buf = find_buffer(tv);
1526
1527 return buf;
1528 }
1529 1464
1530 /* 1465 /*
1531 * Get the buffer from "arg" and give an error and return NULL if it is not 1466 * Get the buffer from "arg" and give an error and return NULL if it is not
1532 * valid. 1467 * valid.
1533 */ 1468 */
5104 { 5039 {
5105 rettv->vval.v_number = ~tv_get_number_chk(&argvars[0], NULL); 5040 rettv->vval.v_number = ~tv_get_number_chk(&argvars[0], NULL);
5106 } 5041 }
5107 5042
5108 /* 5043 /*
5109 * Return TRUE if typeval "tv" is locked: Either that value is locked itself
5110 * or it refers to a List or Dictionary that is locked.
5111 */
5112 static int
5113 tv_islocked(typval_T *tv)
5114 {
5115 return (tv->v_lock & VAR_LOCKED)
5116 || (tv->v_type == VAR_LIST
5117 && tv->vval.v_list != NULL
5118 && (tv->vval.v_list->lv_lock & VAR_LOCKED))
5119 || (tv->v_type == VAR_DICT
5120 && tv->vval.v_dict != NULL
5121 && (tv->vval.v_dict->dv_lock & VAR_LOCKED));
5122 }
5123
5124 /*
5125 * "islocked()" function 5044 * "islocked()" function
5126 */ 5045 */
5127 static void 5046 static void
5128 f_islocked(typval_T *argvars, typval_T *rettv) 5047 f_islocked(typval_T *argvars, typval_T *rettv)
5129 { 5048 {