From 397e0acf90c4e5cf2fb2cfea8708cebf0a39da7e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 7 Apr 2018 10:14:11 +0200 Subject: [PATCH] Cleaned up debugging messages --- TODO | 3 ++- cmds.cc | 14 +++++++++----- jam.h | 2 +- paperjam.cc | 6 +++--- parse.cc | 4 +++- pdf.cc | 6 +++++- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index 6583cfc..e0f9465 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,8 @@ - What if an input page specifies /Rotate? - "-f" switch - Help -- Clean up debugging messages, use more levels +- Parameters vs. arguments +- More precise parsing errors | # Position bbox on a new paper | paper("a4") diff --git a/cmds.cc b/cmds.cc index c809884..ece509d 100644 --- a/cmds.cc +++ b/cmds.cc @@ -1162,10 +1162,11 @@ void nup_cmd::try_config(nup_state &st) st.scale = scale_to_fit(image, window); st.fill_factor = (st.scale*image.width() * st.scale*image.height()) / (st.paper_w * st.paper_h); - debug("Try: %dx%d on %.3f x %.3f => scale %.3f, fill %.6f", - st.cols, st.rows, - st.paper_w, st.paper_h, - st.scale, st.fill_factor); + if (debug_level > 1) + debug("Try: %dx%d on %.3f x %.3f => scale %.3f, fill %.6f", + st.cols, st.rows, + st.paper_w, st.paper_h, + st.scale, st.fill_factor); if (!found_solution || best.fill_factor < st.fill_factor) { @@ -1251,7 +1252,10 @@ void nup_cmd::find_config(vector &in, BBox *page_boxes) if (!found_solution) err("No feasible solution found"); - debug("Best: %dx%d on %.3f x %.3f", best.cols, best.rows, best.paper_w, best.paper_h); + debug("Best: %dx%d on %.3f x %.3f => scale %.3f, fill %.6f", + best.cols, best.rows, + best.paper_w, best.paper_h, + best.scale, best.fill_factor); debug_indent -= 4; } diff --git a/jam.h b/jam.h index b70041b..9081c55 100644 --- a/jam.h +++ b/jam.h @@ -139,7 +139,7 @@ struct pipeline { extern const char *in_name, *out_name; extern bool recalc_bbox; -extern int debug_mode; +extern int debug_level; extern int debug_indent; void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2); diff --git a/paperjam.cc b/paperjam.cc index f5a08f9..f49fd7c 100644 --- a/paperjam.cc +++ b/paperjam.cc @@ -17,14 +17,14 @@ const char *in_name; const char *out_name; bool recalc_bbox; -int debug_mode; +int debug_level; int debug_indent; /*** Messages ***/ void debug(const char *msg, ...) { - if (!debug_mode) + if (!debug_level) return; va_list args; va_start(args, msg); @@ -104,7 +104,7 @@ int main(int argc, char **argv) recalc_bbox = 1; break; case 'd': - debug_mode++; + debug_level++; break; case OPT_VERSION: printf("This is paperjam with no version yet.\n"); // FIXME diff --git a/parse.cc b/parse.cc index 8e7de38..5f1b1d0 100644 --- a/parse.cc +++ b/parse.cc @@ -493,12 +493,14 @@ static void instantiate(list &cmds) void parse(const char *in, list &cmds) { + debug("### Parsing commands"); in_pos = in; parse_commands(cmds); if (next_token() != TOK_END) parse_error("Extra tokens after commands"); - debug_cmds(cmds); + if (debug_level > 1) + debug_cmds(cmds); instantiate(cmds); } diff --git a/pdf.cc b/pdf.cc index f262f5b..d54506e 100644 --- a/pdf.cc +++ b/pdf.cc @@ -75,7 +75,7 @@ void in_page::render(out_context *out, pdf_matrix xform) void debug_pages(vector &pages) { - if (!debug_mode) + if (!debug_level) return; for (auto pg: pages) @@ -111,6 +111,7 @@ vector run_command_list(list &cmds, vector &pages) void process(list &cmds) { + debug("### Reading input"); in_pdf.processFile(in_name); in_pdf.pushInheritedAttributesToPage(); out_pdf.emptyPDF(); @@ -127,8 +128,10 @@ void process(list &cmds) if (recalc_bbox) do_recalc_bbox(pages, in_name); + debug("### Running commands"); pages = run_command_list(cmds, pages); + debug("### Writing output"); for (auto pg: pages) { out_context out; @@ -172,6 +175,7 @@ void process(list &cmds) // Write the output file QPDFWriter writer(out_pdf, out_name); writer.write(); + debug("### Done"); } /*** Re-calculation of bboxes ***/ -- 2.39.2