Mercurial > vim
comparison src/eval.c @ 1360:8d09c1eed8a5 v7.1.074
updated for version 7.1-074
author | vimboss |
---|---|
date | Tue, 14 Aug 2007 20:29:31 +0000 |
parents | 2ae2dd2591fa |
children | 55e117ed6872 |
comparison
equal
deleted
inserted
replaced
1359:a66a49322b6b | 1360:8d09c1eed8a5 |
---|---|
6800 * Return a string with the string representation of a variable. | 6800 * Return a string with the string representation of a variable. |
6801 * If the memory is allocated "tofree" is set to it, otherwise NULL. | 6801 * If the memory is allocated "tofree" is set to it, otherwise NULL. |
6802 * "numbuf" is used for a number. | 6802 * "numbuf" is used for a number. |
6803 * Does not put quotes around strings, as ":echo" displays values. | 6803 * Does not put quotes around strings, as ":echo" displays values. |
6804 * When "copyID" is not NULL replace recursive lists and dicts with "...". | 6804 * When "copyID" is not NULL replace recursive lists and dicts with "...". |
6805 * May return NULL; | 6805 * May return NULL. |
6806 */ | 6806 */ |
6807 static char_u * | 6807 static char_u * |
6808 echo_string(tv, tofree, numbuf, copyID) | 6808 echo_string(tv, tofree, numbuf, copyID) |
6809 typval_T *tv; | 6809 typval_T *tv; |
6810 char_u **tofree; | 6810 char_u **tofree; |
6885 /* | 6885 /* |
6886 * Return a string with the string representation of a variable. | 6886 * Return a string with the string representation of a variable. |
6887 * If the memory is allocated "tofree" is set to it, otherwise NULL. | 6887 * If the memory is allocated "tofree" is set to it, otherwise NULL. |
6888 * "numbuf" is used for a number. | 6888 * "numbuf" is used for a number. |
6889 * Puts quotes around strings, so that they can be parsed back by eval(). | 6889 * Puts quotes around strings, so that they can be parsed back by eval(). |
6890 * May return NULL; | 6890 * May return NULL. |
6891 */ | 6891 */ |
6892 static char_u * | 6892 static char_u * |
6893 tv2string(tv, tofree, numbuf, copyID) | 6893 tv2string(tv, tofree, numbuf, copyID) |
6894 typval_T *tv; | 6894 typval_T *tv; |
6895 char_u **tofree; | 6895 char_u **tofree; |
14972 char_u numbuf1[NUMBUFLEN]; | 14972 char_u numbuf1[NUMBUFLEN]; |
14973 char_u numbuf2[NUMBUFLEN]; | 14973 char_u numbuf2[NUMBUFLEN]; |
14974 | 14974 |
14975 p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1, 0); | 14975 p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1, 0); |
14976 p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2, 0); | 14976 p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2, 0); |
14977 if (p1 == NULL) | |
14978 p1 = (char_u *)""; | |
14979 if (p2 == NULL) | |
14980 p2 = (char_u *)""; | |
14977 if (item_compare_ic) | 14981 if (item_compare_ic) |
14978 res = STRICMP(p1, p2); | 14982 res = STRICMP(p1, p2); |
14979 else | 14983 else |
14980 res = STRCMP(p1, p2); | 14984 res = STRCMP(p1, p2); |
14981 vim_free(tofree1); | 14985 vim_free(tofree1); |
15461 char_u *tofree; | 15465 char_u *tofree; |
15462 char_u numbuf[NUMBUFLEN]; | 15466 char_u numbuf[NUMBUFLEN]; |
15463 | 15467 |
15464 rettv->v_type = VAR_STRING; | 15468 rettv->v_type = VAR_STRING; |
15465 rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, 0); | 15469 rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, 0); |
15466 if (tofree == NULL) | 15470 /* Make a copy if we have a value but it's not in allocate memory. */ |
15471 if (rettv->vval.v_string != NULL && tofree == NULL) | |
15467 rettv->vval.v_string = vim_strsave(rettv->vval.v_string); | 15472 rettv->vval.v_string = vim_strsave(rettv->vval.v_string); |
15468 } | 15473 } |
15469 | 15474 |
15470 /* | 15475 /* |
15471 * "strlen()" function | 15476 * "strlen()" function |
20165 if (p_verbose >= 14) | 20170 if (p_verbose >= 14) |
20166 { | 20171 { |
20167 char_u buf[MSG_BUF_LEN]; | 20172 char_u buf[MSG_BUF_LEN]; |
20168 char_u numbuf2[NUMBUFLEN]; | 20173 char_u numbuf2[NUMBUFLEN]; |
20169 char_u *tofree; | 20174 char_u *tofree; |
20175 char_u *s; | |
20170 | 20176 |
20171 msg_puts((char_u *)"("); | 20177 msg_puts((char_u *)"("); |
20172 for (i = 0; i < argcount; ++i) | 20178 for (i = 0; i < argcount; ++i) |
20173 { | 20179 { |
20174 if (i > 0) | 20180 if (i > 0) |
20175 msg_puts((char_u *)", "); | 20181 msg_puts((char_u *)", "); |
20176 if (argvars[i].v_type == VAR_NUMBER) | 20182 if (argvars[i].v_type == VAR_NUMBER) |
20177 msg_outnum((long)argvars[i].vval.v_number); | 20183 msg_outnum((long)argvars[i].vval.v_number); |
20178 else | 20184 else |
20179 { | 20185 { |
20180 trunc_string(tv2string(&argvars[i], &tofree, | 20186 s = tv2string(&argvars[i], &tofree, numbuf2, 0); |
20181 numbuf2, 0), buf, MSG_BUF_CLEN); | 20187 if (s != NULL) |
20182 msg_puts(buf); | 20188 { |
20183 vim_free(tofree); | 20189 trunc_string(s, buf, MSG_BUF_CLEN); |
20190 msg_puts(buf); | |
20191 vim_free(tofree); | |
20192 } | |
20184 } | 20193 } |
20185 } | 20194 } |
20186 msg_puts((char_u *)")"); | 20195 msg_puts((char_u *)")"); |
20187 } | 20196 } |
20188 msg_puts((char_u *)"\n"); /* don't overwrite this either */ | 20197 msg_puts((char_u *)"\n"); /* don't overwrite this either */ |
20256 else | 20265 else |
20257 { | 20266 { |
20258 char_u buf[MSG_BUF_LEN]; | 20267 char_u buf[MSG_BUF_LEN]; |
20259 char_u numbuf2[NUMBUFLEN]; | 20268 char_u numbuf2[NUMBUFLEN]; |
20260 char_u *tofree; | 20269 char_u *tofree; |
20270 char_u *s; | |
20261 | 20271 |
20262 /* The value may be very long. Skip the middle part, so that we | 20272 /* The value may be very long. Skip the middle part, so that we |
20263 * have some idea how it starts and ends. smsg() would always | 20273 * have some idea how it starts and ends. smsg() would always |
20264 * truncate it at the end. */ | 20274 * truncate it at the end. */ |
20265 trunc_string(tv2string(fc.rettv, &tofree, numbuf2, 0), | 20275 s = tv2string(fc.rettv, &tofree, numbuf2, 0); |
20266 buf, MSG_BUF_CLEN); | 20276 if (s != NULL) |
20267 smsg((char_u *)_("%s returning %s"), sourcing_name, buf); | 20277 { |
20268 vim_free(tofree); | 20278 trunc_string(s, buf, MSG_BUF_CLEN); |
20279 smsg((char_u *)_("%s returning %s"), sourcing_name, buf); | |
20280 vim_free(tofree); | |
20281 } | |
20269 } | 20282 } |
20270 msg_puts((char_u *)"\n"); /* don't overwrite this either */ | 20283 msg_puts((char_u *)"\n"); /* don't overwrite this either */ |
20271 | 20284 |
20272 verbose_leave_scroll(); | 20285 verbose_leave_scroll(); |
20273 --no_wait_return; | 20286 --no_wait_return; |