From 8fb0cbf4720d1a3ae16e6afb3b1997700d06914a Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Sun, 25 Aug 2019 17:32:14 +0300 Subject: [PATCH] Finish re-arranging printer options --- c/print.h | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/c/print.h b/c/print.h index 27e5b3a..cb955e0 100644 --- a/c/print.h +++ b/c/print.h @@ -1,17 +1,11 @@ extern void *memrchr(const void *s, int c, size_t n); struct printer_options { - int display; // Use `display` repr instead of `write` repr - int indent; // Write indented lines instead of one long line. - - // *print-width* -- maximum line length when indenting, ignored when not - int width; - - // *print-length* -- truncate lists after N items and write "..." - fixnum_t length; - - // *print-level* -- print only the outermost N levels of nested structures - fixnum_t level; + int display; // Use `display` repr instead of `write` repr + int indent; // Write indented lines instead of one long line. + int width; // maximum line length when indenting, ignored when not + fixnum_t length; // truncate lists after N items and write "..." + fixnum_t level; // print only the outermost N levels of nested structure }; struct printer { @@ -892,24 +886,15 @@ void fl_print(struct ios *f, value_t v) struct printer_options opts; value_t pl; + memset(&opts, 0, sizeof(opts)); + // *print-readably* opts.display = (symbol_value(printreadablysym) == FL_F); // *print-pretty* opts.indent = (symbol_value(printprettysym) != FL_F); - pl = symbol_value(printlengthsym); - if (isfixnum(pl)) - opts.length = numval(pl); - else - opts.length = -1; - - pl = symbol_value(printlevelsym); - if (isfixnum(pl)) - opts.level = numval(pl); - else - opts.level = -1; - + // *print-width* pl = symbol_value(printwidthsym); if (isfixnum(pl)) opts.width = numval(pl); @@ -918,5 +903,19 @@ void fl_print(struct ios *f, value_t v) if (opts.width < 20) opts.width = 20; + // *print-length* + pl = symbol_value(printlengthsym); + if (isfixnum(pl)) + opts.length = numval(pl); + else + opts.length = -1; + + // *print-level* + pl = symbol_value(printlevelsym); + if (isfixnum(pl)) + opts.level = numval(pl); + else + opts.level = -1; + print_with_options(f, v, &opts); }