Mercurial > vim
comparison src/filepath.c @ 21873:62e61424482f v8.2.1486
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Commit: https://github.com/vim/vim/commit/f8abbf37d66c41d980284e28e0e38a399890e918
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 19 16:00:06 2020 +0200
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Problem: Vim9: readdir() expression doesn't accept bool.
Solution: Merge with code for readdirex(). (closes https://github.com/vim/vim/issues/6737)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 19 Aug 2020 16:15:05 +0200 |
parents | e27555ca1093 |
children | 2b04c5bf4dc3 |
comparison
equal
deleted
inserted
replaced
21872:5ba0e37bca94 | 21873:62e61424482f |
---|---|
1371 shorten_dir(p); | 1371 shorten_dir(p); |
1372 } | 1372 } |
1373 } | 1373 } |
1374 | 1374 |
1375 /* | 1375 /* |
1376 * Evaluate "expr" (= "context") for readdir(). | 1376 * Common code for readdir_checkitem() and readdirex_checkitem(). |
1377 * Either "name" or "dict" is NULL. | |
1377 */ | 1378 */ |
1378 static int | 1379 static int |
1379 readdir_checkitem(void *context, void *item) | 1380 checkitem_common(void *context, char_u *name, dict_T *dict) |
1380 { | 1381 { |
1381 typval_T *expr = (typval_T *)context; | 1382 typval_T *expr = (typval_T *)context; |
1382 typval_T save_val; | 1383 typval_T save_val; |
1383 typval_T rettv; | 1384 typval_T rettv; |
1384 typval_T argv[2]; | 1385 typval_T argv[2]; |
1385 int retval = 0; | 1386 int retval = 0; |
1386 int error = FALSE; | 1387 int error = FALSE; |
1387 char_u *name = (char_u*)item; | |
1388 | 1388 |
1389 prepare_vimvar(VV_VAL, &save_val); | 1389 prepare_vimvar(VV_VAL, &save_val); |
1390 set_vim_var_string(VV_VAL, name, -1); | 1390 if (name != NULL) |
1391 argv[0].v_type = VAR_STRING; | 1391 { |
1392 argv[0].vval.v_string = name; | 1392 set_vim_var_string(VV_VAL, name, -1); |
1393 argv[0].v_type = VAR_STRING; | |
1394 argv[0].vval.v_string = name; | |
1395 } | |
1396 else | |
1397 { | |
1398 set_vim_var_dict(VV_VAL, dict); | |
1399 argv[0].v_type = VAR_DICT; | |
1400 argv[0].vval.v_dict = dict; | |
1401 } | |
1393 | 1402 |
1394 if (eval_expr_typval(expr, argv, 1, &rettv) == FAIL) | 1403 if (eval_expr_typval(expr, argv, 1, &rettv) == FAIL) |
1395 goto theend; | 1404 goto theend; |
1396 | 1405 |
1406 // We want to use -1, but also true/false should be allowed. | |
1407 if (rettv.v_type == VAR_SPECIAL || rettv.v_type == VAR_BOOL) | |
1408 { | |
1409 rettv.v_type = VAR_NUMBER; | |
1410 rettv.vval.v_number = rettv.vval.v_number == VVAL_TRUE; | |
1411 } | |
1397 retval = tv_get_number_chk(&rettv, &error); | 1412 retval = tv_get_number_chk(&rettv, &error); |
1398 if (error) | 1413 if (error) |
1399 retval = -1; | 1414 retval = -1; |
1400 clear_tv(&rettv); | 1415 clear_tv(&rettv); |
1401 | 1416 |
1402 theend: | 1417 theend: |
1403 set_vim_var_string(VV_VAL, NULL, 0); | 1418 if (name != NULL) |
1419 set_vim_var_string(VV_VAL, NULL, 0); | |
1420 else | |
1421 set_vim_var_dict(VV_VAL, NULL); | |
1404 restore_vimvar(VV_VAL, &save_val); | 1422 restore_vimvar(VV_VAL, &save_val); |
1405 return retval; | 1423 return retval; |
1424 } | |
1425 | |
1426 /* | |
1427 * Evaluate "expr" (= "context") for readdir(). | |
1428 */ | |
1429 static int | |
1430 readdir_checkitem(void *context, void *item) | |
1431 { | |
1432 char_u *name = (char_u *)item; | |
1433 | |
1434 return checkitem_common(context, name, NULL); | |
1406 } | 1435 } |
1407 | 1436 |
1408 static int | 1437 static int |
1409 readdirex_dict_arg(typval_T *tv, int *cmp) | 1438 readdirex_dict_arg(typval_T *tv, int *cmp) |
1410 { | 1439 { |
1475 * Evaluate "expr" (= "context") for readdirex(). | 1504 * Evaluate "expr" (= "context") for readdirex(). |
1476 */ | 1505 */ |
1477 static int | 1506 static int |
1478 readdirex_checkitem(void *context, void *item) | 1507 readdirex_checkitem(void *context, void *item) |
1479 { | 1508 { |
1480 typval_T *expr = (typval_T *)context; | |
1481 typval_T save_val; | |
1482 typval_T rettv; | |
1483 typval_T argv[2]; | |
1484 int retval = 0; | |
1485 int error = FALSE; | |
1486 dict_T *dict = (dict_T*)item; | 1509 dict_T *dict = (dict_T*)item; |
1487 | 1510 |
1488 prepare_vimvar(VV_VAL, &save_val); | 1511 return checkitem_common(context, NULL, dict); |
1489 set_vim_var_dict(VV_VAL, dict); | |
1490 argv[0].v_type = VAR_DICT; | |
1491 argv[0].vval.v_dict = dict; | |
1492 | |
1493 if (eval_expr_typval(expr, argv, 1, &rettv) == FAIL) | |
1494 goto theend; | |
1495 | |
1496 // We want to use -1, but also true/false should be allowed. | |
1497 if (rettv.v_type == VAR_SPECIAL || rettv.v_type == VAR_BOOL) | |
1498 { | |
1499 rettv.v_type = VAR_NUMBER; | |
1500 rettv.vval.v_number = rettv.vval.v_number == VVAL_TRUE; | |
1501 } | |
1502 retval = tv_get_number_chk(&rettv, &error); | |
1503 if (error) | |
1504 retval = -1; | |
1505 clear_tv(&rettv); | |
1506 | |
1507 theend: | |
1508 set_vim_var_dict(VV_VAL, NULL); | |
1509 restore_vimvar(VV_VAL, &save_val); | |
1510 return retval; | |
1511 } | 1512 } |
1512 | 1513 |
1513 /* | 1514 /* |
1514 * "readdirex()" function | 1515 * "readdirex()" function |
1515 */ | 1516 */ |