summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-22 18:29:09 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-22 18:29:09 -0800
commite4e0db3b369e74bd9a619b190f710706a40a64d4 (patch)
treee705e8a3fe5ac4b3e2705bf576f63e43cce16f2d /stream.c
parentcd7f176ebd9de3e731d4f02223c796b6738dd217 (diff)
downloadtxr-e4e0db3b369e74bd9a619b190f710706a40a64d4.tar.gz
txr-e4e0db3b369e74bd9a619b190f710706a40a64d4.tar.bz2
txr-e4e0db3b369e74bd9a619b190f710706a40a64d4.zip
* stream.c (vformat): If width is specified for ~s or ~a, and
the object is not a string or number, then print it to a string and treat it as a string, adjusting it within the field. Also, do not simply abort on an unknown format directive but throw a proper exception.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/stream.c b/stream.c
index f959898e..38af8afe 100644
--- a/stream.c
+++ b/stream.c
@@ -1020,6 +1020,11 @@ val vformat(val stream, val fmtstr, va_list vl)
pnum = (char *) chk_malloc(nchars + 1);
mp_toradix(mp(obj), (unsigned char *) pnum, 10);
goto output_num;
+ } else if (width != 0) {
+ val str = format(nil, ch == 'a' ? lit("~a") : lit("~s"), obj, nao);
+ if (!vformat_str(stream, str, width, left, precision))
+ return nil;
+ continue;
}
if (ch == 'a')
obj_pprint(obj, stream);
@@ -1032,7 +1037,8 @@ val vformat(val stream, val fmtstr, va_list vl)
sprintf(num_buf, num_fmt->hex, value);
goto output_num;
default:
- abort();
+ uw_throwf(error_s, lit("unknown format directive character ~s\n"),
+ chr(ch), nao);
output_num:
{
val res = vformat_num(stream, pnum, width, left,