From 9cfc6030cf1c38e37345d8e85396ee03bffa67b3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 18 Apr 2019 06:01:52 -0700 Subject: 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. --- stream.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'stream.h') diff --git a/stream.h b/stream.h index a7895064..cba0330a 100644 --- a/stream.h +++ b/stream.h @@ -42,6 +42,8 @@ struct strm_ctx { val obj_hash; val obj_hash_prev; val counter; + cnum depth; + struct strm_base *strm; }; struct strm_base { @@ -51,6 +53,8 @@ struct strm_base { cnum indent_chars; cnum column; unsigned force_break; + cnum max_length; + cnum max_depth; struct strm_ctx *ctx; }; @@ -213,6 +217,8 @@ val set_indent(val stream, val indent); val inc_indent(val stream, val delta); val width_check(val stream, val alt); val force_break(val stream); +val set_max_length(val stream, val length); +val set_max_depth(val stream, val depth); struct strm_ctx *get_set_ctx(val stream, struct strm_ctx *); struct strm_ctx *get_ctx(val stream); val get_string(val stream, val nchars, val close_after_p); -- cgit v1.2.3