summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-04-18 06:01:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-04-18 06:01:52 -0700
commit9cfc6030cf1c38e37345d8e85396ee03bffa67b3 (patch)
tree25fc8ce3a1ed5067f99cb902c04657111fa9a354 /hash.c
parent6eeb29dc80b218019ee927b69d1260a61f7ff3f8 (diff)
downloadtxr-9cfc6030cf1c38e37345d8e85396ee03bffa67b3.tar.gz
txr-9cfc6030cf1c38e37345d8e85396ee03bffa67b3.tar.bz2
txr-9cfc6030cf1c38e37345d8e85396ee03bffa67b3.zip
Support max length and depth for object printing.
* hash.c (hash_print_op): Implement max length. * lib.c (lazy_str_put, out_lazy_str): Take struct strm_base * parameter and implement max length. (out_quasi_str_sym): Don't use obj_print_impl for symbol's name string; just put_string. The use of obj_print_impl causes symbols appearing as variables in quasiliterals to be truncated when max length is imposed. (out_quasi_str): Implement max length. (obj_print_impl): Implement max length and depth. Note that there is now always a non-null ctx pointer. (obj_print): Always set up context pointer for obj_print_impl. Context now has pointer to low-level stream structure, where we can access max_length and max_depth. It also carries the recursion depth. * lib.h (lazy_str_put): Declaration updated. * stream.c (strm_base_init): Add initializers for max_length and max_depth. (put_string): Pass stream structure to lazy_str_put. (set_max_length, set_max_depth): New functions. (stream_init): set-max-length and set-max-depth intrinsics registered. * stream.h (struct strm_ctx): New members depth and strm. (struct strm_base): New members max_length and max_depth. (set_max_length, set_max_depth): Declared. * txr.1: Documented.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 2bf527b9..1aaaa375 100644
--- a/hash.c
+++ b/hash.c
@@ -494,12 +494,20 @@ static void hash_print_op(val hash, val out, val pretty, struct strm_ctx *ctx)
put_string(lit(")"), out);
{
val iter = hash_begin(hash), cell;
+ cnum max_len = ctx->strm->max_length;
+ cnum max_count = max_len;
+
while ((cell = hash_next(iter))) {
val key = us_car(cell);
val value = us_cdr(cell);
if (width_check(out, chr(' ')))
force_br = 1;
+ if (max_len && --max_count < 0) {
+ put_string(lit("..."), out);
+ break;
+ }
+
put_string(lit("("), out);
obj_print_impl(key, out, pretty, ctx);