Finish re-arranging printer options

This commit is contained in:
Lassi Kortela 2019-08-25 17:32:14 +03:00
parent 844b2e219c
commit 8fb0cbf472
1 changed files with 22 additions and 23 deletions

View File

@ -3,15 +3,9 @@ extern void *memrchr(const void *s, int c, size_t n);
struct printer_options { struct printer_options {
int display; // Use `display` repr instead of `write` repr int display; // Use `display` repr instead of `write` repr
int indent; // Write indented lines instead of one long line. int indent; // Write indented lines instead of one long line.
int width; // maximum line length when indenting, ignored when not
// *print-width* -- maximum line length when indenting, ignored when not fixnum_t length; // truncate lists after N items and write "..."
int width; fixnum_t level; // print only the outermost N levels of nested structure
// *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;
}; };
struct printer { struct printer {
@ -892,24 +886,15 @@ void fl_print(struct ios *f, value_t v)
struct printer_options opts; struct printer_options opts;
value_t pl; value_t pl;
memset(&opts, 0, sizeof(opts));
// *print-readably* // *print-readably*
opts.display = (symbol_value(printreadablysym) == FL_F); opts.display = (symbol_value(printreadablysym) == FL_F);
// *print-pretty* // *print-pretty*
opts.indent = (symbol_value(printprettysym) != FL_F); opts.indent = (symbol_value(printprettysym) != FL_F);
pl = symbol_value(printlengthsym); // *print-width*
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;
pl = symbol_value(printwidthsym); pl = symbol_value(printwidthsym);
if (isfixnum(pl)) if (isfixnum(pl))
opts.width = numval(pl); opts.width = numval(pl);
@ -918,5 +903,19 @@ void fl_print(struct ios *f, value_t v)
if (opts.width < 20) if (opts.width < 20)
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); print_with_options(f, v, &opts);
} }