comparison src/eval.c @ 1713:7781fcd2b74f v7.2.011

updated for version 7.2-011
author vimboss
date Sun, 07 Sep 2008 11:55:43 +0000
parents f9f6e35c9f00
children 0f109c56b521
comparison
equal deleted inserted replaced
1712:563bd9a63fdc 1713:7781fcd2b74f
1254 return eval1(pp, &rettv, FALSE); 1254 return eval1(pp, &rettv, FALSE);
1255 } 1255 }
1256 1256
1257 /* 1257 /*
1258 * Top level evaluation function, returning a string. 1258 * Top level evaluation function, returning a string.
1259 * When "convert" is TRUE convert a List into a sequence of lines and convert
1260 * a Float to a String.
1259 * Return pointer to allocated memory, or NULL for failure. 1261 * Return pointer to allocated memory, or NULL for failure.
1260 */ 1262 */
1261 char_u * 1263 char_u *
1262 eval_to_string(arg, nextcmd, dolist) 1264 eval_to_string(arg, nextcmd, convert)
1263 char_u *arg; 1265 char_u *arg;
1264 char_u **nextcmd; 1266 char_u **nextcmd;
1265 int dolist; /* turn List into sequence of lines */ 1267 int convert;
1266 { 1268 {
1267 typval_T tv; 1269 typval_T tv;
1268 char_u *retval; 1270 char_u *retval;
1269 garray_T ga; 1271 garray_T ga;
1272 char_u numbuf[NUMBUFLEN];
1270 1273
1271 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL) 1274 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL)
1272 retval = NULL; 1275 retval = NULL;
1273 else 1276 else
1274 { 1277 {
1275 if (dolist && tv.v_type == VAR_LIST) 1278 if (convert && tv.v_type == VAR_LIST)
1276 { 1279 {
1277 ga_init2(&ga, (int)sizeof(char), 80); 1280 ga_init2(&ga, (int)sizeof(char), 80);
1278 if (tv.vval.v_list != NULL) 1281 if (tv.vval.v_list != NULL)
1279 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, 0); 1282 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, 0);
1280 ga_append(&ga, NUL); 1283 ga_append(&ga, NUL);
1281 retval = (char_u *)ga.ga_data; 1284 retval = (char_u *)ga.ga_data;
1282 } 1285 }
1286 #ifdef FEAT_FLOAT
1287 else if (convert && tv.v_type == VAR_FLOAT)
1288 {
1289 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float);
1290 retval = vim_strsave(numbuf);
1291 }
1292 #endif
1283 else 1293 else
1284 retval = vim_strsave(get_tv_string(&tv)); 1294 retval = vim_strsave(get_tv_string(&tv));
1285 clear_tv(&tv); 1295 clear_tv(&tv);
1286 } 1296 }
1287 1297