Mercurial > vim
comparison src/eval.c @ 408:06234af3a8b7 v7.0106
updated for version 7.0106
author | vimboss |
---|---|
date | Sat, 09 Jul 2005 21:14:46 +0000 |
parents | f92bb1845823 |
children | 5f33b64a6694 |
comparison
equal
deleted
inserted
replaced
407:0f6afaf1b8d1 | 408:06234af3a8b7 |
---|---|
1270 } | 1270 } |
1271 #endif | 1271 #endif |
1272 | 1272 |
1273 #if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) | 1273 #if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) |
1274 /* | 1274 /* |
1275 * Call some vimL function and return the result as a string | 1275 * Call some vimL function and return the result in "*rettv". |
1276 * Uses argv[argc] for the function arguments. | 1276 * Uses argv[argc] for the function arguments. |
1277 */ | 1277 * Returns OK or FAIL. |
1278 char_u * | 1278 */ |
1279 call_vim_function(func, argc, argv, safe) | 1279 static int |
1280 call_vim_function(func, argc, argv, safe, rettv) | |
1280 char_u *func; | 1281 char_u *func; |
1281 int argc; | 1282 int argc; |
1282 char_u **argv; | 1283 char_u **argv; |
1283 int safe; /* use the sandbox */ | 1284 int safe; /* use the sandbox */ |
1284 { | 1285 typval_T *rettv; |
1285 char_u *retval = NULL; | 1286 { |
1286 typval_T rettv; | |
1287 typval_T *argvars; | 1287 typval_T *argvars; |
1288 long n; | 1288 long n; |
1289 int len; | 1289 int len; |
1290 int i; | 1290 int i; |
1291 int doesrange; | 1291 int doesrange; |
1292 void *save_funccalp = NULL; | 1292 void *save_funccalp = NULL; |
1293 int ret; | |
1293 | 1294 |
1294 argvars = (typval_T *)alloc((unsigned)(argc * sizeof(typval_T))); | 1295 argvars = (typval_T *)alloc((unsigned)(argc * sizeof(typval_T))); |
1295 if (argvars == NULL) | 1296 if (argvars == NULL) |
1296 return NULL; | 1297 return FAIL; |
1297 | 1298 |
1298 for (i = 0; i < argc; i++) | 1299 for (i = 0; i < argc; i++) |
1299 { | 1300 { |
1300 /* Pass a NULL or empty argument as an empty string */ | 1301 /* Pass a NULL or empty argument as an empty string */ |
1301 if (argv[i] == NULL || *argv[i] == NUL) | 1302 if (argv[i] == NULL || *argv[i] == NUL) |
1323 { | 1324 { |
1324 save_funccalp = save_funccal(); | 1325 save_funccalp = save_funccal(); |
1325 ++sandbox; | 1326 ++sandbox; |
1326 } | 1327 } |
1327 | 1328 |
1328 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ | 1329 rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ |
1329 if (call_func(func, (int)STRLEN(func), &rettv, argc, argvars, | 1330 ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars, |
1330 curwin->w_cursor.lnum, curwin->w_cursor.lnum, | 1331 curwin->w_cursor.lnum, curwin->w_cursor.lnum, |
1331 &doesrange, TRUE, NULL) == OK) | 1332 &doesrange, TRUE, NULL); |
1332 retval = vim_strsave(get_tv_string(&rettv)); | |
1333 | |
1334 clear_tv(&rettv); | |
1335 vim_free(argvars); | |
1336 | |
1337 if (safe) | 1333 if (safe) |
1338 { | 1334 { |
1339 --sandbox; | 1335 --sandbox; |
1340 restore_funccal(save_funccalp); | 1336 restore_funccal(save_funccalp); |
1341 } | 1337 } |
1338 vim_free(argvars); | |
1339 | |
1340 if (ret == FAIL) | |
1341 clear_tv(rettv); | |
1342 | |
1343 return ret; | |
1344 } | |
1345 | |
1346 /* | |
1347 * Call some vimL function and return the result as a string | |
1348 * Uses argv[argc] for the function arguments. | |
1349 */ | |
1350 void * | |
1351 call_func_retstr(func, argc, argv, safe) | |
1352 char_u *func; | |
1353 int argc; | |
1354 char_u **argv; | |
1355 int safe; /* use the sandbox */ | |
1356 { | |
1357 typval_T rettv; | |
1358 char_u *retval = NULL; | |
1359 | |
1360 if (call_vim_function(func, argc, argv, safe, &rettv) == FAIL) | |
1361 return NULL; | |
1362 | |
1363 retval = vim_strsave(get_tv_string(&rettv)); | |
1364 | |
1365 clear_tv(&rettv); | |
1366 | |
1342 return retval; | 1367 return retval; |
1343 } | 1368 } |
1369 | |
1370 /* | |
1371 * Call some vimL function and return the result as a list | |
1372 * Uses argv[argc] for the function arguments. | |
1373 */ | |
1374 void * | |
1375 call_func_retlist(func, argc, argv, safe) | |
1376 char_u *func; | |
1377 int argc; | |
1378 char_u **argv; | |
1379 int safe; /* use the sandbox */ | |
1380 { | |
1381 typval_T rettv; | |
1382 | |
1383 if (call_vim_function(func, argc, argv, safe, &rettv) == FAIL) | |
1384 return NULL; | |
1385 | |
1386 if (rettv.v_type != VAR_LIST) | |
1387 { | |
1388 clear_tv(&rettv); | |
1389 return NULL; | |
1390 } | |
1391 | |
1392 return rettv.vval.v_list; | |
1393 } | |
1394 | |
1344 #endif | 1395 #endif |
1345 | 1396 |
1346 /* | 1397 /* |
1347 * Save the current function call pointer, and set it to NULL. | 1398 * Save the current function call pointer, and set it to NULL. |
1348 * Used when executing autocommands and for ":source". | 1399 * Used when executing autocommands and for ":source". |
1638 | 1689 |
1639 if (*arg == '[') | 1690 if (*arg == '[') |
1640 { | 1691 { |
1641 /* "[var, var]": find the matching ']'. */ | 1692 /* "[var, var]": find the matching ']'. */ |
1642 p = arg; | 1693 p = arg; |
1643 while (1) | 1694 for (;;) |
1644 { | 1695 { |
1645 p = skipwhite(p + 1); /* skip whites after '[', ';' or ',' */ | 1696 p = skipwhite(p + 1); /* skip whites after '[', ';' or ',' */ |
1646 s = skip_var_one(p); | 1697 s = skip_var_one(p); |
1647 if (s == p) | 1698 if (s == p) |
1648 { | 1699 { |
11313 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | 11364 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
11314 if (regmatch.regprog != NULL) | 11365 if (regmatch.regprog != NULL) |
11315 { | 11366 { |
11316 regmatch.rm_ic = p_ic; | 11367 regmatch.rm_ic = p_ic; |
11317 | 11368 |
11318 while (1) | 11369 for (;;) |
11319 { | 11370 { |
11320 if (l != NULL) | 11371 if (l != NULL) |
11321 { | 11372 { |
11322 if (li == NULL) | 11373 if (li == NULL) |
11323 { | 11374 { |
11470 { | 11521 { |
11471 li = l->lv_first; | 11522 li = l->lv_first; |
11472 if (li != NULL) | 11523 if (li != NULL) |
11473 { | 11524 { |
11474 n = get_tv_number_chk(&li->li_tv, &error); | 11525 n = get_tv_number_chk(&li->li_tv, &error); |
11475 while (1) | 11526 for (;;) |
11476 { | 11527 { |
11477 li = li->li_next; | 11528 li = li->li_next; |
11478 if (li == NULL) | 11529 if (li == NULL) |
11479 break; | 11530 break; |
11480 i = get_tv_number_chk(&li->li_tv, &error); | 11531 i = get_tv_number_chk(&li->li_tv, &error); |