Mercurial > vim
comparison src/eval.c @ 7817:83861277e6a3 v7.4.1205
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 30 15:14:10 2016 +0100
patch 7.4.1205
Problem: Using old style function declarations.
Solution: Change to new style function declarations. (script by Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Jan 2016 15:15:05 +0100 |
parents | 192ae655ac91 |
children | cfed0e9f0ca2 |
comparison
equal
deleted
inserted
replaced
7816:fb4674285a7a | 7817:83861277e6a3 |
---|---|
888 | 888 |
889 /* | 889 /* |
890 * Initialize the global and v: variables. | 890 * Initialize the global and v: variables. |
891 */ | 891 */ |
892 void | 892 void |
893 eval_init() | 893 eval_init(void) |
894 { | 894 { |
895 int i; | 895 int i; |
896 struct vimvar *p; | 896 struct vimvar *p; |
897 | 897 |
898 init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE); | 898 init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE); |
939 #endif | 939 #endif |
940 } | 940 } |
941 | 941 |
942 #if defined(EXITFREE) || defined(PROTO) | 942 #if defined(EXITFREE) || defined(PROTO) |
943 void | 943 void |
944 eval_clear() | 944 eval_clear(void) |
945 { | 945 { |
946 int i; | 946 int i; |
947 struct vimvar *p; | 947 struct vimvar *p; |
948 | 948 |
949 for (i = 0; i < VV_LEN; ++i) | 949 for (i = 0; i < VV_LEN; ++i) |
1004 | 1004 |
1005 /* | 1005 /* |
1006 * Return the address holding the next breakpoint line for a funccall cookie. | 1006 * Return the address holding the next breakpoint line for a funccall cookie. |
1007 */ | 1007 */ |
1008 linenr_T * | 1008 linenr_T * |
1009 func_breakpoint(cookie) | 1009 func_breakpoint(void *cookie) |
1010 void *cookie; | |
1011 { | 1010 { |
1012 return &((funccall_T *)cookie)->breakpoint; | 1011 return &((funccall_T *)cookie)->breakpoint; |
1013 } | 1012 } |
1014 | 1013 |
1015 /* | 1014 /* |
1039 | 1038 |
1040 /* | 1039 /* |
1041 * Return TRUE when a function was ended by a ":return" command. | 1040 * Return TRUE when a function was ended by a ":return" command. |
1042 */ | 1041 */ |
1043 int | 1042 int |
1044 current_func_returned() | 1043 current_func_returned(void) |
1045 { | 1044 { |
1046 return current_funccal->returned; | 1045 return current_funccal->returned; |
1047 } | 1046 } |
1048 | 1047 |
1049 | 1048 |
1181 /* | 1180 /* |
1182 * Stop redirecting command output to a variable. | 1181 * Stop redirecting command output to a variable. |
1183 * Frees the allocated memory. | 1182 * Frees the allocated memory. |
1184 */ | 1183 */ |
1185 void | 1184 void |
1186 var_redir_stop() | 1185 var_redir_stop(void) |
1187 { | 1186 { |
1188 typval_T tv; | 1187 typval_T tv; |
1189 | 1188 |
1190 if (redir_lval != NULL) | 1189 if (redir_lval != NULL) |
1191 { | 1190 { |
1242 } | 1241 } |
1243 # endif | 1242 # endif |
1244 | 1243 |
1245 # if defined(FEAT_POSTSCRIPT) || defined(PROTO) | 1244 # if defined(FEAT_POSTSCRIPT) || defined(PROTO) |
1246 int | 1245 int |
1247 eval_printexpr(fname, args) | 1246 eval_printexpr(char_u *fname, char_u *args) |
1248 char_u *fname; | |
1249 char_u *args; | |
1250 { | 1247 { |
1251 int err = FALSE; | 1248 int err = FALSE; |
1252 | 1249 |
1253 set_vim_var_string(VV_FNAME_IN, fname, -1); | 1250 set_vim_var_string(VV_FNAME_IN, fname, -1); |
1254 set_vim_var_string(VV_CMDARG, args, -1); | 1251 set_vim_var_string(VV_CMDARG, args, -1); |
1266 } | 1263 } |
1267 # endif | 1264 # endif |
1268 | 1265 |
1269 # if defined(FEAT_DIFF) || defined(PROTO) | 1266 # if defined(FEAT_DIFF) || defined(PROTO) |
1270 void | 1267 void |
1271 eval_diff(origfile, newfile, outfile) | 1268 eval_diff( |
1272 char_u *origfile; | 1269 char_u *origfile, |
1273 char_u *newfile; | 1270 char_u *newfile, |
1274 char_u *outfile; | 1271 char_u *outfile) |
1275 { | 1272 { |
1276 int err = FALSE; | 1273 int err = FALSE; |
1277 | 1274 |
1278 set_vim_var_string(VV_FNAME_IN, origfile, -1); | 1275 set_vim_var_string(VV_FNAME_IN, origfile, -1); |
1279 set_vim_var_string(VV_FNAME_NEW, newfile, -1); | 1276 set_vim_var_string(VV_FNAME_NEW, newfile, -1); |
1283 set_vim_var_string(VV_FNAME_NEW, NULL, -1); | 1280 set_vim_var_string(VV_FNAME_NEW, NULL, -1); |
1284 set_vim_var_string(VV_FNAME_OUT, NULL, -1); | 1281 set_vim_var_string(VV_FNAME_OUT, NULL, -1); |
1285 } | 1282 } |
1286 | 1283 |
1287 void | 1284 void |
1288 eval_patch(origfile, difffile, outfile) | 1285 eval_patch( |
1289 char_u *origfile; | 1286 char_u *origfile, |
1290 char_u *difffile; | 1287 char_u *difffile, |
1291 char_u *outfile; | 1288 char_u *outfile) |
1292 { | 1289 { |
1293 int err; | 1290 int err; |
1294 | 1291 |
1295 set_vim_var_string(VV_FNAME_IN, origfile, -1); | 1292 set_vim_var_string(VV_FNAME_IN, origfile, -1); |
1296 set_vim_var_string(VV_FNAME_DIFF, difffile, -1); | 1293 set_vim_var_string(VV_FNAME_DIFF, difffile, -1); |
1306 * Top level evaluation function, returning a boolean. | 1303 * Top level evaluation function, returning a boolean. |
1307 * Sets "error" to TRUE if there was an error. | 1304 * Sets "error" to TRUE if there was an error. |
1308 * Return TRUE or FALSE. | 1305 * Return TRUE or FALSE. |
1309 */ | 1306 */ |
1310 int | 1307 int |
1311 eval_to_bool(arg, error, nextcmd, skip) | 1308 eval_to_bool( |
1312 char_u *arg; | 1309 char_u *arg, |
1313 int *error; | 1310 int *error, |
1314 char_u **nextcmd; | 1311 char_u **nextcmd, |
1315 int skip; /* only parse, don't execute */ | 1312 int skip) /* only parse, don't execute */ |
1316 { | 1313 { |
1317 typval_T tv; | 1314 typval_T tv; |
1318 int retval = FALSE; | 1315 int retval = FALSE; |
1319 | 1316 |
1320 if (skip) | 1317 if (skip) |
1340 * Top level evaluation function, returning a string. If "skip" is TRUE, | 1337 * Top level evaluation function, returning a string. If "skip" is TRUE, |
1341 * only parsing to "nextcmd" is done, without reporting errors. Return | 1338 * only parsing to "nextcmd" is done, without reporting errors. Return |
1342 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | 1339 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. |
1343 */ | 1340 */ |
1344 char_u * | 1341 char_u * |
1345 eval_to_string_skip(arg, nextcmd, skip) | 1342 eval_to_string_skip( |
1346 char_u *arg; | 1343 char_u *arg, |
1347 char_u **nextcmd; | 1344 char_u **nextcmd, |
1348 int skip; /* only parse, don't execute */ | 1345 int skip) /* only parse, don't execute */ |
1349 { | 1346 { |
1350 typval_T tv; | 1347 typval_T tv; |
1351 char_u *retval; | 1348 char_u *retval; |
1352 | 1349 |
1353 if (skip) | 1350 if (skip) |
1368 /* | 1365 /* |
1369 * Skip over an expression at "*pp". | 1366 * Skip over an expression at "*pp". |
1370 * Return FAIL for an error, OK otherwise. | 1367 * Return FAIL for an error, OK otherwise. |
1371 */ | 1368 */ |
1372 int | 1369 int |
1373 skip_expr(pp) | 1370 skip_expr(char_u **pp) |
1374 char_u **pp; | |
1375 { | 1371 { |
1376 typval_T rettv; | 1372 typval_T rettv; |
1377 | 1373 |
1378 *pp = skipwhite(*pp); | 1374 *pp = skipwhite(*pp); |
1379 return eval1(pp, &rettv, FALSE); | 1375 return eval1(pp, &rettv, FALSE); |
1384 * When "convert" is TRUE convert a List into a sequence of lines and convert | 1380 * When "convert" is TRUE convert a List into a sequence of lines and convert |
1385 * a Float to a String. | 1381 * a Float to a String. |
1386 * Return pointer to allocated memory, or NULL for failure. | 1382 * Return pointer to allocated memory, or NULL for failure. |
1387 */ | 1383 */ |
1388 char_u * | 1384 char_u * |
1389 eval_to_string(arg, nextcmd, convert) | 1385 eval_to_string( |
1390 char_u *arg; | 1386 char_u *arg, |
1391 char_u **nextcmd; | 1387 char_u **nextcmd, |
1392 int convert; | 1388 int convert) |
1393 { | 1389 { |
1394 typval_T tv; | 1390 typval_T tv; |
1395 char_u *retval; | 1391 char_u *retval; |
1396 garray_T ga; | 1392 garray_T ga; |
1397 #ifdef FEAT_FLOAT | 1393 #ifdef FEAT_FLOAT |
1432 /* | 1428 /* |
1433 * Call eval_to_string() without using current local variables and using | 1429 * Call eval_to_string() without using current local variables and using |
1434 * textlock. When "use_sandbox" is TRUE use the sandbox. | 1430 * textlock. When "use_sandbox" is TRUE use the sandbox. |
1435 */ | 1431 */ |
1436 char_u * | 1432 char_u * |
1437 eval_to_string_safe(arg, nextcmd, use_sandbox) | 1433 eval_to_string_safe( |
1438 char_u *arg; | 1434 char_u *arg, |
1439 char_u **nextcmd; | 1435 char_u **nextcmd, |
1440 int use_sandbox; | 1436 int use_sandbox) |
1441 { | 1437 { |
1442 char_u *retval; | 1438 char_u *retval; |
1443 void *save_funccalp; | 1439 void *save_funccalp; |
1444 | 1440 |
1445 save_funccalp = save_funccal(); | 1441 save_funccalp = save_funccal(); |
1458 * Top level evaluation function, returning a number. | 1454 * Top level evaluation function, returning a number. |
1459 * Evaluates "expr" silently. | 1455 * Evaluates "expr" silently. |
1460 * Returns -1 for an error. | 1456 * Returns -1 for an error. |
1461 */ | 1457 */ |
1462 int | 1458 int |
1463 eval_to_number(expr) | 1459 eval_to_number(char_u *expr) |
1464 char_u *expr; | |
1465 { | 1460 { |
1466 typval_T rettv; | 1461 typval_T rettv; |
1467 int retval; | 1462 int retval; |
1468 char_u *p = skipwhite(expr); | 1463 char_u *p = skipwhite(expr); |
1469 | 1464 |
1485 * Prepare v: variable "idx" to be used. | 1480 * Prepare v: variable "idx" to be used. |
1486 * Save the current typeval in "save_tv". | 1481 * Save the current typeval in "save_tv". |
1487 * When not used yet add the variable to the v: hashtable. | 1482 * When not used yet add the variable to the v: hashtable. |
1488 */ | 1483 */ |
1489 static void | 1484 static void |
1490 prepare_vimvar(idx, save_tv) | 1485 prepare_vimvar(int idx, typval_T *save_tv) |
1491 int idx; | |
1492 typval_T *save_tv; | |
1493 { | 1486 { |
1494 *save_tv = vimvars[idx].vv_tv; | 1487 *save_tv = vimvars[idx].vv_tv; |
1495 if (vimvars[idx].vv_type == VAR_UNKNOWN) | 1488 if (vimvars[idx].vv_type == VAR_UNKNOWN) |
1496 hash_add(&vimvarht, vimvars[idx].vv_di.di_key); | 1489 hash_add(&vimvarht, vimvars[idx].vv_di.di_key); |
1497 } | 1490 } |
1499 /* | 1492 /* |
1500 * Restore v: variable "idx" to typeval "save_tv". | 1493 * Restore v: variable "idx" to typeval "save_tv". |
1501 * When no longer defined, remove the variable from the v: hashtable. | 1494 * When no longer defined, remove the variable from the v: hashtable. |
1502 */ | 1495 */ |
1503 static void | 1496 static void |
1504 restore_vimvar(idx, save_tv) | 1497 restore_vimvar(int idx, typval_T *save_tv) |
1505 int idx; | |
1506 typval_T *save_tv; | |
1507 { | 1498 { |
1508 hashitem_T *hi; | 1499 hashitem_T *hi; |
1509 | 1500 |
1510 vimvars[idx].vv_tv = *save_tv; | 1501 vimvars[idx].vv_tv = *save_tv; |
1511 if (vimvars[idx].vv_type == VAR_UNKNOWN) | 1502 if (vimvars[idx].vv_type == VAR_UNKNOWN) |
1523 * Evaluate an expression to a list with suggestions. | 1514 * Evaluate an expression to a list with suggestions. |
1524 * For the "expr:" part of 'spellsuggest'. | 1515 * For the "expr:" part of 'spellsuggest'. |
1525 * Returns NULL when there is an error. | 1516 * Returns NULL when there is an error. |
1526 */ | 1517 */ |
1527 list_T * | 1518 list_T * |
1528 eval_spell_expr(badword, expr) | 1519 eval_spell_expr(char_u *badword, char_u *expr) |
1529 char_u *badword; | |
1530 char_u *expr; | |
1531 { | 1520 { |
1532 typval_T save_val; | 1521 typval_T save_val; |
1533 typval_T rettv; | 1522 typval_T rettv; |
1534 list_T *list = NULL; | 1523 list_T *list = NULL; |
1535 char_u *p = skipwhite(expr); | 1524 char_u *p = skipwhite(expr); |
1561 * word in "pp" and the number as the return value. | 1550 * word in "pp" and the number as the return value. |
1562 * Return -1 if anything isn't right. | 1551 * Return -1 if anything isn't right. |
1563 * Used to get the good word and score from the eval_spell_expr() result. | 1552 * Used to get the good word and score from the eval_spell_expr() result. |
1564 */ | 1553 */ |
1565 int | 1554 int |
1566 get_spellword(list, pp) | 1555 get_spellword(list_T *list, char_u **pp) |
1567 list_T *list; | |
1568 char_u **pp; | |
1569 { | 1556 { |
1570 listitem_T *li; | 1557 listitem_T *li; |
1571 | 1558 |
1572 li = list->lv_first; | 1559 li = list->lv_first; |
1573 if (li == NULL) | 1560 if (li == NULL) |
1585 * Top level evaluation function. | 1572 * Top level evaluation function. |
1586 * Returns an allocated typval_T with the result. | 1573 * Returns an allocated typval_T with the result. |
1587 * Returns NULL when there is an error. | 1574 * Returns NULL when there is an error. |
1588 */ | 1575 */ |
1589 typval_T * | 1576 typval_T * |
1590 eval_expr(arg, nextcmd) | 1577 eval_expr(char_u *arg, char_u **nextcmd) |
1591 char_u *arg; | |
1592 char_u **nextcmd; | |
1593 { | 1578 { |
1594 typval_T *tv; | 1579 typval_T *tv; |
1595 | 1580 |
1596 tv = (typval_T *)alloc(sizeof(typval_T)); | 1581 tv = (typval_T *)alloc(sizeof(typval_T)); |
1597 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) | 1582 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) |
1609 * Uses argv[argc] for the function arguments. Only Number and String | 1594 * Uses argv[argc] for the function arguments. Only Number and String |
1610 * arguments are currently supported. | 1595 * arguments are currently supported. |
1611 * Returns OK or FAIL. | 1596 * Returns OK or FAIL. |
1612 */ | 1597 */ |
1613 int | 1598 int |
1614 call_vim_function(func, argc, argv, safe, str_arg_only, rettv) | 1599 call_vim_function( |
1615 char_u *func; | 1600 char_u *func, |
1616 int argc; | 1601 int argc, |
1617 char_u **argv; | 1602 char_u **argv, |
1618 int safe; /* use the sandbox */ | 1603 int safe, /* use the sandbox */ |
1619 int str_arg_only; /* all arguments are strings */ | 1604 int str_arg_only, /* all arguments are strings */ |
1620 typval_T *rettv; | 1605 typval_T *rettv) |
1621 { | 1606 { |
1622 typval_T *argvars; | 1607 typval_T *argvars; |
1623 long n; | 1608 long n; |
1624 int len; | 1609 int len; |
1625 int i; | 1610 int i; |
1685 * Call vimL function "func" and return the result as a number. | 1670 * Call vimL function "func" and return the result as a number. |
1686 * Returns -1 when calling the function fails. | 1671 * Returns -1 when calling the function fails. |
1687 * Uses argv[argc] for the function arguments. | 1672 * Uses argv[argc] for the function arguments. |
1688 */ | 1673 */ |
1689 long | 1674 long |
1690 call_func_retnr(func, argc, argv, safe) | 1675 call_func_retnr( |
1691 char_u *func; | 1676 char_u *func, |
1692 int argc; | 1677 int argc, |
1693 char_u **argv; | 1678 char_u **argv, |
1694 int safe; /* use the sandbox */ | 1679 int safe) /* use the sandbox */ |
1695 { | 1680 { |
1696 typval_T rettv; | 1681 typval_T rettv; |
1697 long retval; | 1682 long retval; |
1698 | 1683 |
1699 /* All arguments are passed as strings, no conversion to number. */ | 1684 /* All arguments are passed as strings, no conversion to number. */ |
1713 * Call vimL function "func" and return the result as a string. | 1698 * Call vimL function "func" and return the result as a string. |
1714 * Returns NULL when calling the function fails. | 1699 * Returns NULL when calling the function fails. |
1715 * Uses argv[argc] for the function arguments. | 1700 * Uses argv[argc] for the function arguments. |
1716 */ | 1701 */ |
1717 void * | 1702 void * |
1718 call_func_retstr(func, argc, argv, safe) | 1703 call_func_retstr( |
1719 char_u *func; | 1704 char_u *func, |
1720 int argc; | 1705 int argc, |
1721 char_u **argv; | 1706 char_u **argv, |
1722 int safe; /* use the sandbox */ | 1707 int safe) /* use the sandbox */ |
1723 { | 1708 { |
1724 typval_T rettv; | 1709 typval_T rettv; |
1725 char_u *retval; | 1710 char_u *retval; |
1726 | 1711 |
1727 /* All arguments are passed as strings, no conversion to number. */ | 1712 /* All arguments are passed as strings, no conversion to number. */ |
1738 * Call vimL function "func" and return the result as a List. | 1723 * Call vimL function "func" and return the result as a List. |
1739 * Uses argv[argc] for the function arguments. | 1724 * Uses argv[argc] for the function arguments. |
1740 * Returns NULL when there is something wrong. | 1725 * Returns NULL when there is something wrong. |
1741 */ | 1726 */ |
1742 void * | 1727 void * |
1743 call_func_retlist(func, argc, argv, safe) | 1728 call_func_retlist( |
1744 char_u *func; | 1729 char_u *func, |
1745 int argc; | 1730 int argc, |
1746 char_u **argv; | 1731 char_u **argv, |
1747 int safe; /* use the sandbox */ | 1732 int safe) /* use the sandbox */ |
1748 { | 1733 { |
1749 typval_T rettv; | 1734 typval_T rettv; |
1750 | 1735 |
1751 /* All arguments are passed as strings, no conversion to number. */ | 1736 /* All arguments are passed as strings, no conversion to number. */ |
1752 if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) | 1737 if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) |
1765 /* | 1750 /* |
1766 * Save the current function call pointer, and set it to NULL. | 1751 * Save the current function call pointer, and set it to NULL. |
1767 * Used when executing autocommands and for ":source". | 1752 * Used when executing autocommands and for ":source". |
1768 */ | 1753 */ |
1769 void * | 1754 void * |
1770 save_funccal() | 1755 save_funccal(void) |
1771 { | 1756 { |
1772 funccall_T *fc = current_funccal; | 1757 funccall_T *fc = current_funccal; |
1773 | 1758 |
1774 current_funccal = NULL; | 1759 current_funccal = NULL; |
1775 return (void *)fc; | 1760 return (void *)fc; |
1776 } | 1761 } |
1777 | 1762 |
1778 void | 1763 void |
1779 restore_funccal(vfc) | 1764 restore_funccal(void *vfc) |
1780 void *vfc; | |
1781 { | 1765 { |
1782 funccall_T *fc = (funccall_T *)vfc; | 1766 funccall_T *fc = (funccall_T *)vfc; |
1783 | 1767 |
1784 current_funccal = fc; | 1768 current_funccal = fc; |
1785 } | 1769 } |
1789 * Prepare profiling for entering a child or something else that is not | 1773 * Prepare profiling for entering a child or something else that is not |
1790 * counted for the script/function itself. | 1774 * counted for the script/function itself. |
1791 * Should always be called in pair with prof_child_exit(). | 1775 * Should always be called in pair with prof_child_exit(). |
1792 */ | 1776 */ |
1793 void | 1777 void |
1794 prof_child_enter(tm) | 1778 prof_child_enter( |
1795 proftime_T *tm; /* place to store waittime */ | 1779 proftime_T *tm) /* place to store waittime */ |
1796 { | 1780 { |
1797 funccall_T *fc = current_funccal; | 1781 funccall_T *fc = current_funccal; |
1798 | 1782 |
1799 if (fc != NULL && fc->func->uf_profiling) | 1783 if (fc != NULL && fc->func->uf_profiling) |
1800 profile_start(&fc->prof_child); | 1784 profile_start(&fc->prof_child); |
1804 /* | 1788 /* |
1805 * Take care of time spent in a child. | 1789 * Take care of time spent in a child. |
1806 * Should always be called after prof_child_enter(). | 1790 * Should always be called after prof_child_enter(). |
1807 */ | 1791 */ |
1808 void | 1792 void |
1809 prof_child_exit(tm) | 1793 prof_child_exit( |
1810 proftime_T *tm; /* where waittime was stored */ | 1794 proftime_T *tm) /* where waittime was stored */ |
1811 { | 1795 { |
1812 funccall_T *fc = current_funccal; | 1796 funccall_T *fc = current_funccal; |
1813 | 1797 |
1814 if (fc != NULL && fc->func->uf_profiling) | 1798 if (fc != NULL && fc->func->uf_profiling) |
1815 { | 1799 { |
1827 /* | 1811 /* |
1828 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | 1812 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding |
1829 * it in "*cp". Doesn't give error messages. | 1813 * it in "*cp". Doesn't give error messages. |
1830 */ | 1814 */ |
1831 int | 1815 int |
1832 eval_foldexpr(arg, cp) | 1816 eval_foldexpr(char_u *arg, int *cp) |
1833 char_u *arg; | |
1834 int *cp; | |
1835 { | 1817 { |
1836 typval_T tv; | 1818 typval_T tv; |
1837 int retval; | 1819 int retval; |
1838 char_u *s; | 1820 char_u *s; |
1839 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", | 1821 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
1881 * ":let var -= expr" assignment command. | 1863 * ":let var -= expr" assignment command. |
1882 * ":let var .= expr" assignment command. | 1864 * ":let var .= expr" assignment command. |
1883 * ":let [var1, var2] = expr" unpack list. | 1865 * ":let [var1, var2] = expr" unpack list. |
1884 */ | 1866 */ |
1885 void | 1867 void |
1886 ex_let(eap) | 1868 ex_let(exarg_T *eap) |
1887 exarg_T *eap; | |
1888 { | 1869 { |
1889 char_u *arg = eap->arg; | 1870 char_u *arg = eap->arg; |
1890 char_u *expr = NULL; | 1871 char_u *expr = NULL; |
1891 typval_T rettv; | 1872 typval_T rettv; |
1892 int i; | 1873 int i; |
1966 * must appear after the variable(s). Use "+", "-" or "." for add, subtract | 1947 * must appear after the variable(s). Use "+", "-" or "." for add, subtract |
1967 * or concatenate. | 1948 * or concatenate. |
1968 * Returns OK or FAIL; | 1949 * Returns OK or FAIL; |
1969 */ | 1950 */ |
1970 static int | 1951 static int |
1971 ex_let_vars(arg_start, tv, copy, semicolon, var_count, nextchars) | 1952 ex_let_vars( |
1972 char_u *arg_start; | 1953 char_u *arg_start, |
1973 typval_T *tv; | 1954 typval_T *tv, |
1974 int copy; /* copy values from "tv", don't move */ | 1955 int copy, /* copy values from "tv", don't move */ |
1975 int semicolon; /* from skip_var_list() */ | 1956 int semicolon, /* from skip_var_list() */ |
1976 int var_count; /* from skip_var_list() */ | 1957 int var_count, /* from skip_var_list() */ |
1977 char_u *nextchars; | 1958 char_u *nextchars) |
1978 { | 1959 { |
1979 char_u *arg = arg_start; | 1960 char_u *arg = arg_start; |
1980 list_T *l; | 1961 list_T *l; |
1981 int i; | 1962 int i; |
1982 listitem_T *item; | 1963 listitem_T *item; |
2064 * For "[var, var]" increment "*var_count" for each variable. | 2045 * For "[var, var]" increment "*var_count" for each variable. |
2065 * for "[var, var; var]" set "semicolon". | 2046 * for "[var, var; var]" set "semicolon". |
2066 * Return NULL for an error. | 2047 * Return NULL for an error. |
2067 */ | 2048 */ |
2068 static char_u * | 2049 static char_u * |
2069 skip_var_list(arg, var_count, semicolon) | 2050 skip_var_list( |
2070 char_u *arg; | 2051 char_u *arg, |
2071 int *var_count; | 2052 int *var_count, |
2072 int *semicolon; | 2053 int *semicolon) |
2073 { | 2054 { |
2074 char_u *p, *s; | 2055 char_u *p, *s; |
2075 | 2056 |
2076 if (*arg == '[') | 2057 if (*arg == '[') |
2077 { | 2058 { |
2115 /* | 2096 /* |
2116 * Skip one (assignable) variable name, including @r, $VAR, &option, d.key, | 2097 * Skip one (assignable) variable name, including @r, $VAR, &option, d.key, |
2117 * l[idx]. | 2098 * l[idx]. |
2118 */ | 2099 */ |
2119 static char_u * | 2100 static char_u * |
2120 skip_var_one(arg) | 2101 skip_var_one(char_u *arg) |
2121 char_u *arg; | |
2122 { | 2102 { |
2123 if (*arg == '@' && arg[1] != NUL) | 2103 if (*arg == '@' && arg[1] != NUL) |
2124 return arg + 2; | 2104 return arg + 2; |
2125 return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, | 2105 return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, |
2126 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); | 2106 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); |
2129 /* | 2109 /* |
2130 * List variables for hashtab "ht" with prefix "prefix". | 2110 * List variables for hashtab "ht" with prefix "prefix". |
2131 * If "empty" is TRUE also list NULL strings as empty strings. | 2111 * If "empty" is TRUE also list NULL strings as empty strings. |
2132 */ | 2112 */ |
2133 static void | 2113 static void |
2134 list_hashtable_vars(ht, prefix, empty, first) | 2114 list_hashtable_vars( |
2135 hashtab_T *ht; | 2115 hashtab_T *ht, |
2136 char_u *prefix; | 2116 char_u *prefix, |
2137 int empty; | 2117 int empty, |
2138 int *first; | 2118 int *first) |
2139 { | 2119 { |
2140 hashitem_T *hi; | 2120 hashitem_T *hi; |
2141 dictitem_T *di; | 2121 dictitem_T *di; |
2142 int todo; | 2122 int todo; |
2143 | 2123 |
2157 | 2137 |
2158 /* | 2138 /* |
2159 * List global variables. | 2139 * List global variables. |
2160 */ | 2140 */ |
2161 static void | 2141 static void |
2162 list_glob_vars(first) | 2142 list_glob_vars(int *first) |
2163 int *first; | |
2164 { | 2143 { |
2165 list_hashtable_vars(&globvarht, (char_u *)"", TRUE, first); | 2144 list_hashtable_vars(&globvarht, (char_u *)"", TRUE, first); |
2166 } | 2145 } |
2167 | 2146 |
2168 /* | 2147 /* |
2169 * List buffer variables. | 2148 * List buffer variables. |
2170 */ | 2149 */ |
2171 static void | 2150 static void |
2172 list_buf_vars(first) | 2151 list_buf_vars(int *first) |
2173 int *first; | |
2174 { | 2152 { |
2175 char_u numbuf[NUMBUFLEN]; | 2153 char_u numbuf[NUMBUFLEN]; |
2176 | 2154 |
2177 list_hashtable_vars(&curbuf->b_vars->dv_hashtab, (char_u *)"b:", | 2155 list_hashtable_vars(&curbuf->b_vars->dv_hashtab, (char_u *)"b:", |
2178 TRUE, first); | 2156 TRUE, first); |
2184 | 2162 |
2185 /* | 2163 /* |
2186 * List window variables. | 2164 * List window variables. |
2187 */ | 2165 */ |
2188 static void | 2166 static void |
2189 list_win_vars(first) | 2167 list_win_vars(int *first) |
2190 int *first; | |
2191 { | 2168 { |
2192 list_hashtable_vars(&curwin->w_vars->dv_hashtab, | 2169 list_hashtable_vars(&curwin->w_vars->dv_hashtab, |
2193 (char_u *)"w:", TRUE, first); | 2170 (char_u *)"w:", TRUE, first); |
2194 } | 2171 } |
2195 | 2172 |
2196 #ifdef FEAT_WINDOWS | 2173 #ifdef FEAT_WINDOWS |
2197 /* | 2174 /* |
2198 * List tab page variables. | 2175 * List tab page variables. |
2199 */ | 2176 */ |
2200 static void | 2177 static void |
2201 list_tab_vars(first) | 2178 list_tab_vars(int *first) |
2202 int *first; | |
2203 { | 2179 { |
2204 list_hashtable_vars(&curtab->tp_vars->dv_hashtab, | 2180 list_hashtable_vars(&curtab->tp_vars->dv_hashtab, |
2205 (char_u *)"t:", TRUE, first); | 2181 (char_u *)"t:", TRUE, first); |
2206 } | 2182 } |
2207 #endif | 2183 #endif |
2208 | 2184 |
2209 /* | 2185 /* |
2210 * List Vim variables. | 2186 * List Vim variables. |
2211 */ | 2187 */ |
2212 static void | 2188 static void |
2213 list_vim_vars(first) | 2189 list_vim_vars(int *first) |
2214 int *first; | |
2215 { | 2190 { |
2216 list_hashtable_vars(&vimvarht, (char_u *)"v:", FALSE, first); | 2191 list_hashtable_vars(&vimvarht, (char_u *)"v:", FALSE, first); |
2217 } | 2192 } |
2218 | 2193 |
2219 /* | 2194 /* |
2220 * List script-local variables, if there is a script. | 2195 * List script-local variables, if there is a script. |
2221 */ | 2196 */ |
2222 static void | 2197 static void |
2223 list_script_vars(first) | 2198 list_script_vars(int *first) |
2224 int *first; | |
2225 { | 2199 { |
2226 if (current_SID > 0 && current_SID <= ga_scripts.ga_len) | 2200 if (current_SID > 0 && current_SID <= ga_scripts.ga_len) |
2227 list_hashtable_vars(&SCRIPT_VARS(current_SID), | 2201 list_hashtable_vars(&SCRIPT_VARS(current_SID), |
2228 (char_u *)"s:", FALSE, first); | 2202 (char_u *)"s:", FALSE, first); |
2229 } | 2203 } |
2230 | 2204 |
2231 /* | 2205 /* |
2232 * List function variables, if there is a function. | 2206 * List function variables, if there is a function. |
2233 */ | 2207 */ |
2234 static void | 2208 static void |
2235 list_func_vars(first) | 2209 list_func_vars(int *first) |
2236 int *first; | |
2237 { | 2210 { |
2238 if (current_funccal != NULL) | 2211 if (current_funccal != NULL) |
2239 list_hashtable_vars(¤t_funccal->l_vars.dv_hashtab, | 2212 list_hashtable_vars(¤t_funccal->l_vars.dv_hashtab, |
2240 (char_u *)"l:", FALSE, first); | 2213 (char_u *)"l:", FALSE, first); |
2241 } | 2214 } |
2242 | 2215 |
2243 /* | 2216 /* |
2244 * List variables in "arg". | 2217 * List variables in "arg". |
2245 */ | 2218 */ |
2246 static char_u * | 2219 static char_u * |
2247 list_arg_vars(eap, arg, first) | 2220 list_arg_vars(exarg_T *eap, char_u *arg, int *first) |
2248 exarg_T *eap; | |
2249 char_u *arg; | |
2250 int *first; | |
2251 { | 2221 { |
2252 int error = FALSE; | 2222 int error = FALSE; |
2253 int len; | 2223 int len; |
2254 char_u *name; | 2224 char_u *name; |
2255 char_u *name_start; | 2225 char_u *name_start; |
2353 * Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value. | 2323 * Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value. |
2354 * Returns a pointer to the char just after the var name. | 2324 * Returns a pointer to the char just after the var name. |
2355 * Returns NULL if there is an error. | 2325 * Returns NULL if there is an error. |
2356 */ | 2326 */ |
2357 static char_u * | 2327 static char_u * |
2358 ex_let_one(arg, tv, copy, endchars, op) | 2328 ex_let_one( |
2359 char_u *arg; /* points to variable name */ | 2329 char_u *arg, /* points to variable name */ |
2360 typval_T *tv; /* value to assign to variable */ | 2330 typval_T *tv, /* value to assign to variable */ |
2361 int copy; /* copy value from "tv" */ | 2331 int copy, /* copy value from "tv" */ |
2362 char_u *endchars; /* valid chars after variable name or NULL */ | 2332 char_u *endchars, /* valid chars after variable name or NULL */ |
2363 char_u *op; /* "+", "-", "." or NULL*/ | 2333 char_u *op) /* "+", "-", "." or NULL*/ |
2364 { | 2334 { |
2365 int c1; | 2335 int c1; |
2366 char_u *name; | 2336 char_u *name; |
2367 char_u *p; | 2337 char_u *p; |
2368 char_u *arg_end = NULL; | 2338 char_u *arg_end = NULL; |
2547 | 2517 |
2548 /* | 2518 /* |
2549 * If "arg" is equal to "b:changedtick" give an error and return TRUE. | 2519 * If "arg" is equal to "b:changedtick" give an error and return TRUE. |
2550 */ | 2520 */ |
2551 static int | 2521 static int |
2552 check_changedtick(arg) | 2522 check_changedtick(char_u *arg) |
2553 char_u *arg; | |
2554 { | 2523 { |
2555 if (STRNCMP(arg, "b:changedtick", 13) == 0 && !eval_isnamec(arg[13])) | 2524 if (STRNCMP(arg, "b:changedtick", 13) == 0 && !eval_isnamec(arg[13])) |
2556 { | 2525 { |
2557 EMSG2(_(e_readonlyvar), arg); | 2526 EMSG2(_(e_readonlyvar), arg); |
2558 return TRUE; | 2527 return TRUE; |
2577 * Returns a pointer to just after the name, including indexes. | 2546 * Returns a pointer to just after the name, including indexes. |
2578 * When an evaluation error occurs "lp->ll_name" is NULL; | 2547 * When an evaluation error occurs "lp->ll_name" is NULL; |
2579 * Returns NULL for a parsing error. Still need to free items in "lp"! | 2548 * Returns NULL for a parsing error. Still need to free items in "lp"! |
2580 */ | 2549 */ |
2581 static char_u * | 2550 static char_u * |
2582 get_lval(name, rettv, lp, unlet, skip, flags, fne_flags) | 2551 get_lval( |
2583 char_u *name; | 2552 char_u *name, |
2584 typval_T *rettv; | 2553 typval_T *rettv, |
2585 lval_T *lp; | 2554 lval_T *lp, |
2586 int unlet; | 2555 int unlet, |
2587 int skip; | 2556 int skip, |
2588 int flags; /* GLV_ values */ | 2557 int flags, /* GLV_ values */ |
2589 int fne_flags; /* flags for find_name_end() */ | 2558 int fne_flags) /* flags for find_name_end() */ |
2590 { | 2559 { |
2591 char_u *p; | 2560 char_u *p; |
2592 char_u *expr_start, *expr_end; | 2561 char_u *expr_start, *expr_end; |
2593 int cc; | 2562 int cc; |
2594 dictitem_T *v; | 2563 dictitem_T *v; |
2922 | 2891 |
2923 /* | 2892 /* |
2924 * Clear lval "lp" that was filled by get_lval(). | 2893 * Clear lval "lp" that was filled by get_lval(). |
2925 */ | 2894 */ |
2926 static void | 2895 static void |
2927 clear_lval(lp) | 2896 clear_lval(lval_T *lp) |
2928 lval_T *lp; | |
2929 { | 2897 { |
2930 vim_free(lp->ll_exp_name); | 2898 vim_free(lp->ll_exp_name); |
2931 vim_free(lp->ll_newkey); | 2899 vim_free(lp->ll_newkey); |
2932 } | 2900 } |
2933 | 2901 |
2935 * Set a variable that was parsed by get_lval() to "rettv". | 2903 * Set a variable that was parsed by get_lval() to "rettv". |
2936 * "endp" points to just after the parsed name. | 2904 * "endp" points to just after the parsed name. |
2937 * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=". | 2905 * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=". |
2938 */ | 2906 */ |
2939 static void | 2907 static void |
2940 set_var_lval(lp, endp, rettv, copy, op) | 2908 set_var_lval( |
2941 lval_T *lp; | 2909 lval_T *lp, |
2942 char_u *endp; | 2910 char_u *endp, |
2943 typval_T *rettv; | 2911 typval_T *rettv, |
2944 int copy; | 2912 int copy, |
2945 char_u *op; | 2913 char_u *op) |
2946 { | 2914 { |
2947 int cc; | 2915 int cc; |
2948 listitem_T *ri; | 2916 listitem_T *ri; |
2949 dictitem_T *di; | 2917 dictitem_T *di; |
2950 | 2918 |
3083 /* | 3051 /* |
3084 * Handle "tv1 += tv2", "tv1 -= tv2" and "tv1 .= tv2" | 3052 * Handle "tv1 += tv2", "tv1 -= tv2" and "tv1 .= tv2" |
3085 * Returns OK or FAIL. | 3053 * Returns OK or FAIL. |
3086 */ | 3054 */ |
3087 static int | 3055 static int |
3088 tv_op(tv1, tv2, op) | 3056 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
3089 typval_T *tv1; | |
3090 typval_T *tv2; | |
3091 char_u *op; | |
3092 { | 3057 { |
3093 long n; | 3058 long n; |
3094 char_u numbuf[NUMBUFLEN]; | 3059 char_u numbuf[NUMBUFLEN]; |
3095 char_u *s; | 3060 char_u *s; |
3096 | 3061 |
3189 | 3154 |
3190 /* | 3155 /* |
3191 * Add a watcher to a list. | 3156 * Add a watcher to a list. |
3192 */ | 3157 */ |
3193 void | 3158 void |
3194 list_add_watch(l, lw) | 3159 list_add_watch(list_T *l, listwatch_T *lw) |
3195 list_T *l; | |
3196 listwatch_T *lw; | |
3197 { | 3160 { |
3198 lw->lw_next = l->lv_watch; | 3161 lw->lw_next = l->lv_watch; |
3199 l->lv_watch = lw; | 3162 l->lv_watch = lw; |
3200 } | 3163 } |
3201 | 3164 |
3202 /* | 3165 /* |
3203 * Remove a watcher from a list. | 3166 * Remove a watcher from a list. |
3204 * No warning when it isn't found... | 3167 * No warning when it isn't found... |
3205 */ | 3168 */ |
3206 void | 3169 void |
3207 list_rem_watch(l, lwrem) | 3170 list_rem_watch(list_T *l, listwatch_T *lwrem) |
3208 list_T *l; | |
3209 listwatch_T *lwrem; | |
3210 { | 3171 { |
3211 listwatch_T *lw, **lwp; | 3172 listwatch_T *lw, **lwp; |
3212 | 3173 |
3213 lwp = &l->lv_watch; | 3174 lwp = &l->lv_watch; |
3214 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) | 3175 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
3225 /* | 3186 /* |
3226 * Just before removing an item from a list: advance watchers to the next | 3187 * Just before removing an item from a list: advance watchers to the next |
3227 * item. | 3188 * item. |
3228 */ | 3189 */ |
3229 static void | 3190 static void |
3230 list_fix_watch(l, item) | 3191 list_fix_watch(list_T *l, listitem_T *item) |
3231 list_T *l; | |
3232 listitem_T *item; | |
3233 { | 3192 { |
3234 listwatch_T *lw; | 3193 listwatch_T *lw; |
3235 | 3194 |
3236 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) | 3195 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
3237 if (lw->lw_item == item) | 3196 if (lw->lw_item == item) |
3243 * "arg" points to "var". | 3202 * "arg" points to "var". |
3244 * Set "*errp" to TRUE for an error, FALSE otherwise; | 3203 * Set "*errp" to TRUE for an error, FALSE otherwise; |
3245 * Return a pointer that holds the info. Null when there is an error. | 3204 * Return a pointer that holds the info. Null when there is an error. |
3246 */ | 3205 */ |
3247 void * | 3206 void * |
3248 eval_for_line(arg, errp, nextcmdp, skip) | 3207 eval_for_line( |
3249 char_u *arg; | 3208 char_u *arg, |
3250 int *errp; | 3209 int *errp, |
3251 char_u **nextcmdp; | 3210 char_u **nextcmdp, |
3252 int skip; | 3211 int skip) |
3253 { | 3212 { |
3254 forinfo_T *fi; | 3213 forinfo_T *fi; |
3255 char_u *expr; | 3214 char_u *expr; |
3256 typval_T tv; | 3215 typval_T tv; |
3257 list_T *l; | 3216 list_T *l; |
3307 * Assign the values to the variable (list). "arg" points to the first one. | 3266 * Assign the values to the variable (list). "arg" points to the first one. |
3308 * Return TRUE when a valid item was found, FALSE when at end of list or | 3267 * Return TRUE when a valid item was found, FALSE when at end of list or |
3309 * something wrong. | 3268 * something wrong. |
3310 */ | 3269 */ |
3311 int | 3270 int |
3312 next_for_item(fi_void, arg) | 3271 next_for_item(void *fi_void, char_u *arg) |
3313 void *fi_void; | |
3314 char_u *arg; | |
3315 { | 3272 { |
3316 forinfo_T *fi = (forinfo_T *)fi_void; | 3273 forinfo_T *fi = (forinfo_T *)fi_void; |
3317 int result; | 3274 int result; |
3318 listitem_T *item; | 3275 listitem_T *item; |
3319 | 3276 |
3331 | 3288 |
3332 /* | 3289 /* |
3333 * Free the structure used to store info used by ":for". | 3290 * Free the structure used to store info used by ":for". |
3334 */ | 3291 */ |
3335 void | 3292 void |
3336 free_for_info(fi_void) | 3293 free_for_info(void *fi_void) |
3337 void *fi_void; | |
3338 { | 3294 { |
3339 forinfo_T *fi = (forinfo_T *)fi_void; | 3295 forinfo_T *fi = (forinfo_T *)fi_void; |
3340 | 3296 |
3341 if (fi != NULL && fi->fi_list != NULL) | 3297 if (fi != NULL && fi->fi_list != NULL) |
3342 { | 3298 { |
3347 } | 3303 } |
3348 | 3304 |
3349 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | 3305 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3350 | 3306 |
3351 void | 3307 void |
3352 set_context_for_expression(xp, arg, cmdidx) | 3308 set_context_for_expression( |
3353 expand_T *xp; | 3309 expand_T *xp, |
3354 char_u *arg; | 3310 char_u *arg, |
3355 cmdidx_T cmdidx; | 3311 cmdidx_T cmdidx) |
3356 { | 3312 { |
3357 int got_eq = FALSE; | 3313 int got_eq = FALSE; |
3358 int c; | 3314 int c; |
3359 char_u *p; | 3315 char_u *p; |
3360 | 3316 |
3460 | 3416 |
3461 /* | 3417 /* |
3462 * ":1,25call func(arg1, arg2)" function call. | 3418 * ":1,25call func(arg1, arg2)" function call. |
3463 */ | 3419 */ |
3464 void | 3420 void |
3465 ex_call(eap) | 3421 ex_call(exarg_T *eap) |
3466 exarg_T *eap; | |
3467 { | 3422 { |
3468 char_u *arg = eap->arg; | 3423 char_u *arg = eap->arg; |
3469 char_u *startarg; | 3424 char_u *startarg; |
3470 char_u *name; | 3425 char_u *name; |
3471 char_u *tofree; | 3426 char_u *tofree; |
3590 | 3545 |
3591 /* | 3546 /* |
3592 * ":unlet[!] var1 ... " command. | 3547 * ":unlet[!] var1 ... " command. |
3593 */ | 3548 */ |
3594 void | 3549 void |
3595 ex_unlet(eap) | 3550 ex_unlet(exarg_T *eap) |
3596 exarg_T *eap; | |
3597 { | 3551 { |
3598 ex_unletlock(eap, eap->arg, 0); | 3552 ex_unletlock(eap, eap->arg, 0); |
3599 } | 3553 } |
3600 | 3554 |
3601 /* | 3555 /* |
3602 * ":lockvar" and ":unlockvar" commands | 3556 * ":lockvar" and ":unlockvar" commands |
3603 */ | 3557 */ |
3604 void | 3558 void |
3605 ex_lockvar(eap) | 3559 ex_lockvar(exarg_T *eap) |
3606 exarg_T *eap; | |
3607 { | 3560 { |
3608 char_u *arg = eap->arg; | 3561 char_u *arg = eap->arg; |
3609 int deep = 2; | 3562 int deep = 2; |
3610 | 3563 |
3611 if (eap->forceit) | 3564 if (eap->forceit) |
3621 | 3574 |
3622 /* | 3575 /* |
3623 * ":unlet", ":lockvar" and ":unlockvar" are quite similar. | 3576 * ":unlet", ":lockvar" and ":unlockvar" are quite similar. |
3624 */ | 3577 */ |
3625 static void | 3578 static void |
3626 ex_unletlock(eap, argstart, deep) | 3579 ex_unletlock( |
3627 exarg_T *eap; | 3580 exarg_T *eap, |
3628 char_u *argstart; | 3581 char_u *argstart, |
3629 int deep; | 3582 int deep) |
3630 { | 3583 { |
3631 char_u *arg = argstart; | 3584 char_u *arg = argstart; |
3632 char_u *name_end; | 3585 char_u *name_end; |
3633 int error = FALSE; | 3586 int error = FALSE; |
3634 lval_T lv; | 3587 lval_T lv; |
3676 | 3629 |
3677 eap->nextcmd = check_nextcmd(arg); | 3630 eap->nextcmd = check_nextcmd(arg); |
3678 } | 3631 } |
3679 | 3632 |
3680 static int | 3633 static int |
3681 do_unlet_var(lp, name_end, forceit) | 3634 do_unlet_var( |
3682 lval_T *lp; | 3635 lval_T *lp, |
3683 char_u *name_end; | 3636 char_u *name_end, |
3684 int forceit; | 3637 int forceit) |
3685 { | 3638 { |
3686 int ret = OK; | 3639 int ret = OK; |
3687 int cc; | 3640 int cc; |
3688 | 3641 |
3689 if (lp->ll_tv == NULL) | 3642 if (lp->ll_tv == NULL) |
3743 /* | 3696 /* |
3744 * "unlet" a variable. Return OK if it existed, FAIL if not. | 3697 * "unlet" a variable. Return OK if it existed, FAIL if not. |
3745 * When "forceit" is TRUE don't complain if the variable doesn't exist. | 3698 * When "forceit" is TRUE don't complain if the variable doesn't exist. |
3746 */ | 3699 */ |
3747 int | 3700 int |
3748 do_unlet(name, forceit) | 3701 do_unlet(char_u *name, int forceit) |
3749 char_u *name; | |
3750 int forceit; | |
3751 { | 3702 { |
3752 hashtab_T *ht; | 3703 hashtab_T *ht; |
3753 hashitem_T *hi; | 3704 hashitem_T *hi; |
3754 char_u *varname; | 3705 char_u *varname; |
3755 dict_T *d; | 3706 dict_T *d; |
3798 * Lock or unlock variable indicated by "lp". | 3749 * Lock or unlock variable indicated by "lp". |
3799 * "deep" is the levels to go (-1 for unlimited); | 3750 * "deep" is the levels to go (-1 for unlimited); |
3800 * "lock" is TRUE for ":lockvar", FALSE for ":unlockvar". | 3751 * "lock" is TRUE for ":lockvar", FALSE for ":unlockvar". |
3801 */ | 3752 */ |
3802 static int | 3753 static int |
3803 do_lock_var(lp, name_end, deep, lock) | 3754 do_lock_var( |
3804 lval_T *lp; | 3755 lval_T *lp, |
3805 char_u *name_end; | 3756 char_u *name_end, |
3806 int deep; | 3757 int deep, |
3807 int lock; | 3758 int lock) |
3808 { | 3759 { |
3809 int ret = OK; | 3760 int ret = OK; |
3810 int cc; | 3761 int cc; |
3811 dictitem_T *di; | 3762 dictitem_T *di; |
3812 | 3763 |
3861 | 3812 |
3862 /* | 3813 /* |
3863 * Lock or unlock an item. "deep" is nr of levels to go. | 3814 * Lock or unlock an item. "deep" is nr of levels to go. |
3864 */ | 3815 */ |
3865 static void | 3816 static void |
3866 item_lock(tv, deep, lock) | 3817 item_lock(typval_T *tv, int deep, int lock) |
3867 typval_T *tv; | |
3868 int deep; | |
3869 int lock; | |
3870 { | 3818 { |
3871 static int recurse = 0; | 3819 static int recurse = 0; |
3872 list_T *l; | 3820 list_T *l; |
3873 listitem_T *li; | 3821 listitem_T *li; |
3874 dict_T *d; | 3822 dict_T *d; |
3933 /* | 3881 /* |
3934 * Return TRUE if typeval "tv" is locked: Either that value is locked itself | 3882 * Return TRUE if typeval "tv" is locked: Either that value is locked itself |
3935 * or it refers to a List or Dictionary that is locked. | 3883 * or it refers to a List or Dictionary that is locked. |
3936 */ | 3884 */ |
3937 static int | 3885 static int |
3938 tv_islocked(tv) | 3886 tv_islocked(typval_T *tv) |
3939 typval_T *tv; | |
3940 { | 3887 { |
3941 return (tv->v_lock & VAR_LOCKED) | 3888 return (tv->v_lock & VAR_LOCKED) |
3942 || (tv->v_type == VAR_LIST | 3889 || (tv->v_type == VAR_LIST |
3943 && tv->vval.v_list != NULL | 3890 && tv->vval.v_list != NULL |
3944 && (tv->vval.v_list->lv_lock & VAR_LOCKED)) | 3891 && (tv->vval.v_list->lv_lock & VAR_LOCKED)) |
3950 #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO) | 3897 #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO) |
3951 /* | 3898 /* |
3952 * Delete all "menutrans_" variables. | 3899 * Delete all "menutrans_" variables. |
3953 */ | 3900 */ |
3954 void | 3901 void |
3955 del_menutrans_vars() | 3902 del_menutrans_vars(void) |
3956 { | 3903 { |
3957 hashitem_T *hi; | 3904 hashitem_T *hi; |
3958 int todo; | 3905 int todo; |
3959 | 3906 |
3960 hash_lock(&globvarht); | 3907 hash_lock(&globvarht); |
3987 | 3934 |
3988 /* | 3935 /* |
3989 * Function to concatenate a prefix and a variable name. | 3936 * Function to concatenate a prefix and a variable name. |
3990 */ | 3937 */ |
3991 static char_u * | 3938 static char_u * |
3992 cat_prefix_varname(prefix, name) | 3939 cat_prefix_varname(int prefix, char_u *name) |
3993 int prefix; | |
3994 char_u *name; | |
3995 { | 3940 { |
3996 int len; | 3941 int len; |
3997 | 3942 |
3998 len = (int)STRLEN(name) + 3; | 3943 len = (int)STRLEN(name) + 3; |
3999 if (len > varnamebuflen) | 3944 if (len > varnamebuflen) |
4017 /* | 3962 /* |
4018 * Function given to ExpandGeneric() to obtain the list of user defined | 3963 * Function given to ExpandGeneric() to obtain the list of user defined |
4019 * (global/buffer/window/built-in) variable names. | 3964 * (global/buffer/window/built-in) variable names. |
4020 */ | 3965 */ |
4021 char_u * | 3966 char_u * |
4022 get_user_var_name(xp, idx) | 3967 get_user_var_name(expand_T *xp, int idx) |
4023 expand_T *xp; | |
4024 int idx; | |
4025 { | 3968 { |
4026 static long_u gdone; | 3969 static long_u gdone; |
4027 static long_u bdone; | 3970 static long_u bdone; |
4028 static long_u wdone; | 3971 static long_u wdone; |
4029 #ifdef FEAT_WINDOWS | 3972 #ifdef FEAT_WINDOWS |
4141 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. | 4084 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
4142 * Note: "rettv.v_lock" is not set. | 4085 * Note: "rettv.v_lock" is not set. |
4143 * Return OK or FAIL. | 4086 * Return OK or FAIL. |
4144 */ | 4087 */ |
4145 static int | 4088 static int |
4146 eval0(arg, rettv, nextcmd, evaluate) | 4089 eval0( |
4147 char_u *arg; | 4090 char_u *arg, |
4148 typval_T *rettv; | 4091 typval_T *rettv, |
4149 char_u **nextcmd; | 4092 char_u **nextcmd, |
4150 int evaluate; | 4093 int evaluate) |
4151 { | 4094 { |
4152 int ret; | 4095 int ret; |
4153 char_u *p; | 4096 char_u *p; |
4154 | 4097 |
4155 p = skipwhite(arg); | 4098 p = skipwhite(arg); |
4183 * Note: "rettv.v_lock" is not set. | 4126 * Note: "rettv.v_lock" is not set. |
4184 * | 4127 * |
4185 * Return OK or FAIL. | 4128 * Return OK or FAIL. |
4186 */ | 4129 */ |
4187 static int | 4130 static int |
4188 eval1(arg, rettv, evaluate) | 4131 eval1(char_u **arg, typval_T *rettv, int evaluate) |
4189 char_u **arg; | |
4190 typval_T *rettv; | |
4191 int evaluate; | |
4192 { | 4132 { |
4193 int result; | 4133 int result; |
4194 typval_T var2; | 4134 typval_T var2; |
4195 | 4135 |
4196 /* | 4136 /* |
4256 * "arg" is advanced to the next non-white after the recognized expression. | 4196 * "arg" is advanced to the next non-white after the recognized expression. |
4257 * | 4197 * |
4258 * Return OK or FAIL. | 4198 * Return OK or FAIL. |
4259 */ | 4199 */ |
4260 static int | 4200 static int |
4261 eval2(arg, rettv, evaluate) | 4201 eval2(char_u **arg, typval_T *rettv, int evaluate) |
4262 char_u **arg; | |
4263 typval_T *rettv; | |
4264 int evaluate; | |
4265 { | 4202 { |
4266 typval_T var2; | 4203 typval_T var2; |
4267 long result; | 4204 long result; |
4268 int first; | 4205 int first; |
4269 int error = FALSE; | 4206 int error = FALSE; |
4327 * "arg" is advanced to the next non-white after the recognized expression. | 4264 * "arg" is advanced to the next non-white after the recognized expression. |
4328 * | 4265 * |
4329 * Return OK or FAIL. | 4266 * Return OK or FAIL. |
4330 */ | 4267 */ |
4331 static int | 4268 static int |
4332 eval3(arg, rettv, evaluate) | 4269 eval3(char_u **arg, typval_T *rettv, int evaluate) |
4333 char_u **arg; | |
4334 typval_T *rettv; | |
4335 int evaluate; | |
4336 { | 4270 { |
4337 typval_T var2; | 4271 typval_T var2; |
4338 long result; | 4272 long result; |
4339 int first; | 4273 int first; |
4340 int error = FALSE; | 4274 int error = FALSE; |
4407 * "arg" is advanced to the next non-white after the recognized expression. | 4341 * "arg" is advanced to the next non-white after the recognized expression. |
4408 * | 4342 * |
4409 * Return OK or FAIL. | 4343 * Return OK or FAIL. |
4410 */ | 4344 */ |
4411 static int | 4345 static int |
4412 eval4(arg, rettv, evaluate) | 4346 eval4(char_u **arg, typval_T *rettv, int evaluate) |
4413 char_u **arg; | |
4414 typval_T *rettv; | |
4415 int evaluate; | |
4416 { | 4347 { |
4417 typval_T var2; | 4348 typval_T var2; |
4418 char_u *p; | 4349 char_u *p; |
4419 int i; | 4350 int i; |
4420 exptype_T type = TYPE_UNKNOWN; | 4351 exptype_T type = TYPE_UNKNOWN; |
4717 * "arg" is advanced to the next non-white after the recognized expression. | 4648 * "arg" is advanced to the next non-white after the recognized expression. |
4718 * | 4649 * |
4719 * Return OK or FAIL. | 4650 * Return OK or FAIL. |
4720 */ | 4651 */ |
4721 static int | 4652 static int |
4722 eval5(arg, rettv, evaluate) | 4653 eval5(char_u **arg, typval_T *rettv, int evaluate) |
4723 char_u **arg; | |
4724 typval_T *rettv; | |
4725 int evaluate; | |
4726 { | 4654 { |
4727 typval_T var2; | 4655 typval_T var2; |
4728 typval_T var3; | 4656 typval_T var3; |
4729 int op; | 4657 int op; |
4730 long n1, n2; | 4658 long n1, n2; |
4902 * "arg" is advanced to the next non-white after the recognized expression. | 4830 * "arg" is advanced to the next non-white after the recognized expression. |
4903 * | 4831 * |
4904 * Return OK or FAIL. | 4832 * Return OK or FAIL. |
4905 */ | 4833 */ |
4906 static int | 4834 static int |
4907 eval6(arg, rettv, evaluate, want_string) | 4835 eval6( |
4908 char_u **arg; | 4836 char_u **arg, |
4909 typval_T *rettv; | 4837 typval_T *rettv, |
4910 int evaluate; | 4838 int evaluate, |
4911 int want_string; /* after "." operator */ | 4839 int want_string) /* after "." operator */ |
4912 { | 4840 { |
4913 typval_T var2; | 4841 typval_T var2; |
4914 int op; | 4842 int op; |
4915 long n1, n2; | 4843 long n1, n2; |
4916 #ifdef FEAT_FLOAT | 4844 #ifdef FEAT_FLOAT |
5084 * "arg" is advanced to the next non-white after the recognized expression. | 5012 * "arg" is advanced to the next non-white after the recognized expression. |
5085 * | 5013 * |
5086 * Return OK or FAIL. | 5014 * Return OK or FAIL. |
5087 */ | 5015 */ |
5088 static int | 5016 static int |
5089 eval7(arg, rettv, evaluate, want_string) | 5017 eval7( |
5090 char_u **arg; | 5018 char_u **arg, |
5091 typval_T *rettv; | 5019 typval_T *rettv, |
5092 int evaluate; | 5020 int evaluate, |
5093 int want_string UNUSED; /* after "." operator */ | 5021 int want_string UNUSED) /* after "." operator */ |
5094 { | 5022 { |
5095 long n; | 5023 long n; |
5096 int len; | 5024 int len; |
5097 char_u *s; | 5025 char_u *s; |
5098 char_u *start_leader, *end_leader; | 5026 char_u *start_leader, *end_leader; |
5376 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". | 5304 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
5377 * "*arg" points to the '[' or '.'. | 5305 * "*arg" points to the '[' or '.'. |
5378 * Returns FAIL or OK. "*arg" is advanced to after the ']'. | 5306 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
5379 */ | 5307 */ |
5380 static int | 5308 static int |
5381 eval_index(arg, rettv, evaluate, verbose) | 5309 eval_index( |
5382 char_u **arg; | 5310 char_u **arg, |
5383 typval_T *rettv; | 5311 typval_T *rettv, |
5384 int evaluate; | 5312 int evaluate, |
5385 int verbose; /* give error messages */ | 5313 int verbose) /* give error messages */ |
5386 { | 5314 { |
5387 int empty1 = FALSE, empty2 = FALSE; | 5315 int empty1 = FALSE, empty2 = FALSE; |
5388 typval_T var1, var2; | 5316 typval_T var1, var2; |
5389 long n1, n2 = 0; | 5317 long n1, n2 = 0; |
5390 long len = -1; | 5318 long len = -1; |
5643 * "arg" points to the '&' or '+' before the option name. | 5571 * "arg" points to the '&' or '+' before the option name. |
5644 * "arg" is advanced to character after the option name. | 5572 * "arg" is advanced to character after the option name. |
5645 * Return OK or FAIL. | 5573 * Return OK or FAIL. |
5646 */ | 5574 */ |
5647 static int | 5575 static int |
5648 get_option_tv(arg, rettv, evaluate) | 5576 get_option_tv( |
5649 char_u **arg; | 5577 char_u **arg, |
5650 typval_T *rettv; /* when NULL, only check if option exists */ | 5578 typval_T *rettv, /* when NULL, only check if option exists */ |
5651 int evaluate; | 5579 int evaluate) |
5652 { | 5580 { |
5653 char_u *option_end; | 5581 char_u *option_end; |
5654 long numval; | 5582 long numval; |
5655 char_u *stringval; | 5583 char_u *stringval; |
5656 int opt_type; | 5584 int opt_type; |
5722 /* | 5650 /* |
5723 * Allocate a variable for a string constant. | 5651 * Allocate a variable for a string constant. |
5724 * Return OK or FAIL. | 5652 * Return OK or FAIL. |
5725 */ | 5653 */ |
5726 static int | 5654 static int |
5727 get_string_tv(arg, rettv, evaluate) | 5655 get_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
5728 char_u **arg; | |
5729 typval_T *rettv; | |
5730 int evaluate; | |
5731 { | 5656 { |
5732 char_u *p; | 5657 char_u *p; |
5733 char_u *name; | 5658 char_u *name; |
5734 int extra = 0; | 5659 int extra = 0; |
5735 | 5660 |
5861 /* | 5786 /* |
5862 * Allocate a variable for a 'str''ing' constant. | 5787 * Allocate a variable for a 'str''ing' constant. |
5863 * Return OK or FAIL. | 5788 * Return OK or FAIL. |
5864 */ | 5789 */ |
5865 static int | 5790 static int |
5866 get_lit_string_tv(arg, rettv, evaluate) | 5791 get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
5867 char_u **arg; | |
5868 typval_T *rettv; | |
5869 int evaluate; | |
5870 { | 5792 { |
5871 char_u *p; | 5793 char_u *p; |
5872 char_u *str; | 5794 char_u *str; |
5873 int reduce = 0; | 5795 int reduce = 0; |
5874 | 5796 |
5927 /* | 5849 /* |
5928 * Allocate a variable for a List and fill it from "*arg". | 5850 * Allocate a variable for a List and fill it from "*arg". |
5929 * Return OK or FAIL. | 5851 * Return OK or FAIL. |
5930 */ | 5852 */ |
5931 static int | 5853 static int |
5932 get_list_tv(arg, rettv, evaluate) | 5854 get_list_tv(char_u **arg, typval_T *rettv, int evaluate) |
5933 char_u **arg; | |
5934 typval_T *rettv; | |
5935 int evaluate; | |
5936 { | 5855 { |
5937 list_T *l = NULL; | 5856 list_T *l = NULL; |
5938 typval_T tv; | 5857 typval_T tv; |
5939 listitem_T *item; | 5858 listitem_T *item; |
5940 | 5859 |
5996 /* | 5915 /* |
5997 * Allocate an empty header for a list. | 5916 * Allocate an empty header for a list. |
5998 * Caller should take care of the reference count. | 5917 * Caller should take care of the reference count. |
5999 */ | 5918 */ |
6000 list_T * | 5919 list_T * |
6001 list_alloc() | 5920 list_alloc(void) |
6002 { | 5921 { |
6003 list_T *l; | 5922 list_T *l; |
6004 | 5923 |
6005 l = (list_T *)alloc_clear(sizeof(list_T)); | 5924 l = (list_T *)alloc_clear(sizeof(list_T)); |
6006 if (l != NULL) | 5925 if (l != NULL) |
6018 /* | 5937 /* |
6019 * Allocate an empty list for a return value. | 5938 * Allocate an empty list for a return value. |
6020 * Returns OK or FAIL. | 5939 * Returns OK or FAIL. |
6021 */ | 5940 */ |
6022 int | 5941 int |
6023 rettv_list_alloc(rettv) | 5942 rettv_list_alloc(typval_T *rettv) |
6024 typval_T *rettv; | |
6025 { | 5943 { |
6026 list_T *l = list_alloc(); | 5944 list_T *l = list_alloc(); |
6027 | 5945 |
6028 if (l == NULL) | 5946 if (l == NULL) |
6029 return FAIL; | 5947 return FAIL; |
6037 /* | 5955 /* |
6038 * Unreference a list: decrement the reference count and free it when it | 5956 * Unreference a list: decrement the reference count and free it when it |
6039 * becomes zero. | 5957 * becomes zero. |
6040 */ | 5958 */ |
6041 void | 5959 void |
6042 list_unref(l) | 5960 list_unref(list_T *l) |
6043 list_T *l; | |
6044 { | 5961 { |
6045 if (l != NULL && --l->lv_refcount <= 0) | 5962 if (l != NULL && --l->lv_refcount <= 0) |
6046 list_free(l, TRUE); | 5963 list_free(l, TRUE); |
6047 } | 5964 } |
6048 | 5965 |
6049 /* | 5966 /* |
6050 * Free a list, including all non-container items it points to. | 5967 * Free a list, including all non-container items it points to. |
6051 * Ignores the reference count. | 5968 * Ignores the reference count. |
6052 */ | 5969 */ |
6053 void | 5970 void |
6054 list_free(l, recurse) | 5971 list_free( |
6055 list_T *l; | 5972 list_T *l, |
6056 int recurse; /* Free Lists and Dictionaries recursively. */ | 5973 int recurse) /* Free Lists and Dictionaries recursively. */ |
6057 { | 5974 { |
6058 listitem_T *item; | 5975 listitem_T *item; |
6059 | 5976 |
6060 /* Remove the list from the list of lists for garbage collection. */ | 5977 /* Remove the list from the list of lists for garbage collection. */ |
6061 if (l->lv_used_prev == NULL) | 5978 if (l->lv_used_prev == NULL) |
6089 | 6006 |
6090 /* | 6007 /* |
6091 * Free a list item. Also clears the value. Does not notify watchers. | 6008 * Free a list item. Also clears the value. Does not notify watchers. |
6092 */ | 6009 */ |
6093 void | 6010 void |
6094 listitem_free(item) | 6011 listitem_free(listitem_T *item) |
6095 listitem_T *item; | |
6096 { | 6012 { |
6097 clear_tv(&item->li_tv); | 6013 clear_tv(&item->li_tv); |
6098 vim_free(item); | 6014 vim_free(item); |
6099 } | 6015 } |
6100 | 6016 |
6101 /* | 6017 /* |
6102 * Remove a list item from a List and free it. Also clears the value. | 6018 * Remove a list item from a List and free it. Also clears the value. |
6103 */ | 6019 */ |
6104 void | 6020 void |
6105 listitem_remove(l, item) | 6021 listitem_remove(list_T *l, listitem_T *item) |
6106 list_T *l; | |
6107 listitem_T *item; | |
6108 { | 6022 { |
6109 vimlist_remove(l, item, item); | 6023 vimlist_remove(l, item, item); |
6110 listitem_free(item); | 6024 listitem_free(item); |
6111 } | 6025 } |
6112 | 6026 |
6113 /* | 6027 /* |
6114 * Get the number of items in a list. | 6028 * Get the number of items in a list. |
6115 */ | 6029 */ |
6116 static long | 6030 static long |
6117 list_len(l) | 6031 list_len(list_T *l) |
6118 list_T *l; | |
6119 { | 6032 { |
6120 if (l == NULL) | 6033 if (l == NULL) |
6121 return 0L; | 6034 return 0L; |
6122 return l->lv_len; | 6035 return l->lv_len; |
6123 } | 6036 } |
6124 | 6037 |
6125 /* | 6038 /* |
6126 * Return TRUE when two lists have exactly the same values. | 6039 * Return TRUE when two lists have exactly the same values. |
6127 */ | 6040 */ |
6128 static int | 6041 static int |
6129 list_equal(l1, l2, ic, recursive) | 6042 list_equal( |
6130 list_T *l1; | 6043 list_T *l1, |
6131 list_T *l2; | 6044 list_T *l2, |
6132 int ic; /* ignore case for strings */ | 6045 int ic, /* ignore case for strings */ |
6133 int recursive; /* TRUE when used recursively */ | 6046 int recursive) /* TRUE when used recursively */ |
6134 { | 6047 { |
6135 listitem_T *item1, *item2; | 6048 listitem_T *item1, *item2; |
6136 | 6049 |
6137 if (l1 == NULL || l2 == NULL) | 6050 if (l1 == NULL || l2 == NULL) |
6138 return FALSE; | 6051 return FALSE; |
6151 | 6064 |
6152 /* | 6065 /* |
6153 * Return the dictitem that an entry in a hashtable points to. | 6066 * Return the dictitem that an entry in a hashtable points to. |
6154 */ | 6067 */ |
6155 dictitem_T * | 6068 dictitem_T * |
6156 dict_lookup(hi) | 6069 dict_lookup(hashitem_T *hi) |
6157 hashitem_T *hi; | |
6158 { | 6070 { |
6159 return HI2DI(hi); | 6071 return HI2DI(hi); |
6160 } | 6072 } |
6161 | 6073 |
6162 /* | 6074 /* |
6163 * Return TRUE when two dictionaries have exactly the same key/values. | 6075 * Return TRUE when two dictionaries have exactly the same key/values. |
6164 */ | 6076 */ |
6165 static int | 6077 static int |
6166 dict_equal(d1, d2, ic, recursive) | 6078 dict_equal( |
6167 dict_T *d1; | 6079 dict_T *d1, |
6168 dict_T *d2; | 6080 dict_T *d2, |
6169 int ic; /* ignore case for strings */ | 6081 int ic, /* ignore case for strings */ |
6170 int recursive; /* TRUE when used recursively */ | 6082 int recursive) /* TRUE when used recursively */ |
6171 { | 6083 { |
6172 hashitem_T *hi; | 6084 hashitem_T *hi; |
6173 dictitem_T *item2; | 6085 dictitem_T *item2; |
6174 int todo; | 6086 int todo; |
6175 | 6087 |
6202 * Return TRUE if "tv1" and "tv2" have the same value. | 6114 * Return TRUE if "tv1" and "tv2" have the same value. |
6203 * Compares the items just like "==" would compare them, but strings and | 6115 * Compares the items just like "==" would compare them, but strings and |
6204 * numbers are different. Floats and numbers are also different. | 6116 * numbers are different. Floats and numbers are also different. |
6205 */ | 6117 */ |
6206 static int | 6118 static int |
6207 tv_equal(tv1, tv2, ic, recursive) | 6119 tv_equal( |
6208 typval_T *tv1; | 6120 typval_T *tv1, |
6209 typval_T *tv2; | 6121 typval_T *tv2, |
6210 int ic; /* ignore case */ | 6122 int ic, /* ignore case */ |
6211 int recursive; /* TRUE when used recursively */ | 6123 int recursive) /* TRUE when used recursively */ |
6212 { | 6124 { |
6213 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | 6125 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
6214 char_u *s1, *s2; | 6126 char_u *s1, *s2; |
6215 static int recursive_cnt = 0; /* catch recursive loops */ | 6127 static int recursive_cnt = 0; /* catch recursive loops */ |
6216 int r; | 6128 int r; |
6276 * Locate item with index "n" in list "l" and return it. | 6188 * Locate item with index "n" in list "l" and return it. |
6277 * A negative index is counted from the end; -1 is the last item. | 6189 * A negative index is counted from the end; -1 is the last item. |
6278 * Returns NULL when "n" is out of range. | 6190 * Returns NULL when "n" is out of range. |
6279 */ | 6191 */ |
6280 listitem_T * | 6192 listitem_T * |
6281 list_find(l, n) | 6193 list_find(list_T *l, long n) |
6282 list_T *l; | |
6283 long n; | |
6284 { | 6194 { |
6285 listitem_T *item; | 6195 listitem_T *item; |
6286 long idx; | 6196 long idx; |
6287 | 6197 |
6288 if (l == NULL) | 6198 if (l == NULL) |
6356 | 6266 |
6357 /* | 6267 /* |
6358 * Get list item "l[idx]" as a number. | 6268 * Get list item "l[idx]" as a number. |
6359 */ | 6269 */ |
6360 static long | 6270 static long |
6361 list_find_nr(l, idx, errorp) | 6271 list_find_nr( |
6362 list_T *l; | 6272 list_T *l, |
6363 long idx; | 6273 long idx, |
6364 int *errorp; /* set to TRUE when something wrong */ | 6274 int *errorp) /* set to TRUE when something wrong */ |
6365 { | 6275 { |
6366 listitem_T *li; | 6276 listitem_T *li; |
6367 | 6277 |
6368 li = list_find(l, idx); | 6278 li = list_find(l, idx); |
6369 if (li == NULL) | 6279 if (li == NULL) |
6377 | 6287 |
6378 /* | 6288 /* |
6379 * Get list item "l[idx - 1]" as a string. Returns NULL for failure. | 6289 * Get list item "l[idx - 1]" as a string. Returns NULL for failure. |
6380 */ | 6290 */ |
6381 char_u * | 6291 char_u * |
6382 list_find_str(l, idx) | 6292 list_find_str(list_T *l, long idx) |
6383 list_T *l; | |
6384 long idx; | |
6385 { | 6293 { |
6386 listitem_T *li; | 6294 listitem_T *li; |
6387 | 6295 |
6388 li = list_find(l, idx - 1); | 6296 li = list_find(l, idx - 1); |
6389 if (li == NULL) | 6297 if (li == NULL) |
6397 /* | 6305 /* |
6398 * Locate "item" list "l" and return its index. | 6306 * Locate "item" list "l" and return its index. |
6399 * Returns -1 when "item" is not in the list. | 6307 * Returns -1 when "item" is not in the list. |
6400 */ | 6308 */ |
6401 static long | 6309 static long |
6402 list_idx_of_item(l, item) | 6310 list_idx_of_item(list_T *l, listitem_T *item) |
6403 list_T *l; | |
6404 listitem_T *item; | |
6405 { | 6311 { |
6406 long idx = 0; | 6312 long idx = 0; |
6407 listitem_T *li; | 6313 listitem_T *li; |
6408 | 6314 |
6409 if (l == NULL) | 6315 if (l == NULL) |
6418 | 6324 |
6419 /* | 6325 /* |
6420 * Append item "item" to the end of list "l". | 6326 * Append item "item" to the end of list "l". |
6421 */ | 6327 */ |
6422 void | 6328 void |
6423 list_append(l, item) | 6329 list_append(list_T *l, listitem_T *item) |
6424 list_T *l; | |
6425 listitem_T *item; | |
6426 { | 6330 { |
6427 if (l->lv_last == NULL) | 6331 if (l->lv_last == NULL) |
6428 { | 6332 { |
6429 /* empty list */ | 6333 /* empty list */ |
6430 l->lv_first = item; | 6334 l->lv_first = item; |
6444 /* | 6348 /* |
6445 * Append typval_T "tv" to the end of list "l". | 6349 * Append typval_T "tv" to the end of list "l". |
6446 * Return FAIL when out of memory. | 6350 * Return FAIL when out of memory. |
6447 */ | 6351 */ |
6448 int | 6352 int |
6449 list_append_tv(l, tv) | 6353 list_append_tv(list_T *l, typval_T *tv) |
6450 list_T *l; | |
6451 typval_T *tv; | |
6452 { | 6354 { |
6453 listitem_T *li = listitem_alloc(); | 6355 listitem_T *li = listitem_alloc(); |
6454 | 6356 |
6455 if (li == NULL) | 6357 if (li == NULL) |
6456 return FAIL; | 6358 return FAIL; |
6462 /* | 6364 /* |
6463 * Add a dictionary to a list. Used by getqflist(). | 6365 * Add a dictionary to a list. Used by getqflist(). |
6464 * Return FAIL when out of memory. | 6366 * Return FAIL when out of memory. |
6465 */ | 6367 */ |
6466 int | 6368 int |
6467 list_append_dict(list, dict) | 6369 list_append_dict(list_T *list, dict_T *dict) |
6468 list_T *list; | |
6469 dict_T *dict; | |
6470 { | 6370 { |
6471 listitem_T *li = listitem_alloc(); | 6371 listitem_T *li = listitem_alloc(); |
6472 | 6372 |
6473 if (li == NULL) | 6373 if (li == NULL) |
6474 return FAIL; | 6374 return FAIL; |
6484 * Make a copy of "str" and append it as an item to list "l". | 6384 * Make a copy of "str" and append it as an item to list "l". |
6485 * When "len" >= 0 use "str[len]". | 6385 * When "len" >= 0 use "str[len]". |
6486 * Returns FAIL when out of memory. | 6386 * Returns FAIL when out of memory. |
6487 */ | 6387 */ |
6488 int | 6388 int |
6489 list_append_string(l, str, len) | 6389 list_append_string(list_T *l, char_u *str, int len) |
6490 list_T *l; | |
6491 char_u *str; | |
6492 int len; | |
6493 { | 6390 { |
6494 listitem_T *li = listitem_alloc(); | 6391 listitem_T *li = listitem_alloc(); |
6495 | 6392 |
6496 if (li == NULL) | 6393 if (li == NULL) |
6497 return FAIL; | 6394 return FAIL; |
6509 /* | 6406 /* |
6510 * Append "n" to list "l". | 6407 * Append "n" to list "l". |
6511 * Returns FAIL when out of memory. | 6408 * Returns FAIL when out of memory. |
6512 */ | 6409 */ |
6513 static int | 6410 static int |
6514 list_append_number(l, n) | 6411 list_append_number(list_T *l, varnumber_T n) |
6515 list_T *l; | |
6516 varnumber_T n; | |
6517 { | 6412 { |
6518 listitem_T *li; | 6413 listitem_T *li; |
6519 | 6414 |
6520 li = listitem_alloc(); | 6415 li = listitem_alloc(); |
6521 if (li == NULL) | 6416 if (li == NULL) |
6531 * Insert typval_T "tv" in list "l" before "item". | 6426 * Insert typval_T "tv" in list "l" before "item". |
6532 * If "item" is NULL append at the end. | 6427 * If "item" is NULL append at the end. |
6533 * Return FAIL when out of memory. | 6428 * Return FAIL when out of memory. |
6534 */ | 6429 */ |
6535 int | 6430 int |
6536 list_insert_tv(l, tv, item) | 6431 list_insert_tv(list_T *l, typval_T *tv, listitem_T *item) |
6537 list_T *l; | |
6538 typval_T *tv; | |
6539 listitem_T *item; | |
6540 { | 6432 { |
6541 listitem_T *ni = listitem_alloc(); | 6433 listitem_T *ni = listitem_alloc(); |
6542 | 6434 |
6543 if (ni == NULL) | 6435 if (ni == NULL) |
6544 return FAIL; | 6436 return FAIL; |
6546 list_insert(l, ni, item); | 6438 list_insert(l, ni, item); |
6547 return OK; | 6439 return OK; |
6548 } | 6440 } |
6549 | 6441 |
6550 void | 6442 void |
6551 list_insert(l, ni, item) | 6443 list_insert(list_T *l, listitem_T *ni, listitem_T *item) |
6552 list_T *l; | |
6553 listitem_T *ni; | |
6554 listitem_T *item; | |
6555 { | 6444 { |
6556 if (item == NULL) | 6445 if (item == NULL) |
6557 /* Append new item at end of list. */ | 6446 /* Append new item at end of list. */ |
6558 list_append(l, ni); | 6447 list_append(l, ni); |
6559 else | 6448 else |
6580 * Extend "l1" with "l2". | 6469 * Extend "l1" with "l2". |
6581 * If "bef" is NULL append at the end, otherwise insert before this item. | 6470 * If "bef" is NULL append at the end, otherwise insert before this item. |
6582 * Returns FAIL when out of memory. | 6471 * Returns FAIL when out of memory. |
6583 */ | 6472 */ |
6584 static int | 6473 static int |
6585 list_extend(l1, l2, bef) | 6474 list_extend(list_T *l1, list_T *l2, listitem_T *bef) |
6586 list_T *l1; | |
6587 list_T *l2; | |
6588 listitem_T *bef; | |
6589 { | 6475 { |
6590 listitem_T *item; | 6476 listitem_T *item; |
6591 int todo = l2->lv_len; | 6477 int todo = l2->lv_len; |
6592 | 6478 |
6593 /* We also quit the loop when we have inserted the original item count of | 6479 /* We also quit the loop when we have inserted the original item count of |
6601 /* | 6487 /* |
6602 * Concatenate lists "l1" and "l2" into a new list, stored in "tv". | 6488 * Concatenate lists "l1" and "l2" into a new list, stored in "tv". |
6603 * Return FAIL when out of memory. | 6489 * Return FAIL when out of memory. |
6604 */ | 6490 */ |
6605 static int | 6491 static int |
6606 list_concat(l1, l2, tv) | 6492 list_concat(list_T *l1, list_T *l2, typval_T *tv) |
6607 list_T *l1; | |
6608 list_T *l2; | |
6609 typval_T *tv; | |
6610 { | 6493 { |
6611 list_T *l; | 6494 list_T *l; |
6612 | 6495 |
6613 if (l1 == NULL || l2 == NULL) | 6496 if (l1 == NULL || l2 == NULL) |
6614 return FAIL; | 6497 return FAIL; |
6629 * The refcount of the new list is set to 1. | 6512 * The refcount of the new list is set to 1. |
6630 * See item_copy() for "copyID". | 6513 * See item_copy() for "copyID". |
6631 * Returns NULL when out of memory. | 6514 * Returns NULL when out of memory. |
6632 */ | 6515 */ |
6633 static list_T * | 6516 static list_T * |
6634 list_copy(orig, deep, copyID) | 6517 list_copy(list_T *orig, int deep, int copyID) |
6635 list_T *orig; | |
6636 int deep; | |
6637 int copyID; | |
6638 { | 6518 { |
6639 list_T *copy; | 6519 list_T *copy; |
6640 listitem_T *item; | 6520 listitem_T *item; |
6641 listitem_T *ni; | 6521 listitem_T *ni; |
6642 | 6522 |
6687 * Does not free the listitem or the value! | 6567 * Does not free the listitem or the value! |
6688 * This used to be called list_remove, but that conflicts with a Sun header | 6568 * This used to be called list_remove, but that conflicts with a Sun header |
6689 * file. | 6569 * file. |
6690 */ | 6570 */ |
6691 void | 6571 void |
6692 vimlist_remove(l, item, item2) | 6572 vimlist_remove(list_T *l, listitem_T *item, listitem_T *item2) |
6693 list_T *l; | |
6694 listitem_T *item; | |
6695 listitem_T *item2; | |
6696 { | 6573 { |
6697 listitem_T *ip; | 6574 listitem_T *ip; |
6698 | 6575 |
6699 /* notify watchers */ | 6576 /* notify watchers */ |
6700 for (ip = item; ip != NULL; ip = ip->li_next) | 6577 for (ip = item; ip != NULL; ip = ip->li_next) |
6719 /* | 6596 /* |
6720 * Return an allocated string with the string representation of a list. | 6597 * Return an allocated string with the string representation of a list. |
6721 * May return NULL. | 6598 * May return NULL. |
6722 */ | 6599 */ |
6723 static char_u * | 6600 static char_u * |
6724 list2string(tv, copyID) | 6601 list2string(typval_T *tv, int copyID) |
6725 typval_T *tv; | |
6726 int copyID; | |
6727 { | 6602 { |
6728 garray_T ga; | 6603 garray_T ga; |
6729 | 6604 |
6730 if (tv->vval.v_list == NULL) | 6605 if (tv->vval.v_list == NULL) |
6731 return NULL; | 6606 return NULL; |
6745 char_u *s; | 6620 char_u *s; |
6746 char_u *tofree; | 6621 char_u *tofree; |
6747 } join_T; | 6622 } join_T; |
6748 | 6623 |
6749 static int | 6624 static int |
6750 list_join_inner(gap, l, sep, echo_style, copyID, join_gap) | 6625 list_join_inner( |
6751 garray_T *gap; /* to store the result in */ | 6626 garray_T *gap, /* to store the result in */ |
6752 list_T *l; | 6627 list_T *l, |
6753 char_u *sep; | 6628 char_u *sep, |
6754 int echo_style; | 6629 int echo_style, |
6755 int copyID; | 6630 int copyID, |
6756 garray_T *join_gap; /* to keep each list item string */ | 6631 garray_T *join_gap) /* to keep each list item string */ |
6757 { | 6632 { |
6758 int i; | 6633 int i; |
6759 join_T *p; | 6634 join_T *p; |
6760 int len; | 6635 int len; |
6761 int sumlen = 0; | 6636 int sumlen = 0; |
6823 * Join list "l" into a string in "*gap", using separator "sep". | 6698 * Join list "l" into a string in "*gap", using separator "sep". |
6824 * When "echo_style" is TRUE use String as echoed, otherwise as inside a List. | 6699 * When "echo_style" is TRUE use String as echoed, otherwise as inside a List. |
6825 * Return FAIL or OK. | 6700 * Return FAIL or OK. |
6826 */ | 6701 */ |
6827 static int | 6702 static int |
6828 list_join(gap, l, sep, echo_style, copyID) | 6703 list_join( |
6829 garray_T *gap; | 6704 garray_T *gap, |
6830 list_T *l; | 6705 list_T *l, |
6831 char_u *sep; | 6706 char_u *sep, |
6832 int echo_style; | 6707 int echo_style, |
6833 int copyID; | 6708 int copyID) |
6834 { | 6709 { |
6835 garray_T join_ga; | 6710 garray_T join_ga; |
6836 int retval; | 6711 int retval; |
6837 join_T *p; | 6712 join_T *p; |
6838 int i; | 6713 int i; |
6860 /* | 6735 /* |
6861 * Return the next (unique) copy ID. | 6736 * Return the next (unique) copy ID. |
6862 * Used for serializing nested structures. | 6737 * Used for serializing nested structures. |
6863 */ | 6738 */ |
6864 int | 6739 int |
6865 get_copyID() | 6740 get_copyID(void) |
6866 { | 6741 { |
6867 current_copyID += COPYID_INC; | 6742 current_copyID += COPYID_INC; |
6868 return current_copyID; | 6743 return current_copyID; |
6869 } | 6744 } |
6870 | 6745 |
6891 /* | 6766 /* |
6892 * Do garbage collection for lists and dicts. | 6767 * Do garbage collection for lists and dicts. |
6893 * Return TRUE if some memory was freed. | 6768 * Return TRUE if some memory was freed. |
6894 */ | 6769 */ |
6895 int | 6770 int |
6896 garbage_collect() | 6771 garbage_collect(void) |
6897 { | 6772 { |
6898 int copyID; | 6773 int copyID; |
6899 int abort = FALSE; | 6774 int abort = FALSE; |
6900 buf_T *buf; | 6775 buf_T *buf; |
6901 win_T *wp; | 6776 win_T *wp; |
7021 | 6896 |
7022 /* | 6897 /* |
7023 * Free lists and dictionaries that are no longer referenced. | 6898 * Free lists and dictionaries that are no longer referenced. |
7024 */ | 6899 */ |
7025 static int | 6900 static int |
7026 free_unref_items(copyID) | 6901 free_unref_items(int copyID) |
7027 int copyID; | |
7028 { | 6902 { |
7029 dict_T *dd, *dd_next; | 6903 dict_T *dd, *dd_next; |
7030 list_T *ll, *ll_next; | 6904 list_T *ll, *ll_next; |
7031 int did_free = FALSE; | 6905 int did_free = FALSE; |
7032 | 6906 |
7074 * "list_stack" is used to add lists to be marked. Can be NULL. | 6948 * "list_stack" is used to add lists to be marked. Can be NULL. |
7075 * | 6949 * |
7076 * Returns TRUE if setting references failed somehow. | 6950 * Returns TRUE if setting references failed somehow. |
7077 */ | 6951 */ |
7078 int | 6952 int |
7079 set_ref_in_ht(ht, copyID, list_stack) | 6953 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
7080 hashtab_T *ht; | |
7081 int copyID; | |
7082 list_stack_T **list_stack; | |
7083 { | 6954 { |
7084 int todo; | 6955 int todo; |
7085 int abort = FALSE; | 6956 int abort = FALSE; |
7086 hashitem_T *hi; | 6957 hashitem_T *hi; |
7087 hashtab_T *cur_ht; | 6958 hashtab_T *cur_ht; |
7124 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | 6995 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
7125 * | 6996 * |
7126 * Returns TRUE if setting references failed somehow. | 6997 * Returns TRUE if setting references failed somehow. |
7127 */ | 6998 */ |
7128 int | 6999 int |
7129 set_ref_in_list(l, copyID, ht_stack) | 7000 set_ref_in_list(list_T *l, int copyID, ht_stack_T **ht_stack) |
7130 list_T *l; | |
7131 int copyID; | |
7132 ht_stack_T **ht_stack; | |
7133 { | 7001 { |
7134 listitem_T *li; | 7002 listitem_T *li; |
7135 int abort = FALSE; | 7003 int abort = FALSE; |
7136 list_T *cur_l; | 7004 list_T *cur_l; |
7137 list_stack_T *list_stack = NULL; | 7005 list_stack_T *list_stack = NULL; |
7166 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | 7034 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
7167 * | 7035 * |
7168 * Returns TRUE if setting references failed somehow. | 7036 * Returns TRUE if setting references failed somehow. |
7169 */ | 7037 */ |
7170 int | 7038 int |
7171 set_ref_in_item(tv, copyID, ht_stack, list_stack) | 7039 set_ref_in_item( |
7172 typval_T *tv; | 7040 typval_T *tv, |
7173 int copyID; | 7041 int copyID, |
7174 ht_stack_T **ht_stack; | 7042 ht_stack_T **ht_stack, |
7175 list_stack_T **list_stack; | 7043 list_stack_T **list_stack) |
7176 { | 7044 { |
7177 dict_T *dd; | 7045 dict_T *dd; |
7178 list_T *ll; | 7046 list_T *ll; |
7179 int abort = FALSE; | 7047 int abort = FALSE; |
7180 | 7048 |
7237 | 7105 |
7238 /* | 7106 /* |
7239 * Allocate an empty header for a dictionary. | 7107 * Allocate an empty header for a dictionary. |
7240 */ | 7108 */ |
7241 dict_T * | 7109 dict_T * |
7242 dict_alloc() | 7110 dict_alloc(void) |
7243 { | 7111 { |
7244 dict_T *d; | 7112 dict_T *d; |
7245 | 7113 |
7246 d = (dict_T *)alloc(sizeof(dict_T)); | 7114 d = (dict_T *)alloc(sizeof(dict_T)); |
7247 if (d != NULL) | 7115 if (d != NULL) |
7265 /* | 7133 /* |
7266 * Allocate an empty dict for a return value. | 7134 * Allocate an empty dict for a return value. |
7267 * Returns OK or FAIL. | 7135 * Returns OK or FAIL. |
7268 */ | 7136 */ |
7269 int | 7137 int |
7270 rettv_dict_alloc(rettv) | 7138 rettv_dict_alloc(typval_T *rettv) |
7271 typval_T *rettv; | |
7272 { | 7139 { |
7273 dict_T *d = dict_alloc(); | 7140 dict_T *d = dict_alloc(); |
7274 | 7141 |
7275 if (d == NULL) | 7142 if (d == NULL) |
7276 return FAIL; | 7143 return FAIL; |
7285 /* | 7152 /* |
7286 * Unreference a Dictionary: decrement the reference count and free it when it | 7153 * Unreference a Dictionary: decrement the reference count and free it when it |
7287 * becomes zero. | 7154 * becomes zero. |
7288 */ | 7155 */ |
7289 void | 7156 void |
7290 dict_unref(d) | 7157 dict_unref(dict_T *d) |
7291 dict_T *d; | |
7292 { | 7158 { |
7293 if (d != NULL && --d->dv_refcount <= 0) | 7159 if (d != NULL && --d->dv_refcount <= 0) |
7294 dict_free(d, TRUE); | 7160 dict_free(d, TRUE); |
7295 } | 7161 } |
7296 | 7162 |
7297 /* | 7163 /* |
7298 * Free a Dictionary, including all non-container items it contains. | 7164 * Free a Dictionary, including all non-container items it contains. |
7299 * Ignores the reference count. | 7165 * Ignores the reference count. |
7300 */ | 7166 */ |
7301 void | 7167 void |
7302 dict_free(d, recurse) | 7168 dict_free( |
7303 dict_T *d; | 7169 dict_T *d, |
7304 int recurse; /* Free Lists and Dictionaries recursively. */ | 7170 int recurse) /* Free Lists and Dictionaries recursively. */ |
7305 { | 7171 { |
7306 int todo; | 7172 int todo; |
7307 hashitem_T *hi; | 7173 hashitem_T *hi; |
7308 dictitem_T *di; | 7174 dictitem_T *di; |
7309 | 7175 |
7342 * The "key" is copied to the new item. | 7208 * The "key" is copied to the new item. |
7343 * Note that the value of the item "di_tv" still needs to be initialized! | 7209 * Note that the value of the item "di_tv" still needs to be initialized! |
7344 * Returns NULL when out of memory. | 7210 * Returns NULL when out of memory. |
7345 */ | 7211 */ |
7346 dictitem_T * | 7212 dictitem_T * |
7347 dictitem_alloc(key) | 7213 dictitem_alloc(char_u *key) |
7348 char_u *key; | |
7349 { | 7214 { |
7350 dictitem_T *di; | 7215 dictitem_T *di; |
7351 | 7216 |
7352 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key))); | 7217 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key))); |
7353 if (di != NULL) | 7218 if (di != NULL) |
7360 | 7225 |
7361 /* | 7226 /* |
7362 * Make a copy of a Dictionary item. | 7227 * Make a copy of a Dictionary item. |
7363 */ | 7228 */ |
7364 static dictitem_T * | 7229 static dictitem_T * |
7365 dictitem_copy(org) | 7230 dictitem_copy(dictitem_T *org) |
7366 dictitem_T *org; | |
7367 { | 7231 { |
7368 dictitem_T *di; | 7232 dictitem_T *di; |
7369 | 7233 |
7370 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) | 7234 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) |
7371 + STRLEN(org->di_key))); | 7235 + STRLEN(org->di_key))); |
7380 | 7244 |
7381 /* | 7245 /* |
7382 * Remove item "item" from Dictionary "dict" and free it. | 7246 * Remove item "item" from Dictionary "dict" and free it. |
7383 */ | 7247 */ |
7384 static void | 7248 static void |
7385 dictitem_remove(dict, item) | 7249 dictitem_remove(dict_T *dict, dictitem_T *item) |
7386 dict_T *dict; | |
7387 dictitem_T *item; | |
7388 { | 7250 { |
7389 hashitem_T *hi; | 7251 hashitem_T *hi; |
7390 | 7252 |
7391 hi = hash_find(&dict->dv_hashtab, item->di_key); | 7253 hi = hash_find(&dict->dv_hashtab, item->di_key); |
7392 if (HASHITEM_EMPTY(hi)) | 7254 if (HASHITEM_EMPTY(hi)) |
7398 | 7260 |
7399 /* | 7261 /* |
7400 * Free a dict item. Also clears the value. | 7262 * Free a dict item. Also clears the value. |
7401 */ | 7263 */ |
7402 void | 7264 void |
7403 dictitem_free(item) | 7265 dictitem_free(dictitem_T *item) |
7404 dictitem_T *item; | |
7405 { | 7266 { |
7406 clear_tv(&item->di_tv); | 7267 clear_tv(&item->di_tv); |
7407 if (item->di_flags & DI_FLAGS_ALLOC) | 7268 if (item->di_flags & DI_FLAGS_ALLOC) |
7408 vim_free(item); | 7269 vim_free(item); |
7409 } | 7270 } |
7413 * The refcount of the new dict is set to 1. | 7274 * The refcount of the new dict is set to 1. |
7414 * See item_copy() for "copyID". | 7275 * See item_copy() for "copyID". |
7415 * Returns NULL when out of memory. | 7276 * Returns NULL when out of memory. |
7416 */ | 7277 */ |
7417 static dict_T * | 7278 static dict_T * |
7418 dict_copy(orig, deep, copyID) | 7279 dict_copy(dict_T *orig, int deep, int copyID) |
7419 dict_T *orig; | |
7420 int deep; | |
7421 int copyID; | |
7422 { | 7280 { |
7423 dict_T *copy; | 7281 dict_T *copy; |
7424 dictitem_T *di; | 7282 dictitem_T *di; |
7425 int todo; | 7283 int todo; |
7426 hashitem_T *hi; | 7284 hashitem_T *hi; |
7479 /* | 7337 /* |
7480 * Add item "item" to Dictionary "d". | 7338 * Add item "item" to Dictionary "d". |
7481 * Returns FAIL when out of memory and when key already exists. | 7339 * Returns FAIL when out of memory and when key already exists. |
7482 */ | 7340 */ |
7483 int | 7341 int |
7484 dict_add(d, item) | 7342 dict_add(dict_T *d, dictitem_T *item) |
7485 dict_T *d; | |
7486 dictitem_T *item; | |
7487 { | 7343 { |
7488 return hash_add(&d->dv_hashtab, item->di_key); | 7344 return hash_add(&d->dv_hashtab, item->di_key); |
7489 } | 7345 } |
7490 | 7346 |
7491 /* | 7347 /* |
7492 * Add a number or string entry to dictionary "d". | 7348 * Add a number or string entry to dictionary "d". |
7493 * When "str" is NULL use number "nr", otherwise use "str". | 7349 * When "str" is NULL use number "nr", otherwise use "str". |
7494 * Returns FAIL when out of memory and when key already exists. | 7350 * Returns FAIL when out of memory and when key already exists. |
7495 */ | 7351 */ |
7496 int | 7352 int |
7497 dict_add_nr_str(d, key, nr, str) | 7353 dict_add_nr_str( |
7498 dict_T *d; | 7354 dict_T *d, |
7499 char *key; | 7355 char *key, |
7500 long nr; | 7356 long nr, |
7501 char_u *str; | 7357 char_u *str) |
7502 { | 7358 { |
7503 dictitem_T *item; | 7359 dictitem_T *item; |
7504 | 7360 |
7505 item = dictitem_alloc((char_u *)key); | 7361 item = dictitem_alloc((char_u *)key); |
7506 if (item == NULL) | 7362 if (item == NULL) |
7527 /* | 7383 /* |
7528 * Add a list entry to dictionary "d". | 7384 * Add a list entry to dictionary "d". |
7529 * Returns FAIL when out of memory and when key already exists. | 7385 * Returns FAIL when out of memory and when key already exists. |
7530 */ | 7386 */ |
7531 int | 7387 int |
7532 dict_add_list(d, key, list) | 7388 dict_add_list(dict_T *d, char *key, list_T *list) |
7533 dict_T *d; | |
7534 char *key; | |
7535 list_T *list; | |
7536 { | 7389 { |
7537 dictitem_T *item; | 7390 dictitem_T *item; |
7538 | 7391 |
7539 item = dictitem_alloc((char_u *)key); | 7392 item = dictitem_alloc((char_u *)key); |
7540 if (item == NULL) | 7393 if (item == NULL) |
7553 | 7406 |
7554 /* | 7407 /* |
7555 * Get the number of items in a Dictionary. | 7408 * Get the number of items in a Dictionary. |
7556 */ | 7409 */ |
7557 static long | 7410 static long |
7558 dict_len(d) | 7411 dict_len(dict_T *d) |
7559 dict_T *d; | |
7560 { | 7412 { |
7561 if (d == NULL) | 7413 if (d == NULL) |
7562 return 0L; | 7414 return 0L; |
7563 return (long)d->dv_hashtab.ht_used; | 7415 return (long)d->dv_hashtab.ht_used; |
7564 } | 7416 } |
7567 * Find item "key[len]" in Dictionary "d". | 7419 * Find item "key[len]" in Dictionary "d". |
7568 * If "len" is negative use strlen(key). | 7420 * If "len" is negative use strlen(key). |
7569 * Returns NULL when not found. | 7421 * Returns NULL when not found. |
7570 */ | 7422 */ |
7571 dictitem_T * | 7423 dictitem_T * |
7572 dict_find(d, key, len) | 7424 dict_find(dict_T *d, char_u *key, int len) |
7573 dict_T *d; | |
7574 char_u *key; | |
7575 int len; | |
7576 { | 7425 { |
7577 #define AKEYLEN 200 | 7426 #define AKEYLEN 200 |
7578 char_u buf[AKEYLEN]; | 7427 char_u buf[AKEYLEN]; |
7579 char_u *akey; | 7428 char_u *akey; |
7580 char_u *tofree = NULL; | 7429 char_u *tofree = NULL; |
7606 * Get a string item from a dictionary. | 7455 * Get a string item from a dictionary. |
7607 * When "save" is TRUE allocate memory for it. | 7456 * When "save" is TRUE allocate memory for it. |
7608 * Returns NULL if the entry doesn't exist or out of memory. | 7457 * Returns NULL if the entry doesn't exist or out of memory. |
7609 */ | 7458 */ |
7610 char_u * | 7459 char_u * |
7611 get_dict_string(d, key, save) | 7460 get_dict_string(dict_T *d, char_u *key, int save) |
7612 dict_T *d; | |
7613 char_u *key; | |
7614 int save; | |
7615 { | 7461 { |
7616 dictitem_T *di; | 7462 dictitem_T *di; |
7617 char_u *s; | 7463 char_u *s; |
7618 | 7464 |
7619 di = dict_find(d, key, -1); | 7465 di = dict_find(d, key, -1); |
7628 /* | 7474 /* |
7629 * Get a number item from a dictionary. | 7475 * Get a number item from a dictionary. |
7630 * Returns 0 if the entry doesn't exist or out of memory. | 7476 * Returns 0 if the entry doesn't exist or out of memory. |
7631 */ | 7477 */ |
7632 long | 7478 long |
7633 get_dict_number(d, key) | 7479 get_dict_number(dict_T *d, char_u *key) |
7634 dict_T *d; | |
7635 char_u *key; | |
7636 { | 7480 { |
7637 dictitem_T *di; | 7481 dictitem_T *di; |
7638 | 7482 |
7639 di = dict_find(d, key, -1); | 7483 di = dict_find(d, key, -1); |
7640 if (di == NULL) | 7484 if (di == NULL) |
7645 /* | 7489 /* |
7646 * Return an allocated string with the string representation of a Dictionary. | 7490 * Return an allocated string with the string representation of a Dictionary. |
7647 * May return NULL. | 7491 * May return NULL. |
7648 */ | 7492 */ |
7649 static char_u * | 7493 static char_u * |
7650 dict2string(tv, copyID) | 7494 dict2string(typval_T *tv, int copyID) |
7651 typval_T *tv; | |
7652 int copyID; | |
7653 { | 7495 { |
7654 garray_T ga; | 7496 garray_T ga; |
7655 int first = TRUE; | 7497 int first = TRUE; |
7656 char_u *tofree; | 7498 char_u *tofree; |
7657 char_u numbuf[NUMBUFLEN]; | 7499 char_u numbuf[NUMBUFLEN]; |
7708 /* | 7550 /* |
7709 * Allocate a variable for a Dictionary and fill it from "*arg". | 7551 * Allocate a variable for a Dictionary and fill it from "*arg". |
7710 * Return OK or FAIL. Returns NOTDONE for {expr}. | 7552 * Return OK or FAIL. Returns NOTDONE for {expr}. |
7711 */ | 7553 */ |
7712 static int | 7554 static int |
7713 get_dict_tv(arg, rettv, evaluate) | 7555 get_dict_tv(char_u **arg, typval_T *rettv, int evaluate) |
7714 char_u **arg; | |
7715 typval_T *rettv; | |
7716 int evaluate; | |
7717 { | 7556 { |
7718 dict_T *d = NULL; | 7557 dict_T *d = NULL; |
7719 typval_T tvkey; | 7558 typval_T tvkey; |
7720 typval_T tv; | 7559 typval_T tv; |
7721 char_u *key = NULL; | 7560 char_u *key = NULL; |
7850 * Does not put quotes around strings, as ":echo" displays values. | 7689 * Does not put quotes around strings, as ":echo" displays values. |
7851 * When "copyID" is not NULL replace recursive lists and dicts with "...". | 7690 * When "copyID" is not NULL replace recursive lists and dicts with "...". |
7852 * May return NULL. | 7691 * May return NULL. |
7853 */ | 7692 */ |
7854 static char_u * | 7693 static char_u * |
7855 echo_string(tv, tofree, numbuf, copyID) | 7694 echo_string( |
7856 typval_T *tv; | 7695 typval_T *tv, |
7857 char_u **tofree; | 7696 char_u **tofree, |
7858 char_u *numbuf; | 7697 char_u *numbuf, |
7859 int copyID; | 7698 int copyID) |
7860 { | 7699 { |
7861 static int recurse = 0; | 7700 static int recurse = 0; |
7862 char_u *r = NULL; | 7701 char_u *r = NULL; |
7863 | 7702 |
7864 if (recurse >= DICT_MAXNEST) | 7703 if (recurse >= DICT_MAXNEST) |
7956 * "numbuf" is used for a number. | 7795 * "numbuf" is used for a number. |
7957 * Puts quotes around strings, so that they can be parsed back by eval(). | 7796 * Puts quotes around strings, so that they can be parsed back by eval(). |
7958 * May return NULL. | 7797 * May return NULL. |
7959 */ | 7798 */ |
7960 static char_u * | 7799 static char_u * |
7961 tv2string(tv, tofree, numbuf, copyID) | 7800 tv2string( |
7962 typval_T *tv; | 7801 typval_T *tv, |
7963 char_u **tofree; | 7802 char_u **tofree, |
7964 char_u *numbuf; | 7803 char_u *numbuf, |
7965 int copyID; | 7804 int copyID) |
7966 { | 7805 { |
7967 switch (tv->v_type) | 7806 switch (tv->v_type) |
7968 { | 7807 { |
7969 case VAR_FUNC: | 7808 case VAR_FUNC: |
7970 *tofree = string_quote(tv->vval.v_string, TRUE); | 7809 *tofree = string_quote(tv->vval.v_string, TRUE); |
7993 * Return string "str" in ' quotes, doubling ' characters. | 7832 * Return string "str" in ' quotes, doubling ' characters. |
7994 * If "str" is NULL an empty string is assumed. | 7833 * If "str" is NULL an empty string is assumed. |
7995 * If "function" is TRUE make it function('string'). | 7834 * If "function" is TRUE make it function('string'). |
7996 */ | 7835 */ |
7997 static char_u * | 7836 static char_u * |
7998 string_quote(str, function) | 7837 string_quote(char_u *str, int function) |
7999 char_u *str; | |
8000 int function; | |
8001 { | 7838 { |
8002 unsigned len; | 7839 unsigned len; |
8003 char_u *p, *r, *s; | 7840 char_u *p, *r, *s; |
8004 | 7841 |
8005 len = (function ? 13 : 3); | 7842 len = (function ? 13 : 3); |
8041 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | 7878 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure |
8042 * this always uses a decimal point. | 7879 * this always uses a decimal point. |
8043 * Returns the length of the text that was consumed. | 7880 * Returns the length of the text that was consumed. |
8044 */ | 7881 */ |
8045 int | 7882 int |
8046 string2float(text, value) | 7883 string2float( |
8047 char_u *text; | 7884 char_u *text, |
8048 float_T *value; /* result stored here */ | 7885 float_T *value) /* result stored here */ |
8049 { | 7886 { |
8050 char *s = (char *)text; | 7887 char *s = (char *)text; |
8051 float_T f; | 7888 float_T f; |
8052 | 7889 |
8053 f = strtod(s, &s); | 7890 f = strtod(s, &s); |
8061 * "arg" is pointing to the '$'. It is advanced to after the name. | 7898 * "arg" is pointing to the '$'. It is advanced to after the name. |
8062 * If the environment variable was not set, silently assume it is empty. | 7899 * If the environment variable was not set, silently assume it is empty. |
8063 * Return FAIL if the name is invalid. | 7900 * Return FAIL if the name is invalid. |
8064 */ | 7901 */ |
8065 static int | 7902 static int |
8066 get_env_tv(arg, rettv, evaluate) | 7903 get_env_tv(char_u **arg, typval_T *rettv, int evaluate) |
8067 char_u **arg; | |
8068 typval_T *rettv; | |
8069 int evaluate; | |
8070 { | 7904 { |
8071 char_u *string = NULL; | 7905 char_u *string = NULL; |
8072 int len; | 7906 int len; |
8073 int cc; | 7907 int cc; |
8074 char_u *name; | 7908 char_u *name; |
8479 /* | 8313 /* |
8480 * Function given to ExpandGeneric() to obtain the list of internal | 8314 * Function given to ExpandGeneric() to obtain the list of internal |
8481 * or user defined function names. | 8315 * or user defined function names. |
8482 */ | 8316 */ |
8483 char_u * | 8317 char_u * |
8484 get_function_name(xp, idx) | 8318 get_function_name(expand_T *xp, int idx) |
8485 expand_T *xp; | |
8486 int idx; | |
8487 { | 8319 { |
8488 static int intidx = -1; | 8320 static int intidx = -1; |
8489 char_u *name; | 8321 char_u *name; |
8490 | 8322 |
8491 if (idx == 0) | 8323 if (idx == 0) |
8511 /* | 8343 /* |
8512 * Function given to ExpandGeneric() to obtain the list of internal or | 8344 * Function given to ExpandGeneric() to obtain the list of internal or |
8513 * user defined variable or function names. | 8345 * user defined variable or function names. |
8514 */ | 8346 */ |
8515 char_u * | 8347 char_u * |
8516 get_expr_name(xp, idx) | 8348 get_expr_name(expand_T *xp, int idx) |
8517 expand_T *xp; | |
8518 int idx; | |
8519 { | 8349 { |
8520 static int intidx = -1; | 8350 static int intidx = -1; |
8521 char_u *name; | 8351 char_u *name; |
8522 | 8352 |
8523 if (idx == 0) | 8353 if (idx == 0) |
8536 #if defined(EBCDIC) || defined(PROTO) | 8366 #if defined(EBCDIC) || defined(PROTO) |
8537 /* | 8367 /* |
8538 * Compare struct fst by function name. | 8368 * Compare struct fst by function name. |
8539 */ | 8369 */ |
8540 static int | 8370 static int |
8541 compare_func_name(s1, s2) | 8371 compare_func_name(const void *s1, const void *s2) |
8542 const void *s1; | |
8543 const void *s2; | |
8544 { | 8372 { |
8545 struct fst *p1 = (struct fst *)s1; | 8373 struct fst *p1 = (struct fst *)s1; |
8546 struct fst *p2 = (struct fst *)s2; | 8374 struct fst *p2 = (struct fst *)s2; |
8547 | 8375 |
8548 return STRCMP(p1->f_name, p2->f_name); | 8376 return STRCMP(p1->f_name, p2->f_name); |
8552 * Sort the function table by function name. | 8380 * Sort the function table by function name. |
8553 * The sorting of the table above is ASCII dependant. | 8381 * The sorting of the table above is ASCII dependant. |
8554 * On machines using EBCDIC we have to sort it. | 8382 * On machines using EBCDIC we have to sort it. |
8555 */ | 8383 */ |
8556 static void | 8384 static void |
8557 sortFunctions() | 8385 sortFunctions(void) |
8558 { | 8386 { |
8559 int funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1; | 8387 int funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1; |
8560 | 8388 |
8561 qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name); | 8389 qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name); |
8562 } | 8390 } |
8566 /* | 8394 /* |
8567 * Find internal function in table above. | 8395 * Find internal function in table above. |
8568 * Return index, or -1 if not found | 8396 * Return index, or -1 if not found |
8569 */ | 8397 */ |
8570 static int | 8398 static int |
8571 find_internal_func(name) | 8399 find_internal_func( |
8572 char_u *name; /* name of the function */ | 8400 char_u *name) /* name of the function */ |
8573 { | 8401 { |
8574 int first = 0; | 8402 int first = 0; |
8575 int last = (int)(sizeof(functions) / sizeof(struct fst)) - 1; | 8403 int last = (int)(sizeof(functions) / sizeof(struct fst)) - 1; |
8576 int cmp; | 8404 int cmp; |
8577 int x; | 8405 int x; |
8596 /* | 8424 /* |
8597 * Check if "name" is a variable of type VAR_FUNC. If so, return the function | 8425 * Check if "name" is a variable of type VAR_FUNC. If so, return the function |
8598 * name it contains, otherwise return "name". | 8426 * name it contains, otherwise return "name". |
8599 */ | 8427 */ |
8600 static char_u * | 8428 static char_u * |
8601 deref_func_name(name, lenp, no_autoload) | 8429 deref_func_name(char_u *name, int *lenp, int no_autoload) |
8602 char_u *name; | |
8603 int *lenp; | |
8604 int no_autoload; | |
8605 { | 8430 { |
8606 dictitem_T *v; | 8431 dictitem_T *v; |
8607 int cc; | 8432 int cc; |
8608 | 8433 |
8609 cc = name[*lenp]; | 8434 cc = name[*lenp]; |
8627 /* | 8452 /* |
8628 * Allocate a variable for the result of a function. | 8453 * Allocate a variable for the result of a function. |
8629 * Return OK or FAIL. | 8454 * Return OK or FAIL. |
8630 */ | 8455 */ |
8631 static int | 8456 static int |
8632 get_func_tv(name, len, rettv, arg, firstline, lastline, doesrange, | 8457 get_func_tv( |
8633 evaluate, selfdict) | 8458 char_u *name, /* name of the function */ |
8634 char_u *name; /* name of the function */ | 8459 int len, /* length of "name" */ |
8635 int len; /* length of "name" */ | 8460 typval_T *rettv, |
8636 typval_T *rettv; | 8461 char_u **arg, /* argument, pointing to the '(' */ |
8637 char_u **arg; /* argument, pointing to the '(' */ | 8462 linenr_T firstline, /* first line of range */ |
8638 linenr_T firstline; /* first line of range */ | 8463 linenr_T lastline, /* last line of range */ |
8639 linenr_T lastline; /* last line of range */ | 8464 int *doesrange, /* return: function handled range */ |
8640 int *doesrange; /* return: function handled range */ | 8465 int evaluate, |
8641 int evaluate; | 8466 dict_T *selfdict) /* Dictionary for "self" */ |
8642 dict_T *selfdict; /* Dictionary for "self" */ | |
8643 { | 8467 { |
8644 char_u *argp; | 8468 char_u *argp; |
8645 int ret = OK; | 8469 int ret = OK; |
8646 typval_T argvars[MAX_FUNC_ARGS + 1]; /* vars for arguments */ | 8470 typval_T argvars[MAX_FUNC_ARGS + 1]; /* vars for arguments */ |
8647 int argcount = 0; /* number of arguments found */ | 8471 int argcount = 0; /* number of arguments found */ |
8692 * Call a function with its resolved parameters | 8516 * Call a function with its resolved parameters |
8693 * Return FAIL when the function can't be called, OK otherwise. | 8517 * Return FAIL when the function can't be called, OK otherwise. |
8694 * Also returns OK when an error was encountered while executing the function. | 8518 * Also returns OK when an error was encountered while executing the function. |
8695 */ | 8519 */ |
8696 int | 8520 int |
8697 call_func(funcname, len, rettv, argcount, argvars, firstline, lastline, | 8521 call_func( |
8698 doesrange, evaluate, selfdict) | 8522 char_u *funcname, /* name of the function */ |
8699 char_u *funcname; /* name of the function */ | 8523 int len, /* length of "name" */ |
8700 int len; /* length of "name" */ | 8524 typval_T *rettv, /* return value goes here */ |
8701 typval_T *rettv; /* return value goes here */ | 8525 int argcount, /* number of "argvars" */ |
8702 int argcount; /* number of "argvars" */ | 8526 typval_T *argvars, /* vars for arguments, must have "argcount" |
8703 typval_T *argvars; /* vars for arguments, must have "argcount" | |
8704 PLUS ONE elements! */ | 8527 PLUS ONE elements! */ |
8705 linenr_T firstline; /* first line of range */ | 8528 linenr_T firstline, /* first line of range */ |
8706 linenr_T lastline; /* last line of range */ | 8529 linenr_T lastline, /* last line of range */ |
8707 int *doesrange; /* return: function handled range */ | 8530 int *doesrange, /* return: function handled range */ |
8708 int evaluate; | 8531 int evaluate, |
8709 dict_T *selfdict; /* Dictionary for "self" */ | 8532 dict_T *selfdict) /* Dictionary for "self" */ |
8710 { | 8533 { |
8711 int ret = FAIL; | 8534 int ret = FAIL; |
8712 #define ERROR_UNKNOWN 0 | 8535 #define ERROR_UNKNOWN 0 |
8713 #define ERROR_TOOMANY 1 | 8536 #define ERROR_TOOMANY 1 |
8714 #define ERROR_TOOFEW 2 | 8537 #define ERROR_TOOFEW 2 |
8931 /* | 8754 /* |
8932 * Give an error message with a function name. Handle <SNR> things. | 8755 * Give an error message with a function name. Handle <SNR> things. |
8933 * "ermsg" is to be passed without translation, use N_() instead of _(). | 8756 * "ermsg" is to be passed without translation, use N_() instead of _(). |
8934 */ | 8757 */ |
8935 static void | 8758 static void |
8936 emsg_funcname(ermsg, name) | 8759 emsg_funcname(char *ermsg, char_u *name) |
8937 char *ermsg; | |
8938 char_u *name; | |
8939 { | 8760 { |
8940 char_u *p; | 8761 char_u *p; |
8941 | 8762 |
8942 if (*name == K_SPECIAL) | 8763 if (*name == K_SPECIAL) |
8943 p = concat_str((char_u *)"<SNR>", name + 3); | 8764 p = concat_str((char_u *)"<SNR>", name + 3); |
8950 | 8771 |
8951 /* | 8772 /* |
8952 * Return TRUE for a non-zero Number and a non-empty String. | 8773 * Return TRUE for a non-zero Number and a non-empty String. |
8953 */ | 8774 */ |
8954 static int | 8775 static int |
8955 non_zero_arg(argvars) | 8776 non_zero_arg(typval_T *argvars) |
8956 typval_T *argvars; | |
8957 { | 8777 { |
8958 return ((argvars[0].v_type == VAR_NUMBER | 8778 return ((argvars[0].v_type == VAR_NUMBER |
8959 && argvars[0].vval.v_number != 0) | 8779 && argvars[0].vval.v_number != 0) |
8960 || (argvars[0].v_type == VAR_STRING | 8780 || (argvars[0].v_type == VAR_STRING |
8961 && argvars[0].vval.v_string != NULL | 8781 && argvars[0].vval.v_string != NULL |
8972 /* | 8792 /* |
8973 * Get the float value of "argvars[0]" into "f". | 8793 * Get the float value of "argvars[0]" into "f". |
8974 * Returns FAIL when the argument is not a Number or Float. | 8794 * Returns FAIL when the argument is not a Number or Float. |
8975 */ | 8795 */ |
8976 static int | 8796 static int |
8977 get_float_arg(argvars, f) | 8797 get_float_arg(typval_T *argvars, float_T *f) |
8978 typval_T *argvars; | |
8979 float_T *f; | |
8980 { | 8798 { |
8981 if (argvars[0].v_type == VAR_FLOAT) | 8799 if (argvars[0].v_type == VAR_FLOAT) |
8982 { | 8800 { |
8983 *f = argvars[0].vval.v_float; | 8801 *f = argvars[0].vval.v_float; |
8984 return OK; | 8802 return OK; |
8994 | 8812 |
8995 /* | 8813 /* |
8996 * "abs(expr)" function | 8814 * "abs(expr)" function |
8997 */ | 8815 */ |
8998 static void | 8816 static void |
8999 f_abs(argvars, rettv) | 8817 f_abs(typval_T *argvars, typval_T *rettv) |
9000 typval_T *argvars; | |
9001 typval_T *rettv; | |
9002 { | 8818 { |
9003 if (argvars[0].v_type == VAR_FLOAT) | 8819 if (argvars[0].v_type == VAR_FLOAT) |
9004 { | 8820 { |
9005 rettv->v_type = VAR_FLOAT; | 8821 rettv->v_type = VAR_FLOAT; |
9006 rettv->vval.v_float = fabs(argvars[0].vval.v_float); | 8822 rettv->vval.v_float = fabs(argvars[0].vval.v_float); |
9022 | 8838 |
9023 /* | 8839 /* |
9024 * "acos()" function | 8840 * "acos()" function |
9025 */ | 8841 */ |
9026 static void | 8842 static void |
9027 f_acos(argvars, rettv) | 8843 f_acos(typval_T *argvars, typval_T *rettv) |
9028 typval_T *argvars; | |
9029 typval_T *rettv; | |
9030 { | 8844 { |
9031 float_T f; | 8845 float_T f; |
9032 | 8846 |
9033 rettv->v_type = VAR_FLOAT; | 8847 rettv->v_type = VAR_FLOAT; |
9034 if (get_float_arg(argvars, &f) == OK) | 8848 if (get_float_arg(argvars, &f) == OK) |
9040 | 8854 |
9041 /* | 8855 /* |
9042 * "add(list, item)" function | 8856 * "add(list, item)" function |
9043 */ | 8857 */ |
9044 static void | 8858 static void |
9045 f_add(argvars, rettv) | 8859 f_add(typval_T *argvars, typval_T *rettv) |
9046 typval_T *argvars; | |
9047 typval_T *rettv; | |
9048 { | 8860 { |
9049 list_T *l; | 8861 list_T *l; |
9050 | 8862 |
9051 rettv->vval.v_number = 1; /* Default: Failed */ | 8863 rettv->vval.v_number = 1; /* Default: Failed */ |
9052 if (argvars[0].v_type == VAR_LIST) | 8864 if (argvars[0].v_type == VAR_LIST) |
9063 | 8875 |
9064 /* | 8876 /* |
9065 * "alloc_fail(id, countdown, repeat)" function | 8877 * "alloc_fail(id, countdown, repeat)" function |
9066 */ | 8878 */ |
9067 static void | 8879 static void |
9068 f_alloc_fail(argvars, rettv) | 8880 f_alloc_fail(typval_T *argvars, typval_T *rettv UNUSED) |
9069 typval_T *argvars; | |
9070 typval_T *rettv UNUSED; | |
9071 { | 8881 { |
9072 if (argvars[0].v_type != VAR_NUMBER | 8882 if (argvars[0].v_type != VAR_NUMBER |
9073 || argvars[0].vval.v_number <= 0 | 8883 || argvars[0].vval.v_number <= 0 |
9074 || argvars[1].v_type != VAR_NUMBER | 8884 || argvars[1].v_type != VAR_NUMBER |
9075 || argvars[1].vval.v_number < 0 | 8885 || argvars[1].vval.v_number < 0 |
9088 | 8898 |
9089 /* | 8899 /* |
9090 * "and(expr, expr)" function | 8900 * "and(expr, expr)" function |
9091 */ | 8901 */ |
9092 static void | 8902 static void |
9093 f_and(argvars, rettv) | 8903 f_and(typval_T *argvars, typval_T *rettv) |
9094 typval_T *argvars; | |
9095 typval_T *rettv; | |
9096 { | 8904 { |
9097 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | 8905 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) |
9098 & get_tv_number_chk(&argvars[1], NULL); | 8906 & get_tv_number_chk(&argvars[1], NULL); |
9099 } | 8907 } |
9100 | 8908 |
9101 /* | 8909 /* |
9102 * "append(lnum, string/list)" function | 8910 * "append(lnum, string/list)" function |
9103 */ | 8911 */ |
9104 static void | 8912 static void |
9105 f_append(argvars, rettv) | 8913 f_append(typval_T *argvars, typval_T *rettv) |
9106 typval_T *argvars; | |
9107 typval_T *rettv; | |
9108 { | 8914 { |
9109 long lnum; | 8915 long lnum; |
9110 char_u *line; | 8916 char_u *line; |
9111 list_T *l = NULL; | 8917 list_T *l = NULL; |
9112 listitem_T *li = NULL; | 8918 listitem_T *li = NULL; |
9164 | 8970 |
9165 /* | 8971 /* |
9166 * "argc()" function | 8972 * "argc()" function |
9167 */ | 8973 */ |
9168 static void | 8974 static void |
9169 f_argc(argvars, rettv) | 8975 f_argc(typval_T *argvars UNUSED, typval_T *rettv) |
9170 typval_T *argvars UNUSED; | |
9171 typval_T *rettv; | |
9172 { | 8976 { |
9173 rettv->vval.v_number = ARGCOUNT; | 8977 rettv->vval.v_number = ARGCOUNT; |
9174 } | 8978 } |
9175 | 8979 |
9176 /* | 8980 /* |
9177 * "argidx()" function | 8981 * "argidx()" function |
9178 */ | 8982 */ |
9179 static void | 8983 static void |
9180 f_argidx(argvars, rettv) | 8984 f_argidx(typval_T *argvars UNUSED, typval_T *rettv) |
9181 typval_T *argvars UNUSED; | |
9182 typval_T *rettv; | |
9183 { | 8985 { |
9184 rettv->vval.v_number = curwin->w_arg_idx; | 8986 rettv->vval.v_number = curwin->w_arg_idx; |
9185 } | 8987 } |
9186 | 8988 |
9187 /* | 8989 /* |
9188 * "arglistid()" function | 8990 * "arglistid()" function |
9189 */ | 8991 */ |
9190 static void | 8992 static void |
9191 f_arglistid(argvars, rettv) | 8993 f_arglistid(typval_T *argvars UNUSED, typval_T *rettv) |
9192 typval_T *argvars UNUSED; | |
9193 typval_T *rettv; | |
9194 { | 8994 { |
9195 win_T *wp; | 8995 win_T *wp; |
9196 | 8996 |
9197 rettv->vval.v_number = -1; | 8997 rettv->vval.v_number = -1; |
9198 wp = find_tabwin(&argvars[0], &argvars[1]); | 8998 wp = find_tabwin(&argvars[0], &argvars[1]); |
9202 | 9002 |
9203 /* | 9003 /* |
9204 * "argv(nr)" function | 9004 * "argv(nr)" function |
9205 */ | 9005 */ |
9206 static void | 9006 static void |
9207 f_argv(argvars, rettv) | 9007 f_argv(typval_T *argvars, typval_T *rettv) |
9208 typval_T *argvars; | |
9209 typval_T *rettv; | |
9210 { | 9008 { |
9211 int idx; | 9009 int idx; |
9212 | 9010 |
9213 if (argvars[0].v_type != VAR_UNKNOWN) | 9011 if (argvars[0].v_type != VAR_UNKNOWN) |
9214 { | 9012 { |
9232 | 9030 |
9233 /* | 9031 /* |
9234 * Prepare "gap" for an assert error and add the sourcing position. | 9032 * Prepare "gap" for an assert error and add the sourcing position. |
9235 */ | 9033 */ |
9236 static void | 9034 static void |
9237 prepare_assert_error(gap) | 9035 prepare_assert_error(garray_T *gap) |
9238 garray_T *gap; | |
9239 { | 9036 { |
9240 char buf[NUMBUFLEN]; | 9037 char buf[NUMBUFLEN]; |
9241 | 9038 |
9242 ga_init2(gap, 1, 100); | 9039 ga_init2(gap, 1, 100); |
9243 if (sourcing_name != NULL) | 9040 if (sourcing_name != NULL) |
9257 | 9054 |
9258 /* | 9055 /* |
9259 * Fill "gap" with information about an assert error. | 9056 * Fill "gap" with information about an assert error. |
9260 */ | 9057 */ |
9261 static void | 9058 static void |
9262 fill_assert_error(gap, opt_msg_tv, exp_str, exp_tv, got_tv) | 9059 fill_assert_error( |
9263 garray_T *gap; | 9060 garray_T *gap, |
9264 typval_T *opt_msg_tv; | 9061 typval_T *opt_msg_tv, |
9265 char_u *exp_str; | 9062 char_u *exp_str, |
9266 typval_T *exp_tv; | 9063 typval_T *exp_tv, |
9267 typval_T *got_tv; | 9064 typval_T *got_tv) |
9268 { | 9065 { |
9269 char_u numbuf[NUMBUFLEN]; | 9066 char_u numbuf[NUMBUFLEN]; |
9270 char_u *tofree; | 9067 char_u *tofree; |
9271 | 9068 |
9272 if (opt_msg_tv->v_type != VAR_UNKNOWN) | 9069 if (opt_msg_tv->v_type != VAR_UNKNOWN) |
9292 | 9089 |
9293 /* | 9090 /* |
9294 * Add an assert error to v:errors. | 9091 * Add an assert error to v:errors. |
9295 */ | 9092 */ |
9296 static void | 9093 static void |
9297 assert_error(gap) | 9094 assert_error(garray_T *gap) |
9298 garray_T *gap; | |
9299 { | 9095 { |
9300 struct vimvar *vp = &vimvars[VV_ERRORS]; | 9096 struct vimvar *vp = &vimvars[VV_ERRORS]; |
9301 | 9097 |
9302 if (vp->vv_type != VAR_LIST || vimvars[VV_ERRORS].vv_list == NULL) | 9098 if (vp->vv_type != VAR_LIST || vimvars[VV_ERRORS].vv_list == NULL) |
9303 /* Make sure v:errors is a list. */ | 9099 /* Make sure v:errors is a list. */ |
9307 | 9103 |
9308 /* | 9104 /* |
9309 * "assert_equal(expected, actual[, msg])" function | 9105 * "assert_equal(expected, actual[, msg])" function |
9310 */ | 9106 */ |
9311 static void | 9107 static void |
9312 f_assert_equal(argvars, rettv) | 9108 f_assert_equal(typval_T *argvars, typval_T *rettv UNUSED) |
9313 typval_T *argvars; | |
9314 typval_T *rettv UNUSED; | |
9315 { | 9109 { |
9316 garray_T ga; | 9110 garray_T ga; |
9317 | 9111 |
9318 if (!tv_equal(&argvars[0], &argvars[1], FALSE, FALSE)) | 9112 if (!tv_equal(&argvars[0], &argvars[1], FALSE, FALSE)) |
9319 { | 9113 { |
9326 | 9120 |
9327 /* | 9121 /* |
9328 * "assert_exception(string[, msg])" function | 9122 * "assert_exception(string[, msg])" function |
9329 */ | 9123 */ |
9330 static void | 9124 static void |
9331 f_assert_exception(argvars, rettv) | 9125 f_assert_exception(typval_T *argvars, typval_T *rettv UNUSED) |
9332 typval_T *argvars; | |
9333 typval_T *rettv UNUSED; | |
9334 { | 9126 { |
9335 garray_T ga; | 9127 garray_T ga; |
9336 char *error; | 9128 char *error; |
9337 | 9129 |
9338 error = (char *)get_tv_string_chk(&argvars[0]); | 9130 error = (char *)get_tv_string_chk(&argvars[0]); |
9356 | 9148 |
9357 /* | 9149 /* |
9358 * "assert_fails(cmd [, error])" function | 9150 * "assert_fails(cmd [, error])" function |
9359 */ | 9151 */ |
9360 static void | 9152 static void |
9361 f_assert_fails(argvars, rettv) | 9153 f_assert_fails(typval_T *argvars, typval_T *rettv UNUSED) |
9362 typval_T *argvars; | |
9363 typval_T *rettv UNUSED; | |
9364 { | 9154 { |
9365 char_u *cmd = get_tv_string_chk(&argvars[0]); | 9155 char_u *cmd = get_tv_string_chk(&argvars[0]); |
9366 garray_T ga; | 9156 garray_T ga; |
9367 | 9157 |
9368 called_emsg = FALSE; | 9158 called_emsg = FALSE; |
9401 | 9191 |
9402 /* | 9192 /* |
9403 * Common for assert_true() and assert_false(). | 9193 * Common for assert_true() and assert_false(). |
9404 */ | 9194 */ |
9405 static void | 9195 static void |
9406 assert_bool(argvars, isTrue) | 9196 assert_bool(typval_T *argvars, int isTrue) |
9407 typval_T *argvars; | |
9408 int isTrue; | |
9409 { | 9197 { |
9410 int error = FALSE; | 9198 int error = FALSE; |
9411 garray_T ga; | 9199 garray_T ga; |
9412 | 9200 |
9413 if (argvars[0].v_type != VAR_NUMBER | 9201 if (argvars[0].v_type != VAR_NUMBER |
9425 | 9213 |
9426 /* | 9214 /* |
9427 * "assert_false(actual[, msg])" function | 9215 * "assert_false(actual[, msg])" function |
9428 */ | 9216 */ |
9429 static void | 9217 static void |
9430 f_assert_false(argvars, rettv) | 9218 f_assert_false(typval_T *argvars, typval_T *rettv UNUSED) |
9431 typval_T *argvars; | |
9432 typval_T *rettv UNUSED; | |
9433 { | 9219 { |
9434 assert_bool(argvars, FALSE); | 9220 assert_bool(argvars, FALSE); |
9435 } | 9221 } |
9436 | 9222 |
9437 /* | 9223 /* |
9438 * "assert_true(actual[, msg])" function | 9224 * "assert_true(actual[, msg])" function |
9439 */ | 9225 */ |
9440 static void | 9226 static void |
9441 f_assert_true(argvars, rettv) | 9227 f_assert_true(typval_T *argvars, typval_T *rettv UNUSED) |
9442 typval_T *argvars; | |
9443 typval_T *rettv UNUSED; | |
9444 { | 9228 { |
9445 assert_bool(argvars, TRUE); | 9229 assert_bool(argvars, TRUE); |
9446 } | 9230 } |
9447 | 9231 |
9448 #ifdef FEAT_FLOAT | 9232 #ifdef FEAT_FLOAT |
9449 /* | 9233 /* |
9450 * "asin()" function | 9234 * "asin()" function |
9451 */ | 9235 */ |
9452 static void | 9236 static void |
9453 f_asin(argvars, rettv) | 9237 f_asin(typval_T *argvars, typval_T *rettv) |
9454 typval_T *argvars; | |
9455 typval_T *rettv; | |
9456 { | 9238 { |
9457 float_T f; | 9239 float_T f; |
9458 | 9240 |
9459 rettv->v_type = VAR_FLOAT; | 9241 rettv->v_type = VAR_FLOAT; |
9460 if (get_float_arg(argvars, &f) == OK) | 9242 if (get_float_arg(argvars, &f) == OK) |
9465 | 9247 |
9466 /* | 9248 /* |
9467 * "atan()" function | 9249 * "atan()" function |
9468 */ | 9250 */ |
9469 static void | 9251 static void |
9470 f_atan(argvars, rettv) | 9252 f_atan(typval_T *argvars, typval_T *rettv) |
9471 typval_T *argvars; | |
9472 typval_T *rettv; | |
9473 { | 9253 { |
9474 float_T f; | 9254 float_T f; |
9475 | 9255 |
9476 rettv->v_type = VAR_FLOAT; | 9256 rettv->v_type = VAR_FLOAT; |
9477 if (get_float_arg(argvars, &f) == OK) | 9257 if (get_float_arg(argvars, &f) == OK) |
9482 | 9262 |
9483 /* | 9263 /* |
9484 * "atan2()" function | 9264 * "atan2()" function |
9485 */ | 9265 */ |
9486 static void | 9266 static void |
9487 f_atan2(argvars, rettv) | 9267 f_atan2(typval_T *argvars, typval_T *rettv) |
9488 typval_T *argvars; | |
9489 typval_T *rettv; | |
9490 { | 9268 { |
9491 float_T fx, fy; | 9269 float_T fx, fy; |
9492 | 9270 |
9493 rettv->v_type = VAR_FLOAT; | 9271 rettv->v_type = VAR_FLOAT; |
9494 if (get_float_arg(argvars, &fx) == OK | 9272 if (get_float_arg(argvars, &fx) == OK |
9501 | 9279 |
9502 /* | 9280 /* |
9503 * "browse(save, title, initdir, default)" function | 9281 * "browse(save, title, initdir, default)" function |
9504 */ | 9282 */ |
9505 static void | 9283 static void |
9506 f_browse(argvars, rettv) | 9284 f_browse(typval_T *argvars UNUSED, typval_T *rettv) |
9507 typval_T *argvars UNUSED; | |
9508 typval_T *rettv; | |
9509 { | 9285 { |
9510 #ifdef FEAT_BROWSE | 9286 #ifdef FEAT_BROWSE |
9511 int save; | 9287 int save; |
9512 char_u *title; | 9288 char_u *title; |
9513 char_u *initdir; | 9289 char_u *initdir; |
9535 | 9311 |
9536 /* | 9312 /* |
9537 * "browsedir(title, initdir)" function | 9313 * "browsedir(title, initdir)" function |
9538 */ | 9314 */ |
9539 static void | 9315 static void |
9540 f_browsedir(argvars, rettv) | 9316 f_browsedir(typval_T *argvars UNUSED, typval_T *rettv) |
9541 typval_T *argvars UNUSED; | |
9542 typval_T *rettv; | |
9543 { | 9317 { |
9544 #ifdef FEAT_BROWSE | 9318 #ifdef FEAT_BROWSE |
9545 char_u *title; | 9319 char_u *title; |
9546 char_u *initdir; | 9320 char_u *initdir; |
9547 char_u buf[NUMBUFLEN]; | 9321 char_u buf[NUMBUFLEN]; |
9564 | 9338 |
9565 /* | 9339 /* |
9566 * Find a buffer by number or exact name. | 9340 * Find a buffer by number or exact name. |
9567 */ | 9341 */ |
9568 static buf_T * | 9342 static buf_T * |
9569 find_buffer(avar) | 9343 find_buffer(typval_T *avar) |
9570 typval_T *avar; | |
9571 { | 9344 { |
9572 buf_T *buf = NULL; | 9345 buf_T *buf = NULL; |
9573 | 9346 |
9574 if (avar->v_type == VAR_NUMBER) | 9347 if (avar->v_type == VAR_NUMBER) |
9575 buf = buflist_findnr((int)avar->vval.v_number); | 9348 buf = buflist_findnr((int)avar->vval.v_number); |
9596 | 9369 |
9597 /* | 9370 /* |
9598 * "bufexists(expr)" function | 9371 * "bufexists(expr)" function |
9599 */ | 9372 */ |
9600 static void | 9373 static void |
9601 f_bufexists(argvars, rettv) | 9374 f_bufexists(typval_T *argvars, typval_T *rettv) |
9602 typval_T *argvars; | |
9603 typval_T *rettv; | |
9604 { | 9375 { |
9605 rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL); | 9376 rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL); |
9606 } | 9377 } |
9607 | 9378 |
9608 /* | 9379 /* |
9609 * "buflisted(expr)" function | 9380 * "buflisted(expr)" function |
9610 */ | 9381 */ |
9611 static void | 9382 static void |
9612 f_buflisted(argvars, rettv) | 9383 f_buflisted(typval_T *argvars, typval_T *rettv) |
9613 typval_T *argvars; | |
9614 typval_T *rettv; | |
9615 { | 9384 { |
9616 buf_T *buf; | 9385 buf_T *buf; |
9617 | 9386 |
9618 buf = find_buffer(&argvars[0]); | 9387 buf = find_buffer(&argvars[0]); |
9619 rettv->vval.v_number = (buf != NULL && buf->b_p_bl); | 9388 rettv->vval.v_number = (buf != NULL && buf->b_p_bl); |
9621 | 9390 |
9622 /* | 9391 /* |
9623 * "bufloaded(expr)" function | 9392 * "bufloaded(expr)" function |
9624 */ | 9393 */ |
9625 static void | 9394 static void |
9626 f_bufloaded(argvars, rettv) | 9395 f_bufloaded(typval_T *argvars, typval_T *rettv) |
9627 typval_T *argvars; | |
9628 typval_T *rettv; | |
9629 { | 9396 { |
9630 buf_T *buf; | 9397 buf_T *buf; |
9631 | 9398 |
9632 buf = find_buffer(&argvars[0]); | 9399 buf = find_buffer(&argvars[0]); |
9633 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); | 9400 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); |
9637 | 9404 |
9638 /* | 9405 /* |
9639 * Get buffer by number or pattern. | 9406 * Get buffer by number or pattern. |
9640 */ | 9407 */ |
9641 static buf_T * | 9408 static buf_T * |
9642 get_buf_tv(tv, curtab_only) | 9409 get_buf_tv(typval_T *tv, int curtab_only) |
9643 typval_T *tv; | |
9644 int curtab_only; | |
9645 { | 9410 { |
9646 char_u *name = tv->vval.v_string; | 9411 char_u *name = tv->vval.v_string; |
9647 int save_magic; | 9412 int save_magic; |
9648 char_u *save_cpo; | 9413 char_u *save_cpo; |
9649 buf_T *buf; | 9414 buf_T *buf; |
9678 | 9443 |
9679 /* | 9444 /* |
9680 * "bufname(expr)" function | 9445 * "bufname(expr)" function |
9681 */ | 9446 */ |
9682 static void | 9447 static void |
9683 f_bufname(argvars, rettv) | 9448 f_bufname(typval_T *argvars, typval_T *rettv) |
9684 typval_T *argvars; | |
9685 typval_T *rettv; | |
9686 { | 9449 { |
9687 buf_T *buf; | 9450 buf_T *buf; |
9688 | 9451 |
9689 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ | 9452 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ |
9690 ++emsg_off; | 9453 ++emsg_off; |
9699 | 9462 |
9700 /* | 9463 /* |
9701 * "bufnr(expr)" function | 9464 * "bufnr(expr)" function |
9702 */ | 9465 */ |
9703 static void | 9466 static void |
9704 f_bufnr(argvars, rettv) | 9467 f_bufnr(typval_T *argvars, typval_T *rettv) |
9705 typval_T *argvars; | |
9706 typval_T *rettv; | |
9707 { | 9468 { |
9708 buf_T *buf; | 9469 buf_T *buf; |
9709 int error = FALSE; | 9470 int error = FALSE; |
9710 char_u *name; | 9471 char_u *name; |
9711 | 9472 |
9732 | 9493 |
9733 /* | 9494 /* |
9734 * "bufwinnr(nr)" function | 9495 * "bufwinnr(nr)" function |
9735 */ | 9496 */ |
9736 static void | 9497 static void |
9737 f_bufwinnr(argvars, rettv) | 9498 f_bufwinnr(typval_T *argvars, typval_T *rettv) |
9738 typval_T *argvars; | |
9739 typval_T *rettv; | |
9740 { | 9499 { |
9741 #ifdef FEAT_WINDOWS | 9500 #ifdef FEAT_WINDOWS |
9742 win_T *wp; | 9501 win_T *wp; |
9743 int winnr = 0; | 9502 int winnr = 0; |
9744 #endif | 9503 #endif |
9763 | 9522 |
9764 /* | 9523 /* |
9765 * "byte2line(byte)" function | 9524 * "byte2line(byte)" function |
9766 */ | 9525 */ |
9767 static void | 9526 static void |
9768 f_byte2line(argvars, rettv) | 9527 f_byte2line(typval_T *argvars UNUSED, typval_T *rettv) |
9769 typval_T *argvars UNUSED; | |
9770 typval_T *rettv; | |
9771 { | 9528 { |
9772 #ifndef FEAT_BYTEOFF | 9529 #ifndef FEAT_BYTEOFF |
9773 rettv->vval.v_number = -1; | 9530 rettv->vval.v_number = -1; |
9774 #else | 9531 #else |
9775 long boff = 0; | 9532 long boff = 0; |
9782 (linenr_T)0, &boff); | 9539 (linenr_T)0, &boff); |
9783 #endif | 9540 #endif |
9784 } | 9541 } |
9785 | 9542 |
9786 static void | 9543 static void |
9787 byteidx(argvars, rettv, comp) | 9544 byteidx(typval_T *argvars, typval_T *rettv, int comp UNUSED) |
9788 typval_T *argvars; | |
9789 typval_T *rettv; | |
9790 int comp UNUSED; | |
9791 { | 9545 { |
9792 #ifdef FEAT_MBYTE | 9546 #ifdef FEAT_MBYTE |
9793 char_u *t; | 9547 char_u *t; |
9794 #endif | 9548 #endif |
9795 char_u *str; | 9549 char_u *str; |
9821 | 9575 |
9822 /* | 9576 /* |
9823 * "byteidx()" function | 9577 * "byteidx()" function |
9824 */ | 9578 */ |
9825 static void | 9579 static void |
9826 f_byteidx(argvars, rettv) | 9580 f_byteidx(typval_T *argvars, typval_T *rettv) |
9827 typval_T *argvars; | |
9828 typval_T *rettv; | |
9829 { | 9581 { |
9830 byteidx(argvars, rettv, FALSE); | 9582 byteidx(argvars, rettv, FALSE); |
9831 } | 9583 } |
9832 | 9584 |
9833 /* | 9585 /* |
9834 * "byteidxcomp()" function | 9586 * "byteidxcomp()" function |
9835 */ | 9587 */ |
9836 static void | 9588 static void |
9837 f_byteidxcomp(argvars, rettv) | 9589 f_byteidxcomp(typval_T *argvars, typval_T *rettv) |
9838 typval_T *argvars; | |
9839 typval_T *rettv; | |
9840 { | 9590 { |
9841 byteidx(argvars, rettv, TRUE); | 9591 byteidx(argvars, rettv, TRUE); |
9842 } | 9592 } |
9843 | 9593 |
9844 int | 9594 int |
9845 func_call(name, args, selfdict, rettv) | 9595 func_call( |
9846 char_u *name; | 9596 char_u *name, |
9847 typval_T *args; | 9597 typval_T *args, |
9848 dict_T *selfdict; | 9598 dict_T *selfdict, |
9849 typval_T *rettv; | 9599 typval_T *rettv) |
9850 { | 9600 { |
9851 listitem_T *item; | 9601 listitem_T *item; |
9852 typval_T argv[MAX_FUNC_ARGS + 1]; | 9602 typval_T argv[MAX_FUNC_ARGS + 1]; |
9853 int argc = 0; | 9603 int argc = 0; |
9854 int dummy; | 9604 int dummy; |
9882 | 9632 |
9883 /* | 9633 /* |
9884 * "call(func, arglist)" function | 9634 * "call(func, arglist)" function |
9885 */ | 9635 */ |
9886 static void | 9636 static void |
9887 f_call(argvars, rettv) | 9637 f_call(typval_T *argvars, typval_T *rettv) |
9888 typval_T *argvars; | |
9889 typval_T *rettv; | |
9890 { | 9638 { |
9891 char_u *func; | 9639 char_u *func; |
9892 dict_T *selfdict = NULL; | 9640 dict_T *selfdict = NULL; |
9893 | 9641 |
9894 if (argvars[1].v_type != VAR_LIST) | 9642 if (argvars[1].v_type != VAR_LIST) |
9922 #ifdef FEAT_FLOAT | 9670 #ifdef FEAT_FLOAT |
9923 /* | 9671 /* |
9924 * "ceil({float})" function | 9672 * "ceil({float})" function |
9925 */ | 9673 */ |
9926 static void | 9674 static void |
9927 f_ceil(argvars, rettv) | 9675 f_ceil(typval_T *argvars, typval_T *rettv) |
9928 typval_T *argvars; | |
9929 typval_T *rettv; | |
9930 { | 9676 { |
9931 float_T f; | 9677 float_T f; |
9932 | 9678 |
9933 rettv->v_type = VAR_FLOAT; | 9679 rettv->v_type = VAR_FLOAT; |
9934 if (get_float_arg(argvars, &f) == OK) | 9680 if (get_float_arg(argvars, &f) == OK) |
9940 | 9686 |
9941 /* | 9687 /* |
9942 * "changenr()" function | 9688 * "changenr()" function |
9943 */ | 9689 */ |
9944 static void | 9690 static void |
9945 f_changenr(argvars, rettv) | 9691 f_changenr(typval_T *argvars UNUSED, typval_T *rettv) |
9946 typval_T *argvars UNUSED; | |
9947 typval_T *rettv; | |
9948 { | 9692 { |
9949 rettv->vval.v_number = curbuf->b_u_seq_cur; | 9693 rettv->vval.v_number = curbuf->b_u_seq_cur; |
9950 } | 9694 } |
9951 | 9695 |
9952 /* | 9696 /* |
9953 * "char2nr(string)" function | 9697 * "char2nr(string)" function |
9954 */ | 9698 */ |
9955 static void | 9699 static void |
9956 f_char2nr(argvars, rettv) | 9700 f_char2nr(typval_T *argvars, typval_T *rettv) |
9957 typval_T *argvars; | |
9958 typval_T *rettv; | |
9959 { | 9701 { |
9960 #ifdef FEAT_MBYTE | 9702 #ifdef FEAT_MBYTE |
9961 if (has_mbyte) | 9703 if (has_mbyte) |
9962 { | 9704 { |
9963 int utf8 = 0; | 9705 int utf8 = 0; |
9977 | 9719 |
9978 /* | 9720 /* |
9979 * "cindent(lnum)" function | 9721 * "cindent(lnum)" function |
9980 */ | 9722 */ |
9981 static void | 9723 static void |
9982 f_cindent(argvars, rettv) | 9724 f_cindent(typval_T *argvars UNUSED, typval_T *rettv) |
9983 typval_T *argvars UNUSED; | |
9984 typval_T *rettv; | |
9985 { | 9725 { |
9986 #ifdef FEAT_CINDENT | 9726 #ifdef FEAT_CINDENT |
9987 pos_T pos; | 9727 pos_T pos; |
9988 linenr_T lnum; | 9728 linenr_T lnum; |
9989 | 9729 |
10002 | 9742 |
10003 /* | 9743 /* |
10004 * "clearmatches()" function | 9744 * "clearmatches()" function |
10005 */ | 9745 */ |
10006 static void | 9746 static void |
10007 f_clearmatches(argvars, rettv) | 9747 f_clearmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10008 typval_T *argvars UNUSED; | |
10009 typval_T *rettv UNUSED; | |
10010 { | 9748 { |
10011 #ifdef FEAT_SEARCH_EXTRA | 9749 #ifdef FEAT_SEARCH_EXTRA |
10012 clear_matches(curwin); | 9750 clear_matches(curwin); |
10013 #endif | 9751 #endif |
10014 } | 9752 } |
10015 | 9753 |
10016 /* | 9754 /* |
10017 * "col(string)" function | 9755 * "col(string)" function |
10018 */ | 9756 */ |
10019 static void | 9757 static void |
10020 f_col(argvars, rettv) | 9758 f_col(typval_T *argvars, typval_T *rettv) |
10021 typval_T *argvars; | |
10022 typval_T *rettv; | |
10023 { | 9759 { |
10024 colnr_T col = 0; | 9760 colnr_T col = 0; |
10025 pos_T *fp; | 9761 pos_T *fp; |
10026 int fnum = curbuf->b_fnum; | 9762 int fnum = curbuf->b_fnum; |
10027 | 9763 |
10069 #if defined(FEAT_INS_EXPAND) | 9805 #if defined(FEAT_INS_EXPAND) |
10070 /* | 9806 /* |
10071 * "complete()" function | 9807 * "complete()" function |
10072 */ | 9808 */ |
10073 static void | 9809 static void |
10074 f_complete(argvars, rettv) | 9810 f_complete(typval_T *argvars, typval_T *rettv UNUSED) |
10075 typval_T *argvars; | |
10076 typval_T *rettv UNUSED; | |
10077 { | 9811 { |
10078 int startcol; | 9812 int startcol; |
10079 | 9813 |
10080 if ((State & INSERT) == 0) | 9814 if ((State & INSERT) == 0) |
10081 { | 9815 { |
10103 | 9837 |
10104 /* | 9838 /* |
10105 * "complete_add()" function | 9839 * "complete_add()" function |
10106 */ | 9840 */ |
10107 static void | 9841 static void |
10108 f_complete_add(argvars, rettv) | 9842 f_complete_add(typval_T *argvars, typval_T *rettv) |
10109 typval_T *argvars; | |
10110 typval_T *rettv; | |
10111 { | 9843 { |
10112 rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); | 9844 rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); |
10113 } | 9845 } |
10114 | 9846 |
10115 /* | 9847 /* |
10116 * "complete_check()" function | 9848 * "complete_check()" function |
10117 */ | 9849 */ |
10118 static void | 9850 static void |
10119 f_complete_check(argvars, rettv) | 9851 f_complete_check(typval_T *argvars UNUSED, typval_T *rettv) |
10120 typval_T *argvars UNUSED; | |
10121 typval_T *rettv; | |
10122 { | 9852 { |
10123 int saved = RedrawingDisabled; | 9853 int saved = RedrawingDisabled; |
10124 | 9854 |
10125 RedrawingDisabled = 0; | 9855 RedrawingDisabled = 0; |
10126 ins_compl_check_keys(0); | 9856 ins_compl_check_keys(0); |
10131 | 9861 |
10132 /* | 9862 /* |
10133 * "confirm(message, buttons[, default [, type]])" function | 9863 * "confirm(message, buttons[, default [, type]])" function |
10134 */ | 9864 */ |
10135 static void | 9865 static void |
10136 f_confirm(argvars, rettv) | 9866 f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10137 typval_T *argvars UNUSED; | |
10138 typval_T *rettv UNUSED; | |
10139 { | 9867 { |
10140 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 9868 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
10141 char_u *message; | 9869 char_u *message; |
10142 char_u *buttons = NULL; | 9870 char_u *buttons = NULL; |
10143 char_u buf[NUMBUFLEN]; | 9871 char_u buf[NUMBUFLEN]; |
10189 | 9917 |
10190 /* | 9918 /* |
10191 * "copy()" function | 9919 * "copy()" function |
10192 */ | 9920 */ |
10193 static void | 9921 static void |
10194 f_copy(argvars, rettv) | 9922 f_copy(typval_T *argvars, typval_T *rettv) |
10195 typval_T *argvars; | |
10196 typval_T *rettv; | |
10197 { | 9923 { |
10198 item_copy(&argvars[0], rettv, FALSE, 0); | 9924 item_copy(&argvars[0], rettv, FALSE, 0); |
10199 } | 9925 } |
10200 | 9926 |
10201 #ifdef FEAT_FLOAT | 9927 #ifdef FEAT_FLOAT |
10202 /* | 9928 /* |
10203 * "cos()" function | 9929 * "cos()" function |
10204 */ | 9930 */ |
10205 static void | 9931 static void |
10206 f_cos(argvars, rettv) | 9932 f_cos(typval_T *argvars, typval_T *rettv) |
10207 typval_T *argvars; | |
10208 typval_T *rettv; | |
10209 { | 9933 { |
10210 float_T f; | 9934 float_T f; |
10211 | 9935 |
10212 rettv->v_type = VAR_FLOAT; | 9936 rettv->v_type = VAR_FLOAT; |
10213 if (get_float_arg(argvars, &f) == OK) | 9937 if (get_float_arg(argvars, &f) == OK) |
10218 | 9942 |
10219 /* | 9943 /* |
10220 * "cosh()" function | 9944 * "cosh()" function |
10221 */ | 9945 */ |
10222 static void | 9946 static void |
10223 f_cosh(argvars, rettv) | 9947 f_cosh(typval_T *argvars, typval_T *rettv) |
10224 typval_T *argvars; | |
10225 typval_T *rettv; | |
10226 { | 9948 { |
10227 float_T f; | 9949 float_T f; |
10228 | 9950 |
10229 rettv->v_type = VAR_FLOAT; | 9951 rettv->v_type = VAR_FLOAT; |
10230 if (get_float_arg(argvars, &f) == OK) | 9952 if (get_float_arg(argvars, &f) == OK) |
10236 | 9958 |
10237 /* | 9959 /* |
10238 * "count()" function | 9960 * "count()" function |
10239 */ | 9961 */ |
10240 static void | 9962 static void |
10241 f_count(argvars, rettv) | 9963 f_count(typval_T *argvars, typval_T *rettv) |
10242 typval_T *argvars; | |
10243 typval_T *rettv; | |
10244 { | 9964 { |
10245 long n = 0; | 9965 long n = 0; |
10246 int ic = FALSE; | 9966 int ic = FALSE; |
10247 | 9967 |
10248 if (argvars[0].v_type == VAR_LIST) | 9968 if (argvars[0].v_type == VAR_LIST) |
10331 | 10051 |
10332 /* | 10052 /* |
10333 * "connect()" function | 10053 * "connect()" function |
10334 */ | 10054 */ |
10335 static void | 10055 static void |
10336 f_connect(argvars, rettv) | 10056 f_connect(typval_T *argvars, typval_T *rettv) |
10337 typval_T *argvars; | |
10338 typval_T *rettv; | |
10339 { | 10057 { |
10340 char_u *address; | 10058 char_u *address; |
10341 char_u *mode; | 10059 char_u *mode; |
10342 char_u *callback = NULL; | 10060 char_u *callback = NULL; |
10343 char_u buf1[NUMBUFLEN]; | 10061 char_u buf1[NUMBUFLEN]; |
10393 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function | 10111 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function |
10394 * | 10112 * |
10395 * Checks the existence of a cscope connection. | 10113 * Checks the existence of a cscope connection. |
10396 */ | 10114 */ |
10397 static void | 10115 static void |
10398 f_cscope_connection(argvars, rettv) | 10116 f_cscope_connection(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10399 typval_T *argvars UNUSED; | |
10400 typval_T *rettv UNUSED; | |
10401 { | 10117 { |
10402 #ifdef FEAT_CSCOPE | 10118 #ifdef FEAT_CSCOPE |
10403 int num = 0; | 10119 int num = 0; |
10404 char_u *dbpath = NULL; | 10120 char_u *dbpath = NULL; |
10405 char_u *prepend = NULL; | 10121 char_u *prepend = NULL; |
10424 * | 10140 * |
10425 * Moves the cursor to the specified line and column. | 10141 * Moves the cursor to the specified line and column. |
10426 * Returns 0 when the position could be set, -1 otherwise. | 10142 * Returns 0 when the position could be set, -1 otherwise. |
10427 */ | 10143 */ |
10428 static void | 10144 static void |
10429 f_cursor(argvars, rettv) | 10145 f_cursor(typval_T *argvars, typval_T *rettv) |
10430 typval_T *argvars; | |
10431 typval_T *rettv; | |
10432 { | 10146 { |
10433 long line, col; | 10147 long line, col; |
10434 #ifdef FEAT_VIRTUALEDIT | 10148 #ifdef FEAT_VIRTUALEDIT |
10435 long coladd = 0; | 10149 long coladd = 0; |
10436 #endif | 10150 #endif |
10495 | 10209 |
10496 /* | 10210 /* |
10497 * "deepcopy()" function | 10211 * "deepcopy()" function |
10498 */ | 10212 */ |
10499 static void | 10213 static void |
10500 f_deepcopy(argvars, rettv) | 10214 f_deepcopy(typval_T *argvars, typval_T *rettv) |
10501 typval_T *argvars; | |
10502 typval_T *rettv; | |
10503 { | 10215 { |
10504 int noref = 0; | 10216 int noref = 0; |
10505 | 10217 |
10506 if (argvars[1].v_type != VAR_UNKNOWN) | 10218 if (argvars[1].v_type != VAR_UNKNOWN) |
10507 noref = get_tv_number_chk(&argvars[1], NULL); | 10219 noref = get_tv_number_chk(&argvars[1], NULL); |
10516 | 10228 |
10517 /* | 10229 /* |
10518 * "delete()" function | 10230 * "delete()" function |
10519 */ | 10231 */ |
10520 static void | 10232 static void |
10521 f_delete(argvars, rettv) | 10233 f_delete(typval_T *argvars, typval_T *rettv) |
10522 typval_T *argvars; | |
10523 typval_T *rettv; | |
10524 { | 10234 { |
10525 char_u nbuf[NUMBUFLEN]; | 10235 char_u nbuf[NUMBUFLEN]; |
10526 char_u *name; | 10236 char_u *name; |
10527 char_u *flags; | 10237 char_u *flags; |
10528 | 10238 |
10557 | 10267 |
10558 /* | 10268 /* |
10559 * "did_filetype()" function | 10269 * "did_filetype()" function |
10560 */ | 10270 */ |
10561 static void | 10271 static void |
10562 f_did_filetype(argvars, rettv) | 10272 f_did_filetype(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10563 typval_T *argvars UNUSED; | |
10564 typval_T *rettv UNUSED; | |
10565 { | 10273 { |
10566 #ifdef FEAT_AUTOCMD | 10274 #ifdef FEAT_AUTOCMD |
10567 rettv->vval.v_number = did_filetype; | 10275 rettv->vval.v_number = did_filetype; |
10568 #endif | 10276 #endif |
10569 } | 10277 } |
10570 | 10278 |
10571 /* | 10279 /* |
10572 * "diff_filler()" function | 10280 * "diff_filler()" function |
10573 */ | 10281 */ |
10574 static void | 10282 static void |
10575 f_diff_filler(argvars, rettv) | 10283 f_diff_filler(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10576 typval_T *argvars UNUSED; | |
10577 typval_T *rettv UNUSED; | |
10578 { | 10284 { |
10579 #ifdef FEAT_DIFF | 10285 #ifdef FEAT_DIFF |
10580 rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars)); | 10286 rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars)); |
10581 #endif | 10287 #endif |
10582 } | 10288 } |
10583 | 10289 |
10584 /* | 10290 /* |
10585 * "diff_hlID()" function | 10291 * "diff_hlID()" function |
10586 */ | 10292 */ |
10587 static void | 10293 static void |
10588 f_diff_hlID(argvars, rettv) | 10294 f_diff_hlID(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
10589 typval_T *argvars UNUSED; | |
10590 typval_T *rettv UNUSED; | |
10591 { | 10295 { |
10592 #ifdef FEAT_DIFF | 10296 #ifdef FEAT_DIFF |
10593 linenr_T lnum = get_tv_lnum(argvars); | 10297 linenr_T lnum = get_tv_lnum(argvars); |
10594 static linenr_T prev_lnum = 0; | 10298 static linenr_T prev_lnum = 0; |
10595 static int changedtick = 0; | 10299 static int changedtick = 0; |
10668 | 10372 |
10669 /* | 10373 /* |
10670 * "disconnect()" function | 10374 * "disconnect()" function |
10671 */ | 10375 */ |
10672 static void | 10376 static void |
10673 f_disconnect(argvars, rettv) | 10377 f_disconnect(typval_T *argvars, typval_T *rettv UNUSED) |
10674 typval_T *argvars; | |
10675 typval_T *rettv UNUSED; | |
10676 { | 10378 { |
10677 int ch_idx = get_channel_arg(&argvars[0]); | 10379 int ch_idx = get_channel_arg(&argvars[0]); |
10678 | 10380 |
10679 if (ch_idx >= 0) | 10381 if (ch_idx >= 0) |
10680 channel_close(ch_idx); | 10382 channel_close(ch_idx); |
10683 | 10385 |
10684 /* | 10386 /* |
10685 * "empty({expr})" function | 10387 * "empty({expr})" function |
10686 */ | 10388 */ |
10687 static void | 10389 static void |
10688 f_empty(argvars, rettv) | 10390 f_empty(typval_T *argvars, typval_T *rettv) |
10689 typval_T *argvars; | |
10690 typval_T *rettv; | |
10691 { | 10391 { |
10692 int n; | 10392 int n; |
10693 | 10393 |
10694 switch (argvars[0].v_type) | 10394 switch (argvars[0].v_type) |
10695 { | 10395 { |
10728 | 10428 |
10729 /* | 10429 /* |
10730 * "escape({string}, {chars})" function | 10430 * "escape({string}, {chars})" function |
10731 */ | 10431 */ |
10732 static void | 10432 static void |
10733 f_escape(argvars, rettv) | 10433 f_escape(typval_T *argvars, typval_T *rettv) |
10734 typval_T *argvars; | |
10735 typval_T *rettv; | |
10736 { | 10434 { |
10737 char_u buf[NUMBUFLEN]; | 10435 char_u buf[NUMBUFLEN]; |
10738 | 10436 |
10739 rettv->vval.v_string = vim_strsave_escaped(get_tv_string(&argvars[0]), | 10437 rettv->vval.v_string = vim_strsave_escaped(get_tv_string(&argvars[0]), |
10740 get_tv_string_buf(&argvars[1], buf)); | 10438 get_tv_string_buf(&argvars[1], buf)); |
10743 | 10441 |
10744 /* | 10442 /* |
10745 * "eval()" function | 10443 * "eval()" function |
10746 */ | 10444 */ |
10747 static void | 10445 static void |
10748 f_eval(argvars, rettv) | 10446 f_eval(typval_T *argvars, typval_T *rettv) |
10749 typval_T *argvars; | |
10750 typval_T *rettv; | |
10751 { | 10447 { |
10752 char_u *s, *p; | 10448 char_u *s, *p; |
10753 | 10449 |
10754 s = get_tv_string_chk(&argvars[0]); | 10450 s = get_tv_string_chk(&argvars[0]); |
10755 if (s != NULL) | 10451 if (s != NULL) |
10770 | 10466 |
10771 /* | 10467 /* |
10772 * "eventhandler()" function | 10468 * "eventhandler()" function |
10773 */ | 10469 */ |
10774 static void | 10470 static void |
10775 f_eventhandler(argvars, rettv) | 10471 f_eventhandler(typval_T *argvars UNUSED, typval_T *rettv) |
10776 typval_T *argvars UNUSED; | |
10777 typval_T *rettv; | |
10778 { | 10472 { |
10779 rettv->vval.v_number = vgetc_busy; | 10473 rettv->vval.v_number = vgetc_busy; |
10780 } | 10474 } |
10781 | 10475 |
10782 /* | 10476 /* |
10783 * "executable()" function | 10477 * "executable()" function |
10784 */ | 10478 */ |
10785 static void | 10479 static void |
10786 f_executable(argvars, rettv) | 10480 f_executable(typval_T *argvars, typval_T *rettv) |
10787 typval_T *argvars; | |
10788 typval_T *rettv; | |
10789 { | 10481 { |
10790 char_u *name = get_tv_string(&argvars[0]); | 10482 char_u *name = get_tv_string(&argvars[0]); |
10791 | 10483 |
10792 /* Check in $PATH and also check directly if there is a directory name. */ | 10484 /* Check in $PATH and also check directly if there is a directory name. */ |
10793 rettv->vval.v_number = mch_can_exe(name, NULL, TRUE) | 10485 rettv->vval.v_number = mch_can_exe(name, NULL, TRUE) |
10796 | 10488 |
10797 /* | 10489 /* |
10798 * "exepath()" function | 10490 * "exepath()" function |
10799 */ | 10491 */ |
10800 static void | 10492 static void |
10801 f_exepath(argvars, rettv) | 10493 f_exepath(typval_T *argvars, typval_T *rettv) |
10802 typval_T *argvars; | |
10803 typval_T *rettv; | |
10804 { | 10494 { |
10805 char_u *p = NULL; | 10495 char_u *p = NULL; |
10806 | 10496 |
10807 (void)mch_can_exe(get_tv_string(&argvars[0]), &p, TRUE); | 10497 (void)mch_can_exe(get_tv_string(&argvars[0]), &p, TRUE); |
10808 rettv->v_type = VAR_STRING; | 10498 rettv->v_type = VAR_STRING; |
10811 | 10501 |
10812 /* | 10502 /* |
10813 * "exists()" function | 10503 * "exists()" function |
10814 */ | 10504 */ |
10815 static void | 10505 static void |
10816 f_exists(argvars, rettv) | 10506 f_exists(typval_T *argvars, typval_T *rettv) |
10817 typval_T *argvars; | |
10818 typval_T *rettv; | |
10819 { | 10507 { |
10820 char_u *p; | 10508 char_u *p; |
10821 char_u *name; | 10509 char_u *name; |
10822 int n = FALSE; | 10510 int n = FALSE; |
10823 int len = 0; | 10511 int len = 0; |
10893 #ifdef FEAT_FLOAT | 10581 #ifdef FEAT_FLOAT |
10894 /* | 10582 /* |
10895 * "exp()" function | 10583 * "exp()" function |
10896 */ | 10584 */ |
10897 static void | 10585 static void |
10898 f_exp(argvars, rettv) | 10586 f_exp(typval_T *argvars, typval_T *rettv) |
10899 typval_T *argvars; | |
10900 typval_T *rettv; | |
10901 { | 10587 { |
10902 float_T f; | 10588 float_T f; |
10903 | 10589 |
10904 rettv->v_type = VAR_FLOAT; | 10590 rettv->v_type = VAR_FLOAT; |
10905 if (get_float_arg(argvars, &f) == OK) | 10591 if (get_float_arg(argvars, &f) == OK) |
10911 | 10597 |
10912 /* | 10598 /* |
10913 * "expand()" function | 10599 * "expand()" function |
10914 */ | 10600 */ |
10915 static void | 10601 static void |
10916 f_expand(argvars, rettv) | 10602 f_expand(typval_T *argvars, typval_T *rettv) |
10917 typval_T *argvars; | |
10918 typval_T *rettv; | |
10919 { | 10603 { |
10920 char_u *s; | 10604 char_u *s; |
10921 int len; | 10605 int len; |
10922 char_u *errormsg; | 10606 char_u *errormsg; |
10923 int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; | 10607 int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; |
10987 * When "action" is "error" then a duplicate key is an error. | 10671 * When "action" is "error" then a duplicate key is an error. |
10988 * When "action" is "force" then a duplicate key is overwritten. | 10672 * When "action" is "force" then a duplicate key is overwritten. |
10989 * Otherwise duplicate keys are ignored ("action" is "keep"). | 10673 * Otherwise duplicate keys are ignored ("action" is "keep"). |
10990 */ | 10674 */ |
10991 void | 10675 void |
10992 dict_extend(d1, d2, action) | 10676 dict_extend(dict_T *d1, dict_T *d2, char_u *action) |
10993 dict_T *d1; | |
10994 dict_T *d2; | |
10995 char_u *action; | |
10996 { | 10677 { |
10997 dictitem_T *di1; | 10678 dictitem_T *di1; |
10998 hashitem_T *hi2; | 10679 hashitem_T *hi2; |
10999 int todo; | 10680 int todo; |
11000 char_u *arg_errmsg = (char_u *)N_("extend() argument"); | 10681 char_u *arg_errmsg = (char_u *)N_("extend() argument"); |
11045 /* | 10726 /* |
11046 * "extend(list, list [, idx])" function | 10727 * "extend(list, list [, idx])" function |
11047 * "extend(dict, dict [, action])" function | 10728 * "extend(dict, dict [, action])" function |
11048 */ | 10729 */ |
11049 static void | 10730 static void |
11050 f_extend(argvars, rettv) | 10731 f_extend(typval_T *argvars, typval_T *rettv) |
11051 typval_T *argvars; | |
11052 typval_T *rettv; | |
11053 { | 10732 { |
11054 char_u *arg_errmsg = (char_u *)N_("extend() argument"); | 10733 char_u *arg_errmsg = (char_u *)N_("extend() argument"); |
11055 | 10734 |
11056 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) | 10735 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) |
11057 { | 10736 { |
11132 | 10811 |
11133 /* | 10812 /* |
11134 * "feedkeys()" function | 10813 * "feedkeys()" function |
11135 */ | 10814 */ |
11136 static void | 10815 static void |
11137 f_feedkeys(argvars, rettv) | 10816 f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED) |
11138 typval_T *argvars; | |
11139 typval_T *rettv UNUSED; | |
11140 { | 10817 { |
11141 int remap = TRUE; | 10818 int remap = TRUE; |
11142 int insert = FALSE; | 10819 int insert = FALSE; |
11143 char_u *keys, *flags; | 10820 char_u *keys, *flags; |
11144 char_u nbuf[NUMBUFLEN]; | 10821 char_u nbuf[NUMBUFLEN]; |
11189 | 10866 |
11190 /* | 10867 /* |
11191 * "filereadable()" function | 10868 * "filereadable()" function |
11192 */ | 10869 */ |
11193 static void | 10870 static void |
11194 f_filereadable(argvars, rettv) | 10871 f_filereadable(typval_T *argvars, typval_T *rettv) |
11195 typval_T *argvars; | |
11196 typval_T *rettv; | |
11197 { | 10872 { |
11198 int fd; | 10873 int fd; |
11199 char_u *p; | 10874 char_u *p; |
11200 int n; | 10875 int n; |
11201 | 10876 |
11218 /* | 10893 /* |
11219 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have | 10894 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have |
11220 * rights to write into. | 10895 * rights to write into. |
11221 */ | 10896 */ |
11222 static void | 10897 static void |
11223 f_filewritable(argvars, rettv) | 10898 f_filewritable(typval_T *argvars, typval_T *rettv) |
11224 typval_T *argvars; | |
11225 typval_T *rettv; | |
11226 { | 10899 { |
11227 rettv->vval.v_number = filewritable(get_tv_string(&argvars[0])); | 10900 rettv->vval.v_number = filewritable(get_tv_string(&argvars[0])); |
11228 } | 10901 } |
11229 | 10902 |
11230 static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what); | 10903 static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what); |
11301 | 10974 |
11302 /* | 10975 /* |
11303 * Implementation of map() and filter(). | 10976 * Implementation of map() and filter(). |
11304 */ | 10977 */ |
11305 static void | 10978 static void |
11306 filter_map(argvars, rettv, map) | 10979 filter_map(typval_T *argvars, typval_T *rettv, int map) |
11307 typval_T *argvars; | |
11308 typval_T *rettv; | |
11309 int map; | |
11310 { | 10980 { |
11311 char_u buf[NUMBUFLEN]; | 10981 char_u buf[NUMBUFLEN]; |
11312 char_u *expr; | 10982 char_u *expr; |
11313 listitem_T *li, *nli; | 10983 listitem_T *li, *nli; |
11314 list_T *l = NULL; | 10984 list_T *l = NULL; |
11421 | 11091 |
11422 copy_tv(&argvars[0], rettv); | 11092 copy_tv(&argvars[0], rettv); |
11423 } | 11093 } |
11424 | 11094 |
11425 static int | 11095 static int |
11426 filter_map_one(tv, expr, map, remp) | 11096 filter_map_one(typval_T *tv, char_u *expr, int map, int *remp) |
11427 typval_T *tv; | |
11428 char_u *expr; | |
11429 int map; | |
11430 int *remp; | |
11431 { | 11097 { |
11432 typval_T rettv; | 11098 typval_T rettv; |
11433 char_u *s; | 11099 char_u *s; |
11434 int retval = FAIL; | 11100 int retval = FAIL; |
11435 | 11101 |
11470 | 11136 |
11471 /* | 11137 /* |
11472 * "filter()" function | 11138 * "filter()" function |
11473 */ | 11139 */ |
11474 static void | 11140 static void |
11475 f_filter(argvars, rettv) | 11141 f_filter(typval_T *argvars, typval_T *rettv) |
11476 typval_T *argvars; | |
11477 typval_T *rettv; | |
11478 { | 11142 { |
11479 filter_map(argvars, rettv, FALSE); | 11143 filter_map(argvars, rettv, FALSE); |
11480 } | 11144 } |
11481 | 11145 |
11482 /* | 11146 /* |
11483 * "finddir({fname}[, {path}[, {count}]])" function | 11147 * "finddir({fname}[, {path}[, {count}]])" function |
11484 */ | 11148 */ |
11485 static void | 11149 static void |
11486 f_finddir(argvars, rettv) | 11150 f_finddir(typval_T *argvars, typval_T *rettv) |
11487 typval_T *argvars; | |
11488 typval_T *rettv; | |
11489 { | 11151 { |
11490 findfilendir(argvars, rettv, FINDFILE_DIR); | 11152 findfilendir(argvars, rettv, FINDFILE_DIR); |
11491 } | 11153 } |
11492 | 11154 |
11493 /* | 11155 /* |
11494 * "findfile({fname}[, {path}[, {count}]])" function | 11156 * "findfile({fname}[, {path}[, {count}]])" function |
11495 */ | 11157 */ |
11496 static void | 11158 static void |
11497 f_findfile(argvars, rettv) | 11159 f_findfile(typval_T *argvars, typval_T *rettv) |
11498 typval_T *argvars; | |
11499 typval_T *rettv; | |
11500 { | 11160 { |
11501 findfilendir(argvars, rettv, FINDFILE_FILE); | 11161 findfilendir(argvars, rettv, FINDFILE_FILE); |
11502 } | 11162 } |
11503 | 11163 |
11504 #ifdef FEAT_FLOAT | 11164 #ifdef FEAT_FLOAT |
11505 /* | 11165 /* |
11506 * "float2nr({float})" function | 11166 * "float2nr({float})" function |
11507 */ | 11167 */ |
11508 static void | 11168 static void |
11509 f_float2nr(argvars, rettv) | 11169 f_float2nr(typval_T *argvars, typval_T *rettv) |
11510 typval_T *argvars; | |
11511 typval_T *rettv; | |
11512 { | 11170 { |
11513 float_T f; | 11171 float_T f; |
11514 | 11172 |
11515 if (get_float_arg(argvars, &f) == OK) | 11173 if (get_float_arg(argvars, &f) == OK) |
11516 { | 11174 { |
11525 | 11183 |
11526 /* | 11184 /* |
11527 * "floor({float})" function | 11185 * "floor({float})" function |
11528 */ | 11186 */ |
11529 static void | 11187 static void |
11530 f_floor(argvars, rettv) | 11188 f_floor(typval_T *argvars, typval_T *rettv) |
11531 typval_T *argvars; | |
11532 typval_T *rettv; | |
11533 { | 11189 { |
11534 float_T f; | 11190 float_T f; |
11535 | 11191 |
11536 rettv->v_type = VAR_FLOAT; | 11192 rettv->v_type = VAR_FLOAT; |
11537 if (get_float_arg(argvars, &f) == OK) | 11193 if (get_float_arg(argvars, &f) == OK) |
11542 | 11198 |
11543 /* | 11199 /* |
11544 * "fmod()" function | 11200 * "fmod()" function |
11545 */ | 11201 */ |
11546 static void | 11202 static void |
11547 f_fmod(argvars, rettv) | 11203 f_fmod(typval_T *argvars, typval_T *rettv) |
11548 typval_T *argvars; | |
11549 typval_T *rettv; | |
11550 { | 11204 { |
11551 float_T fx, fy; | 11205 float_T fx, fy; |
11552 | 11206 |
11553 rettv->v_type = VAR_FLOAT; | 11207 rettv->v_type = VAR_FLOAT; |
11554 if (get_float_arg(argvars, &fx) == OK | 11208 if (get_float_arg(argvars, &fx) == OK |
11561 | 11215 |
11562 /* | 11216 /* |
11563 * "fnameescape({string})" function | 11217 * "fnameescape({string})" function |
11564 */ | 11218 */ |
11565 static void | 11219 static void |
11566 f_fnameescape(argvars, rettv) | 11220 f_fnameescape(typval_T *argvars, typval_T *rettv) |
11567 typval_T *argvars; | |
11568 typval_T *rettv; | |
11569 { | 11221 { |
11570 rettv->vval.v_string = vim_strsave_fnameescape( | 11222 rettv->vval.v_string = vim_strsave_fnameescape( |
11571 get_tv_string(&argvars[0]), FALSE); | 11223 get_tv_string(&argvars[0]), FALSE); |
11572 rettv->v_type = VAR_STRING; | 11224 rettv->v_type = VAR_STRING; |
11573 } | 11225 } |
11574 | 11226 |
11575 /* | 11227 /* |
11576 * "fnamemodify({fname}, {mods})" function | 11228 * "fnamemodify({fname}, {mods})" function |
11577 */ | 11229 */ |
11578 static void | 11230 static void |
11579 f_fnamemodify(argvars, rettv) | 11231 f_fnamemodify(typval_T *argvars, typval_T *rettv) |
11580 typval_T *argvars; | |
11581 typval_T *rettv; | |
11582 { | 11232 { |
11583 char_u *fname; | 11233 char_u *fname; |
11584 char_u *mods; | 11234 char_u *mods; |
11585 int usedlen = 0; | 11235 int usedlen = 0; |
11586 int len; | 11236 int len; |
11609 | 11259 |
11610 /* | 11260 /* |
11611 * "foldclosed()" function | 11261 * "foldclosed()" function |
11612 */ | 11262 */ |
11613 static void | 11263 static void |
11614 foldclosed_both(argvars, rettv, end) | 11264 foldclosed_both( |
11615 typval_T *argvars UNUSED; | 11265 typval_T *argvars UNUSED, |
11616 typval_T *rettv; | 11266 typval_T *rettv, |
11617 int end UNUSED; | 11267 int end UNUSED) |
11618 { | 11268 { |
11619 #ifdef FEAT_FOLDING | 11269 #ifdef FEAT_FOLDING |
11620 linenr_T lnum; | 11270 linenr_T lnum; |
11621 linenr_T first, last; | 11271 linenr_T first, last; |
11622 | 11272 |
11638 | 11288 |
11639 /* | 11289 /* |
11640 * "foldclosed()" function | 11290 * "foldclosed()" function |
11641 */ | 11291 */ |
11642 static void | 11292 static void |
11643 f_foldclosed(argvars, rettv) | 11293 f_foldclosed(typval_T *argvars, typval_T *rettv) |
11644 typval_T *argvars; | |
11645 typval_T *rettv; | |
11646 { | 11294 { |
11647 foldclosed_both(argvars, rettv, FALSE); | 11295 foldclosed_both(argvars, rettv, FALSE); |
11648 } | 11296 } |
11649 | 11297 |
11650 /* | 11298 /* |
11651 * "foldclosedend()" function | 11299 * "foldclosedend()" function |
11652 */ | 11300 */ |
11653 static void | 11301 static void |
11654 f_foldclosedend(argvars, rettv) | 11302 f_foldclosedend(typval_T *argvars, typval_T *rettv) |
11655 typval_T *argvars; | |
11656 typval_T *rettv; | |
11657 { | 11303 { |
11658 foldclosed_both(argvars, rettv, TRUE); | 11304 foldclosed_both(argvars, rettv, TRUE); |
11659 } | 11305 } |
11660 | 11306 |
11661 /* | 11307 /* |
11662 * "foldlevel()" function | 11308 * "foldlevel()" function |
11663 */ | 11309 */ |
11664 static void | 11310 static void |
11665 f_foldlevel(argvars, rettv) | 11311 f_foldlevel(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
11666 typval_T *argvars UNUSED; | |
11667 typval_T *rettv UNUSED; | |
11668 { | 11312 { |
11669 #ifdef FEAT_FOLDING | 11313 #ifdef FEAT_FOLDING |
11670 linenr_T lnum; | 11314 linenr_T lnum; |
11671 | 11315 |
11672 lnum = get_tv_lnum(argvars); | 11316 lnum = get_tv_lnum(argvars); |
11677 | 11321 |
11678 /* | 11322 /* |
11679 * "foldtext()" function | 11323 * "foldtext()" function |
11680 */ | 11324 */ |
11681 static void | 11325 static void |
11682 f_foldtext(argvars, rettv) | 11326 f_foldtext(typval_T *argvars UNUSED, typval_T *rettv) |
11683 typval_T *argvars UNUSED; | |
11684 typval_T *rettv; | |
11685 { | 11327 { |
11686 #ifdef FEAT_FOLDING | 11328 #ifdef FEAT_FOLDING |
11687 linenr_T lnum; | 11329 linenr_T lnum; |
11688 char_u *s; | 11330 char_u *s; |
11689 char_u *r; | 11331 char_u *r; |
11744 | 11386 |
11745 /* | 11387 /* |
11746 * "foldtextresult(lnum)" function | 11388 * "foldtextresult(lnum)" function |
11747 */ | 11389 */ |
11748 static void | 11390 static void |
11749 f_foldtextresult(argvars, rettv) | 11391 f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv) |
11750 typval_T *argvars UNUSED; | |
11751 typval_T *rettv; | |
11752 { | 11392 { |
11753 #ifdef FEAT_FOLDING | 11393 #ifdef FEAT_FOLDING |
11754 linenr_T lnum; | 11394 linenr_T lnum; |
11755 char_u *text; | 11395 char_u *text; |
11756 char_u buf[51]; | 11396 char_u buf[51]; |
11779 | 11419 |
11780 /* | 11420 /* |
11781 * "foreground()" function | 11421 * "foreground()" function |
11782 */ | 11422 */ |
11783 static void | 11423 static void |
11784 f_foreground(argvars, rettv) | 11424 f_foreground(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
11785 typval_T *argvars UNUSED; | |
11786 typval_T *rettv UNUSED; | |
11787 { | 11425 { |
11788 #ifdef FEAT_GUI | 11426 #ifdef FEAT_GUI |
11789 if (gui.in_use) | 11427 if (gui.in_use) |
11790 gui_mch_set_foreground(); | 11428 gui_mch_set_foreground(); |
11791 #else | 11429 #else |
11797 | 11435 |
11798 /* | 11436 /* |
11799 * "function()" function | 11437 * "function()" function |
11800 */ | 11438 */ |
11801 static void | 11439 static void |
11802 f_function(argvars, rettv) | 11440 f_function(typval_T *argvars, typval_T *rettv) |
11803 typval_T *argvars; | |
11804 typval_T *rettv; | |
11805 { | 11441 { |
11806 char_u *s; | 11442 char_u *s; |
11807 | 11443 |
11808 s = get_tv_string(&argvars[0]); | 11444 s = get_tv_string(&argvars[0]); |
11809 if (s == NULL || *s == NUL || VIM_ISDIGIT(*s)) | 11445 if (s == NULL || *s == NUL || VIM_ISDIGIT(*s)) |
11839 | 11475 |
11840 /* | 11476 /* |
11841 * "garbagecollect()" function | 11477 * "garbagecollect()" function |
11842 */ | 11478 */ |
11843 static void | 11479 static void |
11844 f_garbagecollect(argvars, rettv) | 11480 f_garbagecollect(typval_T *argvars, typval_T *rettv UNUSED) |
11845 typval_T *argvars; | |
11846 typval_T *rettv UNUSED; | |
11847 { | 11481 { |
11848 /* This is postponed until we are back at the toplevel, because we may be | 11482 /* This is postponed until we are back at the toplevel, because we may be |
11849 * using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */ | 11483 * using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */ |
11850 want_garbage_collect = TRUE; | 11484 want_garbage_collect = TRUE; |
11851 | 11485 |
11855 | 11489 |
11856 /* | 11490 /* |
11857 * "get()" function | 11491 * "get()" function |
11858 */ | 11492 */ |
11859 static void | 11493 static void |
11860 f_get(argvars, rettv) | 11494 f_get(typval_T *argvars, typval_T *rettv) |
11861 typval_T *argvars; | |
11862 typval_T *rettv; | |
11863 { | 11495 { |
11864 listitem_T *li; | 11496 listitem_T *li; |
11865 list_T *l; | 11497 list_T *l; |
11866 dictitem_T *di; | 11498 dictitem_T *di; |
11867 dict_T *d; | 11499 dict_T *d; |
11906 * Return a range (from start to end) of lines in rettv from the specified | 11538 * Return a range (from start to end) of lines in rettv from the specified |
11907 * buffer. | 11539 * buffer. |
11908 * If 'retlist' is TRUE, then the lines are returned as a Vim List. | 11540 * If 'retlist' is TRUE, then the lines are returned as a Vim List. |
11909 */ | 11541 */ |
11910 static void | 11542 static void |
11911 get_buffer_lines(buf, start, end, retlist, rettv) | 11543 get_buffer_lines( |
11912 buf_T *buf; | 11544 buf_T *buf, |
11913 linenr_T start; | 11545 linenr_T start, |
11914 linenr_T end; | 11546 linenr_T end, |
11915 int retlist; | 11547 int retlist, |
11916 typval_T *rettv; | 11548 typval_T *rettv) |
11917 { | 11549 { |
11918 char_u *p; | 11550 char_u *p; |
11919 | 11551 |
11920 rettv->v_type = VAR_STRING; | 11552 rettv->v_type = VAR_STRING; |
11921 rettv->vval.v_string = NULL; | 11553 rettv->vval.v_string = NULL; |
11951 | 11583 |
11952 /* | 11584 /* |
11953 * "getbufline()" function | 11585 * "getbufline()" function |
11954 */ | 11586 */ |
11955 static void | 11587 static void |
11956 f_getbufline(argvars, rettv) | 11588 f_getbufline(typval_T *argvars, typval_T *rettv) |
11957 typval_T *argvars; | |
11958 typval_T *rettv; | |
11959 { | 11589 { |
11960 linenr_T lnum; | 11590 linenr_T lnum; |
11961 linenr_T end; | 11591 linenr_T end; |
11962 buf_T *buf; | 11592 buf_T *buf; |
11963 | 11593 |
11977 | 11607 |
11978 /* | 11608 /* |
11979 * "getbufvar()" function | 11609 * "getbufvar()" function |
11980 */ | 11610 */ |
11981 static void | 11611 static void |
11982 f_getbufvar(argvars, rettv) | 11612 f_getbufvar(typval_T *argvars, typval_T *rettv) |
11983 typval_T *argvars; | |
11984 typval_T *rettv; | |
11985 { | 11613 { |
11986 buf_T *buf; | 11614 buf_T *buf; |
11987 buf_T *save_curbuf; | 11615 buf_T *save_curbuf; |
11988 char_u *varname; | 11616 char_u *varname; |
11989 dictitem_T *v; | 11617 dictitem_T *v; |
12040 | 11668 |
12041 /* | 11669 /* |
12042 * "getchar()" function | 11670 * "getchar()" function |
12043 */ | 11671 */ |
12044 static void | 11672 static void |
12045 f_getchar(argvars, rettv) | 11673 f_getchar(typval_T *argvars, typval_T *rettv) |
12046 typval_T *argvars; | |
12047 typval_T *rettv; | |
12048 { | 11674 { |
12049 varnumber_T n; | 11675 varnumber_T n; |
12050 int error = FALSE; | 11676 int error = FALSE; |
12051 | 11677 |
12052 /* Position the cursor. Needed after a message that ends in a space. */ | 11678 /* Position the cursor. Needed after a message that ends in a space. */ |
12142 | 11768 |
12143 /* | 11769 /* |
12144 * "getcharmod()" function | 11770 * "getcharmod()" function |
12145 */ | 11771 */ |
12146 static void | 11772 static void |
12147 f_getcharmod(argvars, rettv) | 11773 f_getcharmod(typval_T *argvars UNUSED, typval_T *rettv) |
12148 typval_T *argvars UNUSED; | |
12149 typval_T *rettv; | |
12150 { | 11774 { |
12151 rettv->vval.v_number = mod_mask; | 11775 rettv->vval.v_number = mod_mask; |
12152 } | 11776 } |
12153 | 11777 |
12154 /* | 11778 /* |
12155 * "getcharsearch()" function | 11779 * "getcharsearch()" function |
12156 */ | 11780 */ |
12157 static void | 11781 static void |
12158 f_getcharsearch(argvars, rettv) | 11782 f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv) |
12159 typval_T *argvars UNUSED; | |
12160 typval_T *rettv; | |
12161 { | 11783 { |
12162 if (rettv_dict_alloc(rettv) != FAIL) | 11784 if (rettv_dict_alloc(rettv) != FAIL) |
12163 { | 11785 { |
12164 dict_T *dict = rettv->vval.v_dict; | 11786 dict_T *dict = rettv->vval.v_dict; |
12165 | 11787 |
12171 | 11793 |
12172 /* | 11794 /* |
12173 * "getcmdline()" function | 11795 * "getcmdline()" function |
12174 */ | 11796 */ |
12175 static void | 11797 static void |
12176 f_getcmdline(argvars, rettv) | 11798 f_getcmdline(typval_T *argvars UNUSED, typval_T *rettv) |
12177 typval_T *argvars UNUSED; | |
12178 typval_T *rettv; | |
12179 { | 11799 { |
12180 rettv->v_type = VAR_STRING; | 11800 rettv->v_type = VAR_STRING; |
12181 rettv->vval.v_string = get_cmdline_str(); | 11801 rettv->vval.v_string = get_cmdline_str(); |
12182 } | 11802 } |
12183 | 11803 |
12184 /* | 11804 /* |
12185 * "getcmdpos()" function | 11805 * "getcmdpos()" function |
12186 */ | 11806 */ |
12187 static void | 11807 static void |
12188 f_getcmdpos(argvars, rettv) | 11808 f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv) |
12189 typval_T *argvars UNUSED; | |
12190 typval_T *rettv; | |
12191 { | 11809 { |
12192 rettv->vval.v_number = get_cmdline_pos() + 1; | 11810 rettv->vval.v_number = get_cmdline_pos() + 1; |
12193 } | 11811 } |
12194 | 11812 |
12195 /* | 11813 /* |
12196 * "getcmdtype()" function | 11814 * "getcmdtype()" function |
12197 */ | 11815 */ |
12198 static void | 11816 static void |
12199 f_getcmdtype(argvars, rettv) | 11817 f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv) |
12200 typval_T *argvars UNUSED; | |
12201 typval_T *rettv; | |
12202 { | 11818 { |
12203 rettv->v_type = VAR_STRING; | 11819 rettv->v_type = VAR_STRING; |
12204 rettv->vval.v_string = alloc(2); | 11820 rettv->vval.v_string = alloc(2); |
12205 if (rettv->vval.v_string != NULL) | 11821 if (rettv->vval.v_string != NULL) |
12206 { | 11822 { |
12211 | 11827 |
12212 /* | 11828 /* |
12213 * "getcmdwintype()" function | 11829 * "getcmdwintype()" function |
12214 */ | 11830 */ |
12215 static void | 11831 static void |
12216 f_getcmdwintype(argvars, rettv) | 11832 f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv) |
12217 typval_T *argvars UNUSED; | |
12218 typval_T *rettv; | |
12219 { | 11833 { |
12220 rettv->v_type = VAR_STRING; | 11834 rettv->v_type = VAR_STRING; |
12221 rettv->vval.v_string = NULL; | 11835 rettv->vval.v_string = NULL; |
12222 #ifdef FEAT_CMDWIN | 11836 #ifdef FEAT_CMDWIN |
12223 rettv->vval.v_string = alloc(2); | 11837 rettv->vval.v_string = alloc(2); |
12231 | 11845 |
12232 /* | 11846 /* |
12233 * "getcwd()" function | 11847 * "getcwd()" function |
12234 */ | 11848 */ |
12235 static void | 11849 static void |
12236 f_getcwd(argvars, rettv) | 11850 f_getcwd(typval_T *argvars, typval_T *rettv) |
12237 typval_T *argvars; | |
12238 typval_T *rettv; | |
12239 { | 11851 { |
12240 win_T *wp = NULL; | 11852 win_T *wp = NULL; |
12241 char_u *cwd; | 11853 char_u *cwd; |
12242 | 11854 |
12243 rettv->v_type = VAR_STRING; | 11855 rettv->v_type = VAR_STRING; |
12269 | 11881 |
12270 /* | 11882 /* |
12271 * "getfontname()" function | 11883 * "getfontname()" function |
12272 */ | 11884 */ |
12273 static void | 11885 static void |
12274 f_getfontname(argvars, rettv) | 11886 f_getfontname(typval_T *argvars UNUSED, typval_T *rettv) |
12275 typval_T *argvars UNUSED; | |
12276 typval_T *rettv; | |
12277 { | 11887 { |
12278 rettv->v_type = VAR_STRING; | 11888 rettv->v_type = VAR_STRING; |
12279 rettv->vval.v_string = NULL; | 11889 rettv->vval.v_string = NULL; |
12280 #ifdef FEAT_GUI | 11890 #ifdef FEAT_GUI |
12281 if (gui.in_use) | 11891 if (gui.in_use) |
12308 | 11918 |
12309 /* | 11919 /* |
12310 * "getfperm({fname})" function | 11920 * "getfperm({fname})" function |
12311 */ | 11921 */ |
12312 static void | 11922 static void |
12313 f_getfperm(argvars, rettv) | 11923 f_getfperm(typval_T *argvars, typval_T *rettv) |
12314 typval_T *argvars; | |
12315 typval_T *rettv; | |
12316 { | 11924 { |
12317 char_u *fname; | 11925 char_u *fname; |
12318 struct stat st; | 11926 struct stat st; |
12319 char_u *perm = NULL; | 11927 char_u *perm = NULL; |
12320 char_u flags[] = "rwx"; | 11928 char_u flags[] = "rwx"; |
12340 | 11948 |
12341 /* | 11949 /* |
12342 * "getfsize({fname})" function | 11950 * "getfsize({fname})" function |
12343 */ | 11951 */ |
12344 static void | 11952 static void |
12345 f_getfsize(argvars, rettv) | 11953 f_getfsize(typval_T *argvars, typval_T *rettv) |
12346 typval_T *argvars; | |
12347 typval_T *rettv; | |
12348 { | 11954 { |
12349 char_u *fname; | 11955 char_u *fname; |
12350 struct stat st; | 11956 struct stat st; |
12351 | 11957 |
12352 fname = get_tv_string(&argvars[0]); | 11958 fname = get_tv_string(&argvars[0]); |
12372 | 11978 |
12373 /* | 11979 /* |
12374 * "getftime({fname})" function | 11980 * "getftime({fname})" function |
12375 */ | 11981 */ |
12376 static void | 11982 static void |
12377 f_getftime(argvars, rettv) | 11983 f_getftime(typval_T *argvars, typval_T *rettv) |
12378 typval_T *argvars; | |
12379 typval_T *rettv; | |
12380 { | 11984 { |
12381 char_u *fname; | 11985 char_u *fname; |
12382 struct stat st; | 11986 struct stat st; |
12383 | 11987 |
12384 fname = get_tv_string(&argvars[0]); | 11988 fname = get_tv_string(&argvars[0]); |
12391 | 11995 |
12392 /* | 11996 /* |
12393 * "getftype({fname})" function | 11997 * "getftype({fname})" function |
12394 */ | 11998 */ |
12395 static void | 11999 static void |
12396 f_getftype(argvars, rettv) | 12000 f_getftype(typval_T *argvars, typval_T *rettv) |
12397 typval_T *argvars; | |
12398 typval_T *rettv; | |
12399 { | 12001 { |
12400 char_u *fname; | 12002 char_u *fname; |
12401 struct stat st; | 12003 struct stat st; |
12402 char_u *type = NULL; | 12004 char_u *type = NULL; |
12403 char *t; | 12005 char *t; |
12471 | 12073 |
12472 /* | 12074 /* |
12473 * "getline(lnum, [end])" function | 12075 * "getline(lnum, [end])" function |
12474 */ | 12076 */ |
12475 static void | 12077 static void |
12476 f_getline(argvars, rettv) | 12078 f_getline(typval_T *argvars, typval_T *rettv) |
12477 typval_T *argvars; | |
12478 typval_T *rettv; | |
12479 { | 12079 { |
12480 linenr_T lnum; | 12080 linenr_T lnum; |
12481 linenr_T end; | 12081 linenr_T end; |
12482 int retlist; | 12082 int retlist; |
12483 | 12083 |
12498 | 12098 |
12499 /* | 12099 /* |
12500 * "getmatches()" function | 12100 * "getmatches()" function |
12501 */ | 12101 */ |
12502 static void | 12102 static void |
12503 f_getmatches(argvars, rettv) | 12103 f_getmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
12504 typval_T *argvars UNUSED; | |
12505 typval_T *rettv UNUSED; | |
12506 { | 12104 { |
12507 #ifdef FEAT_SEARCH_EXTRA | 12105 #ifdef FEAT_SEARCH_EXTRA |
12508 dict_T *dict; | 12106 dict_T *dict; |
12509 matchitem_T *cur = curwin->w_match_head; | 12107 matchitem_T *cur = curwin->w_match_head; |
12510 int i; | 12108 int i; |
12566 | 12164 |
12567 /* | 12165 /* |
12568 * "getpid()" function | 12166 * "getpid()" function |
12569 */ | 12167 */ |
12570 static void | 12168 static void |
12571 f_getpid(argvars, rettv) | 12169 f_getpid(typval_T *argvars UNUSED, typval_T *rettv) |
12572 typval_T *argvars UNUSED; | |
12573 typval_T *rettv; | |
12574 { | 12170 { |
12575 rettv->vval.v_number = mch_get_pid(); | 12171 rettv->vval.v_number = mch_get_pid(); |
12576 } | 12172 } |
12577 | 12173 |
12578 static void getpos_both(typval_T *argvars, typval_T *rettv, int getcurpos); | 12174 static void getpos_both(typval_T *argvars, typval_T *rettv, int getcurpos); |
12579 | 12175 |
12580 /* | 12176 /* |
12581 * "getcurpos()" function | 12177 * "getcurpos()" function |
12582 */ | 12178 */ |
12583 static void | 12179 static void |
12584 f_getcurpos(argvars, rettv) | 12180 f_getcurpos(typval_T *argvars, typval_T *rettv) |
12585 typval_T *argvars; | |
12586 typval_T *rettv; | |
12587 { | 12181 { |
12588 getpos_both(argvars, rettv, TRUE); | 12182 getpos_both(argvars, rettv, TRUE); |
12589 } | 12183 } |
12590 | 12184 |
12591 /* | 12185 /* |
12592 * "getpos(string)" function | 12186 * "getpos(string)" function |
12593 */ | 12187 */ |
12594 static void | 12188 static void |
12595 f_getpos(argvars, rettv) | 12189 f_getpos(typval_T *argvars, typval_T *rettv) |
12596 typval_T *argvars; | |
12597 typval_T *rettv; | |
12598 { | 12190 { |
12599 getpos_both(argvars, rettv, FALSE); | 12191 getpos_both(argvars, rettv, FALSE); |
12600 } | 12192 } |
12601 | 12193 |
12602 static void | 12194 static void |
12603 getpos_both(argvars, rettv, getcurpos) | 12195 getpos_both( |
12604 typval_T *argvars; | 12196 typval_T *argvars, |
12605 typval_T *rettv; | 12197 typval_T *rettv, |
12606 int getcurpos; | 12198 int getcurpos) |
12607 { | 12199 { |
12608 pos_T *fp; | 12200 pos_T *fp; |
12609 list_T *l; | 12201 list_T *l; |
12610 int fnum = -1; | 12202 int fnum = -1; |
12611 | 12203 |
12640 | 12232 |
12641 /* | 12233 /* |
12642 * "getqflist()" and "getloclist()" functions | 12234 * "getqflist()" and "getloclist()" functions |
12643 */ | 12235 */ |
12644 static void | 12236 static void |
12645 f_getqflist(argvars, rettv) | 12237 f_getqflist(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
12646 typval_T *argvars UNUSED; | |
12647 typval_T *rettv UNUSED; | |
12648 { | 12238 { |
12649 #ifdef FEAT_QUICKFIX | 12239 #ifdef FEAT_QUICKFIX |
12650 win_T *wp; | 12240 win_T *wp; |
12651 #endif | 12241 #endif |
12652 | 12242 |
12668 | 12258 |
12669 /* | 12259 /* |
12670 * "getreg()" function | 12260 * "getreg()" function |
12671 */ | 12261 */ |
12672 static void | 12262 static void |
12673 f_getreg(argvars, rettv) | 12263 f_getreg(typval_T *argvars, typval_T *rettv) |
12674 typval_T *argvars; | |
12675 typval_T *rettv; | |
12676 { | 12264 { |
12677 char_u *strregname; | 12265 char_u *strregname; |
12678 int regname; | 12266 int regname; |
12679 int arg2 = FALSE; | 12267 int arg2 = FALSE; |
12680 int return_list = FALSE; | 12268 int return_list = FALSE; |
12719 | 12307 |
12720 /* | 12308 /* |
12721 * "getregtype()" function | 12309 * "getregtype()" function |
12722 */ | 12310 */ |
12723 static void | 12311 static void |
12724 f_getregtype(argvars, rettv) | 12312 f_getregtype(typval_T *argvars, typval_T *rettv) |
12725 typval_T *argvars; | |
12726 typval_T *rettv; | |
12727 { | 12313 { |
12728 char_u *strregname; | 12314 char_u *strregname; |
12729 int regname; | 12315 int regname; |
12730 char_u buf[NUMBUFLEN + 2]; | 12316 char_u buf[NUMBUFLEN + 2]; |
12731 long reglen = 0; | 12317 long reglen = 0; |
12765 | 12351 |
12766 /* | 12352 /* |
12767 * "gettabvar()" function | 12353 * "gettabvar()" function |
12768 */ | 12354 */ |
12769 static void | 12355 static void |
12770 f_gettabvar(argvars, rettv) | 12356 f_gettabvar(typval_T *argvars, typval_T *rettv) |
12771 typval_T *argvars; | |
12772 typval_T *rettv; | |
12773 { | 12357 { |
12774 win_T *oldcurwin; | 12358 win_T *oldcurwin; |
12775 tabpage_T *tp, *oldtabpage; | 12359 tabpage_T *tp, *oldtabpage; |
12776 dictitem_T *v; | 12360 dictitem_T *v; |
12777 char_u *varname; | 12361 char_u *varname; |
12810 | 12394 |
12811 /* | 12395 /* |
12812 * "gettabwinvar()" function | 12396 * "gettabwinvar()" function |
12813 */ | 12397 */ |
12814 static void | 12398 static void |
12815 f_gettabwinvar(argvars, rettv) | 12399 f_gettabwinvar(typval_T *argvars, typval_T *rettv) |
12816 typval_T *argvars; | |
12817 typval_T *rettv; | |
12818 { | 12400 { |
12819 getwinvar(argvars, rettv, 1); | 12401 getwinvar(argvars, rettv, 1); |
12820 } | 12402 } |
12821 | 12403 |
12822 /* | 12404 /* |
12823 * "getwinposx()" function | 12405 * "getwinposx()" function |
12824 */ | 12406 */ |
12825 static void | 12407 static void |
12826 f_getwinposx(argvars, rettv) | 12408 f_getwinposx(typval_T *argvars UNUSED, typval_T *rettv) |
12827 typval_T *argvars UNUSED; | |
12828 typval_T *rettv; | |
12829 { | 12409 { |
12830 rettv->vval.v_number = -1; | 12410 rettv->vval.v_number = -1; |
12831 #ifdef FEAT_GUI | 12411 #ifdef FEAT_GUI |
12832 if (gui.in_use) | 12412 if (gui.in_use) |
12833 { | 12413 { |
12841 | 12421 |
12842 /* | 12422 /* |
12843 * "getwinposy()" function | 12423 * "getwinposy()" function |
12844 */ | 12424 */ |
12845 static void | 12425 static void |
12846 f_getwinposy(argvars, rettv) | 12426 f_getwinposy(typval_T *argvars UNUSED, typval_T *rettv) |
12847 typval_T *argvars UNUSED; | |
12848 typval_T *rettv; | |
12849 { | 12427 { |
12850 rettv->vval.v_number = -1; | 12428 rettv->vval.v_number = -1; |
12851 #ifdef FEAT_GUI | 12429 #ifdef FEAT_GUI |
12852 if (gui.in_use) | 12430 if (gui.in_use) |
12853 { | 12431 { |
12861 | 12439 |
12862 /* | 12440 /* |
12863 * Find window specified by "vp" in tabpage "tp". | 12441 * Find window specified by "vp" in tabpage "tp". |
12864 */ | 12442 */ |
12865 static win_T * | 12443 static win_T * |
12866 find_win_by_nr(vp, tp) | 12444 find_win_by_nr( |
12867 typval_T *vp; | 12445 typval_T *vp, |
12868 tabpage_T *tp UNUSED; /* NULL for current tab page */ | 12446 tabpage_T *tp UNUSED) /* NULL for current tab page */ |
12869 { | 12447 { |
12870 #ifdef FEAT_WINDOWS | 12448 #ifdef FEAT_WINDOWS |
12871 win_T *wp; | 12449 win_T *wp; |
12872 #endif | 12450 #endif |
12873 int nr; | 12451 int nr; |
12894 | 12472 |
12895 /* | 12473 /* |
12896 * Find window specified by "wvp" in tabpage "tvp". | 12474 * Find window specified by "wvp" in tabpage "tvp". |
12897 */ | 12475 */ |
12898 static win_T * | 12476 static win_T * |
12899 find_tabwin(wvp, tvp) | 12477 find_tabwin( |
12900 typval_T *wvp; /* VAR_UNKNOWN for current window */ | 12478 typval_T *wvp, /* VAR_UNKNOWN for current window */ |
12901 typval_T *tvp; /* VAR_UNKNOWN for current tab page */ | 12479 typval_T *tvp) /* VAR_UNKNOWN for current tab page */ |
12902 { | 12480 { |
12903 win_T *wp = NULL; | 12481 win_T *wp = NULL; |
12904 tabpage_T *tp = NULL; | 12482 tabpage_T *tp = NULL; |
12905 long n; | 12483 long n; |
12906 | 12484 |
12926 | 12504 |
12927 /* | 12505 /* |
12928 * "getwinvar()" function | 12506 * "getwinvar()" function |
12929 */ | 12507 */ |
12930 static void | 12508 static void |
12931 f_getwinvar(argvars, rettv) | 12509 f_getwinvar(typval_T *argvars, typval_T *rettv) |
12932 typval_T *argvars; | |
12933 typval_T *rettv; | |
12934 { | 12510 { |
12935 getwinvar(argvars, rettv, 0); | 12511 getwinvar(argvars, rettv, 0); |
12936 } | 12512 } |
12937 | 12513 |
12938 /* | 12514 /* |
12939 * getwinvar() and gettabwinvar() | 12515 * getwinvar() and gettabwinvar() |
12940 */ | 12516 */ |
12941 static void | 12517 static void |
12942 getwinvar(argvars, rettv, off) | 12518 getwinvar( |
12943 typval_T *argvars; | 12519 typval_T *argvars, |
12944 typval_T *rettv; | 12520 typval_T *rettv, |
12945 int off; /* 1 for gettabwinvar() */ | 12521 int off) /* 1 for gettabwinvar() */ |
12946 { | 12522 { |
12947 win_T *win; | 12523 win_T *win; |
12948 char_u *varname; | 12524 char_u *varname; |
12949 dictitem_T *v; | 12525 dictitem_T *v; |
12950 tabpage_T *tp = NULL; | 12526 tabpage_T *tp = NULL; |
13014 | 12590 |
13015 /* | 12591 /* |
13016 * "glob()" function | 12592 * "glob()" function |
13017 */ | 12593 */ |
13018 static void | 12594 static void |
13019 f_glob(argvars, rettv) | 12595 f_glob(typval_T *argvars, typval_T *rettv) |
13020 typval_T *argvars; | |
13021 typval_T *rettv; | |
13022 { | 12596 { |
13023 int options = WILD_SILENT|WILD_USE_NL; | 12597 int options = WILD_SILENT|WILD_USE_NL; |
13024 expand_T xpc; | 12598 expand_T xpc; |
13025 int error = FALSE; | 12599 int error = FALSE; |
13026 | 12600 |
13070 | 12644 |
13071 /* | 12645 /* |
13072 * "globpath()" function | 12646 * "globpath()" function |
13073 */ | 12647 */ |
13074 static void | 12648 static void |
13075 f_globpath(argvars, rettv) | 12649 f_globpath(typval_T *argvars, typval_T *rettv) |
13076 typval_T *argvars; | |
13077 typval_T *rettv; | |
13078 { | 12650 { |
13079 int flags = 0; | 12651 int flags = 0; |
13080 char_u buf1[NUMBUFLEN]; | 12652 char_u buf1[NUMBUFLEN]; |
13081 char_u *file = get_tv_string_buf_chk(&argvars[1], buf1); | 12653 char_u *file = get_tv_string_buf_chk(&argvars[1], buf1); |
13082 int error = FALSE; | 12654 int error = FALSE; |
13120 | 12692 |
13121 /* | 12693 /* |
13122 * "glob2regpat()" function | 12694 * "glob2regpat()" function |
13123 */ | 12695 */ |
13124 static void | 12696 static void |
13125 f_glob2regpat(argvars, rettv) | 12697 f_glob2regpat(typval_T *argvars, typval_T *rettv) |
13126 typval_T *argvars; | |
13127 typval_T *rettv; | |
13128 { | 12698 { |
13129 char_u *pat = get_tv_string_chk(&argvars[0]); | 12699 char_u *pat = get_tv_string_chk(&argvars[0]); |
13130 | 12700 |
13131 rettv->v_type = VAR_STRING; | 12701 rettv->v_type = VAR_STRING; |
13132 rettv->vval.v_string = (pat == NULL) | 12702 rettv->vval.v_string = (pat == NULL) |
13135 | 12705 |
13136 /* | 12706 /* |
13137 * "has()" function | 12707 * "has()" function |
13138 */ | 12708 */ |
13139 static void | 12709 static void |
13140 f_has(argvars, rettv) | 12710 f_has(typval_T *argvars, typval_T *rettv) |
13141 typval_T *argvars; | |
13142 typval_T *rettv; | |
13143 { | 12711 { |
13144 int i; | 12712 int i; |
13145 char_u *name; | 12713 char_u *name; |
13146 int n = FALSE; | 12714 int n = FALSE; |
13147 static char *(has_list[]) = | 12715 static char *(has_list[]) = |
13740 | 13308 |
13741 /* | 13309 /* |
13742 * "has_key()" function | 13310 * "has_key()" function |
13743 */ | 13311 */ |
13744 static void | 13312 static void |
13745 f_has_key(argvars, rettv) | 13313 f_has_key(typval_T *argvars, typval_T *rettv) |
13746 typval_T *argvars; | |
13747 typval_T *rettv; | |
13748 { | 13314 { |
13749 if (argvars[0].v_type != VAR_DICT) | 13315 if (argvars[0].v_type != VAR_DICT) |
13750 { | 13316 { |
13751 EMSG(_(e_dictreq)); | 13317 EMSG(_(e_dictreq)); |
13752 return; | 13318 return; |
13760 | 13326 |
13761 /* | 13327 /* |
13762 * "haslocaldir()" function | 13328 * "haslocaldir()" function |
13763 */ | 13329 */ |
13764 static void | 13330 static void |
13765 f_haslocaldir(argvars, rettv) | 13331 f_haslocaldir(typval_T *argvars, typval_T *rettv) |
13766 typval_T *argvars; | |
13767 typval_T *rettv; | |
13768 { | 13332 { |
13769 win_T *wp = NULL; | 13333 win_T *wp = NULL; |
13770 | 13334 |
13771 wp = find_tabwin(&argvars[0], &argvars[1]); | 13335 wp = find_tabwin(&argvars[0], &argvars[1]); |
13772 rettv->vval.v_number = (wp != NULL && wp->w_localdir != NULL); | 13336 rettv->vval.v_number = (wp != NULL && wp->w_localdir != NULL); |
13774 | 13338 |
13775 /* | 13339 /* |
13776 * "hasmapto()" function | 13340 * "hasmapto()" function |
13777 */ | 13341 */ |
13778 static void | 13342 static void |
13779 f_hasmapto(argvars, rettv) | 13343 f_hasmapto(typval_T *argvars, typval_T *rettv) |
13780 typval_T *argvars; | |
13781 typval_T *rettv; | |
13782 { | 13344 { |
13783 char_u *name; | 13345 char_u *name; |
13784 char_u *mode; | 13346 char_u *mode; |
13785 char_u buf[NUMBUFLEN]; | 13347 char_u buf[NUMBUFLEN]; |
13786 int abbr = FALSE; | 13348 int abbr = FALSE; |
13803 | 13365 |
13804 /* | 13366 /* |
13805 * "histadd()" function | 13367 * "histadd()" function |
13806 */ | 13368 */ |
13807 static void | 13369 static void |
13808 f_histadd(argvars, rettv) | 13370 f_histadd(typval_T *argvars UNUSED, typval_T *rettv) |
13809 typval_T *argvars UNUSED; | |
13810 typval_T *rettv; | |
13811 { | 13371 { |
13812 #ifdef FEAT_CMDHIST | 13372 #ifdef FEAT_CMDHIST |
13813 int histype; | 13373 int histype; |
13814 char_u *str; | 13374 char_u *str; |
13815 char_u buf[NUMBUFLEN]; | 13375 char_u buf[NUMBUFLEN]; |
13837 | 13397 |
13838 /* | 13398 /* |
13839 * "histdel()" function | 13399 * "histdel()" function |
13840 */ | 13400 */ |
13841 static void | 13401 static void |
13842 f_histdel(argvars, rettv) | 13402 f_histdel(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
13843 typval_T *argvars UNUSED; | |
13844 typval_T *rettv UNUSED; | |
13845 { | 13403 { |
13846 #ifdef FEAT_CMDHIST | 13404 #ifdef FEAT_CMDHIST |
13847 int n; | 13405 int n; |
13848 char_u buf[NUMBUFLEN]; | 13406 char_u buf[NUMBUFLEN]; |
13849 char_u *str; | 13407 char_u *str; |
13868 | 13426 |
13869 /* | 13427 /* |
13870 * "histget()" function | 13428 * "histget()" function |
13871 */ | 13429 */ |
13872 static void | 13430 static void |
13873 f_histget(argvars, rettv) | 13431 f_histget(typval_T *argvars UNUSED, typval_T *rettv) |
13874 typval_T *argvars UNUSED; | |
13875 typval_T *rettv; | |
13876 { | 13432 { |
13877 #ifdef FEAT_CMDHIST | 13433 #ifdef FEAT_CMDHIST |
13878 int type; | 13434 int type; |
13879 int idx; | 13435 int idx; |
13880 char_u *str; | 13436 char_u *str; |
13900 | 13456 |
13901 /* | 13457 /* |
13902 * "histnr()" function | 13458 * "histnr()" function |
13903 */ | 13459 */ |
13904 static void | 13460 static void |
13905 f_histnr(argvars, rettv) | 13461 f_histnr(typval_T *argvars UNUSED, typval_T *rettv) |
13906 typval_T *argvars UNUSED; | |
13907 typval_T *rettv; | |
13908 { | 13462 { |
13909 int i; | 13463 int i; |
13910 | 13464 |
13911 #ifdef FEAT_CMDHIST | 13465 #ifdef FEAT_CMDHIST |
13912 char_u *history = get_tv_string_chk(&argvars[0]); | 13466 char_u *history = get_tv_string_chk(&argvars[0]); |
13922 | 13476 |
13923 /* | 13477 /* |
13924 * "highlightID(name)" function | 13478 * "highlightID(name)" function |
13925 */ | 13479 */ |
13926 static void | 13480 static void |
13927 f_hlID(argvars, rettv) | 13481 f_hlID(typval_T *argvars, typval_T *rettv) |
13928 typval_T *argvars; | |
13929 typval_T *rettv; | |
13930 { | 13482 { |
13931 rettv->vval.v_number = syn_name2id(get_tv_string(&argvars[0])); | 13483 rettv->vval.v_number = syn_name2id(get_tv_string(&argvars[0])); |
13932 } | 13484 } |
13933 | 13485 |
13934 /* | 13486 /* |
13935 * "highlight_exists()" function | 13487 * "highlight_exists()" function |
13936 */ | 13488 */ |
13937 static void | 13489 static void |
13938 f_hlexists(argvars, rettv) | 13490 f_hlexists(typval_T *argvars, typval_T *rettv) |
13939 typval_T *argvars; | |
13940 typval_T *rettv; | |
13941 { | 13491 { |
13942 rettv->vval.v_number = highlight_exists(get_tv_string(&argvars[0])); | 13492 rettv->vval.v_number = highlight_exists(get_tv_string(&argvars[0])); |
13943 } | 13493 } |
13944 | 13494 |
13945 /* | 13495 /* |
13946 * "hostname()" function | 13496 * "hostname()" function |
13947 */ | 13497 */ |
13948 static void | 13498 static void |
13949 f_hostname(argvars, rettv) | 13499 f_hostname(typval_T *argvars UNUSED, typval_T *rettv) |
13950 typval_T *argvars UNUSED; | |
13951 typval_T *rettv; | |
13952 { | 13500 { |
13953 char_u hostname[256]; | 13501 char_u hostname[256]; |
13954 | 13502 |
13955 mch_get_host_name(hostname, 256); | 13503 mch_get_host_name(hostname, 256); |
13956 rettv->v_type = VAR_STRING; | 13504 rettv->v_type = VAR_STRING; |
13959 | 13507 |
13960 /* | 13508 /* |
13961 * iconv() function | 13509 * iconv() function |
13962 */ | 13510 */ |
13963 static void | 13511 static void |
13964 f_iconv(argvars, rettv) | 13512 f_iconv(typval_T *argvars UNUSED, typval_T *rettv) |
13965 typval_T *argvars UNUSED; | |
13966 typval_T *rettv; | |
13967 { | 13513 { |
13968 #ifdef FEAT_MBYTE | 13514 #ifdef FEAT_MBYTE |
13969 char_u buf1[NUMBUFLEN]; | 13515 char_u buf1[NUMBUFLEN]; |
13970 char_u buf2[NUMBUFLEN]; | 13516 char_u buf2[NUMBUFLEN]; |
13971 char_u *from, *to, *str; | 13517 char_u *from, *to, *str; |
13996 | 13542 |
13997 /* | 13543 /* |
13998 * "indent()" function | 13544 * "indent()" function |
13999 */ | 13545 */ |
14000 static void | 13546 static void |
14001 f_indent(argvars, rettv) | 13547 f_indent(typval_T *argvars, typval_T *rettv) |
14002 typval_T *argvars; | |
14003 typval_T *rettv; | |
14004 { | 13548 { |
14005 linenr_T lnum; | 13549 linenr_T lnum; |
14006 | 13550 |
14007 lnum = get_tv_lnum(argvars); | 13551 lnum = get_tv_lnum(argvars); |
14008 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count) | 13552 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count) |
14013 | 13557 |
14014 /* | 13558 /* |
14015 * "index()" function | 13559 * "index()" function |
14016 */ | 13560 */ |
14017 static void | 13561 static void |
14018 f_index(argvars, rettv) | 13562 f_index(typval_T *argvars, typval_T *rettv) |
14019 typval_T *argvars; | |
14020 typval_T *rettv; | |
14021 { | 13563 { |
14022 list_T *l; | 13564 list_T *l; |
14023 listitem_T *item; | 13565 listitem_T *item; |
14024 long idx = 0; | 13566 long idx = 0; |
14025 int ic = FALSE; | 13567 int ic = FALSE; |
14066 * argument to f_input() specifies the type of completion to use at the | 13608 * argument to f_input() specifies the type of completion to use at the |
14067 * prompt. The third argument to f_inputdialog() specifies the value to return | 13609 * prompt. The third argument to f_inputdialog() specifies the value to return |
14068 * when the user cancels the prompt. | 13610 * when the user cancels the prompt. |
14069 */ | 13611 */ |
14070 static void | 13612 static void |
14071 get_user_input(argvars, rettv, inputdialog) | 13613 get_user_input( |
14072 typval_T *argvars; | 13614 typval_T *argvars, |
14073 typval_T *rettv; | 13615 typval_T *rettv, |
14074 int inputdialog; | 13616 int inputdialog) |
14075 { | 13617 { |
14076 char_u *prompt = get_tv_string_chk(&argvars[0]); | 13618 char_u *prompt = get_tv_string_chk(&argvars[0]); |
14077 char_u *p = NULL; | 13619 char_u *p = NULL; |
14078 int c; | 13620 int c; |
14079 char_u buf[NUMBUFLEN]; | 13621 char_u buf[NUMBUFLEN]; |
14171 /* | 13713 /* |
14172 * "input()" function | 13714 * "input()" function |
14173 * Also handles inputsecret() when inputsecret is set. | 13715 * Also handles inputsecret() when inputsecret is set. |
14174 */ | 13716 */ |
14175 static void | 13717 static void |
14176 f_input(argvars, rettv) | 13718 f_input(typval_T *argvars, typval_T *rettv) |
14177 typval_T *argvars; | |
14178 typval_T *rettv; | |
14179 { | 13719 { |
14180 get_user_input(argvars, rettv, FALSE); | 13720 get_user_input(argvars, rettv, FALSE); |
14181 } | 13721 } |
14182 | 13722 |
14183 /* | 13723 /* |
14184 * "inputdialog()" function | 13724 * "inputdialog()" function |
14185 */ | 13725 */ |
14186 static void | 13726 static void |
14187 f_inputdialog(argvars, rettv) | 13727 f_inputdialog(typval_T *argvars, typval_T *rettv) |
14188 typval_T *argvars; | |
14189 typval_T *rettv; | |
14190 { | 13728 { |
14191 #if defined(FEAT_GUI_TEXTDIALOG) | 13729 #if defined(FEAT_GUI_TEXTDIALOG) |
14192 /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ | 13730 /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ |
14193 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) | 13731 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) |
14194 { | 13732 { |
14225 | 13763 |
14226 /* | 13764 /* |
14227 * "inputlist()" function | 13765 * "inputlist()" function |
14228 */ | 13766 */ |
14229 static void | 13767 static void |
14230 f_inputlist(argvars, rettv) | 13768 f_inputlist(typval_T *argvars, typval_T *rettv) |
14231 typval_T *argvars; | |
14232 typval_T *rettv; | |
14233 { | 13769 { |
14234 listitem_T *li; | 13770 listitem_T *li; |
14235 int selected; | 13771 int selected; |
14236 int mouse_used; | 13772 int mouse_used; |
14237 | 13773 |
14271 | 13807 |
14272 /* | 13808 /* |
14273 * "inputrestore()" function | 13809 * "inputrestore()" function |
14274 */ | 13810 */ |
14275 static void | 13811 static void |
14276 f_inputrestore(argvars, rettv) | 13812 f_inputrestore(typval_T *argvars UNUSED, typval_T *rettv) |
14277 typval_T *argvars UNUSED; | |
14278 typval_T *rettv; | |
14279 { | 13813 { |
14280 if (ga_userinput.ga_len > 0) | 13814 if (ga_userinput.ga_len > 0) |
14281 { | 13815 { |
14282 --ga_userinput.ga_len; | 13816 --ga_userinput.ga_len; |
14283 restore_typeahead((tasave_T *)(ga_userinput.ga_data) | 13817 restore_typeahead((tasave_T *)(ga_userinput.ga_data) |
14293 | 13827 |
14294 /* | 13828 /* |
14295 * "inputsave()" function | 13829 * "inputsave()" function |
14296 */ | 13830 */ |
14297 static void | 13831 static void |
14298 f_inputsave(argvars, rettv) | 13832 f_inputsave(typval_T *argvars UNUSED, typval_T *rettv) |
14299 typval_T *argvars UNUSED; | |
14300 typval_T *rettv; | |
14301 { | 13833 { |
14302 /* Add an entry to the stack of typeahead storage. */ | 13834 /* Add an entry to the stack of typeahead storage. */ |
14303 if (ga_grow(&ga_userinput, 1) == OK) | 13835 if (ga_grow(&ga_userinput, 1) == OK) |
14304 { | 13836 { |
14305 save_typeahead((tasave_T *)(ga_userinput.ga_data) | 13837 save_typeahead((tasave_T *)(ga_userinput.ga_data) |
14313 | 13845 |
14314 /* | 13846 /* |
14315 * "inputsecret()" function | 13847 * "inputsecret()" function |
14316 */ | 13848 */ |
14317 static void | 13849 static void |
14318 f_inputsecret(argvars, rettv) | 13850 f_inputsecret(typval_T *argvars, typval_T *rettv) |
14319 typval_T *argvars; | |
14320 typval_T *rettv; | |
14321 { | 13851 { |
14322 ++cmdline_star; | 13852 ++cmdline_star; |
14323 ++inputsecret_flag; | 13853 ++inputsecret_flag; |
14324 f_input(argvars, rettv); | 13854 f_input(argvars, rettv); |
14325 --cmdline_star; | 13855 --cmdline_star; |
14328 | 13858 |
14329 /* | 13859 /* |
14330 * "insert()" function | 13860 * "insert()" function |
14331 */ | 13861 */ |
14332 static void | 13862 static void |
14333 f_insert(argvars, rettv) | 13863 f_insert(typval_T *argvars, typval_T *rettv) |
14334 typval_T *argvars; | |
14335 typval_T *rettv; | |
14336 { | 13864 { |
14337 long before = 0; | 13865 long before = 0; |
14338 listitem_T *item; | 13866 listitem_T *item; |
14339 list_T *l; | 13867 list_T *l; |
14340 int error = FALSE; | 13868 int error = FALSE; |
14370 | 13898 |
14371 /* | 13899 /* |
14372 * "invert(expr)" function | 13900 * "invert(expr)" function |
14373 */ | 13901 */ |
14374 static void | 13902 static void |
14375 f_invert(argvars, rettv) | 13903 f_invert(typval_T *argvars, typval_T *rettv) |
14376 typval_T *argvars; | |
14377 typval_T *rettv; | |
14378 { | 13904 { |
14379 rettv->vval.v_number = ~get_tv_number_chk(&argvars[0], NULL); | 13905 rettv->vval.v_number = ~get_tv_number_chk(&argvars[0], NULL); |
14380 } | 13906 } |
14381 | 13907 |
14382 /* | 13908 /* |
14383 * "isdirectory()" function | 13909 * "isdirectory()" function |
14384 */ | 13910 */ |
14385 static void | 13911 static void |
14386 f_isdirectory(argvars, rettv) | 13912 f_isdirectory(typval_T *argvars, typval_T *rettv) |
14387 typval_T *argvars; | |
14388 typval_T *rettv; | |
14389 { | 13913 { |
14390 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0])); | 13914 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0])); |
14391 } | 13915 } |
14392 | 13916 |
14393 /* | 13917 /* |
14394 * "islocked()" function | 13918 * "islocked()" function |
14395 */ | 13919 */ |
14396 static void | 13920 static void |
14397 f_islocked(argvars, rettv) | 13921 f_islocked(typval_T *argvars, typval_T *rettv) |
14398 typval_T *argvars; | |
14399 typval_T *rettv; | |
14400 { | 13922 { |
14401 lval_T lv; | 13923 lval_T lv; |
14402 char_u *end; | 13924 char_u *end; |
14403 dictitem_T *di; | 13925 dictitem_T *di; |
14404 | 13926 |
14453 * "what" == 0: list of keys | 13975 * "what" == 0: list of keys |
14454 * "what" == 1: list of values | 13976 * "what" == 1: list of values |
14455 * "what" == 2: list of items | 13977 * "what" == 2: list of items |
14456 */ | 13978 */ |
14457 static void | 13979 static void |
14458 dict_list(argvars, rettv, what) | 13980 dict_list(typval_T *argvars, typval_T *rettv, int what) |
14459 typval_T *argvars; | |
14460 typval_T *rettv; | |
14461 int what; | |
14462 { | 13981 { |
14463 list_T *l2; | 13982 list_T *l2; |
14464 dictitem_T *di; | 13983 dictitem_T *di; |
14465 hashitem_T *hi; | 13984 hashitem_T *hi; |
14466 listitem_T *li; | 13985 listitem_T *li; |
14535 | 14054 |
14536 /* | 14055 /* |
14537 * "items(dict)" function | 14056 * "items(dict)" function |
14538 */ | 14057 */ |
14539 static void | 14058 static void |
14540 f_items(argvars, rettv) | 14059 f_items(typval_T *argvars, typval_T *rettv) |
14541 typval_T *argvars; | |
14542 typval_T *rettv; | |
14543 { | 14060 { |
14544 dict_list(argvars, rettv, 2); | 14061 dict_list(argvars, rettv, 2); |
14545 } | 14062 } |
14546 | 14063 |
14547 /* | 14064 /* |
14548 * "join()" function | 14065 * "join()" function |
14549 */ | 14066 */ |
14550 static void | 14067 static void |
14551 f_join(argvars, rettv) | 14068 f_join(typval_T *argvars, typval_T *rettv) |
14552 typval_T *argvars; | |
14553 typval_T *rettv; | |
14554 { | 14069 { |
14555 garray_T ga; | 14070 garray_T ga; |
14556 char_u *sep; | 14071 char_u *sep; |
14557 | 14072 |
14558 if (argvars[0].v_type != VAR_LIST) | 14073 if (argvars[0].v_type != VAR_LIST) |
14582 | 14097 |
14583 /* | 14098 /* |
14584 * "jsondecode()" function | 14099 * "jsondecode()" function |
14585 */ | 14100 */ |
14586 static void | 14101 static void |
14587 f_jsondecode(argvars, rettv) | 14102 f_jsondecode(typval_T *argvars, typval_T *rettv) |
14588 typval_T *argvars; | |
14589 typval_T *rettv; | |
14590 { | 14103 { |
14591 js_read_T reader; | 14104 js_read_T reader; |
14592 | 14105 |
14593 reader.js_buf = get_tv_string(&argvars[0]); | 14106 reader.js_buf = get_tv_string(&argvars[0]); |
14594 reader.js_eof = TRUE; | 14107 reader.js_eof = TRUE; |
14598 | 14111 |
14599 /* | 14112 /* |
14600 * "jsonencode()" function | 14113 * "jsonencode()" function |
14601 */ | 14114 */ |
14602 static void | 14115 static void |
14603 f_jsonencode(argvars, rettv) | 14116 f_jsonencode(typval_T *argvars, typval_T *rettv) |
14604 typval_T *argvars; | |
14605 typval_T *rettv; | |
14606 { | 14117 { |
14607 rettv->v_type = VAR_STRING; | 14118 rettv->v_type = VAR_STRING; |
14608 rettv->vval.v_string = json_encode(&argvars[0]); | 14119 rettv->vval.v_string = json_encode(&argvars[0]); |
14609 } | 14120 } |
14610 | 14121 |
14611 /* | 14122 /* |
14612 * "keys()" function | 14123 * "keys()" function |
14613 */ | 14124 */ |
14614 static void | 14125 static void |
14615 f_keys(argvars, rettv) | 14126 f_keys(typval_T *argvars, typval_T *rettv) |
14616 typval_T *argvars; | |
14617 typval_T *rettv; | |
14618 { | 14127 { |
14619 dict_list(argvars, rettv, 0); | 14128 dict_list(argvars, rettv, 0); |
14620 } | 14129 } |
14621 | 14130 |
14622 /* | 14131 /* |
14623 * "last_buffer_nr()" function. | 14132 * "last_buffer_nr()" function. |
14624 */ | 14133 */ |
14625 static void | 14134 static void |
14626 f_last_buffer_nr(argvars, rettv) | 14135 f_last_buffer_nr(typval_T *argvars UNUSED, typval_T *rettv) |
14627 typval_T *argvars UNUSED; | |
14628 typval_T *rettv; | |
14629 { | 14136 { |
14630 int n = 0; | 14137 int n = 0; |
14631 buf_T *buf; | 14138 buf_T *buf; |
14632 | 14139 |
14633 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | 14140 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
14639 | 14146 |
14640 /* | 14147 /* |
14641 * "len()" function | 14148 * "len()" function |
14642 */ | 14149 */ |
14643 static void | 14150 static void |
14644 f_len(argvars, rettv) | 14151 f_len(typval_T *argvars, typval_T *rettv) |
14645 typval_T *argvars; | |
14646 typval_T *rettv; | |
14647 { | 14152 { |
14648 switch (argvars[0].v_type) | 14153 switch (argvars[0].v_type) |
14649 { | 14154 { |
14650 case VAR_STRING: | 14155 case VAR_STRING: |
14651 case VAR_NUMBER: | 14156 case VAR_NUMBER: |
14665 } | 14170 } |
14666 | 14171 |
14667 static void libcall_common(typval_T *argvars, typval_T *rettv, int type); | 14172 static void libcall_common(typval_T *argvars, typval_T *rettv, int type); |
14668 | 14173 |
14669 static void | 14174 static void |
14670 libcall_common(argvars, rettv, type) | 14175 libcall_common(typval_T *argvars, typval_T *rettv, int type) |
14671 typval_T *argvars; | |
14672 typval_T *rettv; | |
14673 int type; | |
14674 { | 14176 { |
14675 #ifdef FEAT_LIBCALL | 14177 #ifdef FEAT_LIBCALL |
14676 char_u *string_in; | 14178 char_u *string_in; |
14677 char_u **string_result; | 14179 char_u **string_result; |
14678 int nr_result; | 14180 int nr_result; |
14710 | 14212 |
14711 /* | 14213 /* |
14712 * "libcall()" function | 14214 * "libcall()" function |
14713 */ | 14215 */ |
14714 static void | 14216 static void |
14715 f_libcall(argvars, rettv) | 14217 f_libcall(typval_T *argvars, typval_T *rettv) |
14716 typval_T *argvars; | |
14717 typval_T *rettv; | |
14718 { | 14218 { |
14719 libcall_common(argvars, rettv, VAR_STRING); | 14219 libcall_common(argvars, rettv, VAR_STRING); |
14720 } | 14220 } |
14721 | 14221 |
14722 /* | 14222 /* |
14723 * "libcallnr()" function | 14223 * "libcallnr()" function |
14724 */ | 14224 */ |
14725 static void | 14225 static void |
14726 f_libcallnr(argvars, rettv) | 14226 f_libcallnr(typval_T *argvars, typval_T *rettv) |
14727 typval_T *argvars; | |
14728 typval_T *rettv; | |
14729 { | 14227 { |
14730 libcall_common(argvars, rettv, VAR_NUMBER); | 14228 libcall_common(argvars, rettv, VAR_NUMBER); |
14731 } | 14229 } |
14732 | 14230 |
14733 /* | 14231 /* |
14734 * "line(string)" function | 14232 * "line(string)" function |
14735 */ | 14233 */ |
14736 static void | 14234 static void |
14737 f_line(argvars, rettv) | 14235 f_line(typval_T *argvars, typval_T *rettv) |
14738 typval_T *argvars; | |
14739 typval_T *rettv; | |
14740 { | 14236 { |
14741 linenr_T lnum = 0; | 14237 linenr_T lnum = 0; |
14742 pos_T *fp; | 14238 pos_T *fp; |
14743 int fnum; | 14239 int fnum; |
14744 | 14240 |
14750 | 14246 |
14751 /* | 14247 /* |
14752 * "line2byte(lnum)" function | 14248 * "line2byte(lnum)" function |
14753 */ | 14249 */ |
14754 static void | 14250 static void |
14755 f_line2byte(argvars, rettv) | 14251 f_line2byte(typval_T *argvars UNUSED, typval_T *rettv) |
14756 typval_T *argvars UNUSED; | |
14757 typval_T *rettv; | |
14758 { | 14252 { |
14759 #ifndef FEAT_BYTEOFF | 14253 #ifndef FEAT_BYTEOFF |
14760 rettv->vval.v_number = -1; | 14254 rettv->vval.v_number = -1; |
14761 #else | 14255 #else |
14762 linenr_T lnum; | 14256 linenr_T lnum; |
14773 | 14267 |
14774 /* | 14268 /* |
14775 * "lispindent(lnum)" function | 14269 * "lispindent(lnum)" function |
14776 */ | 14270 */ |
14777 static void | 14271 static void |
14778 f_lispindent(argvars, rettv) | 14272 f_lispindent(typval_T *argvars UNUSED, typval_T *rettv) |
14779 typval_T *argvars UNUSED; | |
14780 typval_T *rettv; | |
14781 { | 14273 { |
14782 #ifdef FEAT_LISP | 14274 #ifdef FEAT_LISP |
14783 pos_T pos; | 14275 pos_T pos; |
14784 linenr_T lnum; | 14276 linenr_T lnum; |
14785 | 14277 |
14798 | 14290 |
14799 /* | 14291 /* |
14800 * "localtime()" function | 14292 * "localtime()" function |
14801 */ | 14293 */ |
14802 static void | 14294 static void |
14803 f_localtime(argvars, rettv) | 14295 f_localtime(typval_T *argvars UNUSED, typval_T *rettv) |
14804 typval_T *argvars UNUSED; | |
14805 typval_T *rettv; | |
14806 { | 14296 { |
14807 rettv->vval.v_number = (varnumber_T)time(NULL); | 14297 rettv->vval.v_number = (varnumber_T)time(NULL); |
14808 } | 14298 } |
14809 | 14299 |
14810 static void get_maparg(typval_T *argvars, typval_T *rettv, int exact); | 14300 static void get_maparg(typval_T *argvars, typval_T *rettv, int exact); |
14811 | 14301 |
14812 static void | 14302 static void |
14813 get_maparg(argvars, rettv, exact) | 14303 get_maparg(typval_T *argvars, typval_T *rettv, int exact) |
14814 typval_T *argvars; | |
14815 typval_T *rettv; | |
14816 int exact; | |
14817 { | 14304 { |
14818 char_u *keys; | 14305 char_u *keys; |
14819 char_u *which; | 14306 char_u *which; |
14820 char_u buf[NUMBUFLEN]; | 14307 char_u buf[NUMBUFLEN]; |
14821 char_u *keys_buf = NULL; | 14308 char_u *keys_buf = NULL; |
14887 #ifdef FEAT_FLOAT | 14374 #ifdef FEAT_FLOAT |
14888 /* | 14375 /* |
14889 * "log()" function | 14376 * "log()" function |
14890 */ | 14377 */ |
14891 static void | 14378 static void |
14892 f_log(argvars, rettv) | 14379 f_log(typval_T *argvars, typval_T *rettv) |
14893 typval_T *argvars; | |
14894 typval_T *rettv; | |
14895 { | 14380 { |
14896 float_T f; | 14381 float_T f; |
14897 | 14382 |
14898 rettv->v_type = VAR_FLOAT; | 14383 rettv->v_type = VAR_FLOAT; |
14899 if (get_float_arg(argvars, &f) == OK) | 14384 if (get_float_arg(argvars, &f) == OK) |
14904 | 14389 |
14905 /* | 14390 /* |
14906 * "log10()" function | 14391 * "log10()" function |
14907 */ | 14392 */ |
14908 static void | 14393 static void |
14909 f_log10(argvars, rettv) | 14394 f_log10(typval_T *argvars, typval_T *rettv) |
14910 typval_T *argvars; | |
14911 typval_T *rettv; | |
14912 { | 14395 { |
14913 float_T f; | 14396 float_T f; |
14914 | 14397 |
14915 rettv->v_type = VAR_FLOAT; | 14398 rettv->v_type = VAR_FLOAT; |
14916 if (get_float_arg(argvars, &f) == OK) | 14399 if (get_float_arg(argvars, &f) == OK) |
14923 #ifdef FEAT_LUA | 14406 #ifdef FEAT_LUA |
14924 /* | 14407 /* |
14925 * "luaeval()" function | 14408 * "luaeval()" function |
14926 */ | 14409 */ |
14927 static void | 14410 static void |
14928 f_luaeval(argvars, rettv) | 14411 f_luaeval(typval_T *argvars, typval_T *rettv) |
14929 typval_T *argvars; | |
14930 typval_T *rettv; | |
14931 { | 14412 { |
14932 char_u *str; | 14413 char_u *str; |
14933 char_u buf[NUMBUFLEN]; | 14414 char_u buf[NUMBUFLEN]; |
14934 | 14415 |
14935 str = get_tv_string_buf(&argvars[0], buf); | 14416 str = get_tv_string_buf(&argvars[0], buf); |
14939 | 14420 |
14940 /* | 14421 /* |
14941 * "map()" function | 14422 * "map()" function |
14942 */ | 14423 */ |
14943 static void | 14424 static void |
14944 f_map(argvars, rettv) | 14425 f_map(typval_T *argvars, typval_T *rettv) |
14945 typval_T *argvars; | |
14946 typval_T *rettv; | |
14947 { | 14426 { |
14948 filter_map(argvars, rettv, TRUE); | 14427 filter_map(argvars, rettv, TRUE); |
14949 } | 14428 } |
14950 | 14429 |
14951 /* | 14430 /* |
14952 * "maparg()" function | 14431 * "maparg()" function |
14953 */ | 14432 */ |
14954 static void | 14433 static void |
14955 f_maparg(argvars, rettv) | 14434 f_maparg(typval_T *argvars, typval_T *rettv) |
14956 typval_T *argvars; | |
14957 typval_T *rettv; | |
14958 { | 14435 { |
14959 get_maparg(argvars, rettv, TRUE); | 14436 get_maparg(argvars, rettv, TRUE); |
14960 } | 14437 } |
14961 | 14438 |
14962 /* | 14439 /* |
14963 * "mapcheck()" function | 14440 * "mapcheck()" function |
14964 */ | 14441 */ |
14965 static void | 14442 static void |
14966 f_mapcheck(argvars, rettv) | 14443 f_mapcheck(typval_T *argvars, typval_T *rettv) |
14967 typval_T *argvars; | |
14968 typval_T *rettv; | |
14969 { | 14444 { |
14970 get_maparg(argvars, rettv, FALSE); | 14445 get_maparg(argvars, rettv, FALSE); |
14971 } | 14446 } |
14972 | 14447 |
14973 static void find_some_match(typval_T *argvars, typval_T *rettv, int start); | 14448 static void find_some_match(typval_T *argvars, typval_T *rettv, int start); |
14974 | 14449 |
14975 static void | 14450 static void |
14976 find_some_match(argvars, rettv, type) | 14451 find_some_match(typval_T *argvars, typval_T *rettv, int type) |
14977 typval_T *argvars; | |
14978 typval_T *rettv; | |
14979 int type; | |
14980 { | 14452 { |
14981 char_u *str = NULL; | 14453 char_u *str = NULL; |
14982 long len = 0; | 14454 long len = 0; |
14983 char_u *expr = NULL; | 14455 char_u *expr = NULL; |
14984 char_u *pat; | 14456 char_u *pat; |
15170 | 14642 |
15171 /* | 14643 /* |
15172 * "match()" function | 14644 * "match()" function |
15173 */ | 14645 */ |
15174 static void | 14646 static void |
15175 f_match(argvars, rettv) | 14647 f_match(typval_T *argvars, typval_T *rettv) |
15176 typval_T *argvars; | |
15177 typval_T *rettv; | |
15178 { | 14648 { |
15179 find_some_match(argvars, rettv, 1); | 14649 find_some_match(argvars, rettv, 1); |
15180 } | 14650 } |
15181 | 14651 |
15182 /* | 14652 /* |
15183 * "matchadd()" function | 14653 * "matchadd()" function |
15184 */ | 14654 */ |
15185 static void | 14655 static void |
15186 f_matchadd(argvars, rettv) | 14656 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
15187 typval_T *argvars UNUSED; | |
15188 typval_T *rettv UNUSED; | |
15189 { | 14657 { |
15190 #ifdef FEAT_SEARCH_EXTRA | 14658 #ifdef FEAT_SEARCH_EXTRA |
15191 char_u buf[NUMBUFLEN]; | 14659 char_u buf[NUMBUFLEN]; |
15192 char_u *grp = get_tv_string_buf_chk(&argvars[0], buf); /* group */ | 14660 char_u *grp = get_tv_string_buf_chk(&argvars[0], buf); /* group */ |
15193 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */ | 14661 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */ |
15235 | 14703 |
15236 /* | 14704 /* |
15237 * "matchaddpos()" function | 14705 * "matchaddpos()" function |
15238 */ | 14706 */ |
15239 static void | 14707 static void |
15240 f_matchaddpos(argvars, rettv) | 14708 f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
15241 typval_T *argvars UNUSED; | |
15242 typval_T *rettv UNUSED; | |
15243 { | 14709 { |
15244 #ifdef FEAT_SEARCH_EXTRA | 14710 #ifdef FEAT_SEARCH_EXTRA |
15245 char_u buf[NUMBUFLEN]; | 14711 char_u buf[NUMBUFLEN]; |
15246 char_u *group; | 14712 char_u *group; |
15247 int prio = 10; | 14713 int prio = 10; |
15302 | 14768 |
15303 /* | 14769 /* |
15304 * "matcharg()" function | 14770 * "matcharg()" function |
15305 */ | 14771 */ |
15306 static void | 14772 static void |
15307 f_matcharg(argvars, rettv) | 14773 f_matcharg(typval_T *argvars UNUSED, typval_T *rettv) |
15308 typval_T *argvars UNUSED; | |
15309 typval_T *rettv; | |
15310 { | 14774 { |
15311 if (rettv_list_alloc(rettv) == OK) | 14775 if (rettv_list_alloc(rettv) == OK) |
15312 { | 14776 { |
15313 #ifdef FEAT_SEARCH_EXTRA | 14777 #ifdef FEAT_SEARCH_EXTRA |
15314 int id = get_tv_number(&argvars[0]); | 14778 int id = get_tv_number(&argvars[0]); |
15334 | 14798 |
15335 /* | 14799 /* |
15336 * "matchdelete()" function | 14800 * "matchdelete()" function |
15337 */ | 14801 */ |
15338 static void | 14802 static void |
15339 f_matchdelete(argvars, rettv) | 14803 f_matchdelete(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
15340 typval_T *argvars UNUSED; | |
15341 typval_T *rettv UNUSED; | |
15342 { | 14804 { |
15343 #ifdef FEAT_SEARCH_EXTRA | 14805 #ifdef FEAT_SEARCH_EXTRA |
15344 rettv->vval.v_number = match_delete(curwin, | 14806 rettv->vval.v_number = match_delete(curwin, |
15345 (int)get_tv_number(&argvars[0]), TRUE); | 14807 (int)get_tv_number(&argvars[0]), TRUE); |
15346 #endif | 14808 #endif |
15348 | 14810 |
15349 /* | 14811 /* |
15350 * "matchend()" function | 14812 * "matchend()" function |
15351 */ | 14813 */ |
15352 static void | 14814 static void |
15353 f_matchend(argvars, rettv) | 14815 f_matchend(typval_T *argvars, typval_T *rettv) |
15354 typval_T *argvars; | |
15355 typval_T *rettv; | |
15356 { | 14816 { |
15357 find_some_match(argvars, rettv, 0); | 14817 find_some_match(argvars, rettv, 0); |
15358 } | 14818 } |
15359 | 14819 |
15360 /* | 14820 /* |
15361 * "matchlist()" function | 14821 * "matchlist()" function |
15362 */ | 14822 */ |
15363 static void | 14823 static void |
15364 f_matchlist(argvars, rettv) | 14824 f_matchlist(typval_T *argvars, typval_T *rettv) |
15365 typval_T *argvars; | |
15366 typval_T *rettv; | |
15367 { | 14825 { |
15368 find_some_match(argvars, rettv, 3); | 14826 find_some_match(argvars, rettv, 3); |
15369 } | 14827 } |
15370 | 14828 |
15371 /* | 14829 /* |
15372 * "matchstr()" function | 14830 * "matchstr()" function |
15373 */ | 14831 */ |
15374 static void | 14832 static void |
15375 f_matchstr(argvars, rettv) | 14833 f_matchstr(typval_T *argvars, typval_T *rettv) |
15376 typval_T *argvars; | |
15377 typval_T *rettv; | |
15378 { | 14834 { |
15379 find_some_match(argvars, rettv, 2); | 14835 find_some_match(argvars, rettv, 2); |
15380 } | 14836 } |
15381 | 14837 |
15382 static void max_min(typval_T *argvars, typval_T *rettv, int domax); | 14838 static void max_min(typval_T *argvars, typval_T *rettv, int domax); |
15383 | 14839 |
15384 static void | 14840 static void |
15385 max_min(argvars, rettv, domax) | 14841 max_min(typval_T *argvars, typval_T *rettv, int domax) |
15386 typval_T *argvars; | |
15387 typval_T *rettv; | |
15388 int domax; | |
15389 { | 14842 { |
15390 long n = 0; | 14843 long n = 0; |
15391 long i; | 14844 long i; |
15392 int error = FALSE; | 14845 int error = FALSE; |
15393 | 14846 |
15450 | 14903 |
15451 /* | 14904 /* |
15452 * "max()" function | 14905 * "max()" function |
15453 */ | 14906 */ |
15454 static void | 14907 static void |
15455 f_max(argvars, rettv) | 14908 f_max(typval_T *argvars, typval_T *rettv) |
15456 typval_T *argvars; | |
15457 typval_T *rettv; | |
15458 { | 14909 { |
15459 max_min(argvars, rettv, TRUE); | 14910 max_min(argvars, rettv, TRUE); |
15460 } | 14911 } |
15461 | 14912 |
15462 /* | 14913 /* |
15463 * "min()" function | 14914 * "min()" function |
15464 */ | 14915 */ |
15465 static void | 14916 static void |
15466 f_min(argvars, rettv) | 14917 f_min(typval_T *argvars, typval_T *rettv) |
15467 typval_T *argvars; | |
15468 typval_T *rettv; | |
15469 { | 14918 { |
15470 max_min(argvars, rettv, FALSE); | 14919 max_min(argvars, rettv, FALSE); |
15471 } | 14920 } |
15472 | 14921 |
15473 static int mkdir_recurse(char_u *dir, int prot); | 14922 static int mkdir_recurse(char_u *dir, int prot); |
15475 /* | 14924 /* |
15476 * Create the directory in which "dir" is located, and higher levels when | 14925 * Create the directory in which "dir" is located, and higher levels when |
15477 * needed. | 14926 * needed. |
15478 */ | 14927 */ |
15479 static int | 14928 static int |
15480 mkdir_recurse(dir, prot) | 14929 mkdir_recurse(char_u *dir, int prot) |
15481 char_u *dir; | |
15482 int prot; | |
15483 { | 14930 { |
15484 char_u *p; | 14931 char_u *p; |
15485 char_u *updir; | 14932 char_u *updir; |
15486 int r = FAIL; | 14933 int r = FAIL; |
15487 | 14934 |
15506 #ifdef vim_mkdir | 14953 #ifdef vim_mkdir |
15507 /* | 14954 /* |
15508 * "mkdir()" function | 14955 * "mkdir()" function |
15509 */ | 14956 */ |
15510 static void | 14957 static void |
15511 f_mkdir(argvars, rettv) | 14958 f_mkdir(typval_T *argvars, typval_T *rettv) |
15512 typval_T *argvars; | |
15513 typval_T *rettv; | |
15514 { | 14959 { |
15515 char_u *dir; | 14960 char_u *dir; |
15516 char_u buf[NUMBUFLEN]; | 14961 char_u buf[NUMBUFLEN]; |
15517 int prot = 0755; | 14962 int prot = 0755; |
15518 | 14963 |
15543 | 14988 |
15544 /* | 14989 /* |
15545 * "mode()" function | 14990 * "mode()" function |
15546 */ | 14991 */ |
15547 static void | 14992 static void |
15548 f_mode(argvars, rettv) | 14993 f_mode(typval_T *argvars, typval_T *rettv) |
15549 typval_T *argvars; | |
15550 typval_T *rettv; | |
15551 { | 14994 { |
15552 char_u buf[3]; | 14995 char_u buf[3]; |
15553 | 14996 |
15554 buf[1] = NUL; | 14997 buf[1] = NUL; |
15555 buf[2] = NUL; | 14998 buf[2] = NUL; |
15617 #if defined(FEAT_MZSCHEME) || defined(PROTO) | 15060 #if defined(FEAT_MZSCHEME) || defined(PROTO) |
15618 /* | 15061 /* |
15619 * "mzeval()" function | 15062 * "mzeval()" function |
15620 */ | 15063 */ |
15621 static void | 15064 static void |
15622 f_mzeval(argvars, rettv) | 15065 f_mzeval(typval_T *argvars, typval_T *rettv) |
15623 typval_T *argvars; | |
15624 typval_T *rettv; | |
15625 { | 15066 { |
15626 char_u *str; | 15067 char_u *str; |
15627 char_u buf[NUMBUFLEN]; | 15068 char_u buf[NUMBUFLEN]; |
15628 | 15069 |
15629 str = get_tv_string_buf(&argvars[0], buf); | 15070 str = get_tv_string_buf(&argvars[0], buf); |
15630 do_mzeval(str, rettv); | 15071 do_mzeval(str, rettv); |
15631 } | 15072 } |
15632 | 15073 |
15633 void | 15074 void |
15634 mzscheme_call_vim(name, args, rettv) | 15075 mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv) |
15635 char_u *name; | |
15636 typval_T *args; | |
15637 typval_T *rettv; | |
15638 { | 15076 { |
15639 typval_T argvars[3]; | 15077 typval_T argvars[3]; |
15640 | 15078 |
15641 argvars[0].v_type = VAR_STRING; | 15079 argvars[0].v_type = VAR_STRING; |
15642 argvars[0].vval.v_string = name; | 15080 argvars[0].vval.v_string = name; |
15649 | 15087 |
15650 /* | 15088 /* |
15651 * "nextnonblank()" function | 15089 * "nextnonblank()" function |
15652 */ | 15090 */ |
15653 static void | 15091 static void |
15654 f_nextnonblank(argvars, rettv) | 15092 f_nextnonblank(typval_T *argvars, typval_T *rettv) |
15655 typval_T *argvars; | |
15656 typval_T *rettv; | |
15657 { | 15093 { |
15658 linenr_T lnum; | 15094 linenr_T lnum; |
15659 | 15095 |
15660 for (lnum = get_tv_lnum(argvars); ; ++lnum) | 15096 for (lnum = get_tv_lnum(argvars); ; ++lnum) |
15661 { | 15097 { |
15672 | 15108 |
15673 /* | 15109 /* |
15674 * "nr2char()" function | 15110 * "nr2char()" function |
15675 */ | 15111 */ |
15676 static void | 15112 static void |
15677 f_nr2char(argvars, rettv) | 15113 f_nr2char(typval_T *argvars, typval_T *rettv) |
15678 typval_T *argvars; | |
15679 typval_T *rettv; | |
15680 { | 15114 { |
15681 char_u buf[NUMBUFLEN]; | 15115 char_u buf[NUMBUFLEN]; |
15682 | 15116 |
15683 #ifdef FEAT_MBYTE | 15117 #ifdef FEAT_MBYTE |
15684 if (has_mbyte) | 15118 if (has_mbyte) |
15704 | 15138 |
15705 /* | 15139 /* |
15706 * "or(expr, expr)" function | 15140 * "or(expr, expr)" function |
15707 */ | 15141 */ |
15708 static void | 15142 static void |
15709 f_or(argvars, rettv) | 15143 f_or(typval_T *argvars, typval_T *rettv) |
15710 typval_T *argvars; | |
15711 typval_T *rettv; | |
15712 { | 15144 { |
15713 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | 15145 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) |
15714 | get_tv_number_chk(&argvars[1], NULL); | 15146 | get_tv_number_chk(&argvars[1], NULL); |
15715 } | 15147 } |
15716 | 15148 |
15717 /* | 15149 /* |
15718 * "pathshorten()" function | 15150 * "pathshorten()" function |
15719 */ | 15151 */ |
15720 static void | 15152 static void |
15721 f_pathshorten(argvars, rettv) | 15153 f_pathshorten(typval_T *argvars, typval_T *rettv) |
15722 typval_T *argvars; | |
15723 typval_T *rettv; | |
15724 { | 15154 { |
15725 char_u *p; | 15155 char_u *p; |
15726 | 15156 |
15727 rettv->v_type = VAR_STRING; | 15157 rettv->v_type = VAR_STRING; |
15728 p = get_tv_string_chk(&argvars[0]); | 15158 p = get_tv_string_chk(&argvars[0]); |
15740 #ifdef FEAT_PERL | 15170 #ifdef FEAT_PERL |
15741 /* | 15171 /* |
15742 * "perleval()" function | 15172 * "perleval()" function |
15743 */ | 15173 */ |
15744 static void | 15174 static void |
15745 f_perleval(argvars, rettv) | 15175 f_perleval(typval_T *argvars, typval_T *rettv) |
15746 typval_T *argvars; | |
15747 typval_T *rettv; | |
15748 { | 15176 { |
15749 char_u *str; | 15177 char_u *str; |
15750 char_u buf[NUMBUFLEN]; | 15178 char_u buf[NUMBUFLEN]; |
15751 | 15179 |
15752 str = get_tv_string_buf(&argvars[0], buf); | 15180 str = get_tv_string_buf(&argvars[0], buf); |
15757 #ifdef FEAT_FLOAT | 15185 #ifdef FEAT_FLOAT |
15758 /* | 15186 /* |
15759 * "pow()" function | 15187 * "pow()" function |
15760 */ | 15188 */ |
15761 static void | 15189 static void |
15762 f_pow(argvars, rettv) | 15190 f_pow(typval_T *argvars, typval_T *rettv) |
15763 typval_T *argvars; | |
15764 typval_T *rettv; | |
15765 { | 15191 { |
15766 float_T fx, fy; | 15192 float_T fx, fy; |
15767 | 15193 |
15768 rettv->v_type = VAR_FLOAT; | 15194 rettv->v_type = VAR_FLOAT; |
15769 if (get_float_arg(argvars, &fx) == OK | 15195 if (get_float_arg(argvars, &fx) == OK |
15776 | 15202 |
15777 /* | 15203 /* |
15778 * "prevnonblank()" function | 15204 * "prevnonblank()" function |
15779 */ | 15205 */ |
15780 static void | 15206 static void |
15781 f_prevnonblank(argvars, rettv) | 15207 f_prevnonblank(typval_T *argvars, typval_T *rettv) |
15782 typval_T *argvars; | |
15783 typval_T *rettv; | |
15784 { | 15208 { |
15785 linenr_T lnum; | 15209 linenr_T lnum; |
15786 | 15210 |
15787 lnum = get_tv_lnum(argvars); | 15211 lnum = get_tv_lnum(argvars); |
15788 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) | 15212 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) |
15803 | 15227 |
15804 /* | 15228 /* |
15805 * "printf()" function | 15229 * "printf()" function |
15806 */ | 15230 */ |
15807 static void | 15231 static void |
15808 f_printf(argvars, rettv) | 15232 f_printf(typval_T *argvars, typval_T *rettv) |
15809 typval_T *argvars; | |
15810 typval_T *rettv; | |
15811 { | 15233 { |
15812 rettv->v_type = VAR_STRING; | 15234 rettv->v_type = VAR_STRING; |
15813 rettv->vval.v_string = NULL; | 15235 rettv->vval.v_string = NULL; |
15814 #ifdef HAVE_STDARG_H /* only very old compilers can't do this */ | 15236 #ifdef HAVE_STDARG_H /* only very old compilers can't do this */ |
15815 { | 15237 { |
15839 | 15261 |
15840 /* | 15262 /* |
15841 * "pumvisible()" function | 15263 * "pumvisible()" function |
15842 */ | 15264 */ |
15843 static void | 15265 static void |
15844 f_pumvisible(argvars, rettv) | 15266 f_pumvisible(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
15845 typval_T *argvars UNUSED; | |
15846 typval_T *rettv UNUSED; | |
15847 { | 15267 { |
15848 #ifdef FEAT_INS_EXPAND | 15268 #ifdef FEAT_INS_EXPAND |
15849 if (pum_visible()) | 15269 if (pum_visible()) |
15850 rettv->vval.v_number = 1; | 15270 rettv->vval.v_number = 1; |
15851 #endif | 15271 #endif |
15854 #ifdef FEAT_PYTHON3 | 15274 #ifdef FEAT_PYTHON3 |
15855 /* | 15275 /* |
15856 * "py3eval()" function | 15276 * "py3eval()" function |
15857 */ | 15277 */ |
15858 static void | 15278 static void |
15859 f_py3eval(argvars, rettv) | 15279 f_py3eval(typval_T *argvars, typval_T *rettv) |
15860 typval_T *argvars; | |
15861 typval_T *rettv; | |
15862 { | 15280 { |
15863 char_u *str; | 15281 char_u *str; |
15864 char_u buf[NUMBUFLEN]; | 15282 char_u buf[NUMBUFLEN]; |
15865 | 15283 |
15866 str = get_tv_string_buf(&argvars[0], buf); | 15284 str = get_tv_string_buf(&argvars[0], buf); |
15871 #ifdef FEAT_PYTHON | 15289 #ifdef FEAT_PYTHON |
15872 /* | 15290 /* |
15873 * "pyeval()" function | 15291 * "pyeval()" function |
15874 */ | 15292 */ |
15875 static void | 15293 static void |
15876 f_pyeval(argvars, rettv) | 15294 f_pyeval(typval_T *argvars, typval_T *rettv) |
15877 typval_T *argvars; | |
15878 typval_T *rettv; | |
15879 { | 15295 { |
15880 char_u *str; | 15296 char_u *str; |
15881 char_u buf[NUMBUFLEN]; | 15297 char_u buf[NUMBUFLEN]; |
15882 | 15298 |
15883 str = get_tv_string_buf(&argvars[0], buf); | 15299 str = get_tv_string_buf(&argvars[0], buf); |
15887 | 15303 |
15888 /* | 15304 /* |
15889 * "range()" function | 15305 * "range()" function |
15890 */ | 15306 */ |
15891 static void | 15307 static void |
15892 f_range(argvars, rettv) | 15308 f_range(typval_T *argvars, typval_T *rettv) |
15893 typval_T *argvars; | |
15894 typval_T *rettv; | |
15895 { | 15309 { |
15896 long start; | 15310 long start; |
15897 long end; | 15311 long end; |
15898 long stride = 1; | 15312 long stride = 1; |
15899 long i; | 15313 long i; |
15930 | 15344 |
15931 /* | 15345 /* |
15932 * "readfile()" function | 15346 * "readfile()" function |
15933 */ | 15347 */ |
15934 static void | 15348 static void |
15935 f_readfile(argvars, rettv) | 15349 f_readfile(typval_T *argvars, typval_T *rettv) |
15936 typval_T *argvars; | |
15937 typval_T *rettv; | |
15938 { | 15350 { |
15939 int binary = FALSE; | 15351 int binary = FALSE; |
15940 int failed = FALSE; | 15352 int failed = FALSE; |
15941 char_u *fname; | 15353 char_u *fname; |
15942 FILE *fd; | 15354 FILE *fd; |
16148 /* | 15560 /* |
16149 * Convert a List to proftime_T. | 15561 * Convert a List to proftime_T. |
16150 * Return FAIL when there is something wrong. | 15562 * Return FAIL when there is something wrong. |
16151 */ | 15563 */ |
16152 static int | 15564 static int |
16153 list2proftime(arg, tm) | 15565 list2proftime(typval_T *arg, proftime_T *tm) |
16154 typval_T *arg; | |
16155 proftime_T *tm; | |
16156 { | 15566 { |
16157 long n1, n2; | 15567 long n1, n2; |
16158 int error = FALSE; | 15568 int error = FALSE; |
16159 | 15569 |
16160 if (arg->v_type != VAR_LIST || arg->vval.v_list == NULL | 15570 if (arg->v_type != VAR_LIST || arg->vval.v_list == NULL |
16175 | 15585 |
16176 /* | 15586 /* |
16177 * "reltime()" function | 15587 * "reltime()" function |
16178 */ | 15588 */ |
16179 static void | 15589 static void |
16180 f_reltime(argvars, rettv) | 15590 f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
16181 typval_T *argvars UNUSED; | |
16182 typval_T *rettv UNUSED; | |
16183 { | 15591 { |
16184 #ifdef FEAT_RELTIME | 15592 #ifdef FEAT_RELTIME |
16185 proftime_T res; | 15593 proftime_T res; |
16186 proftime_T start; | 15594 proftime_T start; |
16187 | 15595 |
16224 | 15632 |
16225 /* | 15633 /* |
16226 * "reltimestr()" function | 15634 * "reltimestr()" function |
16227 */ | 15635 */ |
16228 static void | 15636 static void |
16229 f_reltimestr(argvars, rettv) | 15637 f_reltimestr(typval_T *argvars UNUSED, typval_T *rettv) |
16230 typval_T *argvars UNUSED; | |
16231 typval_T *rettv; | |
16232 { | 15638 { |
16233 #ifdef FEAT_RELTIME | 15639 #ifdef FEAT_RELTIME |
16234 proftime_T tm; | 15640 proftime_T tm; |
16235 #endif | 15641 #endif |
16236 | 15642 |
16245 #if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) | 15651 #if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) |
16246 static void make_connection(void); | 15652 static void make_connection(void); |
16247 static int check_connection(void); | 15653 static int check_connection(void); |
16248 | 15654 |
16249 static void | 15655 static void |
16250 make_connection() | 15656 make_connection(void) |
16251 { | 15657 { |
16252 if (X_DISPLAY == NULL | 15658 if (X_DISPLAY == NULL |
16253 # ifdef FEAT_GUI | 15659 # ifdef FEAT_GUI |
16254 && !gui.in_use | 15660 && !gui.in_use |
16255 # endif | 15661 # endif |
16260 x_force_connect = FALSE; | 15666 x_force_connect = FALSE; |
16261 } | 15667 } |
16262 } | 15668 } |
16263 | 15669 |
16264 static int | 15670 static int |
16265 check_connection() | 15671 check_connection(void) |
16266 { | 15672 { |
16267 make_connection(); | 15673 make_connection(); |
16268 if (X_DISPLAY == NULL) | 15674 if (X_DISPLAY == NULL) |
16269 { | 15675 { |
16270 EMSG(_("E240: No connection to Vim server")); | 15676 EMSG(_("E240: No connection to Vim server")); |
16276 | 15682 |
16277 #ifdef FEAT_CLIENTSERVER | 15683 #ifdef FEAT_CLIENTSERVER |
16278 static void remote_common(typval_T *argvars, typval_T *rettv, int expr); | 15684 static void remote_common(typval_T *argvars, typval_T *rettv, int expr); |
16279 | 15685 |
16280 static void | 15686 static void |
16281 remote_common(argvars, rettv, expr) | 15687 remote_common(typval_T *argvars, typval_T *rettv, int expr) |
16282 typval_T *argvars; | |
16283 typval_T *rettv; | |
16284 int expr; | |
16285 { | 15688 { |
16286 char_u *server_name; | 15689 char_u *server_name; |
16287 char_u *keys; | 15690 char_u *keys; |
16288 char_u *r = NULL; | 15691 char_u *r = NULL; |
16289 char_u buf[NUMBUFLEN]; | 15692 char_u buf[NUMBUFLEN]; |
16340 | 15743 |
16341 /* | 15744 /* |
16342 * "remote_expr()" function | 15745 * "remote_expr()" function |
16343 */ | 15746 */ |
16344 static void | 15747 static void |
16345 f_remote_expr(argvars, rettv) | 15748 f_remote_expr(typval_T *argvars UNUSED, typval_T *rettv) |
16346 typval_T *argvars UNUSED; | |
16347 typval_T *rettv; | |
16348 { | 15749 { |
16349 rettv->v_type = VAR_STRING; | 15750 rettv->v_type = VAR_STRING; |
16350 rettv->vval.v_string = NULL; | 15751 rettv->vval.v_string = NULL; |
16351 #ifdef FEAT_CLIENTSERVER | 15752 #ifdef FEAT_CLIENTSERVER |
16352 remote_common(argvars, rettv, TRUE); | 15753 remote_common(argvars, rettv, TRUE); |
16355 | 15756 |
16356 /* | 15757 /* |
16357 * "remote_foreground()" function | 15758 * "remote_foreground()" function |
16358 */ | 15759 */ |
16359 static void | 15760 static void |
16360 f_remote_foreground(argvars, rettv) | 15761 f_remote_foreground(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
16361 typval_T *argvars UNUSED; | |
16362 typval_T *rettv UNUSED; | |
16363 { | 15762 { |
16364 #ifdef FEAT_CLIENTSERVER | 15763 #ifdef FEAT_CLIENTSERVER |
16365 # ifdef WIN32 | 15764 # ifdef WIN32 |
16366 /* On Win32 it's done in this application. */ | 15765 /* On Win32 it's done in this application. */ |
16367 { | 15766 { |
16380 # endif | 15779 # endif |
16381 #endif | 15780 #endif |
16382 } | 15781 } |
16383 | 15782 |
16384 static void | 15783 static void |
16385 f_remote_peek(argvars, rettv) | 15784 f_remote_peek(typval_T *argvars UNUSED, typval_T *rettv) |
16386 typval_T *argvars UNUSED; | |
16387 typval_T *rettv; | |
16388 { | 15785 { |
16389 #ifdef FEAT_CLIENTSERVER | 15786 #ifdef FEAT_CLIENTSERVER |
16390 dictitem_T v; | 15787 dictitem_T v; |
16391 char_u *s = NULL; | 15788 char_u *s = NULL; |
16392 # ifdef WIN32 | 15789 # ifdef WIN32 |
16437 rettv->vval.v_number = -1; | 15834 rettv->vval.v_number = -1; |
16438 #endif | 15835 #endif |
16439 } | 15836 } |
16440 | 15837 |
16441 static void | 15838 static void |
16442 f_remote_read(argvars, rettv) | 15839 f_remote_read(typval_T *argvars UNUSED, typval_T *rettv) |
16443 typval_T *argvars UNUSED; | |
16444 typval_T *rettv; | |
16445 { | 15840 { |
16446 char_u *r = NULL; | 15841 char_u *r = NULL; |
16447 | 15842 |
16448 #ifdef FEAT_CLIENTSERVER | 15843 #ifdef FEAT_CLIENTSERVER |
16449 char_u *serverid = get_tv_string_chk(&argvars[0]); | 15844 char_u *serverid = get_tv_string_chk(&argvars[0]); |
16471 | 15866 |
16472 /* | 15867 /* |
16473 * "remote_send()" function | 15868 * "remote_send()" function |
16474 */ | 15869 */ |
16475 static void | 15870 static void |
16476 f_remote_send(argvars, rettv) | 15871 f_remote_send(typval_T *argvars UNUSED, typval_T *rettv) |
16477 typval_T *argvars UNUSED; | |
16478 typval_T *rettv; | |
16479 { | 15872 { |
16480 rettv->v_type = VAR_STRING; | 15873 rettv->v_type = VAR_STRING; |
16481 rettv->vval.v_string = NULL; | 15874 rettv->vval.v_string = NULL; |
16482 #ifdef FEAT_CLIENTSERVER | 15875 #ifdef FEAT_CLIENTSERVER |
16483 remote_common(argvars, rettv, FALSE); | 15876 remote_common(argvars, rettv, FALSE); |
16486 | 15879 |
16487 /* | 15880 /* |
16488 * "remove()" function | 15881 * "remove()" function |
16489 */ | 15882 */ |
16490 static void | 15883 static void |
16491 f_remove(argvars, rettv) | 15884 f_remove(typval_T *argvars, typval_T *rettv) |
16492 typval_T *argvars; | |
16493 typval_T *rettv; | |
16494 { | 15885 { |
16495 list_T *l; | 15886 list_T *l; |
16496 listitem_T *item, *item2; | 15887 listitem_T *item, *item2; |
16497 listitem_T *li; | 15888 listitem_T *li; |
16498 long idx; | 15889 long idx; |
16587 | 15978 |
16588 /* | 15979 /* |
16589 * "rename({from}, {to})" function | 15980 * "rename({from}, {to})" function |
16590 */ | 15981 */ |
16591 static void | 15982 static void |
16592 f_rename(argvars, rettv) | 15983 f_rename(typval_T *argvars, typval_T *rettv) |
16593 typval_T *argvars; | |
16594 typval_T *rettv; | |
16595 { | 15984 { |
16596 char_u buf[NUMBUFLEN]; | 15985 char_u buf[NUMBUFLEN]; |
16597 | 15986 |
16598 if (check_restricted() || check_secure()) | 15987 if (check_restricted() || check_secure()) |
16599 rettv->vval.v_number = -1; | 15988 rettv->vval.v_number = -1; |
16604 | 15993 |
16605 /* | 15994 /* |
16606 * "repeat()" function | 15995 * "repeat()" function |
16607 */ | 15996 */ |
16608 static void | 15997 static void |
16609 f_repeat(argvars, rettv) | 15998 f_repeat(typval_T *argvars, typval_T *rettv) |
16610 typval_T *argvars; | |
16611 typval_T *rettv; | |
16612 { | 15999 { |
16613 char_u *p; | 16000 char_u *p; |
16614 int n; | 16001 int n; |
16615 int slen; | 16002 int slen; |
16616 int len; | 16003 int len; |
16651 | 16038 |
16652 /* | 16039 /* |
16653 * "resolve()" function | 16040 * "resolve()" function |
16654 */ | 16041 */ |
16655 static void | 16042 static void |
16656 f_resolve(argvars, rettv) | 16043 f_resolve(typval_T *argvars, typval_T *rettv) |
16657 typval_T *argvars; | |
16658 typval_T *rettv; | |
16659 { | 16044 { |
16660 char_u *p; | 16045 char_u *p; |
16661 #ifdef HAVE_READLINK | 16046 #ifdef HAVE_READLINK |
16662 char_u *buf = NULL; | 16047 char_u *buf = NULL; |
16663 #endif | 16048 #endif |
16860 | 16245 |
16861 /* | 16246 /* |
16862 * "reverse({list})" function | 16247 * "reverse({list})" function |
16863 */ | 16248 */ |
16864 static void | 16249 static void |
16865 f_reverse(argvars, rettv) | 16250 f_reverse(typval_T *argvars, typval_T *rettv) |
16866 typval_T *argvars; | |
16867 typval_T *rettv; | |
16868 { | 16251 { |
16869 list_T *l; | 16252 list_T *l; |
16870 listitem_T *li, *ni; | 16253 listitem_T *li, *ni; |
16871 | 16254 |
16872 if (argvars[0].v_type != VAR_LIST) | 16255 if (argvars[0].v_type != VAR_LIST) |
16906 * Get flags for a search function. | 16289 * Get flags for a search function. |
16907 * Possibly sets "p_ws". | 16290 * Possibly sets "p_ws". |
16908 * Returns BACKWARD, FORWARD or zero (for an error). | 16291 * Returns BACKWARD, FORWARD or zero (for an error). |
16909 */ | 16292 */ |
16910 static int | 16293 static int |
16911 get_search_arg(varp, flagsp) | 16294 get_search_arg(typval_T *varp, int *flagsp) |
16912 typval_T *varp; | |
16913 int *flagsp; | |
16914 { | 16295 { |
16915 int dir = FORWARD; | 16296 int dir = FORWARD; |
16916 char_u *flags; | 16297 char_u *flags; |
16917 char_u nbuf[NUMBUFLEN]; | 16298 char_u nbuf[NUMBUFLEN]; |
16918 int mask; | 16299 int mask; |
16960 | 16341 |
16961 /* | 16342 /* |
16962 * Shared by search() and searchpos() functions. | 16343 * Shared by search() and searchpos() functions. |
16963 */ | 16344 */ |
16964 static int | 16345 static int |
16965 search_cmn(argvars, match_pos, flagsp) | 16346 search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp) |
16966 typval_T *argvars; | |
16967 pos_T *match_pos; | |
16968 int *flagsp; | |
16969 { | 16347 { |
16970 int flags; | 16348 int flags; |
16971 char_u *pat; | 16349 char_u *pat; |
16972 pos_T pos; | 16350 pos_T pos; |
16973 pos_T save_cursor; | 16351 pos_T save_cursor; |
17066 | 16444 |
17067 /* | 16445 /* |
17068 * round() is not in C90, use ceil() or floor() instead. | 16446 * round() is not in C90, use ceil() or floor() instead. |
17069 */ | 16447 */ |
17070 float_T | 16448 float_T |
17071 vim_round(f) | 16449 vim_round(float_T f) |
17072 float_T f; | |
17073 { | 16450 { |
17074 return f > 0 ? floor(f + 0.5) : ceil(f - 0.5); | 16451 return f > 0 ? floor(f + 0.5) : ceil(f - 0.5); |
17075 } | 16452 } |
17076 | 16453 |
17077 /* | 16454 /* |
17078 * "round({float})" function | 16455 * "round({float})" function |
17079 */ | 16456 */ |
17080 static void | 16457 static void |
17081 f_round(argvars, rettv) | 16458 f_round(typval_T *argvars, typval_T *rettv) |
17082 typval_T *argvars; | |
17083 typval_T *rettv; | |
17084 { | 16459 { |
17085 float_T f; | 16460 float_T f; |
17086 | 16461 |
17087 rettv->v_type = VAR_FLOAT; | 16462 rettv->v_type = VAR_FLOAT; |
17088 if (get_float_arg(argvars, &f) == OK) | 16463 if (get_float_arg(argvars, &f) == OK) |
17094 | 16469 |
17095 /* | 16470 /* |
17096 * "screenattr()" function | 16471 * "screenattr()" function |
17097 */ | 16472 */ |
17098 static void | 16473 static void |
17099 f_screenattr(argvars, rettv) | 16474 f_screenattr(typval_T *argvars UNUSED, typval_T *rettv) |
17100 typval_T *argvars UNUSED; | |
17101 typval_T *rettv; | |
17102 { | 16475 { |
17103 int row; | 16476 int row; |
17104 int col; | 16477 int col; |
17105 int c; | 16478 int c; |
17106 | 16479 |
17116 | 16489 |
17117 /* | 16490 /* |
17118 * "screenchar()" function | 16491 * "screenchar()" function |
17119 */ | 16492 */ |
17120 static void | 16493 static void |
17121 f_screenchar(argvars, rettv) | 16494 f_screenchar(typval_T *argvars UNUSED, typval_T *rettv) |
17122 typval_T *argvars UNUSED; | |
17123 typval_T *rettv; | |
17124 { | 16495 { |
17125 int row; | 16496 int row; |
17126 int col; | 16497 int col; |
17127 int off; | 16498 int off; |
17128 int c; | 16499 int c; |
17149 * "screencol()" function | 16520 * "screencol()" function |
17150 * | 16521 * |
17151 * First column is 1 to be consistent with virtcol(). | 16522 * First column is 1 to be consistent with virtcol(). |
17152 */ | 16523 */ |
17153 static void | 16524 static void |
17154 f_screencol(argvars, rettv) | 16525 f_screencol(typval_T *argvars UNUSED, typval_T *rettv) |
17155 typval_T *argvars UNUSED; | |
17156 typval_T *rettv; | |
17157 { | 16526 { |
17158 rettv->vval.v_number = screen_screencol() + 1; | 16527 rettv->vval.v_number = screen_screencol() + 1; |
17159 } | 16528 } |
17160 | 16529 |
17161 /* | 16530 /* |
17162 * "screenrow()" function | 16531 * "screenrow()" function |
17163 */ | 16532 */ |
17164 static void | 16533 static void |
17165 f_screenrow(argvars, rettv) | 16534 f_screenrow(typval_T *argvars UNUSED, typval_T *rettv) |
17166 typval_T *argvars UNUSED; | |
17167 typval_T *rettv; | |
17168 { | 16535 { |
17169 rettv->vval.v_number = screen_screenrow() + 1; | 16536 rettv->vval.v_number = screen_screenrow() + 1; |
17170 } | 16537 } |
17171 | 16538 |
17172 /* | 16539 /* |
17173 * "search()" function | 16540 * "search()" function |
17174 */ | 16541 */ |
17175 static void | 16542 static void |
17176 f_search(argvars, rettv) | 16543 f_search(typval_T *argvars, typval_T *rettv) |
17177 typval_T *argvars; | |
17178 typval_T *rettv; | |
17179 { | 16544 { |
17180 int flags = 0; | 16545 int flags = 0; |
17181 | 16546 |
17182 rettv->vval.v_number = search_cmn(argvars, NULL, &flags); | 16547 rettv->vval.v_number = search_cmn(argvars, NULL, &flags); |
17183 } | 16548 } |
17184 | 16549 |
17185 /* | 16550 /* |
17186 * "searchdecl()" function | 16551 * "searchdecl()" function |
17187 */ | 16552 */ |
17188 static void | 16553 static void |
17189 f_searchdecl(argvars, rettv) | 16554 f_searchdecl(typval_T *argvars, typval_T *rettv) |
17190 typval_T *argvars; | |
17191 typval_T *rettv; | |
17192 { | 16555 { |
17193 int locally = 1; | 16556 int locally = 1; |
17194 int thisblock = 0; | 16557 int thisblock = 0; |
17195 int error = FALSE; | 16558 int error = FALSE; |
17196 char_u *name; | 16559 char_u *name; |
17211 | 16574 |
17212 /* | 16575 /* |
17213 * Used by searchpair() and searchpairpos() | 16576 * Used by searchpair() and searchpairpos() |
17214 */ | 16577 */ |
17215 static int | 16578 static int |
17216 searchpair_cmn(argvars, match_pos) | 16579 searchpair_cmn(typval_T *argvars, pos_T *match_pos) |
17217 typval_T *argvars; | |
17218 pos_T *match_pos; | |
17219 { | 16580 { |
17220 char_u *spat, *mpat, *epat; | 16581 char_u *spat, *mpat, *epat; |
17221 char_u *skip; | 16582 char_u *skip; |
17222 int save_p_ws = p_ws; | 16583 int save_p_ws = p_ws; |
17223 int dir; | 16584 int dir; |
17291 | 16652 |
17292 /* | 16653 /* |
17293 * "searchpair()" function | 16654 * "searchpair()" function |
17294 */ | 16655 */ |
17295 static void | 16656 static void |
17296 f_searchpair(argvars, rettv) | 16657 f_searchpair(typval_T *argvars, typval_T *rettv) |
17297 typval_T *argvars; | |
17298 typval_T *rettv; | |
17299 { | 16658 { |
17300 rettv->vval.v_number = searchpair_cmn(argvars, NULL); | 16659 rettv->vval.v_number = searchpair_cmn(argvars, NULL); |
17301 } | 16660 } |
17302 | 16661 |
17303 /* | 16662 /* |
17304 * "searchpairpos()" function | 16663 * "searchpairpos()" function |
17305 */ | 16664 */ |
17306 static void | 16665 static void |
17307 f_searchpairpos(argvars, rettv) | 16666 f_searchpairpos(typval_T *argvars, typval_T *rettv) |
17308 typval_T *argvars; | |
17309 typval_T *rettv; | |
17310 { | 16667 { |
17311 pos_T match_pos; | 16668 pos_T match_pos; |
17312 int lnum = 0; | 16669 int lnum = 0; |
17313 int col = 0; | 16670 int col = 0; |
17314 | 16671 |
17329 * Search for a start/middle/end thing. | 16686 * Search for a start/middle/end thing. |
17330 * Used by searchpair(), see its documentation for the details. | 16687 * Used by searchpair(), see its documentation for the details. |
17331 * Returns 0 or -1 for no match, | 16688 * Returns 0 or -1 for no match, |
17332 */ | 16689 */ |
17333 long | 16690 long |
17334 do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, | 16691 do_searchpair( |
17335 lnum_stop, time_limit) | 16692 char_u *spat, /* start pattern */ |
17336 char_u *spat; /* start pattern */ | 16693 char_u *mpat, /* middle pattern */ |
17337 char_u *mpat; /* middle pattern */ | 16694 char_u *epat, /* end pattern */ |
17338 char_u *epat; /* end pattern */ | 16695 int dir, /* BACKWARD or FORWARD */ |
17339 int dir; /* BACKWARD or FORWARD */ | 16696 char_u *skip, /* skip expression */ |
17340 char_u *skip; /* skip expression */ | 16697 int flags, /* SP_SETPCMARK and other SP_ values */ |
17341 int flags; /* SP_SETPCMARK and other SP_ values */ | 16698 pos_T *match_pos, |
17342 pos_T *match_pos; | 16699 linenr_T lnum_stop, /* stop at this line if not zero */ |
17343 linenr_T lnum_stop; /* stop at this line if not zero */ | 16700 long time_limit UNUSED) /* stop after this many msec */ |
17344 long time_limit UNUSED; /* stop after this many msec */ | |
17345 { | 16701 { |
17346 char_u *save_cpo; | 16702 char_u *save_cpo; |
17347 char_u *pat, *pat2 = NULL, *pat3 = NULL; | 16703 char_u *pat, *pat2 = NULL, *pat3 = NULL; |
17348 long retval = 0; | 16704 long retval = 0; |
17349 pos_T pos; | 16705 pos_T pos; |
17486 | 16842 |
17487 /* | 16843 /* |
17488 * "searchpos()" function | 16844 * "searchpos()" function |
17489 */ | 16845 */ |
17490 static void | 16846 static void |
17491 f_searchpos(argvars, rettv) | 16847 f_searchpos(typval_T *argvars, typval_T *rettv) |
17492 typval_T *argvars; | |
17493 typval_T *rettv; | |
17494 { | 16848 { |
17495 pos_T match_pos; | 16849 pos_T match_pos; |
17496 int lnum = 0; | 16850 int lnum = 0; |
17497 int col = 0; | 16851 int col = 0; |
17498 int n; | 16852 int n; |
17550 | 16904 |
17551 /* | 16905 /* |
17552 * "sendexpr()" function | 16906 * "sendexpr()" function |
17553 */ | 16907 */ |
17554 static void | 16908 static void |
17555 f_sendexpr(argvars, rettv) | 16909 f_sendexpr(typval_T *argvars, typval_T *rettv) |
17556 typval_T *argvars; | |
17557 typval_T *rettv; | |
17558 { | 16910 { |
17559 char_u *text; | 16911 char_u *text; |
17560 char_u *resp; | 16912 char_u *resp; |
17561 typval_T nrtv; | 16913 typval_T nrtv; |
17562 typval_T listtv; | 16914 typval_T listtv; |
17596 | 16948 |
17597 /* | 16949 /* |
17598 * "sendraw()" function | 16950 * "sendraw()" function |
17599 */ | 16951 */ |
17600 static void | 16952 static void |
17601 f_sendraw(argvars, rettv) | 16953 f_sendraw(typval_T *argvars, typval_T *rettv) |
17602 typval_T *argvars; | |
17603 typval_T *rettv; | |
17604 { | 16954 { |
17605 char_u buf[NUMBUFLEN]; | 16955 char_u buf[NUMBUFLEN]; |
17606 char_u *text; | 16956 char_u *text; |
17607 int ch_idx; | 16957 int ch_idx; |
17608 | 16958 |
17617 } | 16967 } |
17618 #endif | 16968 #endif |
17619 | 16969 |
17620 | 16970 |
17621 static void | 16971 static void |
17622 f_server2client(argvars, rettv) | 16972 f_server2client(typval_T *argvars UNUSED, typval_T *rettv) |
17623 typval_T *argvars UNUSED; | |
17624 typval_T *rettv; | |
17625 { | 16973 { |
17626 #ifdef FEAT_CLIENTSERVER | 16974 #ifdef FEAT_CLIENTSERVER |
17627 char_u buf[NUMBUFLEN]; | 16975 char_u buf[NUMBUFLEN]; |
17628 char_u *server = get_tv_string_chk(&argvars[0]); | 16976 char_u *server = get_tv_string_chk(&argvars[0]); |
17629 char_u *reply = get_tv_string_buf_chk(&argvars[1], buf); | 16977 char_u *reply = get_tv_string_buf_chk(&argvars[1], buf); |
17648 rettv->vval.v_number = -1; | 16996 rettv->vval.v_number = -1; |
17649 #endif | 16997 #endif |
17650 } | 16998 } |
17651 | 16999 |
17652 static void | 17000 static void |
17653 f_serverlist(argvars, rettv) | 17001 f_serverlist(typval_T *argvars UNUSED, typval_T *rettv) |
17654 typval_T *argvars UNUSED; | |
17655 typval_T *rettv; | |
17656 { | 17002 { |
17657 char_u *r = NULL; | 17003 char_u *r = NULL; |
17658 | 17004 |
17659 #ifdef FEAT_CLIENTSERVER | 17005 #ifdef FEAT_CLIENTSERVER |
17660 # ifdef WIN32 | 17006 # ifdef WIN32 |
17671 | 17017 |
17672 /* | 17018 /* |
17673 * "setbufvar()" function | 17019 * "setbufvar()" function |
17674 */ | 17020 */ |
17675 static void | 17021 static void |
17676 f_setbufvar(argvars, rettv) | 17022 f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED) |
17677 typval_T *argvars; | |
17678 typval_T *rettv UNUSED; | |
17679 { | 17023 { |
17680 buf_T *buf; | 17024 buf_T *buf; |
17681 aco_save_T aco; | 17025 aco_save_T aco; |
17682 char_u *varname, *bufvarname; | 17026 char_u *varname, *bufvarname; |
17683 typval_T *varp; | 17027 typval_T *varp; |
17723 aucmd_restbuf(&aco); | 17067 aucmd_restbuf(&aco); |
17724 } | 17068 } |
17725 } | 17069 } |
17726 | 17070 |
17727 static void | 17071 static void |
17728 f_setcharsearch(argvars, rettv) | 17072 f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED) |
17729 typval_T *argvars; | |
17730 typval_T *rettv UNUSED; | |
17731 { | 17073 { |
17732 dict_T *d; | 17074 dict_T *d; |
17733 dictitem_T *di; | 17075 dictitem_T *di; |
17734 char_u *csearch; | 17076 char_u *csearch; |
17735 | 17077 |
17771 | 17113 |
17772 /* | 17114 /* |
17773 * "setcmdpos()" function | 17115 * "setcmdpos()" function |
17774 */ | 17116 */ |
17775 static void | 17117 static void |
17776 f_setcmdpos(argvars, rettv) | 17118 f_setcmdpos(typval_T *argvars, typval_T *rettv) |
17777 typval_T *argvars; | |
17778 typval_T *rettv; | |
17779 { | 17119 { |
17780 int pos = (int)get_tv_number(&argvars[0]) - 1; | 17120 int pos = (int)get_tv_number(&argvars[0]) - 1; |
17781 | 17121 |
17782 if (pos >= 0) | 17122 if (pos >= 0) |
17783 rettv->vval.v_number = set_cmdline_pos(pos); | 17123 rettv->vval.v_number = set_cmdline_pos(pos); |
17785 | 17125 |
17786 /* | 17126 /* |
17787 * "setline()" function | 17127 * "setline()" function |
17788 */ | 17128 */ |
17789 static void | 17129 static void |
17790 f_setline(argvars, rettv) | 17130 f_setline(typval_T *argvars, typval_T *rettv) |
17791 typval_T *argvars; | |
17792 typval_T *rettv; | |
17793 { | 17131 { |
17794 linenr_T lnum; | 17132 linenr_T lnum; |
17795 char_u *line = NULL; | 17133 char_u *line = NULL; |
17796 list_T *l = NULL; | 17134 list_T *l = NULL; |
17797 listitem_T *li = NULL; | 17135 listitem_T *li = NULL; |
17863 | 17201 |
17864 /* | 17202 /* |
17865 * Used by "setqflist()" and "setloclist()" functions | 17203 * Used by "setqflist()" and "setloclist()" functions |
17866 */ | 17204 */ |
17867 static void | 17205 static void |
17868 set_qf_ll_list(wp, list_arg, action_arg, rettv) | 17206 set_qf_ll_list( |
17869 win_T *wp UNUSED; | 17207 win_T *wp UNUSED, |
17870 typval_T *list_arg UNUSED; | 17208 typval_T *list_arg UNUSED, |
17871 typval_T *action_arg UNUSED; | 17209 typval_T *action_arg UNUSED, |
17872 typval_T *rettv; | 17210 typval_T *rettv) |
17873 { | 17211 { |
17874 #ifdef FEAT_QUICKFIX | 17212 #ifdef FEAT_QUICKFIX |
17875 char_u *act; | 17213 char_u *act; |
17876 int action = ' '; | 17214 int action = ' '; |
17877 #endif | 17215 #endif |
17903 | 17241 |
17904 /* | 17242 /* |
17905 * "setloclist()" function | 17243 * "setloclist()" function |
17906 */ | 17244 */ |
17907 static void | 17245 static void |
17908 f_setloclist(argvars, rettv) | 17246 f_setloclist(typval_T *argvars, typval_T *rettv) |
17909 typval_T *argvars; | |
17910 typval_T *rettv; | |
17911 { | 17247 { |
17912 win_T *win; | 17248 win_T *win; |
17913 | 17249 |
17914 rettv->vval.v_number = -1; | 17250 rettv->vval.v_number = -1; |
17915 | 17251 |
17920 | 17256 |
17921 /* | 17257 /* |
17922 * "setmatches()" function | 17258 * "setmatches()" function |
17923 */ | 17259 */ |
17924 static void | 17260 static void |
17925 f_setmatches(argvars, rettv) | 17261 f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
17926 typval_T *argvars UNUSED; | |
17927 typval_T *rettv UNUSED; | |
17928 { | 17262 { |
17929 #ifdef FEAT_SEARCH_EXTRA | 17263 #ifdef FEAT_SEARCH_EXTRA |
17930 list_T *l; | 17264 list_T *l; |
17931 listitem_T *li; | 17265 listitem_T *li; |
17932 dict_T *d; | 17266 dict_T *d; |
18031 | 17365 |
18032 /* | 17366 /* |
18033 * "setpos()" function | 17367 * "setpos()" function |
18034 */ | 17368 */ |
18035 static void | 17369 static void |
18036 f_setpos(argvars, rettv) | 17370 f_setpos(typval_T *argvars, typval_T *rettv) |
18037 typval_T *argvars; | |
18038 typval_T *rettv; | |
18039 { | 17371 { |
18040 pos_T pos; | 17372 pos_T pos; |
18041 int fnum; | 17373 int fnum; |
18042 char_u *name; | 17374 char_u *name; |
18043 colnr_T curswant = -1; | 17375 colnr_T curswant = -1; |
18081 | 17413 |
18082 /* | 17414 /* |
18083 * "setqflist()" function | 17415 * "setqflist()" function |
18084 */ | 17416 */ |
18085 static void | 17417 static void |
18086 f_setqflist(argvars, rettv) | 17418 f_setqflist(typval_T *argvars, typval_T *rettv) |
18087 typval_T *argvars; | |
18088 typval_T *rettv; | |
18089 { | 17419 { |
18090 set_qf_ll_list(NULL, &argvars[0], &argvars[1], rettv); | 17420 set_qf_ll_list(NULL, &argvars[0], &argvars[1], rettv); |
18091 } | 17421 } |
18092 | 17422 |
18093 /* | 17423 /* |
18094 * "setreg()" function | 17424 * "setreg()" function |
18095 */ | 17425 */ |
18096 static void | 17426 static void |
18097 f_setreg(argvars, rettv) | 17427 f_setreg(typval_T *argvars, typval_T *rettv) |
18098 typval_T *argvars; | |
18099 typval_T *rettv; | |
18100 { | 17428 { |
18101 int regname; | 17429 int regname; |
18102 char_u *strregname; | 17430 char_u *strregname; |
18103 char_u *stropt; | 17431 char_u *stropt; |
18104 char_u *strval; | 17432 char_u *strval; |
18206 | 17534 |
18207 /* | 17535 /* |
18208 * "settabvar()" function | 17536 * "settabvar()" function |
18209 */ | 17537 */ |
18210 static void | 17538 static void |
18211 f_settabvar(argvars, rettv) | 17539 f_settabvar(typval_T *argvars, typval_T *rettv) |
18212 typval_T *argvars; | |
18213 typval_T *rettv; | |
18214 { | 17540 { |
18215 #ifdef FEAT_WINDOWS | 17541 #ifdef FEAT_WINDOWS |
18216 tabpage_T *save_curtab; | 17542 tabpage_T *save_curtab; |
18217 tabpage_T *tp; | 17543 tabpage_T *tp; |
18218 #endif | 17544 #endif |
18260 | 17586 |
18261 /* | 17587 /* |
18262 * "settabwinvar()" function | 17588 * "settabwinvar()" function |
18263 */ | 17589 */ |
18264 static void | 17590 static void |
18265 f_settabwinvar(argvars, rettv) | 17591 f_settabwinvar(typval_T *argvars, typval_T *rettv) |
18266 typval_T *argvars; | |
18267 typval_T *rettv; | |
18268 { | 17592 { |
18269 setwinvar(argvars, rettv, 1); | 17593 setwinvar(argvars, rettv, 1); |
18270 } | 17594 } |
18271 | 17595 |
18272 /* | 17596 /* |
18273 * "setwinvar()" function | 17597 * "setwinvar()" function |
18274 */ | 17598 */ |
18275 static void | 17599 static void |
18276 f_setwinvar(argvars, rettv) | 17600 f_setwinvar(typval_T *argvars, typval_T *rettv) |
18277 typval_T *argvars; | |
18278 typval_T *rettv; | |
18279 { | 17601 { |
18280 setwinvar(argvars, rettv, 0); | 17602 setwinvar(argvars, rettv, 0); |
18281 } | 17603 } |
18282 | 17604 |
18283 /* | 17605 /* |
18284 * "setwinvar()" and "settabwinvar()" functions | 17606 * "setwinvar()" and "settabwinvar()" functions |
18285 */ | 17607 */ |
18286 | 17608 |
18287 static void | 17609 static void |
18288 setwinvar(argvars, rettv, off) | 17610 setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off) |
18289 typval_T *argvars; | |
18290 typval_T *rettv UNUSED; | |
18291 int off; | |
18292 { | 17611 { |
18293 win_T *win; | 17612 win_T *win; |
18294 #ifdef FEAT_WINDOWS | 17613 #ifdef FEAT_WINDOWS |
18295 win_T *save_curwin; | 17614 win_T *save_curwin; |
18296 tabpage_T *save_curtab; | 17615 tabpage_T *save_curtab; |
18356 #ifdef FEAT_CRYPT | 17675 #ifdef FEAT_CRYPT |
18357 /* | 17676 /* |
18358 * "sha256({string})" function | 17677 * "sha256({string})" function |
18359 */ | 17678 */ |
18360 static void | 17679 static void |
18361 f_sha256(argvars, rettv) | 17680 f_sha256(typval_T *argvars, typval_T *rettv) |
18362 typval_T *argvars; | |
18363 typval_T *rettv; | |
18364 { | 17681 { |
18365 char_u *p; | 17682 char_u *p; |
18366 | 17683 |
18367 p = get_tv_string(&argvars[0]); | 17684 p = get_tv_string(&argvars[0]); |
18368 rettv->vval.v_string = vim_strsave( | 17685 rettv->vval.v_string = vim_strsave( |
18373 | 17690 |
18374 /* | 17691 /* |
18375 * "shellescape({string})" function | 17692 * "shellescape({string})" function |
18376 */ | 17693 */ |
18377 static void | 17694 static void |
18378 f_shellescape(argvars, rettv) | 17695 f_shellescape(typval_T *argvars, typval_T *rettv) |
18379 typval_T *argvars; | |
18380 typval_T *rettv; | |
18381 { | 17696 { |
18382 rettv->vval.v_string = vim_strsave_shellescape( | 17697 rettv->vval.v_string = vim_strsave_shellescape( |
18383 get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), TRUE); | 17698 get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), TRUE); |
18384 rettv->v_type = VAR_STRING; | 17699 rettv->v_type = VAR_STRING; |
18385 } | 17700 } |
18386 | 17701 |
18387 /* | 17702 /* |
18388 * shiftwidth() function | 17703 * shiftwidth() function |
18389 */ | 17704 */ |
18390 static void | 17705 static void |
18391 f_shiftwidth(argvars, rettv) | 17706 f_shiftwidth(typval_T *argvars UNUSED, typval_T *rettv) |
18392 typval_T *argvars UNUSED; | |
18393 typval_T *rettv; | |
18394 { | 17707 { |
18395 rettv->vval.v_number = get_sw_value(curbuf); | 17708 rettv->vval.v_number = get_sw_value(curbuf); |
18396 } | 17709 } |
18397 | 17710 |
18398 /* | 17711 /* |
18399 * "simplify()" function | 17712 * "simplify()" function |
18400 */ | 17713 */ |
18401 static void | 17714 static void |
18402 f_simplify(argvars, rettv) | 17715 f_simplify(typval_T *argvars, typval_T *rettv) |
18403 typval_T *argvars; | |
18404 typval_T *rettv; | |
18405 { | 17716 { |
18406 char_u *p; | 17717 char_u *p; |
18407 | 17718 |
18408 p = get_tv_string(&argvars[0]); | 17719 p = get_tv_string(&argvars[0]); |
18409 rettv->vval.v_string = vim_strsave(p); | 17720 rettv->vval.v_string = vim_strsave(p); |
18414 #ifdef FEAT_FLOAT | 17725 #ifdef FEAT_FLOAT |
18415 /* | 17726 /* |
18416 * "sin()" function | 17727 * "sin()" function |
18417 */ | 17728 */ |
18418 static void | 17729 static void |
18419 f_sin(argvars, rettv) | 17730 f_sin(typval_T *argvars, typval_T *rettv) |
18420 typval_T *argvars; | |
18421 typval_T *rettv; | |
18422 { | 17731 { |
18423 float_T f; | 17732 float_T f; |
18424 | 17733 |
18425 rettv->v_type = VAR_FLOAT; | 17734 rettv->v_type = VAR_FLOAT; |
18426 if (get_float_arg(argvars, &f) == OK) | 17735 if (get_float_arg(argvars, &f) == OK) |
18431 | 17740 |
18432 /* | 17741 /* |
18433 * "sinh()" function | 17742 * "sinh()" function |
18434 */ | 17743 */ |
18435 static void | 17744 static void |
18436 f_sinh(argvars, rettv) | 17745 f_sinh(typval_T *argvars, typval_T *rettv) |
18437 typval_T *argvars; | |
18438 typval_T *rettv; | |
18439 { | 17746 { |
18440 float_T f; | 17747 float_T f; |
18441 | 17748 |
18442 rettv->v_type = VAR_FLOAT; | 17749 rettv->v_type = VAR_FLOAT; |
18443 if (get_float_arg(argvars, &f) == OK) | 17750 if (get_float_arg(argvars, &f) == OK) |
18483 */ | 17790 */ |
18484 static int | 17791 static int |
18485 #ifdef __BORLANDC__ | 17792 #ifdef __BORLANDC__ |
18486 _RTLENTRYF | 17793 _RTLENTRYF |
18487 #endif | 17794 #endif |
18488 item_compare(s1, s2) | 17795 item_compare(const void *s1, const void *s2) |
18489 const void *s1; | |
18490 const void *s2; | |
18491 { | 17796 { |
18492 sortItem_T *si1, *si2; | 17797 sortItem_T *si1, *si2; |
18493 typval_T *tv1, *tv2; | 17798 typval_T *tv1, *tv2; |
18494 char_u *p1, *p2; | 17799 char_u *p1, *p2; |
18495 char_u *tofree1 = NULL, *tofree2 = NULL; | 17800 char_u *tofree1 = NULL, *tofree2 = NULL; |
18572 | 17877 |
18573 static int | 17878 static int |
18574 #ifdef __BORLANDC__ | 17879 #ifdef __BORLANDC__ |
18575 _RTLENTRYF | 17880 _RTLENTRYF |
18576 #endif | 17881 #endif |
18577 item_compare2(s1, s2) | 17882 item_compare2(const void *s1, const void *s2) |
18578 const void *s1; | |
18579 const void *s2; | |
18580 { | 17883 { |
18581 sortItem_T *si1, *si2; | 17884 sortItem_T *si1, *si2; |
18582 int res; | 17885 int res; |
18583 typval_T rettv; | 17886 typval_T rettv; |
18584 typval_T argv[3]; | 17887 typval_T argv[3]; |
18621 | 17924 |
18622 /* | 17925 /* |
18623 * "sort({list})" function | 17926 * "sort({list})" function |
18624 */ | 17927 */ |
18625 static void | 17928 static void |
18626 do_sort_uniq(argvars, rettv, sort) | 17929 do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort) |
18627 typval_T *argvars; | |
18628 typval_T *rettv; | |
18629 int sort; | |
18630 { | 17930 { |
18631 list_T *l; | 17931 list_T *l; |
18632 listitem_T *li; | 17932 listitem_T *li; |
18633 sortItem_T *ptrs; | 17933 sortItem_T *ptrs; |
18634 long len; | 17934 long len; |
18799 | 18099 |
18800 /* | 18100 /* |
18801 * "sort({list})" function | 18101 * "sort({list})" function |
18802 */ | 18102 */ |
18803 static void | 18103 static void |
18804 f_sort(argvars, rettv) | 18104 f_sort(typval_T *argvars, typval_T *rettv) |
18805 typval_T *argvars; | |
18806 typval_T *rettv; | |
18807 { | 18105 { |
18808 do_sort_uniq(argvars, rettv, TRUE); | 18106 do_sort_uniq(argvars, rettv, TRUE); |
18809 } | 18107 } |
18810 | 18108 |
18811 /* | 18109 /* |
18812 * "uniq({list})" function | 18110 * "uniq({list})" function |
18813 */ | 18111 */ |
18814 static void | 18112 static void |
18815 f_uniq(argvars, rettv) | 18113 f_uniq(typval_T *argvars, typval_T *rettv) |
18816 typval_T *argvars; | |
18817 typval_T *rettv; | |
18818 { | 18114 { |
18819 do_sort_uniq(argvars, rettv, FALSE); | 18115 do_sort_uniq(argvars, rettv, FALSE); |
18820 } | 18116 } |
18821 | 18117 |
18822 /* | 18118 /* |
18823 * "soundfold({word})" function | 18119 * "soundfold({word})" function |
18824 */ | 18120 */ |
18825 static void | 18121 static void |
18826 f_soundfold(argvars, rettv) | 18122 f_soundfold(typval_T *argvars, typval_T *rettv) |
18827 typval_T *argvars; | |
18828 typval_T *rettv; | |
18829 { | 18123 { |
18830 char_u *s; | 18124 char_u *s; |
18831 | 18125 |
18832 rettv->v_type = VAR_STRING; | 18126 rettv->v_type = VAR_STRING; |
18833 s = get_tv_string(&argvars[0]); | 18127 s = get_tv_string(&argvars[0]); |
18840 | 18134 |
18841 /* | 18135 /* |
18842 * "spellbadword()" function | 18136 * "spellbadword()" function |
18843 */ | 18137 */ |
18844 static void | 18138 static void |
18845 f_spellbadword(argvars, rettv) | 18139 f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv) |
18846 typval_T *argvars UNUSED; | |
18847 typval_T *rettv; | |
18848 { | 18140 { |
18849 char_u *word = (char_u *)""; | 18141 char_u *word = (char_u *)""; |
18850 hlf_T attr = HLF_COUNT; | 18142 hlf_T attr = HLF_COUNT; |
18851 int len = 0; | 18143 int len = 0; |
18852 | 18144 |
18894 | 18186 |
18895 /* | 18187 /* |
18896 * "spellsuggest()" function | 18188 * "spellsuggest()" function |
18897 */ | 18189 */ |
18898 static void | 18190 static void |
18899 f_spellsuggest(argvars, rettv) | 18191 f_spellsuggest(typval_T *argvars UNUSED, typval_T *rettv) |
18900 typval_T *argvars UNUSED; | |
18901 typval_T *rettv; | |
18902 { | 18192 { |
18903 #ifdef FEAT_SPELL | 18193 #ifdef FEAT_SPELL |
18904 char_u *str; | 18194 char_u *str; |
18905 int typeerr = FALSE; | 18195 int typeerr = FALSE; |
18906 int maxcount; | 18196 int maxcount; |
18953 } | 18243 } |
18954 #endif | 18244 #endif |
18955 } | 18245 } |
18956 | 18246 |
18957 static void | 18247 static void |
18958 f_split(argvars, rettv) | 18248 f_split(typval_T *argvars, typval_T *rettv) |
18959 typval_T *argvars; | |
18960 typval_T *rettv; | |
18961 { | 18249 { |
18962 char_u *str; | 18250 char_u *str; |
18963 char_u *end; | 18251 char_u *end; |
18964 char_u *pat = NULL; | 18252 char_u *pat = NULL; |
18965 regmatch_T regmatch; | 18253 regmatch_T regmatch; |
19038 #ifdef FEAT_FLOAT | 18326 #ifdef FEAT_FLOAT |
19039 /* | 18327 /* |
19040 * "sqrt()" function | 18328 * "sqrt()" function |
19041 */ | 18329 */ |
19042 static void | 18330 static void |
19043 f_sqrt(argvars, rettv) | 18331 f_sqrt(typval_T *argvars, typval_T *rettv) |
19044 typval_T *argvars; | |
19045 typval_T *rettv; | |
19046 { | 18332 { |
19047 float_T f; | 18333 float_T f; |
19048 | 18334 |
19049 rettv->v_type = VAR_FLOAT; | 18335 rettv->v_type = VAR_FLOAT; |
19050 if (get_float_arg(argvars, &f) == OK) | 18336 if (get_float_arg(argvars, &f) == OK) |
19055 | 18341 |
19056 /* | 18342 /* |
19057 * "str2float()" function | 18343 * "str2float()" function |
19058 */ | 18344 */ |
19059 static void | 18345 static void |
19060 f_str2float(argvars, rettv) | 18346 f_str2float(typval_T *argvars, typval_T *rettv) |
19061 typval_T *argvars; | |
19062 typval_T *rettv; | |
19063 { | 18347 { |
19064 char_u *p = skipwhite(get_tv_string(&argvars[0])); | 18348 char_u *p = skipwhite(get_tv_string(&argvars[0])); |
19065 | 18349 |
19066 if (*p == '+') | 18350 if (*p == '+') |
19067 p = skipwhite(p + 1); | 18351 p = skipwhite(p + 1); |
19072 | 18356 |
19073 /* | 18357 /* |
19074 * "str2nr()" function | 18358 * "str2nr()" function |
19075 */ | 18359 */ |
19076 static void | 18360 static void |
19077 f_str2nr(argvars, rettv) | 18361 f_str2nr(typval_T *argvars, typval_T *rettv) |
19078 typval_T *argvars; | |
19079 typval_T *rettv; | |
19080 { | 18362 { |
19081 int base = 10; | 18363 int base = 10; |
19082 char_u *p; | 18364 char_u *p; |
19083 long n; | 18365 long n; |
19084 int what; | 18366 int what; |
19110 #ifdef HAVE_STRFTIME | 18392 #ifdef HAVE_STRFTIME |
19111 /* | 18393 /* |
19112 * "strftime({format}[, {time}])" function | 18394 * "strftime({format}[, {time}])" function |
19113 */ | 18395 */ |
19114 static void | 18396 static void |
19115 f_strftime(argvars, rettv) | 18397 f_strftime(typval_T *argvars, typval_T *rettv) |
19116 typval_T *argvars; | |
19117 typval_T *rettv; | |
19118 { | 18398 { |
19119 char_u result_buf[256]; | 18399 char_u result_buf[256]; |
19120 struct tm *curtime; | 18400 struct tm *curtime; |
19121 time_t seconds; | 18401 time_t seconds; |
19122 char_u *p; | 18402 char_u *p; |
19171 | 18451 |
19172 /* | 18452 /* |
19173 * "stridx()" function | 18453 * "stridx()" function |
19174 */ | 18454 */ |
19175 static void | 18455 static void |
19176 f_stridx(argvars, rettv) | 18456 f_stridx(typval_T *argvars, typval_T *rettv) |
19177 typval_T *argvars; | |
19178 typval_T *rettv; | |
19179 { | 18457 { |
19180 char_u buf[NUMBUFLEN]; | 18458 char_u buf[NUMBUFLEN]; |
19181 char_u *needle; | 18459 char_u *needle; |
19182 char_u *haystack; | 18460 char_u *haystack; |
19183 char_u *save_haystack; | 18461 char_u *save_haystack; |
19208 | 18486 |
19209 /* | 18487 /* |
19210 * "string()" function | 18488 * "string()" function |
19211 */ | 18489 */ |
19212 static void | 18490 static void |
19213 f_string(argvars, rettv) | 18491 f_string(typval_T *argvars, typval_T *rettv) |
19214 typval_T *argvars; | |
19215 typval_T *rettv; | |
19216 { | 18492 { |
19217 char_u *tofree; | 18493 char_u *tofree; |
19218 char_u numbuf[NUMBUFLEN]; | 18494 char_u numbuf[NUMBUFLEN]; |
19219 | 18495 |
19220 rettv->v_type = VAR_STRING; | 18496 rettv->v_type = VAR_STRING; |
19226 | 18502 |
19227 /* | 18503 /* |
19228 * "strlen()" function | 18504 * "strlen()" function |
19229 */ | 18505 */ |
19230 static void | 18506 static void |
19231 f_strlen(argvars, rettv) | 18507 f_strlen(typval_T *argvars, typval_T *rettv) |
19232 typval_T *argvars; | |
19233 typval_T *rettv; | |
19234 { | 18508 { |
19235 rettv->vval.v_number = (varnumber_T)(STRLEN( | 18509 rettv->vval.v_number = (varnumber_T)(STRLEN( |
19236 get_tv_string(&argvars[0]))); | 18510 get_tv_string(&argvars[0]))); |
19237 } | 18511 } |
19238 | 18512 |
19239 /* | 18513 /* |
19240 * "strchars()" function | 18514 * "strchars()" function |
19241 */ | 18515 */ |
19242 static void | 18516 static void |
19243 f_strchars(argvars, rettv) | 18517 f_strchars(typval_T *argvars, typval_T *rettv) |
19244 typval_T *argvars; | |
19245 typval_T *rettv; | |
19246 { | 18518 { |
19247 char_u *s = get_tv_string(&argvars[0]); | 18519 char_u *s = get_tv_string(&argvars[0]); |
19248 int skipcc = 0; | 18520 int skipcc = 0; |
19249 #ifdef FEAT_MBYTE | 18521 #ifdef FEAT_MBYTE |
19250 varnumber_T len = 0; | 18522 varnumber_T len = 0; |
19273 | 18545 |
19274 /* | 18546 /* |
19275 * "strdisplaywidth()" function | 18547 * "strdisplaywidth()" function |
19276 */ | 18548 */ |
19277 static void | 18549 static void |
19278 f_strdisplaywidth(argvars, rettv) | 18550 f_strdisplaywidth(typval_T *argvars, typval_T *rettv) |
19279 typval_T *argvars; | |
19280 typval_T *rettv; | |
19281 { | 18551 { |
19282 char_u *s = get_tv_string(&argvars[0]); | 18552 char_u *s = get_tv_string(&argvars[0]); |
19283 int col = 0; | 18553 int col = 0; |
19284 | 18554 |
19285 if (argvars[1].v_type != VAR_UNKNOWN) | 18555 if (argvars[1].v_type != VAR_UNKNOWN) |
19290 | 18560 |
19291 /* | 18561 /* |
19292 * "strwidth()" function | 18562 * "strwidth()" function |
19293 */ | 18563 */ |
19294 static void | 18564 static void |
19295 f_strwidth(argvars, rettv) | 18565 f_strwidth(typval_T *argvars, typval_T *rettv) |
19296 typval_T *argvars; | |
19297 typval_T *rettv; | |
19298 { | 18566 { |
19299 char_u *s = get_tv_string(&argvars[0]); | 18567 char_u *s = get_tv_string(&argvars[0]); |
19300 | 18568 |
19301 rettv->vval.v_number = (varnumber_T)( | 18569 rettv->vval.v_number = (varnumber_T)( |
19302 #ifdef FEAT_MBYTE | 18570 #ifdef FEAT_MBYTE |
19309 | 18577 |
19310 /* | 18578 /* |
19311 * "strpart()" function | 18579 * "strpart()" function |
19312 */ | 18580 */ |
19313 static void | 18581 static void |
19314 f_strpart(argvars, rettv) | 18582 f_strpart(typval_T *argvars, typval_T *rettv) |
19315 typval_T *argvars; | |
19316 typval_T *rettv; | |
19317 { | 18583 { |
19318 char_u *p; | 18584 char_u *p; |
19319 int n; | 18585 int n; |
19320 int len; | 18586 int len; |
19321 int slen; | 18587 int slen; |
19354 | 18620 |
19355 /* | 18621 /* |
19356 * "strridx()" function | 18622 * "strridx()" function |
19357 */ | 18623 */ |
19358 static void | 18624 static void |
19359 f_strridx(argvars, rettv) | 18625 f_strridx(typval_T *argvars, typval_T *rettv) |
19360 typval_T *argvars; | |
19361 typval_T *rettv; | |
19362 { | 18626 { |
19363 char_u buf[NUMBUFLEN]; | 18627 char_u buf[NUMBUFLEN]; |
19364 char_u *needle; | 18628 char_u *needle; |
19365 char_u *haystack; | 18629 char_u *haystack; |
19366 char_u *rest; | 18630 char_u *rest; |
19409 | 18673 |
19410 /* | 18674 /* |
19411 * "strtrans()" function | 18675 * "strtrans()" function |
19412 */ | 18676 */ |
19413 static void | 18677 static void |
19414 f_strtrans(argvars, rettv) | 18678 f_strtrans(typval_T *argvars, typval_T *rettv) |
19415 typval_T *argvars; | |
19416 typval_T *rettv; | |
19417 { | 18679 { |
19418 rettv->v_type = VAR_STRING; | 18680 rettv->v_type = VAR_STRING; |
19419 rettv->vval.v_string = transstr(get_tv_string(&argvars[0])); | 18681 rettv->vval.v_string = transstr(get_tv_string(&argvars[0])); |
19420 } | 18682 } |
19421 | 18683 |
19422 /* | 18684 /* |
19423 * "submatch()" function | 18685 * "submatch()" function |
19424 */ | 18686 */ |
19425 static void | 18687 static void |
19426 f_submatch(argvars, rettv) | 18688 f_submatch(typval_T *argvars, typval_T *rettv) |
19427 typval_T *argvars; | |
19428 typval_T *rettv; | |
19429 { | 18689 { |
19430 int error = FALSE; | 18690 int error = FALSE; |
19431 int no; | 18691 int no; |
19432 int retList = 0; | 18692 int retList = 0; |
19433 | 18693 |
19454 | 18714 |
19455 /* | 18715 /* |
19456 * "substitute()" function | 18716 * "substitute()" function |
19457 */ | 18717 */ |
19458 static void | 18718 static void |
19459 f_substitute(argvars, rettv) | 18719 f_substitute(typval_T *argvars, typval_T *rettv) |
19460 typval_T *argvars; | |
19461 typval_T *rettv; | |
19462 { | 18720 { |
19463 char_u patbuf[NUMBUFLEN]; | 18721 char_u patbuf[NUMBUFLEN]; |
19464 char_u subbuf[NUMBUFLEN]; | 18722 char_u subbuf[NUMBUFLEN]; |
19465 char_u flagsbuf[NUMBUFLEN]; | 18723 char_u flagsbuf[NUMBUFLEN]; |
19466 | 18724 |
19478 | 18736 |
19479 /* | 18737 /* |
19480 * "synID(lnum, col, trans)" function | 18738 * "synID(lnum, col, trans)" function |
19481 */ | 18739 */ |
19482 static void | 18740 static void |
19483 f_synID(argvars, rettv) | 18741 f_synID(typval_T *argvars UNUSED, typval_T *rettv) |
19484 typval_T *argvars UNUSED; | |
19485 typval_T *rettv; | |
19486 { | 18742 { |
19487 int id = 0; | 18743 int id = 0; |
19488 #ifdef FEAT_SYN_HL | 18744 #ifdef FEAT_SYN_HL |
19489 long lnum; | 18745 long lnum; |
19490 long col; | 18746 long col; |
19505 | 18761 |
19506 /* | 18762 /* |
19507 * "synIDattr(id, what [, mode])" function | 18763 * "synIDattr(id, what [, mode])" function |
19508 */ | 18764 */ |
19509 static void | 18765 static void |
19510 f_synIDattr(argvars, rettv) | 18766 f_synIDattr(typval_T *argvars UNUSED, typval_T *rettv) |
19511 typval_T *argvars UNUSED; | |
19512 typval_T *rettv; | |
19513 { | 18767 { |
19514 char_u *p = NULL; | 18768 char_u *p = NULL; |
19515 #ifdef FEAT_SYN_HL | 18769 #ifdef FEAT_SYN_HL |
19516 int id; | 18770 int id; |
19517 char_u *what; | 18771 char_u *what; |
19596 | 18850 |
19597 /* | 18851 /* |
19598 * "synIDtrans(id)" function | 18852 * "synIDtrans(id)" function |
19599 */ | 18853 */ |
19600 static void | 18854 static void |
19601 f_synIDtrans(argvars, rettv) | 18855 f_synIDtrans(typval_T *argvars UNUSED, typval_T *rettv) |
19602 typval_T *argvars UNUSED; | |
19603 typval_T *rettv; | |
19604 { | 18856 { |
19605 int id; | 18857 int id; |
19606 | 18858 |
19607 #ifdef FEAT_SYN_HL | 18859 #ifdef FEAT_SYN_HL |
19608 id = get_tv_number(&argvars[0]); | 18860 id = get_tv_number(&argvars[0]); |
19618 | 18870 |
19619 /* | 18871 /* |
19620 * "synconcealed(lnum, col)" function | 18872 * "synconcealed(lnum, col)" function |
19621 */ | 18873 */ |
19622 static void | 18874 static void |
19623 f_synconcealed(argvars, rettv) | 18875 f_synconcealed(typval_T *argvars UNUSED, typval_T *rettv) |
19624 typval_T *argvars UNUSED; | |
19625 typval_T *rettv; | |
19626 { | 18876 { |
19627 #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) | 18877 #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) |
19628 long lnum; | 18878 long lnum; |
19629 long col; | 18879 long col; |
19630 int syntax_flags = 0; | 18880 int syntax_flags = 0; |
19680 | 18930 |
19681 /* | 18931 /* |
19682 * "synstack(lnum, col)" function | 18932 * "synstack(lnum, col)" function |
19683 */ | 18933 */ |
19684 static void | 18934 static void |
19685 f_synstack(argvars, rettv) | 18935 f_synstack(typval_T *argvars UNUSED, typval_T *rettv) |
19686 typval_T *argvars UNUSED; | |
19687 typval_T *rettv; | |
19688 { | 18936 { |
19689 #ifdef FEAT_SYN_HL | 18937 #ifdef FEAT_SYN_HL |
19690 long lnum; | 18938 long lnum; |
19691 long col; | 18939 long col; |
19692 int i; | 18940 int i; |
19716 } | 18964 } |
19717 #endif | 18965 #endif |
19718 } | 18966 } |
19719 | 18967 |
19720 static void | 18968 static void |
19721 get_cmd_output_as_rettv(argvars, rettv, retlist) | 18969 get_cmd_output_as_rettv( |
19722 typval_T *argvars; | 18970 typval_T *argvars, |
19723 typval_T *rettv; | 18971 typval_T *rettv, |
19724 int retlist; | 18972 int retlist) |
19725 { | 18973 { |
19726 char_u *res = NULL; | 18974 char_u *res = NULL; |
19727 char_u *p; | 18975 char_u *p; |
19728 char_u *infile = NULL; | 18976 char_u *infile = NULL; |
19729 char_u buf[NUMBUFLEN]; | 18977 char_u buf[NUMBUFLEN]; |
19888 | 19136 |
19889 /* | 19137 /* |
19890 * "system()" function | 19138 * "system()" function |
19891 */ | 19139 */ |
19892 static void | 19140 static void |
19893 f_system(argvars, rettv) | 19141 f_system(typval_T *argvars, typval_T *rettv) |
19894 typval_T *argvars; | |
19895 typval_T *rettv; | |
19896 { | 19142 { |
19897 get_cmd_output_as_rettv(argvars, rettv, FALSE); | 19143 get_cmd_output_as_rettv(argvars, rettv, FALSE); |
19898 } | 19144 } |
19899 | 19145 |
19900 /* | 19146 /* |
19901 * "systemlist()" function | 19147 * "systemlist()" function |
19902 */ | 19148 */ |
19903 static void | 19149 static void |
19904 f_systemlist(argvars, rettv) | 19150 f_systemlist(typval_T *argvars, typval_T *rettv) |
19905 typval_T *argvars; | |
19906 typval_T *rettv; | |
19907 { | 19151 { |
19908 get_cmd_output_as_rettv(argvars, rettv, TRUE); | 19152 get_cmd_output_as_rettv(argvars, rettv, TRUE); |
19909 } | 19153 } |
19910 | 19154 |
19911 /* | 19155 /* |
19912 * "tabpagebuflist()" function | 19156 * "tabpagebuflist()" function |
19913 */ | 19157 */ |
19914 static void | 19158 static void |
19915 f_tabpagebuflist(argvars, rettv) | 19159 f_tabpagebuflist(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
19916 typval_T *argvars UNUSED; | |
19917 typval_T *rettv UNUSED; | |
19918 { | 19160 { |
19919 #ifdef FEAT_WINDOWS | 19161 #ifdef FEAT_WINDOWS |
19920 tabpage_T *tp; | 19162 tabpage_T *tp; |
19921 win_T *wp = NULL; | 19163 win_T *wp = NULL; |
19922 | 19164 |
19941 | 19183 |
19942 /* | 19184 /* |
19943 * "tabpagenr()" function | 19185 * "tabpagenr()" function |
19944 */ | 19186 */ |
19945 static void | 19187 static void |
19946 f_tabpagenr(argvars, rettv) | 19188 f_tabpagenr(typval_T *argvars UNUSED, typval_T *rettv) |
19947 typval_T *argvars UNUSED; | |
19948 typval_T *rettv; | |
19949 { | 19189 { |
19950 int nr = 1; | 19190 int nr = 1; |
19951 #ifdef FEAT_WINDOWS | 19191 #ifdef FEAT_WINDOWS |
19952 char_u *arg; | 19192 char_u *arg; |
19953 | 19193 |
19975 | 19215 |
19976 /* | 19216 /* |
19977 * Common code for tabpagewinnr() and winnr(). | 19217 * Common code for tabpagewinnr() and winnr(). |
19978 */ | 19218 */ |
19979 static int | 19219 static int |
19980 get_winnr(tp, argvar) | 19220 get_winnr(tabpage_T *tp, typval_T *argvar) |
19981 tabpage_T *tp; | |
19982 typval_T *argvar; | |
19983 { | 19221 { |
19984 win_T *twin; | 19222 win_T *twin; |
19985 int nr = 1; | 19223 int nr = 1; |
19986 win_T *wp; | 19224 win_T *wp; |
19987 char_u *arg; | 19225 char_u *arg; |
20025 | 19263 |
20026 /* | 19264 /* |
20027 * "tabpagewinnr()" function | 19265 * "tabpagewinnr()" function |
20028 */ | 19266 */ |
20029 static void | 19267 static void |
20030 f_tabpagewinnr(argvars, rettv) | 19268 f_tabpagewinnr(typval_T *argvars UNUSED, typval_T *rettv) |
20031 typval_T *argvars UNUSED; | |
20032 typval_T *rettv; | |
20033 { | 19269 { |
20034 int nr = 1; | 19270 int nr = 1; |
20035 #ifdef FEAT_WINDOWS | 19271 #ifdef FEAT_WINDOWS |
20036 tabpage_T *tp; | 19272 tabpage_T *tp; |
20037 | 19273 |
20047 | 19283 |
20048 /* | 19284 /* |
20049 * "tagfiles()" function | 19285 * "tagfiles()" function |
20050 */ | 19286 */ |
20051 static void | 19287 static void |
20052 f_tagfiles(argvars, rettv) | 19288 f_tagfiles(typval_T *argvars UNUSED, typval_T *rettv) |
20053 typval_T *argvars UNUSED; | |
20054 typval_T *rettv; | |
20055 { | 19289 { |
20056 char_u *fname; | 19290 char_u *fname; |
20057 tagname_T tn; | 19291 tagname_T tn; |
20058 int first; | 19292 int first; |
20059 | 19293 |
20073 | 19307 |
20074 /* | 19308 /* |
20075 * "taglist()" function | 19309 * "taglist()" function |
20076 */ | 19310 */ |
20077 static void | 19311 static void |
20078 f_taglist(argvars, rettv) | 19312 f_taglist(typval_T *argvars, typval_T *rettv) |
20079 typval_T *argvars; | |
20080 typval_T *rettv; | |
20081 { | 19313 { |
20082 char_u *tag_pattern; | 19314 char_u *tag_pattern; |
20083 | 19315 |
20084 tag_pattern = get_tv_string(&argvars[0]); | 19316 tag_pattern = get_tv_string(&argvars[0]); |
20085 | 19317 |
20093 | 19325 |
20094 /* | 19326 /* |
20095 * "tempname()" function | 19327 * "tempname()" function |
20096 */ | 19328 */ |
20097 static void | 19329 static void |
20098 f_tempname(argvars, rettv) | 19330 f_tempname(typval_T *argvars UNUSED, typval_T *rettv) |
20099 typval_T *argvars UNUSED; | |
20100 typval_T *rettv; | |
20101 { | 19331 { |
20102 static int x = 'A'; | 19332 static int x = 'A'; |
20103 | 19333 |
20104 rettv->v_type = VAR_STRING; | 19334 rettv->v_type = VAR_STRING; |
20105 rettv->vval.v_string = vim_tempname(x, FALSE); | 19335 rettv->vval.v_string = vim_tempname(x, FALSE); |
20128 | 19358 |
20129 /* | 19359 /* |
20130 * "test(list)" function: Just checking the walls... | 19360 * "test(list)" function: Just checking the walls... |
20131 */ | 19361 */ |
20132 static void | 19362 static void |
20133 f_test(argvars, rettv) | 19363 f_test(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
20134 typval_T *argvars UNUSED; | |
20135 typval_T *rettv UNUSED; | |
20136 { | 19364 { |
20137 /* Used for unit testing. Change the code below to your liking. */ | 19365 /* Used for unit testing. Change the code below to your liking. */ |
20138 #if 0 | 19366 #if 0 |
20139 listitem_T *li; | 19367 listitem_T *li; |
20140 list_T *l; | 19368 list_T *l; |
20160 #ifdef FEAT_FLOAT | 19388 #ifdef FEAT_FLOAT |
20161 /* | 19389 /* |
20162 * "tan()" function | 19390 * "tan()" function |
20163 */ | 19391 */ |
20164 static void | 19392 static void |
20165 f_tan(argvars, rettv) | 19393 f_tan(typval_T *argvars, typval_T *rettv) |
20166 typval_T *argvars; | |
20167 typval_T *rettv; | |
20168 { | 19394 { |
20169 float_T f; | 19395 float_T f; |
20170 | 19396 |
20171 rettv->v_type = VAR_FLOAT; | 19397 rettv->v_type = VAR_FLOAT; |
20172 if (get_float_arg(argvars, &f) == OK) | 19398 if (get_float_arg(argvars, &f) == OK) |
20177 | 19403 |
20178 /* | 19404 /* |
20179 * "tanh()" function | 19405 * "tanh()" function |
20180 */ | 19406 */ |
20181 static void | 19407 static void |
20182 f_tanh(argvars, rettv) | 19408 f_tanh(typval_T *argvars, typval_T *rettv) |
20183 typval_T *argvars; | |
20184 typval_T *rettv; | |
20185 { | 19409 { |
20186 float_T f; | 19410 float_T f; |
20187 | 19411 |
20188 rettv->v_type = VAR_FLOAT; | 19412 rettv->v_type = VAR_FLOAT; |
20189 if (get_float_arg(argvars, &f) == OK) | 19413 if (get_float_arg(argvars, &f) == OK) |
20195 | 19419 |
20196 /* | 19420 /* |
20197 * "tolower(string)" function | 19421 * "tolower(string)" function |
20198 */ | 19422 */ |
20199 static void | 19423 static void |
20200 f_tolower(argvars, rettv) | 19424 f_tolower(typval_T *argvars, typval_T *rettv) |
20201 typval_T *argvars; | |
20202 typval_T *rettv; | |
20203 { | 19425 { |
20204 char_u *p; | 19426 char_u *p; |
20205 | 19427 |
20206 p = vim_strsave(get_tv_string(&argvars[0])); | 19428 p = vim_strsave(get_tv_string(&argvars[0])); |
20207 rettv->v_type = VAR_STRING; | 19429 rettv->v_type = VAR_STRING; |
20238 | 19460 |
20239 /* | 19461 /* |
20240 * "toupper(string)" function | 19462 * "toupper(string)" function |
20241 */ | 19463 */ |
20242 static void | 19464 static void |
20243 f_toupper(argvars, rettv) | 19465 f_toupper(typval_T *argvars, typval_T *rettv) |
20244 typval_T *argvars; | |
20245 typval_T *rettv; | |
20246 { | 19466 { |
20247 rettv->v_type = VAR_STRING; | 19467 rettv->v_type = VAR_STRING; |
20248 rettv->vval.v_string = strup_save(get_tv_string(&argvars[0])); | 19468 rettv->vval.v_string = strup_save(get_tv_string(&argvars[0])); |
20249 } | 19469 } |
20250 | 19470 |
20251 /* | 19471 /* |
20252 * "tr(string, fromstr, tostr)" function | 19472 * "tr(string, fromstr, tostr)" function |
20253 */ | 19473 */ |
20254 static void | 19474 static void |
20255 f_tr(argvars, rettv) | 19475 f_tr(typval_T *argvars, typval_T *rettv) |
20256 typval_T *argvars; | |
20257 typval_T *rettv; | |
20258 { | 19476 { |
20259 char_u *in_str; | 19477 char_u *in_str; |
20260 char_u *fromstr; | 19478 char_u *fromstr; |
20261 char_u *tostr; | 19479 char_u *tostr; |
20262 char_u *p; | 19480 char_u *p; |
20374 #ifdef FEAT_FLOAT | 19592 #ifdef FEAT_FLOAT |
20375 /* | 19593 /* |
20376 * "trunc({float})" function | 19594 * "trunc({float})" function |
20377 */ | 19595 */ |
20378 static void | 19596 static void |
20379 f_trunc(argvars, rettv) | 19597 f_trunc(typval_T *argvars, typval_T *rettv) |
20380 typval_T *argvars; | |
20381 typval_T *rettv; | |
20382 { | 19598 { |
20383 float_T f; | 19599 float_T f; |
20384 | 19600 |
20385 rettv->v_type = VAR_FLOAT; | 19601 rettv->v_type = VAR_FLOAT; |
20386 if (get_float_arg(argvars, &f) == OK) | 19602 if (get_float_arg(argvars, &f) == OK) |
20393 | 19609 |
20394 /* | 19610 /* |
20395 * "type(expr)" function | 19611 * "type(expr)" function |
20396 */ | 19612 */ |
20397 static void | 19613 static void |
20398 f_type(argvars, rettv) | 19614 f_type(typval_T *argvars, typval_T *rettv) |
20399 typval_T *argvars; | |
20400 typval_T *rettv; | |
20401 { | 19615 { |
20402 int n; | 19616 int n; |
20403 | 19617 |
20404 switch (argvars[0].v_type) | 19618 switch (argvars[0].v_type) |
20405 { | 19619 { |
20425 | 19639 |
20426 /* | 19640 /* |
20427 * "undofile(name)" function | 19641 * "undofile(name)" function |
20428 */ | 19642 */ |
20429 static void | 19643 static void |
20430 f_undofile(argvars, rettv) | 19644 f_undofile(typval_T *argvars UNUSED, typval_T *rettv) |
20431 typval_T *argvars UNUSED; | |
20432 typval_T *rettv; | |
20433 { | 19645 { |
20434 rettv->v_type = VAR_STRING; | 19646 rettv->v_type = VAR_STRING; |
20435 #ifdef FEAT_PERSISTENT_UNDO | 19647 #ifdef FEAT_PERSISTENT_UNDO |
20436 { | 19648 { |
20437 char_u *fname = get_tv_string(&argvars[0]); | 19649 char_u *fname = get_tv_string(&argvars[0]); |
20457 | 19669 |
20458 /* | 19670 /* |
20459 * "undotree()" function | 19671 * "undotree()" function |
20460 */ | 19672 */ |
20461 static void | 19673 static void |
20462 f_undotree(argvars, rettv) | 19674 f_undotree(typval_T *argvars UNUSED, typval_T *rettv) |
20463 typval_T *argvars UNUSED; | |
20464 typval_T *rettv; | |
20465 { | 19675 { |
20466 if (rettv_dict_alloc(rettv) == OK) | 19676 if (rettv_dict_alloc(rettv) == OK) |
20467 { | 19677 { |
20468 dict_T *dict = rettv->vval.v_dict; | 19678 dict_T *dict = rettv->vval.v_dict; |
20469 list_T *list; | 19679 list_T *list; |
20487 | 19697 |
20488 /* | 19698 /* |
20489 * "values(dict)" function | 19699 * "values(dict)" function |
20490 */ | 19700 */ |
20491 static void | 19701 static void |
20492 f_values(argvars, rettv) | 19702 f_values(typval_T *argvars, typval_T *rettv) |
20493 typval_T *argvars; | |
20494 typval_T *rettv; | |
20495 { | 19703 { |
20496 dict_list(argvars, rettv, 1); | 19704 dict_list(argvars, rettv, 1); |
20497 } | 19705 } |
20498 | 19706 |
20499 /* | 19707 /* |
20500 * "virtcol(string)" function | 19708 * "virtcol(string)" function |
20501 */ | 19709 */ |
20502 static void | 19710 static void |
20503 f_virtcol(argvars, rettv) | 19711 f_virtcol(typval_T *argvars, typval_T *rettv) |
20504 typval_T *argvars; | |
20505 typval_T *rettv; | |
20506 { | 19712 { |
20507 colnr_T vcol = 0; | 19713 colnr_T vcol = 0; |
20508 pos_T *fp; | 19714 pos_T *fp; |
20509 int fnum = curbuf->b_fnum; | 19715 int fnum = curbuf->b_fnum; |
20510 | 19716 |
20521 | 19727 |
20522 /* | 19728 /* |
20523 * "visualmode()" function | 19729 * "visualmode()" function |
20524 */ | 19730 */ |
20525 static void | 19731 static void |
20526 f_visualmode(argvars, rettv) | 19732 f_visualmode(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
20527 typval_T *argvars UNUSED; | |
20528 typval_T *rettv UNUSED; | |
20529 { | 19733 { |
20530 char_u str[2]; | 19734 char_u str[2]; |
20531 | 19735 |
20532 rettv->v_type = VAR_STRING; | 19736 rettv->v_type = VAR_STRING; |
20533 str[0] = curbuf->b_visual_mode_eval; | 19737 str[0] = curbuf->b_visual_mode_eval; |
20541 | 19745 |
20542 /* | 19746 /* |
20543 * "wildmenumode()" function | 19747 * "wildmenumode()" function |
20544 */ | 19748 */ |
20545 static void | 19749 static void |
20546 f_wildmenumode(argvars, rettv) | 19750 f_wildmenumode(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
20547 typval_T *argvars UNUSED; | |
20548 typval_T *rettv UNUSED; | |
20549 { | 19751 { |
20550 #ifdef FEAT_WILDMENU | 19752 #ifdef FEAT_WILDMENU |
20551 if (wild_menu_showing) | 19753 if (wild_menu_showing) |
20552 rettv->vval.v_number = 1; | 19754 rettv->vval.v_number = 1; |
20553 #endif | 19755 #endif |
20555 | 19757 |
20556 /* | 19758 /* |
20557 * "winbufnr(nr)" function | 19759 * "winbufnr(nr)" function |
20558 */ | 19760 */ |
20559 static void | 19761 static void |
20560 f_winbufnr(argvars, rettv) | 19762 f_winbufnr(typval_T *argvars, typval_T *rettv) |
20561 typval_T *argvars; | |
20562 typval_T *rettv; | |
20563 { | 19763 { |
20564 win_T *wp; | 19764 win_T *wp; |
20565 | 19765 |
20566 wp = find_win_by_nr(&argvars[0], NULL); | 19766 wp = find_win_by_nr(&argvars[0], NULL); |
20567 if (wp == NULL) | 19767 if (wp == NULL) |
20572 | 19772 |
20573 /* | 19773 /* |
20574 * "wincol()" function | 19774 * "wincol()" function |
20575 */ | 19775 */ |
20576 static void | 19776 static void |
20577 f_wincol(argvars, rettv) | 19777 f_wincol(typval_T *argvars UNUSED, typval_T *rettv) |
20578 typval_T *argvars UNUSED; | |
20579 typval_T *rettv; | |
20580 { | 19778 { |
20581 validate_cursor(); | 19779 validate_cursor(); |
20582 rettv->vval.v_number = curwin->w_wcol + 1; | 19780 rettv->vval.v_number = curwin->w_wcol + 1; |
20583 } | 19781 } |
20584 | 19782 |
20585 /* | 19783 /* |
20586 * "winheight(nr)" function | 19784 * "winheight(nr)" function |
20587 */ | 19785 */ |
20588 static void | 19786 static void |
20589 f_winheight(argvars, rettv) | 19787 f_winheight(typval_T *argvars, typval_T *rettv) |
20590 typval_T *argvars; | |
20591 typval_T *rettv; | |
20592 { | 19788 { |
20593 win_T *wp; | 19789 win_T *wp; |
20594 | 19790 |
20595 wp = find_win_by_nr(&argvars[0], NULL); | 19791 wp = find_win_by_nr(&argvars[0], NULL); |
20596 if (wp == NULL) | 19792 if (wp == NULL) |
20601 | 19797 |
20602 /* | 19798 /* |
20603 * "winline()" function | 19799 * "winline()" function |
20604 */ | 19800 */ |
20605 static void | 19801 static void |
20606 f_winline(argvars, rettv) | 19802 f_winline(typval_T *argvars UNUSED, typval_T *rettv) |
20607 typval_T *argvars UNUSED; | |
20608 typval_T *rettv; | |
20609 { | 19803 { |
20610 validate_cursor(); | 19804 validate_cursor(); |
20611 rettv->vval.v_number = curwin->w_wrow + 1; | 19805 rettv->vval.v_number = curwin->w_wrow + 1; |
20612 } | 19806 } |
20613 | 19807 |
20614 /* | 19808 /* |
20615 * "winnr()" function | 19809 * "winnr()" function |
20616 */ | 19810 */ |
20617 static void | 19811 static void |
20618 f_winnr(argvars, rettv) | 19812 f_winnr(typval_T *argvars UNUSED, typval_T *rettv) |
20619 typval_T *argvars UNUSED; | |
20620 typval_T *rettv; | |
20621 { | 19813 { |
20622 int nr = 1; | 19814 int nr = 1; |
20623 | 19815 |
20624 #ifdef FEAT_WINDOWS | 19816 #ifdef FEAT_WINDOWS |
20625 nr = get_winnr(curtab, &argvars[0]); | 19817 nr = get_winnr(curtab, &argvars[0]); |
20629 | 19821 |
20630 /* | 19822 /* |
20631 * "winrestcmd()" function | 19823 * "winrestcmd()" function |
20632 */ | 19824 */ |
20633 static void | 19825 static void |
20634 f_winrestcmd(argvars, rettv) | 19826 f_winrestcmd(typval_T *argvars UNUSED, typval_T *rettv) |
20635 typval_T *argvars UNUSED; | |
20636 typval_T *rettv; | |
20637 { | 19827 { |
20638 #ifdef FEAT_WINDOWS | 19828 #ifdef FEAT_WINDOWS |
20639 win_T *wp; | 19829 win_T *wp; |
20640 int winnr = 1; | 19830 int winnr = 1; |
20641 garray_T ga; | 19831 garray_T ga; |
20663 | 19853 |
20664 /* | 19854 /* |
20665 * "winrestview()" function | 19855 * "winrestview()" function |
20666 */ | 19856 */ |
20667 static void | 19857 static void |
20668 f_winrestview(argvars, rettv) | 19858 f_winrestview(typval_T *argvars, typval_T *rettv UNUSED) |
20669 typval_T *argvars; | |
20670 typval_T *rettv UNUSED; | |
20671 { | 19859 { |
20672 dict_T *dict; | 19860 dict_T *dict; |
20673 | 19861 |
20674 if (argvars[0].v_type != VAR_DICT | 19862 if (argvars[0].v_type != VAR_DICT |
20675 || (dict = argvars[0].vval.v_dict) == NULL) | 19863 || (dict = argvars[0].vval.v_dict) == NULL) |
20720 | 19908 |
20721 /* | 19909 /* |
20722 * "winsaveview()" function | 19910 * "winsaveview()" function |
20723 */ | 19911 */ |
20724 static void | 19912 static void |
20725 f_winsaveview(argvars, rettv) | 19913 f_winsaveview(typval_T *argvars UNUSED, typval_T *rettv) |
20726 typval_T *argvars UNUSED; | |
20727 typval_T *rettv; | |
20728 { | 19914 { |
20729 dict_T *dict; | 19915 dict_T *dict; |
20730 | 19916 |
20731 if (rettv_dict_alloc(rettv) == FAIL) | 19917 if (rettv_dict_alloc(rettv) == FAIL) |
20732 return; | 19918 return; |
20750 | 19936 |
20751 /* | 19937 /* |
20752 * "winwidth(nr)" function | 19938 * "winwidth(nr)" function |
20753 */ | 19939 */ |
20754 static void | 19940 static void |
20755 f_winwidth(argvars, rettv) | 19941 f_winwidth(typval_T *argvars, typval_T *rettv) |
20756 typval_T *argvars; | |
20757 typval_T *rettv; | |
20758 { | 19942 { |
20759 win_T *wp; | 19943 win_T *wp; |
20760 | 19944 |
20761 wp = find_win_by_nr(&argvars[0], NULL); | 19945 wp = find_win_by_nr(&argvars[0], NULL); |
20762 if (wp == NULL) | 19946 if (wp == NULL) |
20771 | 19955 |
20772 /* | 19956 /* |
20773 * "wordcount()" function | 19957 * "wordcount()" function |
20774 */ | 19958 */ |
20775 static void | 19959 static void |
20776 f_wordcount(argvars, rettv) | 19960 f_wordcount(typval_T *argvars UNUSED, typval_T *rettv) |
20777 typval_T *argvars UNUSED; | |
20778 typval_T *rettv; | |
20779 { | 19961 { |
20780 if (rettv_dict_alloc(rettv) == FAIL) | 19962 if (rettv_dict_alloc(rettv) == FAIL) |
20781 return; | 19963 return; |
20782 cursor_pos_info(rettv->vval.v_dict); | 19964 cursor_pos_info(rettv->vval.v_dict); |
20783 } | 19965 } |
20784 | 19966 |
20785 /* | 19967 /* |
20786 * Write list of strings to file | 19968 * Write list of strings to file |
20787 */ | 19969 */ |
20788 static int | 19970 static int |
20789 write_list(fd, list, binary) | 19971 write_list(FILE *fd, list_T *list, int binary) |
20790 FILE *fd; | |
20791 list_T *list; | |
20792 int binary; | |
20793 { | 19972 { |
20794 listitem_T *li; | 19973 listitem_T *li; |
20795 int c; | 19974 int c; |
20796 int ret = OK; | 19975 int ret = OK; |
20797 char_u *s; | 19976 char_u *s; |
20827 | 20006 |
20828 /* | 20007 /* |
20829 * "writefile()" function | 20008 * "writefile()" function |
20830 */ | 20009 */ |
20831 static void | 20010 static void |
20832 f_writefile(argvars, rettv) | 20011 f_writefile(typval_T *argvars, typval_T *rettv) |
20833 typval_T *argvars; | |
20834 typval_T *rettv; | |
20835 { | 20012 { |
20836 int binary = FALSE; | 20013 int binary = FALSE; |
20837 int append = FALSE; | 20014 int append = FALSE; |
20838 char_u *fname; | 20015 char_u *fname; |
20839 FILE *fd; | 20016 FILE *fd; |
20879 | 20056 |
20880 /* | 20057 /* |
20881 * "xor(expr, expr)" function | 20058 * "xor(expr, expr)" function |
20882 */ | 20059 */ |
20883 static void | 20060 static void |
20884 f_xor(argvars, rettv) | 20061 f_xor(typval_T *argvars, typval_T *rettv) |
20885 typval_T *argvars; | |
20886 typval_T *rettv; | |
20887 { | 20062 { |
20888 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | 20063 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) |
20889 ^ get_tv_number_chk(&argvars[1], NULL); | 20064 ^ get_tv_number_chk(&argvars[1], NULL); |
20890 } | 20065 } |
20891 | 20066 |
20893 /* | 20068 /* |
20894 * Translate a String variable into a position. | 20069 * Translate a String variable into a position. |
20895 * Returns NULL when there is an error. | 20070 * Returns NULL when there is an error. |
20896 */ | 20071 */ |
20897 static pos_T * | 20072 static pos_T * |
20898 var2fpos(varp, dollar_lnum, fnum) | 20073 var2fpos( |
20899 typval_T *varp; | 20074 typval_T *varp, |
20900 int dollar_lnum; /* TRUE when $ is last line */ | 20075 int dollar_lnum, /* TRUE when $ is last line */ |
20901 int *fnum; /* set to fnum for '0, 'A, etc. */ | 20076 int *fnum) /* set to fnum for '0, 'A, etc. */ |
20902 { | 20077 { |
20903 char_u *name; | 20078 char_u *name; |
20904 static pos_T pos; | 20079 static pos_T pos; |
20905 pos_T *pp; | 20080 pos_T *pp; |
20906 | 20081 |
21012 * it to use 1 for the first column. | 20187 * it to use 1 for the first column. |
21013 * Return FAIL when conversion is not possible, doesn't check the position for | 20188 * Return FAIL when conversion is not possible, doesn't check the position for |
21014 * validity. | 20189 * validity. |
21015 */ | 20190 */ |
21016 static int | 20191 static int |
21017 list2fpos(arg, posp, fnump, curswantp) | 20192 list2fpos( |
21018 typval_T *arg; | 20193 typval_T *arg, |
21019 pos_T *posp; | 20194 pos_T *posp, |
21020 int *fnump; | 20195 int *fnump, |
21021 colnr_T *curswantp; | 20196 colnr_T *curswantp) |
21022 { | 20197 { |
21023 list_T *l = arg->vval.v_list; | 20198 list_T *l = arg->vval.v_list; |
21024 long i = 0; | 20199 long i = 0; |
21025 long n; | 20200 long n; |
21026 | 20201 |
21070 * Get the length of an environment variable name. | 20245 * Get the length of an environment variable name. |
21071 * Advance "arg" to the first character after the name. | 20246 * Advance "arg" to the first character after the name. |
21072 * Return 0 for error. | 20247 * Return 0 for error. |
21073 */ | 20248 */ |
21074 static int | 20249 static int |
21075 get_env_len(arg) | 20250 get_env_len(char_u **arg) |
21076 char_u **arg; | |
21077 { | 20251 { |
21078 char_u *p; | 20252 char_u *p; |
21079 int len; | 20253 int len; |
21080 | 20254 |
21081 for (p = *arg; vim_isIDc(*p); ++p) | 20255 for (p = *arg; vim_isIDc(*p); ++p) |
21092 * Get the length of the name of a function or internal variable. | 20266 * Get the length of the name of a function or internal variable. |
21093 * "arg" is advanced to the first non-white character after the name. | 20267 * "arg" is advanced to the first non-white character after the name. |
21094 * Return 0 if something is wrong. | 20268 * Return 0 if something is wrong. |
21095 */ | 20269 */ |
21096 static int | 20270 static int |
21097 get_id_len(arg) | 20271 get_id_len(char_u **arg) |
21098 char_u **arg; | |
21099 { | 20272 { |
21100 char_u *p; | 20273 char_u *p; |
21101 int len; | 20274 int len; |
21102 | 20275 |
21103 /* Find the end of the name. */ | 20276 /* Find the end of the name. */ |
21130 * Return 0 if something else is wrong. | 20303 * Return 0 if something else is wrong. |
21131 * If the name contains 'magic' {}'s, expand them and return the | 20304 * If the name contains 'magic' {}'s, expand them and return the |
21132 * expanded name in an allocated string via 'alias' - caller must free. | 20305 * expanded name in an allocated string via 'alias' - caller must free. |
21133 */ | 20306 */ |
21134 static int | 20307 static int |
21135 get_name_len(arg, alias, evaluate, verbose) | 20308 get_name_len( |
21136 char_u **arg; | 20309 char_u **arg, |
21137 char_u **alias; | 20310 char_u **alias, |
21138 int evaluate; | 20311 int evaluate, |
21139 int verbose; | 20312 int verbose) |
21140 { | 20313 { |
21141 int len; | 20314 int len; |
21142 char_u *p; | 20315 char_u *p; |
21143 char_u *expr_start; | 20316 char_u *expr_start; |
21144 char_u *expr_end; | 20317 char_u *expr_end; |
21201 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. | 20374 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
21202 * Return a pointer to just after the name. Equal to "arg" if there is no | 20375 * Return a pointer to just after the name. Equal to "arg" if there is no |
21203 * valid name. | 20376 * valid name. |
21204 */ | 20377 */ |
21205 static char_u * | 20378 static char_u * |
21206 find_name_end(arg, expr_start, expr_end, flags) | 20379 find_name_end( |
21207 char_u *arg; | 20380 char_u *arg, |
21208 char_u **expr_start; | 20381 char_u **expr_start, |
21209 char_u **expr_end; | 20382 char_u **expr_end, |
21210 int flags; | 20383 int flags) |
21211 { | 20384 { |
21212 int mb_nest = 0; | 20385 int mb_nest = 0; |
21213 int br_nest = 0; | 20386 int br_nest = 0; |
21214 char_u *p; | 20387 char_u *p; |
21215 int len; | 20388 int len; |
21298 * | 20471 * |
21299 * Returns a new allocated string, which the caller must free. | 20472 * Returns a new allocated string, which the caller must free. |
21300 * Returns NULL for failure. | 20473 * Returns NULL for failure. |
21301 */ | 20474 */ |
21302 static char_u * | 20475 static char_u * |
21303 make_expanded_name(in_start, expr_start, expr_end, in_end) | 20476 make_expanded_name( |
21304 char_u *in_start; | 20477 char_u *in_start, |
21305 char_u *expr_start; | 20478 char_u *expr_start, |
21306 char_u *expr_end; | 20479 char_u *expr_end, |
21307 char_u *in_end; | 20480 char_u *in_end) |
21308 { | 20481 { |
21309 char_u c1; | 20482 char_u c1; |
21310 char_u *retval = NULL; | 20483 char_u *retval = NULL; |
21311 char_u *temp_result; | 20484 char_u *temp_result; |
21312 char_u *nextcmd = NULL; | 20485 char_u *nextcmd = NULL; |
21355 /* | 20528 /* |
21356 * Return TRUE if character "c" can be used in a variable or function name. | 20529 * Return TRUE if character "c" can be used in a variable or function name. |
21357 * Does not include '{' or '}' for magic braces. | 20530 * Does not include '{' or '}' for magic braces. |
21358 */ | 20531 */ |
21359 static int | 20532 static int |
21360 eval_isnamec(c) | 20533 eval_isnamec(int c) |
21361 int c; | |
21362 { | 20534 { |
21363 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); | 20535 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); |
21364 } | 20536 } |
21365 | 20537 |
21366 /* | 20538 /* |
21367 * Return TRUE if character "c" can be used as the first character in a | 20539 * Return TRUE if character "c" can be used as the first character in a |
21368 * variable or function name (excluding '{' and '}'). | 20540 * variable or function name (excluding '{' and '}'). |
21369 */ | 20541 */ |
21370 static int | 20542 static int |
21371 eval_isnamec1(c) | 20543 eval_isnamec1(int c) |
21372 int c; | |
21373 { | 20544 { |
21374 return (ASCII_ISALPHA(c) || c == '_'); | 20545 return (ASCII_ISALPHA(c) || c == '_'); |
21375 } | 20546 } |
21376 | 20547 |
21377 /* | 20548 /* |
21378 * Set number v: variable to "val". | 20549 * Set number v: variable to "val". |
21379 */ | 20550 */ |
21380 void | 20551 void |
21381 set_vim_var_nr(idx, val) | 20552 set_vim_var_nr(int idx, long val) |
21382 int idx; | |
21383 long val; | |
21384 { | 20553 { |
21385 vimvars[idx].vv_nr = val; | 20554 vimvars[idx].vv_nr = val; |
21386 } | 20555 } |
21387 | 20556 |
21388 /* | 20557 /* |
21389 * Get number v: variable value. | 20558 * Get number v: variable value. |
21390 */ | 20559 */ |
21391 long | 20560 long |
21392 get_vim_var_nr(idx) | 20561 get_vim_var_nr(int idx) |
21393 int idx; | |
21394 { | 20562 { |
21395 return vimvars[idx].vv_nr; | 20563 return vimvars[idx].vv_nr; |
21396 } | 20564 } |
21397 | 20565 |
21398 /* | 20566 /* |
21399 * Get string v: variable value. Uses a static buffer, can only be used once. | 20567 * Get string v: variable value. Uses a static buffer, can only be used once. |
21400 */ | 20568 */ |
21401 char_u * | 20569 char_u * |
21402 get_vim_var_str(idx) | 20570 get_vim_var_str(int idx) |
21403 int idx; | |
21404 { | 20571 { |
21405 return get_tv_string(&vimvars[idx].vv_tv); | 20572 return get_tv_string(&vimvars[idx].vv_tv); |
21406 } | 20573 } |
21407 | 20574 |
21408 /* | 20575 /* |
21409 * Get List v: variable value. Caller must take care of reference count when | 20576 * Get List v: variable value. Caller must take care of reference count when |
21410 * needed. | 20577 * needed. |
21411 */ | 20578 */ |
21412 list_T * | 20579 list_T * |
21413 get_vim_var_list(idx) | 20580 get_vim_var_list(int idx) |
21414 int idx; | |
21415 { | 20581 { |
21416 return vimvars[idx].vv_list; | 20582 return vimvars[idx].vv_list; |
21417 } | 20583 } |
21418 | 20584 |
21419 /* | 20585 /* |
21420 * Set v:char to character "c". | 20586 * Set v:char to character "c". |
21421 */ | 20587 */ |
21422 void | 20588 void |
21423 set_vim_var_char(c) | 20589 set_vim_var_char(int c) |
21424 int c; | |
21425 { | 20590 { |
21426 char_u buf[MB_MAXBYTES + 1]; | 20591 char_u buf[MB_MAXBYTES + 1]; |
21427 | 20592 |
21428 #ifdef FEAT_MBYTE | 20593 #ifdef FEAT_MBYTE |
21429 if (has_mbyte) | 20594 if (has_mbyte) |
21440 /* | 20605 /* |
21441 * Set v:count to "count" and v:count1 to "count1". | 20606 * Set v:count to "count" and v:count1 to "count1". |
21442 * When "set_prevcount" is TRUE first set v:prevcount from v:count. | 20607 * When "set_prevcount" is TRUE first set v:prevcount from v:count. |
21443 */ | 20608 */ |
21444 void | 20609 void |
21445 set_vcount(count, count1, set_prevcount) | 20610 set_vcount( |
21446 long count; | 20611 long count, |
21447 long count1; | 20612 long count1, |
21448 int set_prevcount; | 20613 int set_prevcount) |
21449 { | 20614 { |
21450 if (set_prevcount) | 20615 if (set_prevcount) |
21451 vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr; | 20616 vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr; |
21452 vimvars[VV_COUNT].vv_nr = count; | 20617 vimvars[VV_COUNT].vv_nr = count; |
21453 vimvars[VV_COUNT1].vv_nr = count1; | 20618 vimvars[VV_COUNT1].vv_nr = count1; |
21455 | 20620 |
21456 /* | 20621 /* |
21457 * Set string v: variable to a copy of "val". | 20622 * Set string v: variable to a copy of "val". |
21458 */ | 20623 */ |
21459 void | 20624 void |
21460 set_vim_var_string(idx, val, len) | 20625 set_vim_var_string( |
21461 int idx; | 20626 int idx, |
21462 char_u *val; | 20627 char_u *val, |
21463 int len; /* length of "val" to use or -1 (whole string) */ | 20628 int len) /* length of "val" to use or -1 (whole string) */ |
21464 { | 20629 { |
21465 /* Need to do this (at least) once, since we can't initialize a union. | 20630 /* Need to do this (at least) once, since we can't initialize a union. |
21466 * Will always be invoked when "v:progname" is set. */ | 20631 * Will always be invoked when "v:progname" is set. */ |
21467 vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; | 20632 vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; |
21468 | 20633 |
21477 | 20642 |
21478 /* | 20643 /* |
21479 * Set List v: variable to "val". | 20644 * Set List v: variable to "val". |
21480 */ | 20645 */ |
21481 void | 20646 void |
21482 set_vim_var_list(idx, val) | 20647 set_vim_var_list(int idx, list_T *val) |
21483 int idx; | |
21484 list_T *val; | |
21485 { | 20648 { |
21486 list_unref(vimvars[idx].vv_list); | 20649 list_unref(vimvars[idx].vv_list); |
21487 vimvars[idx].vv_list = val; | 20650 vimvars[idx].vv_list = val; |
21488 if (val != NULL) | 20651 if (val != NULL) |
21489 ++val->lv_refcount; | 20652 ++val->lv_refcount; |
21491 | 20654 |
21492 /* | 20655 /* |
21493 * Set Dictionary v: variable to "val". | 20656 * Set Dictionary v: variable to "val". |
21494 */ | 20657 */ |
21495 void | 20658 void |
21496 set_vim_var_dict(idx, val) | 20659 set_vim_var_dict(int idx, dict_T *val) |
21497 int idx; | |
21498 dict_T *val; | |
21499 { | 20660 { |
21500 int todo; | 20661 int todo; |
21501 hashitem_T *hi; | 20662 hashitem_T *hi; |
21502 | 20663 |
21503 dict_unref(vimvars[idx].vv_dict); | 20664 dict_unref(vimvars[idx].vv_dict); |
21520 | 20681 |
21521 /* | 20682 /* |
21522 * Set v:register if needed. | 20683 * Set v:register if needed. |
21523 */ | 20684 */ |
21524 void | 20685 void |
21525 set_reg_var(c) | 20686 set_reg_var(int c) |
21526 int c; | |
21527 { | 20687 { |
21528 char_u regname; | 20688 char_u regname; |
21529 | 20689 |
21530 if (c == 0 || c == ' ') | 20690 if (c == 0 || c == ' ') |
21531 regname = '"'; | 20691 regname = '"'; |
21541 * Otherwise, restore the value to "oldval" and return NULL. | 20701 * Otherwise, restore the value to "oldval" and return NULL. |
21542 * Must always be called in pairs to save and restore v:exception! Does not | 20702 * Must always be called in pairs to save and restore v:exception! Does not |
21543 * take care of memory allocations. | 20703 * take care of memory allocations. |
21544 */ | 20704 */ |
21545 char_u * | 20705 char_u * |
21546 v_exception(oldval) | 20706 v_exception(char_u *oldval) |
21547 char_u *oldval; | |
21548 { | 20707 { |
21549 if (oldval == NULL) | 20708 if (oldval == NULL) |
21550 return vimvars[VV_EXCEPTION].vv_str; | 20709 return vimvars[VV_EXCEPTION].vv_str; |
21551 | 20710 |
21552 vimvars[VV_EXCEPTION].vv_str = oldval; | 20711 vimvars[VV_EXCEPTION].vv_str = oldval; |
21558 * Otherwise, restore the value to "oldval" and return NULL. | 20717 * Otherwise, restore the value to "oldval" and return NULL. |
21559 * Must always be called in pairs to save and restore v:throwpoint! Does not | 20718 * Must always be called in pairs to save and restore v:throwpoint! Does not |
21560 * take care of memory allocations. | 20719 * take care of memory allocations. |
21561 */ | 20720 */ |
21562 char_u * | 20721 char_u * |
21563 v_throwpoint(oldval) | 20722 v_throwpoint(char_u *oldval) |
21564 char_u *oldval; | |
21565 { | 20723 { |
21566 if (oldval == NULL) | 20724 if (oldval == NULL) |
21567 return vimvars[VV_THROWPOINT].vv_str; | 20725 return vimvars[VV_THROWPOINT].vv_str; |
21568 | 20726 |
21569 vimvars[VV_THROWPOINT].vv_str = oldval; | 20727 vimvars[VV_THROWPOINT].vv_str = oldval; |
21576 * If "eap" != NULL, use "eap" to generate the value and return the old value. | 20734 * If "eap" != NULL, use "eap" to generate the value and return the old value. |
21577 * If "oldarg" != NULL, restore the value to "oldarg" and return NULL. | 20735 * If "oldarg" != NULL, restore the value to "oldarg" and return NULL. |
21578 * Must always be called in pairs! | 20736 * Must always be called in pairs! |
21579 */ | 20737 */ |
21580 char_u * | 20738 char_u * |
21581 set_cmdarg(eap, oldarg) | 20739 set_cmdarg(exarg_T *eap, char_u *oldarg) |
21582 exarg_T *eap; | |
21583 char_u *oldarg; | |
21584 { | 20740 { |
21585 char_u *oldval; | 20741 char_u *oldval; |
21586 char_u *newval; | 20742 char_u *newval; |
21587 unsigned len; | 20743 unsigned len; |
21588 | 20744 |
21649 /* | 20805 /* |
21650 * Get the value of internal variable "name". | 20806 * Get the value of internal variable "name". |
21651 * Return OK or FAIL. | 20807 * Return OK or FAIL. |
21652 */ | 20808 */ |
21653 static int | 20809 static int |
21654 get_var_tv(name, len, rettv, dip, verbose, no_autoload) | 20810 get_var_tv( |
21655 char_u *name; | 20811 char_u *name, |
21656 int len; /* length of "name" */ | 20812 int len, /* length of "name" */ |
21657 typval_T *rettv; /* NULL when only checking existence */ | 20813 typval_T *rettv, /* NULL when only checking existence */ |
21658 dictitem_T **dip; /* non-NULL when typval's dict item is needed */ | 20814 dictitem_T **dip, /* non-NULL when typval's dict item is needed */ |
21659 int verbose; /* may give error message */ | 20815 int verbose, /* may give error message */ |
21660 int no_autoload; /* do not use script autoloading */ | 20816 int no_autoload) /* do not use script autoloading */ |
21661 { | 20817 { |
21662 int ret = OK; | 20818 int ret = OK; |
21663 typval_T *tv = NULL; | 20819 typval_T *tv = NULL; |
21664 typval_T atv; | 20820 typval_T atv; |
21665 dictitem_T *v; | 20821 dictitem_T *v; |
21711 * Handle expr[expr], expr[expr:expr] subscript and .name lookup. | 20867 * Handle expr[expr], expr[expr:expr] subscript and .name lookup. |
21712 * Also handle function call with Funcref variable: func(expr) | 20868 * Also handle function call with Funcref variable: func(expr) |
21713 * Can all be combined: dict.func(expr)[idx]['func'](expr) | 20869 * Can all be combined: dict.func(expr)[idx]['func'](expr) |
21714 */ | 20870 */ |
21715 static int | 20871 static int |
21716 handle_subscript(arg, rettv, evaluate, verbose) | 20872 handle_subscript( |
21717 char_u **arg; | 20873 char_u **arg, |
21718 typval_T *rettv; | 20874 typval_T *rettv, |
21719 int evaluate; /* do more than finding the end */ | 20875 int evaluate, /* do more than finding the end */ |
21720 int verbose; /* give error messages */ | 20876 int verbose) /* give error messages */ |
21721 { | 20877 { |
21722 int ret = OK; | 20878 int ret = OK; |
21723 dict_T *selfdict = NULL; | 20879 dict_T *selfdict = NULL; |
21724 char_u *s; | 20880 char_u *s; |
21725 int len; | 20881 int len; |
21790 /* | 20946 /* |
21791 * Allocate memory for a variable type-value, and make it empty (0 or NULL | 20947 * Allocate memory for a variable type-value, and make it empty (0 or NULL |
21792 * value). | 20948 * value). |
21793 */ | 20949 */ |
21794 static typval_T * | 20950 static typval_T * |
21795 alloc_tv() | 20951 alloc_tv(void) |
21796 { | 20952 { |
21797 return (typval_T *)alloc_clear((unsigned)sizeof(typval_T)); | 20953 return (typval_T *)alloc_clear((unsigned)sizeof(typval_T)); |
21798 } | 20954 } |
21799 | 20955 |
21800 /* | 20956 /* |
21801 * Allocate memory for a variable type-value, and assign a string to it. | 20957 * Allocate memory for a variable type-value, and assign a string to it. |
21802 * The string "s" must have been allocated, it is consumed. | 20958 * The string "s" must have been allocated, it is consumed. |
21803 * Return NULL for out of memory, the variable otherwise. | 20959 * Return NULL for out of memory, the variable otherwise. |
21804 */ | 20960 */ |
21805 static typval_T * | 20961 static typval_T * |
21806 alloc_string_tv(s) | 20962 alloc_string_tv(char_u *s) |
21807 char_u *s; | |
21808 { | 20963 { |
21809 typval_T *rettv; | 20964 typval_T *rettv; |
21810 | 20965 |
21811 rettv = alloc_tv(); | 20966 rettv = alloc_tv(); |
21812 if (rettv != NULL) | 20967 if (rettv != NULL) |
21821 | 20976 |
21822 /* | 20977 /* |
21823 * Free the memory for a variable type-value. | 20978 * Free the memory for a variable type-value. |
21824 */ | 20979 */ |
21825 void | 20980 void |
21826 free_tv(varp) | 20981 free_tv(typval_T *varp) |
21827 typval_T *varp; | |
21828 { | 20982 { |
21829 if (varp != NULL) | 20983 if (varp != NULL) |
21830 { | 20984 { |
21831 switch (varp->v_type) | 20985 switch (varp->v_type) |
21832 { | 20986 { |
21859 | 21013 |
21860 /* | 21014 /* |
21861 * Free the memory for a variable value and set the value to NULL or 0. | 21015 * Free the memory for a variable value and set the value to NULL or 0. |
21862 */ | 21016 */ |
21863 void | 21017 void |
21864 clear_tv(varp) | 21018 clear_tv(typval_T *varp) |
21865 typval_T *varp; | |
21866 { | 21019 { |
21867 if (varp != NULL) | 21020 if (varp != NULL) |
21868 { | 21021 { |
21869 switch (varp->v_type) | 21022 switch (varp->v_type) |
21870 { | 21023 { |
21903 | 21056 |
21904 /* | 21057 /* |
21905 * Set the value of a variable to NULL without freeing items. | 21058 * Set the value of a variable to NULL without freeing items. |
21906 */ | 21059 */ |
21907 static void | 21060 static void |
21908 init_tv(varp) | 21061 init_tv(typval_T *varp) |
21909 typval_T *varp; | |
21910 { | 21062 { |
21911 if (varp != NULL) | 21063 if (varp != NULL) |
21912 vim_memset(varp, 0, sizeof(typval_T)); | 21064 vim_memset(varp, 0, sizeof(typval_T)); |
21913 } | 21065 } |
21914 | 21066 |
21919 * get_tv_number_chk() is similar to get_tv_number(), but informs the | 21071 * get_tv_number_chk() is similar to get_tv_number(), but informs the |
21920 * caller of incompatible types: it sets *denote to TRUE if "denote" | 21072 * caller of incompatible types: it sets *denote to TRUE if "denote" |
21921 * is not NULL or returns -1 otherwise. | 21073 * is not NULL or returns -1 otherwise. |
21922 */ | 21074 */ |
21923 static long | 21075 static long |
21924 get_tv_number(varp) | 21076 get_tv_number(typval_T *varp) |
21925 typval_T *varp; | |
21926 { | 21077 { |
21927 int error = FALSE; | 21078 int error = FALSE; |
21928 | 21079 |
21929 return get_tv_number_chk(varp, &error); /* return 0L on error */ | 21080 return get_tv_number_chk(varp, &error); /* return 0L on error */ |
21930 } | 21081 } |
21931 | 21082 |
21932 long | 21083 long |
21933 get_tv_number_chk(varp, denote) | 21084 get_tv_number_chk(typval_T *varp, int *denote) |
21934 typval_T *varp; | |
21935 int *denote; | |
21936 { | 21085 { |
21937 long n = 0L; | 21086 long n = 0L; |
21938 | 21087 |
21939 switch (varp->v_type) | 21088 switch (varp->v_type) |
21940 { | 21089 { |
21973 return n; | 21122 return n; |
21974 } | 21123 } |
21975 | 21124 |
21976 #ifdef FEAT_FLOAT | 21125 #ifdef FEAT_FLOAT |
21977 static float_T | 21126 static float_T |
21978 get_tv_float(varp) | 21127 get_tv_float(typval_T *varp) |
21979 typval_T *varp; | |
21980 { | 21128 { |
21981 switch (varp->v_type) | 21129 switch (varp->v_type) |
21982 { | 21130 { |
21983 case VAR_NUMBER: | 21131 case VAR_NUMBER: |
21984 return (float_T)(varp->vval.v_number); | 21132 return (float_T)(varp->vval.v_number); |
22011 * Get the lnum from the first argument. | 21159 * Get the lnum from the first argument. |
22012 * Also accepts ".", "$", etc., but that only works for the current buffer. | 21160 * Also accepts ".", "$", etc., but that only works for the current buffer. |
22013 * Returns -1 on error. | 21161 * Returns -1 on error. |
22014 */ | 21162 */ |
22015 static linenr_T | 21163 static linenr_T |
22016 get_tv_lnum(argvars) | 21164 get_tv_lnum(typval_T *argvars) |
22017 typval_T *argvars; | |
22018 { | 21165 { |
22019 typval_T rettv; | 21166 typval_T rettv; |
22020 linenr_T lnum; | 21167 linenr_T lnum; |
22021 | 21168 |
22022 lnum = get_tv_number_chk(&argvars[0], NULL); | 21169 lnum = get_tv_number_chk(&argvars[0], NULL); |
22034 * Get the lnum from the first argument. | 21181 * Get the lnum from the first argument. |
22035 * Also accepts "$", then "buf" is used. | 21182 * Also accepts "$", then "buf" is used. |
22036 * Returns 0 on error. | 21183 * Returns 0 on error. |
22037 */ | 21184 */ |
22038 static linenr_T | 21185 static linenr_T |
22039 get_tv_lnum_buf(argvars, buf) | 21186 get_tv_lnum_buf(typval_T *argvars, buf_T *buf) |
22040 typval_T *argvars; | |
22041 buf_T *buf; | |
22042 { | 21187 { |
22043 if (argvars[0].v_type == VAR_STRING | 21188 if (argvars[0].v_type == VAR_STRING |
22044 && argvars[0].vval.v_string != NULL | 21189 && argvars[0].vval.v_string != NULL |
22045 && argvars[0].vval.v_string[0] == '$' | 21190 && argvars[0].vval.v_string[0] == '$' |
22046 && buf != NULL) | 21191 && buf != NULL) |
22057 * Never returns NULL; | 21202 * Never returns NULL; |
22058 * get_tv_string_chk() and get_tv_string_buf_chk() are similar, but return | 21203 * get_tv_string_chk() and get_tv_string_buf_chk() are similar, but return |
22059 * NULL on error. | 21204 * NULL on error. |
22060 */ | 21205 */ |
22061 static char_u * | 21206 static char_u * |
22062 get_tv_string(varp) | 21207 get_tv_string(typval_T *varp) |
22063 typval_T *varp; | |
22064 { | 21208 { |
22065 static char_u mybuf[NUMBUFLEN]; | 21209 static char_u mybuf[NUMBUFLEN]; |
22066 | 21210 |
22067 return get_tv_string_buf(varp, mybuf); | 21211 return get_tv_string_buf(varp, mybuf); |
22068 } | 21212 } |
22069 | 21213 |
22070 static char_u * | 21214 static char_u * |
22071 get_tv_string_buf(varp, buf) | 21215 get_tv_string_buf(typval_T *varp, char_u *buf) |
22072 typval_T *varp; | |
22073 char_u *buf; | |
22074 { | 21216 { |
22075 char_u *res = get_tv_string_buf_chk(varp, buf); | 21217 char_u *res = get_tv_string_buf_chk(varp, buf); |
22076 | 21218 |
22077 return res != NULL ? res : (char_u *)""; | 21219 return res != NULL ? res : (char_u *)""; |
22078 } | 21220 } |
22079 | 21221 |
22080 /* | 21222 /* |
22081 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! | 21223 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |
22082 */ | 21224 */ |
22083 char_u * | 21225 char_u * |
22084 get_tv_string_chk(varp) | 21226 get_tv_string_chk(typval_T *varp) |
22085 typval_T *varp; | |
22086 { | 21227 { |
22087 static char_u mybuf[NUMBUFLEN]; | 21228 static char_u mybuf[NUMBUFLEN]; |
22088 | 21229 |
22089 return get_tv_string_buf_chk(varp, mybuf); | 21230 return get_tv_string_buf_chk(varp, mybuf); |
22090 } | 21231 } |
22091 | 21232 |
22092 char_u * | 21233 char_u * |
22093 get_tv_string_buf_chk(varp, buf) | 21234 get_tv_string_buf_chk(typval_T *varp, char_u *buf) |
22094 typval_T *varp; | |
22095 char_u *buf; | |
22096 { | 21235 { |
22097 switch (varp->v_type) | 21236 switch (varp->v_type) |
22098 { | 21237 { |
22099 case VAR_NUMBER: | 21238 case VAR_NUMBER: |
22100 sprintf((char *)buf, "%ld", (long)varp->vval.v_number); | 21239 sprintf((char *)buf, "%ld", (long)varp->vval.v_number); |
22134 * Careful: "a:0" variables don't have a name. | 21273 * Careful: "a:0" variables don't have a name. |
22135 * When "htp" is not NULL we are writing to the variable, set "htp" to the | 21274 * When "htp" is not NULL we are writing to the variable, set "htp" to the |
22136 * hashtab_T used. | 21275 * hashtab_T used. |
22137 */ | 21276 */ |
22138 static dictitem_T * | 21277 static dictitem_T * |
22139 find_var(name, htp, no_autoload) | 21278 find_var(char_u *name, hashtab_T **htp, int no_autoload) |
22140 char_u *name; | |
22141 hashtab_T **htp; | |
22142 int no_autoload; | |
22143 { | 21279 { |
22144 char_u *varname; | 21280 char_u *varname; |
22145 hashtab_T *ht; | 21281 hashtab_T *ht; |
22146 | 21282 |
22147 ht = find_var_ht(name, &varname); | 21283 ht = find_var_ht(name, &varname); |
22155 /* | 21291 /* |
22156 * Find variable "varname" in hashtab "ht" with name "htname". | 21292 * Find variable "varname" in hashtab "ht" with name "htname". |
22157 * Returns NULL if not found. | 21293 * Returns NULL if not found. |
22158 */ | 21294 */ |
22159 static dictitem_T * | 21295 static dictitem_T * |
22160 find_var_in_ht(ht, htname, varname, no_autoload) | 21296 find_var_in_ht( |
22161 hashtab_T *ht; | 21297 hashtab_T *ht, |
22162 int htname; | 21298 int htname, |
22163 char_u *varname; | 21299 char_u *varname, |
22164 int no_autoload; | 21300 int no_autoload) |
22165 { | 21301 { |
22166 hashitem_T *hi; | 21302 hashitem_T *hi; |
22167 | 21303 |
22168 if (*varname == NUL) | 21304 if (*varname == NUL) |
22169 { | 21305 { |
22211 * Find the hashtab used for a variable name. | 21347 * Find the hashtab used for a variable name. |
22212 * Return NULL if the name is not valid. | 21348 * Return NULL if the name is not valid. |
22213 * Set "varname" to the start of name without ':'. | 21349 * Set "varname" to the start of name without ':'. |
22214 */ | 21350 */ |
22215 static hashtab_T * | 21351 static hashtab_T * |
22216 find_var_ht(name, varname) | 21352 find_var_ht(char_u *name, char_u **varname) |
22217 char_u *name; | |
22218 char_u **varname; | |
22219 { | 21353 { |
22220 hashitem_T *hi; | 21354 hashitem_T *hi; |
22221 | 21355 |
22222 if (name[0] == NUL) | 21356 if (name[0] == NUL) |
22223 return NULL; | 21357 return NULL; |
22267 | 21401 |
22268 /* | 21402 /* |
22269 * Get function call environment based on bactrace debug level | 21403 * Get function call environment based on bactrace debug level |
22270 */ | 21404 */ |
22271 static funccall_T * | 21405 static funccall_T * |
22272 get_funccal() | 21406 get_funccal(void) |
22273 { | 21407 { |
22274 int i; | 21408 int i; |
22275 funccall_T *funccal; | 21409 funccall_T *funccal; |
22276 funccall_T *temp_funccal; | 21410 funccall_T *temp_funccal; |
22277 | 21411 |
22295 * Get the string value of a (global/local) variable. | 21429 * Get the string value of a (global/local) variable. |
22296 * Note: see get_tv_string() for how long the pointer remains valid. | 21430 * Note: see get_tv_string() for how long the pointer remains valid. |
22297 * Returns NULL when it doesn't exist. | 21431 * Returns NULL when it doesn't exist. |
22298 */ | 21432 */ |
22299 char_u * | 21433 char_u * |
22300 get_var_value(name) | 21434 get_var_value(char_u *name) |
22301 char_u *name; | |
22302 { | 21435 { |
22303 dictitem_T *v; | 21436 dictitem_T *v; |
22304 | 21437 |
22305 v = find_var(name, NULL, FALSE); | 21438 v = find_var(name, NULL, FALSE); |
22306 if (v == NULL) | 21439 if (v == NULL) |
22311 /* | 21444 /* |
22312 * Allocate a new hashtab for a sourced script. It will be used while | 21445 * Allocate a new hashtab for a sourced script. It will be used while |
22313 * sourcing this script and when executing functions defined in the script. | 21446 * sourcing this script and when executing functions defined in the script. |
22314 */ | 21447 */ |
22315 void | 21448 void |
22316 new_script_vars(id) | 21449 new_script_vars(scid_T id) |
22317 scid_T id; | |
22318 { | 21450 { |
22319 int i; | 21451 int i; |
22320 hashtab_T *ht; | 21452 hashtab_T *ht; |
22321 scriptvar_T *sv; | 21453 scriptvar_T *sv; |
22322 | 21454 |
22347 /* | 21479 /* |
22348 * Initialize dictionary "dict" as a scope and set variable "dict_var" to | 21480 * Initialize dictionary "dict" as a scope and set variable "dict_var" to |
22349 * point to it. | 21481 * point to it. |
22350 */ | 21482 */ |
22351 void | 21483 void |
22352 init_var_dict(dict, dict_var, scope) | 21484 init_var_dict(dict_T *dict, dictitem_T *dict_var, int scope) |
22353 dict_T *dict; | |
22354 dictitem_T *dict_var; | |
22355 int scope; | |
22356 { | 21485 { |
22357 hash_init(&dict->dv_hashtab); | 21486 hash_init(&dict->dv_hashtab); |
22358 dict->dv_lock = 0; | 21487 dict->dv_lock = 0; |
22359 dict->dv_scope = scope; | 21488 dict->dv_scope = scope; |
22360 dict->dv_refcount = DO_NOT_FREE_CNT; | 21489 dict->dv_refcount = DO_NOT_FREE_CNT; |
22368 | 21497 |
22369 /* | 21498 /* |
22370 * Unreference a dictionary initialized by init_var_dict(). | 21499 * Unreference a dictionary initialized by init_var_dict(). |
22371 */ | 21500 */ |
22372 void | 21501 void |
22373 unref_var_dict(dict) | 21502 unref_var_dict(dict_T *dict) |
22374 dict_T *dict; | |
22375 { | 21503 { |
22376 /* Now the dict needs to be freed if no one else is using it, go back to | 21504 /* Now the dict needs to be freed if no one else is using it, go back to |
22377 * normal reference counting. */ | 21505 * normal reference counting. */ |
22378 dict->dv_refcount -= DO_NOT_FREE_CNT - 1; | 21506 dict->dv_refcount -= DO_NOT_FREE_CNT - 1; |
22379 dict_unref(dict); | 21507 dict_unref(dict); |
22383 * Clean up a list of internal variables. | 21511 * Clean up a list of internal variables. |
22384 * Frees all allocated variables and the value they contain. | 21512 * Frees all allocated variables and the value they contain. |
22385 * Clears hashtab "ht", does not free it. | 21513 * Clears hashtab "ht", does not free it. |
22386 */ | 21514 */ |
22387 void | 21515 void |
22388 vars_clear(ht) | 21516 vars_clear(hashtab_T *ht) |
22389 hashtab_T *ht; | |
22390 { | 21517 { |
22391 vars_clear_ext(ht, TRUE); | 21518 vars_clear_ext(ht, TRUE); |
22392 } | 21519 } |
22393 | 21520 |
22394 /* | 21521 /* |
22395 * Like vars_clear(), but only free the value if "free_val" is TRUE. | 21522 * Like vars_clear(), but only free the value if "free_val" is TRUE. |
22396 */ | 21523 */ |
22397 static void | 21524 static void |
22398 vars_clear_ext(ht, free_val) | 21525 vars_clear_ext(hashtab_T *ht, int free_val) |
22399 hashtab_T *ht; | |
22400 int free_val; | |
22401 { | 21526 { |
22402 int todo; | 21527 int todo; |
22403 hashitem_T *hi; | 21528 hashitem_T *hi; |
22404 dictitem_T *v; | 21529 dictitem_T *v; |
22405 | 21530 |
22428 /* | 21553 /* |
22429 * Delete a variable from hashtab "ht" at item "hi". | 21554 * Delete a variable from hashtab "ht" at item "hi". |
22430 * Clear the variable value and free the dictitem. | 21555 * Clear the variable value and free the dictitem. |
22431 */ | 21556 */ |
22432 static void | 21557 static void |
22433 delete_var(ht, hi) | 21558 delete_var(hashtab_T *ht, hashitem_T *hi) |
22434 hashtab_T *ht; | |
22435 hashitem_T *hi; | |
22436 { | 21559 { |
22437 dictitem_T *di = HI2DI(hi); | 21560 dictitem_T *di = HI2DI(hi); |
22438 | 21561 |
22439 hash_remove(ht, hi); | 21562 hash_remove(ht, hi); |
22440 clear_tv(&di->di_tv); | 21563 clear_tv(&di->di_tv); |
22443 | 21566 |
22444 /* | 21567 /* |
22445 * List the value of one internal variable. | 21568 * List the value of one internal variable. |
22446 */ | 21569 */ |
22447 static void | 21570 static void |
22448 list_one_var(v, prefix, first) | 21571 list_one_var(dictitem_T *v, char_u *prefix, int *first) |
22449 dictitem_T *v; | |
22450 char_u *prefix; | |
22451 int *first; | |
22452 { | 21572 { |
22453 char_u *tofree; | 21573 char_u *tofree; |
22454 char_u *s; | 21574 char_u *s; |
22455 char_u numbuf[NUMBUFLEN]; | 21575 char_u numbuf[NUMBUFLEN]; |
22456 | 21576 |
22459 s == NULL ? (char_u *)"" : s, first); | 21579 s == NULL ? (char_u *)"" : s, first); |
22460 vim_free(tofree); | 21580 vim_free(tofree); |
22461 } | 21581 } |
22462 | 21582 |
22463 static void | 21583 static void |
22464 list_one_var_a(prefix, name, type, string, first) | 21584 list_one_var_a( |
22465 char_u *prefix; | 21585 char_u *prefix, |
22466 char_u *name; | 21586 char_u *name, |
22467 int type; | 21587 int type, |
22468 char_u *string; | 21588 char_u *string, |
22469 int *first; /* when TRUE clear rest of screen and set to FALSE */ | 21589 int *first) /* when TRUE clear rest of screen and set to FALSE */ |
22470 { | 21590 { |
22471 /* don't use msg() or msg_attr() to avoid overwriting "v:statusmsg" */ | 21591 /* don't use msg() or msg_attr() to avoid overwriting "v:statusmsg" */ |
22472 msg_start(); | 21592 msg_start(); |
22473 msg_puts(prefix); | 21593 msg_puts(prefix); |
22474 if (name != NULL) /* "a:" vars don't have a name stored */ | 21594 if (name != NULL) /* "a:" vars don't have a name stored */ |
22509 * Set variable "name" to value in "tv". | 21629 * Set variable "name" to value in "tv". |
22510 * If the variable already exists, the value is updated. | 21630 * If the variable already exists, the value is updated. |
22511 * Otherwise the variable is created. | 21631 * Otherwise the variable is created. |
22512 */ | 21632 */ |
22513 static void | 21633 static void |
22514 set_var(name, tv, copy) | 21634 set_var( |
22515 char_u *name; | 21635 char_u *name, |
22516 typval_T *tv; | 21636 typval_T *tv, |
22517 int copy; /* make copy of value in "tv" */ | 21637 int copy) /* make copy of value in "tv" */ |
22518 { | 21638 { |
22519 dictitem_T *v; | 21639 dictitem_T *v; |
22520 char_u *varname; | 21640 char_u *varname; |
22521 hashtab_T *ht; | 21641 hashtab_T *ht; |
22522 | 21642 |
22632 /* | 21752 /* |
22633 * Return TRUE if di_flags "flags" indicates variable "name" is read-only. | 21753 * Return TRUE if di_flags "flags" indicates variable "name" is read-only. |
22634 * Also give an error message. | 21754 * Also give an error message. |
22635 */ | 21755 */ |
22636 static int | 21756 static int |
22637 var_check_ro(flags, name, use_gettext) | 21757 var_check_ro(int flags, char_u *name, int use_gettext) |
22638 int flags; | |
22639 char_u *name; | |
22640 int use_gettext; | |
22641 { | 21758 { |
22642 if (flags & DI_FLAGS_RO) | 21759 if (flags & DI_FLAGS_RO) |
22643 { | 21760 { |
22644 EMSG2(_(e_readonlyvar), use_gettext ? (char_u *)_(name) : name); | 21761 EMSG2(_(e_readonlyvar), use_gettext ? (char_u *)_(name) : name); |
22645 return TRUE; | 21762 return TRUE; |
22655 /* | 21772 /* |
22656 * Return TRUE if di_flags "flags" indicates variable "name" is fixed. | 21773 * Return TRUE if di_flags "flags" indicates variable "name" is fixed. |
22657 * Also give an error message. | 21774 * Also give an error message. |
22658 */ | 21775 */ |
22659 static int | 21776 static int |
22660 var_check_fixed(flags, name, use_gettext) | 21777 var_check_fixed(int flags, char_u *name, int use_gettext) |
22661 int flags; | |
22662 char_u *name; | |
22663 int use_gettext; | |
22664 { | 21778 { |
22665 if (flags & DI_FLAGS_FIX) | 21779 if (flags & DI_FLAGS_FIX) |
22666 { | 21780 { |
22667 EMSG2(_("E795: Cannot delete variable %s"), | 21781 EMSG2(_("E795: Cannot delete variable %s"), |
22668 use_gettext ? (char_u *)_(name) : name); | 21782 use_gettext ? (char_u *)_(name) : name); |
22674 /* | 21788 /* |
22675 * Check if a funcref is assigned to a valid variable name. | 21789 * Check if a funcref is assigned to a valid variable name. |
22676 * Return TRUE and give an error if not. | 21790 * Return TRUE and give an error if not. |
22677 */ | 21791 */ |
22678 static int | 21792 static int |
22679 var_check_func_name(name, new_var) | 21793 var_check_func_name( |
22680 char_u *name; /* points to start of variable name */ | 21794 char_u *name, /* points to start of variable name */ |
22681 int new_var; /* TRUE when creating the variable */ | 21795 int new_var) /* TRUE when creating the variable */ |
22682 { | 21796 { |
22683 /* Allow for w: b: s: and t:. */ | 21797 /* Allow for w: b: s: and t:. */ |
22684 if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') | 21798 if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') |
22685 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') | 21799 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') |
22686 ? name[2] : name[0])) | 21800 ? name[2] : name[0])) |
22704 /* | 21818 /* |
22705 * Check if a variable name is valid. | 21819 * Check if a variable name is valid. |
22706 * Return FALSE and give an error if not. | 21820 * Return FALSE and give an error if not. |
22707 */ | 21821 */ |
22708 static int | 21822 static int |
22709 valid_varname(varname) | 21823 valid_varname(char_u *varname) |
22710 char_u *varname; | |
22711 { | 21824 { |
22712 char_u *p; | 21825 char_u *p; |
22713 | 21826 |
22714 for (p = varname; *p != NUL; ++p) | 21827 for (p = varname; *p != NUL; ++p) |
22715 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) | 21828 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) |
22725 * Return TRUE if typeval "tv" is set to be locked (immutable). | 21838 * Return TRUE if typeval "tv" is set to be locked (immutable). |
22726 * Also give an error message, using "name" or _("name") when use_gettext is | 21839 * Also give an error message, using "name" or _("name") when use_gettext is |
22727 * TRUE. | 21840 * TRUE. |
22728 */ | 21841 */ |
22729 static int | 21842 static int |
22730 tv_check_lock(lock, name, use_gettext) | 21843 tv_check_lock(int lock, char_u *name, int use_gettext) |
22731 int lock; | |
22732 char_u *name; | |
22733 int use_gettext; | |
22734 { | 21844 { |
22735 if (lock & VAR_LOCKED) | 21845 if (lock & VAR_LOCKED) |
22736 { | 21846 { |
22737 EMSG2(_("E741: Value is locked: %s"), | 21847 EMSG2(_("E741: Value is locked: %s"), |
22738 name == NULL ? (char_u *)_("Unknown") | 21848 name == NULL ? (char_u *)_("Unknown") |
22757 * Does not make a copy of a list or dict but copies the reference! | 21867 * Does not make a copy of a list or dict but copies the reference! |
22758 * It is OK for "from" and "to" to point to the same item. This is used to | 21868 * It is OK for "from" and "to" to point to the same item. This is used to |
22759 * make a copy later. | 21869 * make a copy later. |
22760 */ | 21870 */ |
22761 void | 21871 void |
22762 copy_tv(from, to) | 21872 copy_tv(typval_T *from, typval_T *to) |
22763 typval_T *from; | |
22764 typval_T *to; | |
22765 { | 21873 { |
22766 to->v_type = from->v_type; | 21874 to->v_type = from->v_type; |
22767 to->v_lock = 0; | 21875 to->v_lock = 0; |
22768 switch (from->v_type) | 21876 switch (from->v_type) |
22769 { | 21877 { |
22817 * For deepcopy() "copyID" is zero for a full copy or the ID for when a | 21925 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
22818 * reference to an already copied list/dict can be used. | 21926 * reference to an already copied list/dict can be used. |
22819 * Returns FAIL or OK. | 21927 * Returns FAIL or OK. |
22820 */ | 21928 */ |
22821 static int | 21929 static int |
22822 item_copy(from, to, deep, copyID) | 21930 item_copy( |
22823 typval_T *from; | 21931 typval_T *from, |
22824 typval_T *to; | 21932 typval_T *to, |
22825 int deep; | 21933 int deep, |
22826 int copyID; | 21934 int copyID) |
22827 { | 21935 { |
22828 static int recurse = 0; | 21936 static int recurse = 0; |
22829 int ret = OK; | 21937 int ret = OK; |
22830 | 21938 |
22831 if (recurse >= DICT_MAXNEST) | 21939 if (recurse >= DICT_MAXNEST) |
22889 * ":echo expr1 ..." print each argument separated with a space, add a | 21997 * ":echo expr1 ..." print each argument separated with a space, add a |
22890 * newline at the end. | 21998 * newline at the end. |
22891 * ":echon expr1 ..." print each argument plain. | 21999 * ":echon expr1 ..." print each argument plain. |
22892 */ | 22000 */ |
22893 void | 22001 void |
22894 ex_echo(eap) | 22002 ex_echo(exarg_T *eap) |
22895 exarg_T *eap; | |
22896 { | 22003 { |
22897 char_u *arg = eap->arg; | 22004 char_u *arg = eap->arg; |
22898 typval_T rettv; | 22005 typval_T rettv; |
22899 char_u *tofree; | 22006 char_u *tofree; |
22900 char_u *p; | 22007 char_u *p; |
22993 | 22100 |
22994 /* | 22101 /* |
22995 * ":echohl {name}". | 22102 * ":echohl {name}". |
22996 */ | 22103 */ |
22997 void | 22104 void |
22998 ex_echohl(eap) | 22105 ex_echohl(exarg_T *eap) |
22999 exarg_T *eap; | |
23000 { | 22106 { |
23001 int id; | 22107 int id; |
23002 | 22108 |
23003 id = syn_name2id(eap->arg); | 22109 id = syn_name2id(eap->arg); |
23004 if (id == 0) | 22110 if (id == 0) |
23013 * ":echoerr expr1 ..." Print an error | 22119 * ":echoerr expr1 ..." Print an error |
23014 * Each gets spaces around each argument and a newline at the end for | 22120 * Each gets spaces around each argument and a newline at the end for |
23015 * echo commands | 22121 * echo commands |
23016 */ | 22122 */ |
23017 void | 22123 void |
23018 ex_execute(eap) | 22124 ex_execute(exarg_T *eap) |
23019 exarg_T *eap; | |
23020 { | 22125 { |
23021 char_u *arg = eap->arg; | 22126 char_u *arg = eap->arg; |
23022 typval_T rettv; | 22127 typval_T rettv; |
23023 int ret = OK; | 22128 int ret = OK; |
23024 char_u *p; | 22129 char_u *p; |
23099 * "arg" points to the "&" or '+' when called, to "option" when returning. | 22204 * "arg" points to the "&" or '+' when called, to "option" when returning. |
23100 * Returns NULL when no option name found. Otherwise pointer to the char | 22205 * Returns NULL when no option name found. Otherwise pointer to the char |
23101 * after the option name. | 22206 * after the option name. |
23102 */ | 22207 */ |
23103 static char_u * | 22208 static char_u * |
23104 find_option_end(arg, opt_flags) | 22209 find_option_end(char_u **arg, int *opt_flags) |
23105 char_u **arg; | |
23106 int *opt_flags; | |
23107 { | 22210 { |
23108 char_u *p = *arg; | 22211 char_u *p = *arg; |
23109 | 22212 |
23110 ++p; | 22213 ++p; |
23111 if (*p == 'g' && p[1] == ':') | 22214 if (*p == 'g' && p[1] == ':') |
23135 | 22238 |
23136 /* | 22239 /* |
23137 * ":function" | 22240 * ":function" |
23138 */ | 22241 */ |
23139 void | 22242 void |
23140 ex_function(eap) | 22243 ex_function(exarg_T *eap) |
23141 exarg_T *eap; | |
23142 { | 22244 { |
23143 char_u *theline; | 22245 char_u *theline; |
23144 int i; | 22246 int i; |
23145 int j; | 22247 int j; |
23146 int c; | 22248 int c; |
23809 * TFN_QUIET: be quiet | 22911 * TFN_QUIET: be quiet |
23810 * TFN_NO_AUTOLOAD: do not use script autoloading | 22912 * TFN_NO_AUTOLOAD: do not use script autoloading |
23811 * Advances "pp" to just after the function name (if no error). | 22913 * Advances "pp" to just after the function name (if no error). |
23812 */ | 22914 */ |
23813 static char_u * | 22915 static char_u * |
23814 trans_function_name(pp, skip, flags, fdp) | 22916 trans_function_name( |
23815 char_u **pp; | 22917 char_u **pp, |
23816 int skip; /* only find the end, don't evaluate */ | 22918 int skip, /* only find the end, don't evaluate */ |
23817 int flags; | 22919 int flags, |
23818 funcdict_T *fdp; /* return: info about dictionary used */ | 22920 funcdict_T *fdp) /* return: info about dictionary used */ |
23819 { | 22921 { |
23820 char_u *name = NULL; | 22922 char_u *name = NULL; |
23821 char_u *start; | 22923 char_u *start; |
23822 char_u *end; | 22924 char_u *end; |
23823 int lead; | 22925 int lead; |
24020 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case). | 23122 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case). |
24021 * Return 2 if "p" starts with "s:". | 23123 * Return 2 if "p" starts with "s:". |
24022 * Return 0 otherwise. | 23124 * Return 0 otherwise. |
24023 */ | 23125 */ |
24024 static int | 23126 static int |
24025 eval_fname_script(p) | 23127 eval_fname_script(char_u *p) |
24026 char_u *p; | |
24027 { | 23128 { |
24028 /* Use MB_STRICMP() because in Turkish comparing the "I" may not work with | 23129 /* Use MB_STRICMP() because in Turkish comparing the "I" may not work with |
24029 * the standard library function. */ | 23130 * the standard library function. */ |
24030 if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0 | 23131 if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0 |
24031 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) | 23132 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) |
24038 /* | 23139 /* |
24039 * Return TRUE if "p" starts with "<SID>" or "s:". | 23140 * Return TRUE if "p" starts with "<SID>" or "s:". |
24040 * Only works if eval_fname_script() returned non-zero for "p"! | 23141 * Only works if eval_fname_script() returned non-zero for "p"! |
24041 */ | 23142 */ |
24042 static int | 23143 static int |
24043 eval_fname_sid(p) | 23144 eval_fname_sid(char_u *p) |
24044 char_u *p; | |
24045 { | 23145 { |
24046 return (*p == 's' || TOUPPER_ASC(p[2]) == 'I'); | 23146 return (*p == 's' || TOUPPER_ASC(p[2]) == 'I'); |
24047 } | 23147 } |
24048 | 23148 |
24049 /* | 23149 /* |
24050 * List the head of the function: "name(arg1, arg2)". | 23150 * List the head of the function: "name(arg1, arg2)". |
24051 */ | 23151 */ |
24052 static void | 23152 static void |
24053 list_func_head(fp, indent) | 23153 list_func_head(ufunc_T *fp, int indent) |
24054 ufunc_T *fp; | |
24055 int indent; | |
24056 { | 23154 { |
24057 int j; | 23155 int j; |
24058 | 23156 |
24059 msg_start(); | 23157 msg_start(); |
24060 if (indent) | 23158 if (indent) |
24095 /* | 23193 /* |
24096 * Find a function by name, return pointer to it in ufuncs. | 23194 * Find a function by name, return pointer to it in ufuncs. |
24097 * Return NULL for unknown function. | 23195 * Return NULL for unknown function. |
24098 */ | 23196 */ |
24099 static ufunc_T * | 23197 static ufunc_T * |
24100 find_func(name) | 23198 find_func(char_u *name) |
24101 char_u *name; | |
24102 { | 23199 { |
24103 hashitem_T *hi; | 23200 hashitem_T *hi; |
24104 | 23201 |
24105 hi = hash_find(&func_hashtab, name); | 23202 hi = hash_find(&func_hashtab, name); |
24106 if (!HASHITEM_EMPTY(hi)) | 23203 if (!HASHITEM_EMPTY(hi)) |
24108 return NULL; | 23205 return NULL; |
24109 } | 23206 } |
24110 | 23207 |
24111 #if defined(EXITFREE) || defined(PROTO) | 23208 #if defined(EXITFREE) || defined(PROTO) |
24112 void | 23209 void |
24113 free_all_functions() | 23210 free_all_functions(void) |
24114 { | 23211 { |
24115 hashitem_T *hi; | 23212 hashitem_T *hi; |
24116 | 23213 |
24117 /* Need to start all over every time, because func_free() may change the | 23214 /* Need to start all over every time, because func_free() may change the |
24118 * hash table. */ | 23215 * hash table. */ |
24125 } | 23222 } |
24126 } | 23223 } |
24127 #endif | 23224 #endif |
24128 | 23225 |
24129 int | 23226 int |
24130 translated_function_exists(name) | 23227 translated_function_exists(char_u *name) |
24131 char_u *name; | |
24132 { | 23228 { |
24133 if (builtin_function(name, -1)) | 23229 if (builtin_function(name, -1)) |
24134 return find_internal_func(name) >= 0; | 23230 return find_internal_func(name) >= 0; |
24135 return find_func(name) != NULL; | 23231 return find_func(name) != NULL; |
24136 } | 23232 } |
24137 | 23233 |
24138 /* | 23234 /* |
24139 * Return TRUE if a function "name" exists. | 23235 * Return TRUE if a function "name" exists. |
24140 */ | 23236 */ |
24141 static int | 23237 static int |
24142 function_exists(name) | 23238 function_exists(char_u *name) |
24143 char_u *name; | |
24144 { | 23239 { |
24145 char_u *nm = name; | 23240 char_u *nm = name; |
24146 char_u *p; | 23241 char_u *p; |
24147 int n = FALSE; | 23242 int n = FALSE; |
24148 | 23243 |
24157 vim_free(p); | 23252 vim_free(p); |
24158 return n; | 23253 return n; |
24159 } | 23254 } |
24160 | 23255 |
24161 char_u * | 23256 char_u * |
24162 get_expanded_name(name, check) | 23257 get_expanded_name(char_u *name, int check) |
24163 char_u *name; | |
24164 int check; | |
24165 { | 23258 { |
24166 char_u *nm = name; | 23259 char_u *nm = name; |
24167 char_u *p; | 23260 char_u *p; |
24168 | 23261 |
24169 p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL); | 23262 p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL); |
24180 * Return TRUE if "name" looks like a builtin function name: starts with a | 23273 * Return TRUE if "name" looks like a builtin function name: starts with a |
24181 * lower case letter and doesn't contain AUTOLOAD_CHAR. | 23274 * lower case letter and doesn't contain AUTOLOAD_CHAR. |
24182 * "len" is the length of "name", or -1 for NUL terminated. | 23275 * "len" is the length of "name", or -1 for NUL terminated. |
24183 */ | 23276 */ |
24184 static int | 23277 static int |
24185 builtin_function(name, len) | 23278 builtin_function(char_u *name, int len) |
24186 char_u *name; | |
24187 int len; | |
24188 { | 23279 { |
24189 char_u *p; | 23280 char_u *p; |
24190 | 23281 |
24191 if (!ASCII_ISLOWER(name[0])) | 23282 if (!ASCII_ISLOWER(name[0])) |
24192 return FALSE; | 23283 return FALSE; |
24197 #if defined(FEAT_PROFILE) || defined(PROTO) | 23288 #if defined(FEAT_PROFILE) || defined(PROTO) |
24198 /* | 23289 /* |
24199 * Start profiling function "fp". | 23290 * Start profiling function "fp". |
24200 */ | 23291 */ |
24201 static void | 23292 static void |
24202 func_do_profile(fp) | 23293 func_do_profile(ufunc_T *fp) |
24203 ufunc_T *fp; | |
24204 { | 23294 { |
24205 int len = fp->uf_lines.ga_len; | 23295 int len = fp->uf_lines.ga_len; |
24206 | 23296 |
24207 if (len == 0) | 23297 if (len == 0) |
24208 len = 1; /* avoid getting error for allocating zero bytes */ | 23298 len = 1; /* avoid getting error for allocating zero bytes */ |
24227 | 23317 |
24228 /* | 23318 /* |
24229 * Dump the profiling results for all functions in file "fd". | 23319 * Dump the profiling results for all functions in file "fd". |
24230 */ | 23320 */ |
24231 void | 23321 void |
24232 func_dump_profile(fd) | 23322 func_dump_profile(FILE *fd) |
24233 FILE *fd; | |
24234 { | 23323 { |
24235 hashitem_T *hi; | 23324 hashitem_T *hi; |
24236 int todo; | 23325 int todo; |
24237 ufunc_T *fp; | 23326 ufunc_T *fp; |
24238 int i; | 23327 int i; |
24294 | 23383 |
24295 vim_free(sorttab); | 23384 vim_free(sorttab); |
24296 } | 23385 } |
24297 | 23386 |
24298 static void | 23387 static void |
24299 prof_sort_list(fd, sorttab, st_len, title, prefer_self) | 23388 prof_sort_list( |
24300 FILE *fd; | 23389 FILE *fd, |
24301 ufunc_T **sorttab; | 23390 ufunc_T **sorttab, |
24302 int st_len; | 23391 int st_len, |
24303 char *title; | 23392 char *title, |
24304 int prefer_self; /* when equal print only self time */ | 23393 int prefer_self) /* when equal print only self time */ |
24305 { | 23394 { |
24306 int i; | 23395 int i; |
24307 ufunc_T *fp; | 23396 ufunc_T *fp; |
24308 | 23397 |
24309 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title); | 23398 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title); |
24323 | 23412 |
24324 /* | 23413 /* |
24325 * Print the count and times for one function or function line. | 23414 * Print the count and times for one function or function line. |
24326 */ | 23415 */ |
24327 static void | 23416 static void |
24328 prof_func_line(fd, count, total, self, prefer_self) | 23417 prof_func_line( |
24329 FILE *fd; | 23418 FILE *fd, |
24330 int count; | 23419 int count, |
24331 proftime_T *total; | 23420 proftime_T *total, |
24332 proftime_T *self; | 23421 proftime_T *self, |
24333 int prefer_self; /* when equal print only self time */ | 23422 int prefer_self) /* when equal print only self time */ |
24334 { | 23423 { |
24335 if (count > 0) | 23424 if (count > 0) |
24336 { | 23425 { |
24337 fprintf(fd, "%5d ", count); | 23426 fprintf(fd, "%5d ", count); |
24338 if (prefer_self && profile_equal(total, self)) | 23427 if (prefer_self && profile_equal(total, self)) |
24353 */ | 23442 */ |
24354 static int | 23443 static int |
24355 #ifdef __BORLANDC__ | 23444 #ifdef __BORLANDC__ |
24356 _RTLENTRYF | 23445 _RTLENTRYF |
24357 #endif | 23446 #endif |
24358 prof_total_cmp(s1, s2) | 23447 prof_total_cmp(const void *s1, const void *s2) |
24359 const void *s1; | |
24360 const void *s2; | |
24361 { | 23448 { |
24362 ufunc_T *p1, *p2; | 23449 ufunc_T *p1, *p2; |
24363 | 23450 |
24364 p1 = *(ufunc_T **)s1; | 23451 p1 = *(ufunc_T **)s1; |
24365 p2 = *(ufunc_T **)s2; | 23452 p2 = *(ufunc_T **)s2; |
24371 */ | 23458 */ |
24372 static int | 23459 static int |
24373 #ifdef __BORLANDC__ | 23460 #ifdef __BORLANDC__ |
24374 _RTLENTRYF | 23461 _RTLENTRYF |
24375 #endif | 23462 #endif |
24376 prof_self_cmp(s1, s2) | 23463 prof_self_cmp(const void *s1, const void *s2) |
24377 const void *s1; | |
24378 const void *s2; | |
24379 { | 23464 { |
24380 ufunc_T *p1, *p2; | 23465 ufunc_T *p1, *p2; |
24381 | 23466 |
24382 p1 = *(ufunc_T **)s1; | 23467 p1 = *(ufunc_T **)s1; |
24383 p2 = *(ufunc_T **)s2; | 23468 p2 = *(ufunc_T **)s2; |
24389 /* | 23474 /* |
24390 * If "name" has a package name try autoloading the script for it. | 23475 * If "name" has a package name try autoloading the script for it. |
24391 * Return TRUE if a package was loaded. | 23476 * Return TRUE if a package was loaded. |
24392 */ | 23477 */ |
24393 static int | 23478 static int |
24394 script_autoload(name, reload) | 23479 script_autoload( |
24395 char_u *name; | 23480 char_u *name, |
24396 int reload; /* load script again when already loaded */ | 23481 int reload) /* load script again when already loaded */ |
24397 { | 23482 { |
24398 char_u *p; | 23483 char_u *p; |
24399 char_u *scriptname, *tofree; | 23484 char_u *scriptname, *tofree; |
24400 int ret = FALSE; | 23485 int ret = FALSE; |
24401 int i; | 23486 int i; |
24435 /* | 23520 /* |
24436 * Return the autoload script name for a function or variable name. | 23521 * Return the autoload script name for a function or variable name. |
24437 * Returns NULL when out of memory. | 23522 * Returns NULL when out of memory. |
24438 */ | 23523 */ |
24439 static char_u * | 23524 static char_u * |
24440 autoload_name(name) | 23525 autoload_name(char_u *name) |
24441 char_u *name; | |
24442 { | 23526 { |
24443 char_u *p; | 23527 char_u *p; |
24444 char_u *scriptname; | 23528 char_u *scriptname; |
24445 | 23529 |
24446 /* Get the script file name: replace '#' with '/', append ".vim". */ | 23530 /* Get the script file name: replace '#' with '/', append ".vim". */ |
24461 /* | 23545 /* |
24462 * Function given to ExpandGeneric() to obtain the list of user defined | 23546 * Function given to ExpandGeneric() to obtain the list of user defined |
24463 * function names. | 23547 * function names. |
24464 */ | 23548 */ |
24465 char_u * | 23549 char_u * |
24466 get_user_func_name(xp, idx) | 23550 get_user_func_name(expand_T *xp, int idx) |
24467 expand_T *xp; | |
24468 int idx; | |
24469 { | 23551 { |
24470 static long_u done; | 23552 static long_u done; |
24471 static hashitem_T *hi; | 23553 static hashitem_T *hi; |
24472 ufunc_T *fp; | 23554 ufunc_T *fp; |
24473 | 23555 |
24508 * Copy the function name of "fp" to buffer "buf". | 23590 * Copy the function name of "fp" to buffer "buf". |
24509 * "buf" must be able to hold the function name plus three bytes. | 23591 * "buf" must be able to hold the function name plus three bytes. |
24510 * Takes care of script-local function names. | 23592 * Takes care of script-local function names. |
24511 */ | 23593 */ |
24512 static void | 23594 static void |
24513 cat_func_name(buf, fp) | 23595 cat_func_name(char_u *buf, ufunc_T *fp) |
24514 char_u *buf; | |
24515 ufunc_T *fp; | |
24516 { | 23596 { |
24517 if (fp->uf_name[0] == K_SPECIAL) | 23597 if (fp->uf_name[0] == K_SPECIAL) |
24518 { | 23598 { |
24519 STRCPY(buf, "<SNR>"); | 23599 STRCPY(buf, "<SNR>"); |
24520 STRCAT(buf, fp->uf_name + 3); | 23600 STRCAT(buf, fp->uf_name + 3); |
24525 | 23605 |
24526 /* | 23606 /* |
24527 * ":delfunction {name}" | 23607 * ":delfunction {name}" |
24528 */ | 23608 */ |
24529 void | 23609 void |
24530 ex_delfunction(eap) | 23610 ex_delfunction(exarg_T *eap) |
24531 exarg_T *eap; | |
24532 { | 23611 { |
24533 ufunc_T *fp = NULL; | 23612 ufunc_T *fp = NULL; |
24534 char_u *p; | 23613 char_u *p; |
24535 char_u *name; | 23614 char_u *name; |
24536 funcdict_T fudi; | 23615 funcdict_T fudi; |
24584 | 23663 |
24585 /* | 23664 /* |
24586 * Free a function and remove it from the list of functions. | 23665 * Free a function and remove it from the list of functions. |
24587 */ | 23666 */ |
24588 static void | 23667 static void |
24589 func_free(fp) | 23668 func_free(ufunc_T *fp) |
24590 ufunc_T *fp; | |
24591 { | 23669 { |
24592 hashitem_T *hi; | 23670 hashitem_T *hi; |
24593 | 23671 |
24594 /* clear this function */ | 23672 /* clear this function */ |
24595 ga_clear_strings(&(fp->uf_args)); | 23673 ga_clear_strings(&(fp->uf_args)); |
24613 /* | 23691 /* |
24614 * Unreference a Function: decrement the reference count and free it when it | 23692 * Unreference a Function: decrement the reference count and free it when it |
24615 * becomes zero. Only for numbered functions. | 23693 * becomes zero. Only for numbered functions. |
24616 */ | 23694 */ |
24617 void | 23695 void |
24618 func_unref(name) | 23696 func_unref(char_u *name) |
24619 char_u *name; | |
24620 { | 23697 { |
24621 ufunc_T *fp; | 23698 ufunc_T *fp; |
24622 | 23699 |
24623 if (name != NULL && isdigit(*name)) | 23700 if (name != NULL && isdigit(*name)) |
24624 { | 23701 { |
24637 | 23714 |
24638 /* | 23715 /* |
24639 * Count a reference to a Function. | 23716 * Count a reference to a Function. |
24640 */ | 23717 */ |
24641 void | 23718 void |
24642 func_ref(name) | 23719 func_ref(char_u *name) |
24643 char_u *name; | |
24644 { | 23720 { |
24645 ufunc_T *fp; | 23721 ufunc_T *fp; |
24646 | 23722 |
24647 if (name != NULL && isdigit(*name)) | 23723 if (name != NULL && isdigit(*name)) |
24648 { | 23724 { |
24656 | 23732 |
24657 /* | 23733 /* |
24658 * Call a user function. | 23734 * Call a user function. |
24659 */ | 23735 */ |
24660 static void | 23736 static void |
24661 call_user_func(fp, argcount, argvars, rettv, firstline, lastline, selfdict) | 23737 call_user_func( |
24662 ufunc_T *fp; /* pointer to function */ | 23738 ufunc_T *fp, /* pointer to function */ |
24663 int argcount; /* nr of args */ | 23739 int argcount, /* nr of args */ |
24664 typval_T *argvars; /* arguments */ | 23740 typval_T *argvars, /* arguments */ |
24665 typval_T *rettv; /* return value */ | 23741 typval_T *rettv, /* return value */ |
24666 linenr_T firstline; /* first line of range */ | 23742 linenr_T firstline, /* first line of range */ |
24667 linenr_T lastline; /* last line of range */ | 23743 linenr_T lastline, /* last line of range */ |
24668 dict_T *selfdict; /* Dictionary for "self" */ | 23744 dict_T *selfdict) /* Dictionary for "self" */ |
24669 { | 23745 { |
24670 char_u *save_sourcing_name; | 23746 char_u *save_sourcing_name; |
24671 linenr_T save_sourcing_lnum; | 23747 linenr_T save_sourcing_lnum; |
24672 scid_T save_current_SID; | 23748 scid_T save_current_SID; |
24673 funccall_T *fc; | 23749 funccall_T *fc; |
25029 /* | 24105 /* |
25030 * Return TRUE if items in "fc" do not have "copyID". That means they are not | 24106 * Return TRUE if items in "fc" do not have "copyID". That means they are not |
25031 * referenced from anywhere that is in use. | 24107 * referenced from anywhere that is in use. |
25032 */ | 24108 */ |
25033 static int | 24109 static int |
25034 can_free_funccal(fc, copyID) | 24110 can_free_funccal(funccall_T *fc, int copyID) |
25035 funccall_T *fc; | |
25036 int copyID; | |
25037 { | 24111 { |
25038 return (fc->l_varlist.lv_copyID != copyID | 24112 return (fc->l_varlist.lv_copyID != copyID |
25039 && fc->l_vars.dv_copyID != copyID | 24113 && fc->l_vars.dv_copyID != copyID |
25040 && fc->l_avars.dv_copyID != copyID); | 24114 && fc->l_avars.dv_copyID != copyID); |
25041 } | 24115 } |
25042 | 24116 |
25043 /* | 24117 /* |
25044 * Free "fc" and what it contains. | 24118 * Free "fc" and what it contains. |
25045 */ | 24119 */ |
25046 static void | 24120 static void |
25047 free_funccal(fc, free_val) | 24121 free_funccal( |
25048 funccall_T *fc; | 24122 funccall_T *fc, |
25049 int free_val; /* a: vars were allocated */ | 24123 int free_val) /* a: vars were allocated */ |
25050 { | 24124 { |
25051 listitem_T *li; | 24125 listitem_T *li; |
25052 | 24126 |
25053 /* The a: variables typevals may not have been allocated, only free the | 24127 /* The a: variables typevals may not have been allocated, only free the |
25054 * allocated variables. */ | 24128 * allocated variables. */ |
25067 | 24141 |
25068 /* | 24142 /* |
25069 * Add a number variable "name" to dict "dp" with value "nr". | 24143 * Add a number variable "name" to dict "dp" with value "nr". |
25070 */ | 24144 */ |
25071 static void | 24145 static void |
25072 add_nr_var(dp, v, name, nr) | 24146 add_nr_var( |
25073 dict_T *dp; | 24147 dict_T *dp, |
25074 dictitem_T *v; | 24148 dictitem_T *v, |
25075 char *name; | 24149 char *name, |
25076 varnumber_T nr; | 24150 varnumber_T nr) |
25077 { | 24151 { |
25078 STRCPY(v->di_key, name); | 24152 STRCPY(v->di_key, name); |
25079 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | 24153 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
25080 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); | 24154 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); |
25081 v->di_tv.v_type = VAR_NUMBER; | 24155 v->di_tv.v_type = VAR_NUMBER; |
25085 | 24159 |
25086 /* | 24160 /* |
25087 * ":return [expr]" | 24161 * ":return [expr]" |
25088 */ | 24162 */ |
25089 void | 24163 void |
25090 ex_return(eap) | 24164 ex_return(exarg_T *eap) |
25091 exarg_T *eap; | |
25092 { | 24165 { |
25093 char_u *arg = eap->arg; | 24166 char_u *arg = eap->arg; |
25094 typval_T rettv; | 24167 typval_T rettv; |
25095 int returning = FALSE; | 24168 int returning = FALSE; |
25096 | 24169 |
25142 * when called due to a ":return" command. "rettv" may point to a typval_T | 24215 * when called due to a ":return" command. "rettv" may point to a typval_T |
25143 * with the return rettv. Returns TRUE when the return can be carried out, | 24216 * with the return rettv. Returns TRUE when the return can be carried out, |
25144 * FALSE when the return gets pending. | 24217 * FALSE when the return gets pending. |
25145 */ | 24218 */ |
25146 int | 24219 int |
25147 do_return(eap, reanimate, is_cmd, rettv) | 24220 do_return( |
25148 exarg_T *eap; | 24221 exarg_T *eap, |
25149 int reanimate; | 24222 int reanimate, |
25150 int is_cmd; | 24223 int is_cmd, |
25151 void *rettv; | 24224 void *rettv) |
25152 { | 24225 { |
25153 int idx; | 24226 int idx; |
25154 struct condstack *cstack = eap->cstack; | 24227 struct condstack *cstack = eap->cstack; |
25155 | 24228 |
25156 if (reanimate) | 24229 if (reanimate) |
25223 | 24296 |
25224 /* | 24297 /* |
25225 * Free the variable with a pending return value. | 24298 * Free the variable with a pending return value. |
25226 */ | 24299 */ |
25227 void | 24300 void |
25228 discard_pending_return(rettv) | 24301 discard_pending_return(void *rettv) |
25229 void *rettv; | |
25230 { | 24302 { |
25231 free_tv((typval_T *)rettv); | 24303 free_tv((typval_T *)rettv); |
25232 } | 24304 } |
25233 | 24305 |
25234 /* | 24306 /* |
25235 * Generate a return command for producing the value of "rettv". The result | 24307 * Generate a return command for producing the value of "rettv". The result |
25236 * is an allocated string. Used by report_pending() for verbose messages. | 24308 * is an allocated string. Used by report_pending() for verbose messages. |
25237 */ | 24309 */ |
25238 char_u * | 24310 char_u * |
25239 get_return_cmd(rettv) | 24311 get_return_cmd(void *rettv) |
25240 void *rettv; | |
25241 { | 24312 { |
25242 char_u *s = NULL; | 24313 char_u *s = NULL; |
25243 char_u *tofree = NULL; | 24314 char_u *tofree = NULL; |
25244 char_u numbuf[NUMBUFLEN]; | 24315 char_u numbuf[NUMBUFLEN]; |
25245 | 24316 |
25260 * Get next function line. | 24331 * Get next function line. |
25261 * Called by do_cmdline() to get the next line. | 24332 * Called by do_cmdline() to get the next line. |
25262 * Returns allocated string, or NULL for end of function. | 24333 * Returns allocated string, or NULL for end of function. |
25263 */ | 24334 */ |
25264 char_u * | 24335 char_u * |
25265 get_func_line(c, cookie, indent) | 24336 get_func_line( |
25266 int c UNUSED; | 24337 int c UNUSED, |
25267 void *cookie; | 24338 void *cookie, |
25268 int indent UNUSED; | 24339 int indent UNUSED) |
25269 { | 24340 { |
25270 funccall_T *fcp = (funccall_T *)cookie; | 24341 funccall_T *fcp = (funccall_T *)cookie; |
25271 ufunc_T *fp = fcp->func; | 24342 ufunc_T *fp = fcp->func; |
25272 char_u *retval; | 24343 char_u *retval; |
25273 garray_T *gap; /* growarray with function lines */ | 24344 garray_T *gap; /* growarray with function lines */ |
25326 * "sourcing_lnum" must be correct! | 24397 * "sourcing_lnum" must be correct! |
25327 * When skipping lines it may not actually be executed, but we won't find out | 24398 * When skipping lines it may not actually be executed, but we won't find out |
25328 * until later and we need to store the time now. | 24399 * until later and we need to store the time now. |
25329 */ | 24400 */ |
25330 void | 24401 void |
25331 func_line_start(cookie) | 24402 func_line_start(void *cookie) |
25332 void *cookie; | |
25333 { | 24403 { |
25334 funccall_T *fcp = (funccall_T *)cookie; | 24404 funccall_T *fcp = (funccall_T *)cookie; |
25335 ufunc_T *fp = fcp->func; | 24405 ufunc_T *fp = fcp->func; |
25336 | 24406 |
25337 if (fp->uf_profiling && sourcing_lnum >= 1 | 24407 if (fp->uf_profiling && sourcing_lnum >= 1 |
25350 | 24420 |
25351 /* | 24421 /* |
25352 * Called when actually executing a function line. | 24422 * Called when actually executing a function line. |
25353 */ | 24423 */ |
25354 void | 24424 void |
25355 func_line_exec(cookie) | 24425 func_line_exec(void *cookie) |
25356 void *cookie; | |
25357 { | 24426 { |
25358 funccall_T *fcp = (funccall_T *)cookie; | 24427 funccall_T *fcp = (funccall_T *)cookie; |
25359 ufunc_T *fp = fcp->func; | 24428 ufunc_T *fp = fcp->func; |
25360 | 24429 |
25361 if (fp->uf_profiling && fp->uf_tml_idx >= 0) | 24430 if (fp->uf_profiling && fp->uf_tml_idx >= 0) |
25364 | 24433 |
25365 /* | 24434 /* |
25366 * Called when done with a function line. | 24435 * Called when done with a function line. |
25367 */ | 24436 */ |
25368 void | 24437 void |
25369 func_line_end(cookie) | 24438 func_line_end(void *cookie) |
25370 void *cookie; | |
25371 { | 24439 { |
25372 funccall_T *fcp = (funccall_T *)cookie; | 24440 funccall_T *fcp = (funccall_T *)cookie; |
25373 ufunc_T *fp = fcp->func; | 24441 ufunc_T *fp = fcp->func; |
25374 | 24442 |
25375 if (fp->uf_profiling && fp->uf_tml_idx >= 0) | 24443 if (fp->uf_profiling && fp->uf_tml_idx >= 0) |
25391 /* | 24459 /* |
25392 * Return TRUE if the currently active function should be ended, because a | 24460 * Return TRUE if the currently active function should be ended, because a |
25393 * return was encountered or an error occurred. Used inside a ":while". | 24461 * return was encountered or an error occurred. Used inside a ":while". |
25394 */ | 24462 */ |
25395 int | 24463 int |
25396 func_has_ended(cookie) | 24464 func_has_ended(void *cookie) |
25397 void *cookie; | |
25398 { | 24465 { |
25399 funccall_T *fcp = (funccall_T *)cookie; | 24466 funccall_T *fcp = (funccall_T *)cookie; |
25400 | 24467 |
25401 /* Ignore the "abort" flag if the abortion behavior has been changed due to | 24468 /* Ignore the "abort" flag if the abortion behavior has been changed due to |
25402 * an error inside a try conditional. */ | 24469 * an error inside a try conditional. */ |
25406 | 24473 |
25407 /* | 24474 /* |
25408 * return TRUE if cookie indicates a function which "abort"s on errors. | 24475 * return TRUE if cookie indicates a function which "abort"s on errors. |
25409 */ | 24476 */ |
25410 int | 24477 int |
25411 func_has_abort(cookie) | 24478 func_has_abort( |
25412 void *cookie; | 24479 void *cookie) |
25413 { | 24480 { |
25414 return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT; | 24481 return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT; |
25415 } | 24482 } |
25416 | 24483 |
25417 #if defined(FEAT_VIMINFO) || defined(FEAT_SESSION) | 24484 #if defined(FEAT_VIMINFO) || defined(FEAT_SESSION) |
25423 } var_flavour_T; | 24490 } var_flavour_T; |
25424 | 24491 |
25425 static var_flavour_T var_flavour(char_u *varname); | 24492 static var_flavour_T var_flavour(char_u *varname); |
25426 | 24493 |
25427 static var_flavour_T | 24494 static var_flavour_T |
25428 var_flavour(varname) | 24495 var_flavour(char_u *varname) |
25429 char_u *varname; | |
25430 { | 24496 { |
25431 char_u *p = varname; | 24497 char_u *p = varname; |
25432 | 24498 |
25433 if (ASCII_ISUPPER(*p)) | 24499 if (ASCII_ISUPPER(*p)) |
25434 { | 24500 { |
25445 #if defined(FEAT_VIMINFO) || defined(PROTO) | 24511 #if defined(FEAT_VIMINFO) || defined(PROTO) |
25446 /* | 24512 /* |
25447 * Restore global vars that start with a capital from the viminfo file | 24513 * Restore global vars that start with a capital from the viminfo file |
25448 */ | 24514 */ |
25449 int | 24515 int |
25450 read_viminfo_varlist(virp, writing) | 24516 read_viminfo_varlist(vir_T *virp, int writing) |
25451 vir_T *virp; | |
25452 int writing; | |
25453 { | 24517 { |
25454 char_u *tab; | 24518 char_u *tab; |
25455 int type = VAR_NUMBER; | 24519 int type = VAR_NUMBER; |
25456 typval_T tv; | 24520 typval_T tv; |
25457 funccall_T *save_funccal; | 24521 funccall_T *save_funccal; |
25520 | 24584 |
25521 /* | 24585 /* |
25522 * Write global vars that start with a capital to the viminfo file | 24586 * Write global vars that start with a capital to the viminfo file |
25523 */ | 24587 */ |
25524 void | 24588 void |
25525 write_viminfo_varlist(fp) | 24589 write_viminfo_varlist(FILE *fp) |
25526 FILE *fp; | |
25527 { | 24590 { |
25528 hashitem_T *hi; | 24591 hashitem_T *hi; |
25529 dictitem_T *this_var; | 24592 dictitem_T *this_var; |
25530 int todo; | 24593 int todo; |
25531 char *s; | 24594 char *s; |
25569 } | 24632 } |
25570 #endif | 24633 #endif |
25571 | 24634 |
25572 #if defined(FEAT_SESSION) || defined(PROTO) | 24635 #if defined(FEAT_SESSION) || defined(PROTO) |
25573 int | 24636 int |
25574 store_session_globals(fd) | 24637 store_session_globals(FILE *fd) |
25575 FILE *fd; | |
25576 { | 24638 { |
25577 hashitem_T *hi; | 24639 hashitem_T *hi; |
25578 dictitem_T *this_var; | 24640 dictitem_T *this_var; |
25579 int todo; | 24641 int todo; |
25580 char_u *p, *t; | 24642 char_u *p, *t; |
25642 /* | 24704 /* |
25643 * Display script name where an item was last set. | 24705 * Display script name where an item was last set. |
25644 * Should only be invoked when 'verbose' is non-zero. | 24706 * Should only be invoked when 'verbose' is non-zero. |
25645 */ | 24707 */ |
25646 void | 24708 void |
25647 last_set_msg(scriptID) | 24709 last_set_msg(scid_T scriptID) |
25648 scid_T scriptID; | |
25649 { | 24710 { |
25650 char_u *p; | 24711 char_u *p; |
25651 | 24712 |
25652 if (scriptID != 0) | 24713 if (scriptID != 0) |
25653 { | 24714 { |
25665 | 24726 |
25666 /* | 24727 /* |
25667 * List v:oldfiles in a nice way. | 24728 * List v:oldfiles in a nice way. |
25668 */ | 24729 */ |
25669 void | 24730 void |
25670 ex_oldfiles(eap) | 24731 ex_oldfiles(exarg_T *eap UNUSED) |
25671 exarg_T *eap UNUSED; | |
25672 { | 24732 { |
25673 list_T *l = vimvars[VV_OLDFILES].vv_list; | 24733 list_T *l = vimvars[VV_OLDFILES].vv_list; |
25674 listitem_T *li; | 24734 listitem_T *li; |
25675 int nr = 0; | 24735 int nr = 0; |
25676 | 24736 |
25718 } | 24778 } |
25719 } | 24779 } |
25720 | 24780 |
25721 /* reset v:option_new, v:option_old and v:option_type */ | 24781 /* reset v:option_new, v:option_old and v:option_type */ |
25722 void | 24782 void |
25723 reset_v_option_vars() | 24783 reset_v_option_vars(void) |
25724 { | 24784 { |
25725 set_vim_var_string(VV_OPTION_NEW, NULL, -1); | 24785 set_vim_var_string(VV_OPTION_NEW, NULL, -1); |
25726 set_vim_var_string(VV_OPTION_OLD, NULL, -1); | 24786 set_vim_var_string(VV_OPTION_OLD, NULL, -1); |
25727 set_vim_var_string(VV_OPTION_TYPE, NULL, -1); | 24787 set_vim_var_string(VV_OPTION_TYPE, NULL, -1); |
25728 } | 24788 } |
25748 * is put in "bufp". | 24808 * is put in "bufp". |
25749 * *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path. | 24809 * *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path. |
25750 * Returns OK on success, FAIL on failure. | 24810 * Returns OK on success, FAIL on failure. |
25751 */ | 24811 */ |
25752 static int | 24812 static int |
25753 get_short_pathname(fnamep, bufp, fnamelen) | 24813 get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen) |
25754 char_u **fnamep; | |
25755 char_u **bufp; | |
25756 int *fnamelen; | |
25757 { | 24814 { |
25758 int l, len; | 24815 int l, len; |
25759 char_u *newbuf; | 24816 char_u *newbuf; |
25760 | 24817 |
25761 len = *fnamelen; | 24818 len = *fnamelen; |
25793 * fnamelen - Length of the filename pointed to by fname | 24850 * fnamelen - Length of the filename pointed to by fname |
25794 * | 24851 * |
25795 * Returns OK on success (or nothing done) and FAIL on failure (out of memory). | 24852 * Returns OK on success (or nothing done) and FAIL on failure (out of memory). |
25796 */ | 24853 */ |
25797 static int | 24854 static int |
25798 shortpath_for_invalid_fname(fname, bufp, fnamelen) | 24855 shortpath_for_invalid_fname( |
25799 char_u **fname; | 24856 char_u **fname, |
25800 char_u **bufp; | 24857 char_u **bufp, |
25801 int *fnamelen; | 24858 int *fnamelen) |
25802 { | 24859 { |
25803 char_u *short_fname, *save_fname, *pbuf_unused; | 24860 char_u *short_fname, *save_fname, *pbuf_unused; |
25804 char_u *endp, *save_endp; | 24861 char_u *endp, *save_endp; |
25805 char_u ch; | 24862 char_u ch; |
25806 int old_len, len; | 24863 int old_len, len; |
25900 /* | 24957 /* |
25901 * Get a pathname for a partial path. | 24958 * Get a pathname for a partial path. |
25902 * Returns OK for success, FAIL for failure. | 24959 * Returns OK for success, FAIL for failure. |
25903 */ | 24960 */ |
25904 static int | 24961 static int |
25905 shortpath_for_partial(fnamep, bufp, fnamelen) | 24962 shortpath_for_partial( |
25906 char_u **fnamep; | 24963 char_u **fnamep, |
25907 char_u **bufp; | 24964 char_u **bufp, |
25908 int *fnamelen; | 24965 int *fnamelen) |
25909 { | 24966 { |
25910 int sepcount, len, tflen; | 24967 int sepcount, len, tflen; |
25911 char_u *p; | 24968 char_u *p; |
25912 char_u *pbuf, *tfname; | 24969 char_u *pbuf, *tfname; |
25913 int hasTilde; | 24970 int hasTilde; |
25984 * determined by *fnamelen. | 25041 * determined by *fnamelen. |
25985 * Returns VALID_ flags or -1 for failure. | 25042 * Returns VALID_ flags or -1 for failure. |
25986 * When there is an error, *fnamep is set to NULL. | 25043 * When there is an error, *fnamep is set to NULL. |
25987 */ | 25044 */ |
25988 int | 25045 int |
25989 modify_fname(src, usedlen, fnamep, bufp, fnamelen) | 25046 modify_fname( |
25990 char_u *src; /* string with modifiers */ | 25047 char_u *src, /* string with modifiers */ |
25991 int *usedlen; /* characters after src that are used */ | 25048 int *usedlen, /* characters after src that are used */ |
25992 char_u **fnamep; /* file name so far */ | 25049 char_u **fnamep, /* file name so far */ |
25993 char_u **bufp; /* buffer for allocated file name or NULL */ | 25050 char_u **bufp, /* buffer for allocated file name or NULL */ |
25994 int *fnamelen; /* length of fnamep */ | 25051 int *fnamelen) /* length of fnamep */ |
25995 { | 25052 { |
25996 int valid = 0; | 25053 int valid = 0; |
25997 char_u *tail; | 25054 char_u *tail; |
25998 char_u *s, *p, *pbuf; | 25055 char_u *s, *p, *pbuf; |
25999 char_u dirname[MAXPATHL]; | 25056 char_u dirname[MAXPATHL]; |
26373 * Perform a substitution on "str" with pattern "pat" and substitute "sub". | 25430 * Perform a substitution on "str" with pattern "pat" and substitute "sub". |
26374 * "flags" can be "g" to do a global substitute. | 25431 * "flags" can be "g" to do a global substitute. |
26375 * Returns an allocated string, NULL for error. | 25432 * Returns an allocated string, NULL for error. |
26376 */ | 25433 */ |
26377 char_u * | 25434 char_u * |
26378 do_string_sub(str, pat, sub, flags) | 25435 do_string_sub( |
26379 char_u *str; | 25436 char_u *str, |
26380 char_u *pat; | 25437 char_u *pat, |
26381 char_u *sub; | 25438 char_u *sub, |
26382 char_u *flags; | 25439 char_u *flags) |
26383 { | 25440 { |
26384 int sublen; | 25441 int sublen; |
26385 regmatch_T regmatch; | 25442 regmatch_T regmatch; |
26386 int i; | 25443 int i; |
26387 int do_all; | 25444 int do_all; |