]> mj.ucw.cz Git - paperjam.git/commitdiff
Cleaned up debugging messages
authorMartin Mares <mj@ucw.cz>
Sat, 7 Apr 2018 08:14:11 +0000 (10:14 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 7 Apr 2018 08:14:11 +0000 (10:14 +0200)
TODO
cmds.cc
jam.h
paperjam.cc
parse.cc
pdf.cc

diff --git a/TODO b/TODO
index 6583cfca65c9bb45ff6f42410d0a46954ab8ae83..e0f9465351164a77d0f46dd577d8fd1b9fa08cf4 100644 (file)
--- 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 c809884027c02b8e78ab7b6e0be30efcf3c1c3d3..ece509d8cfb9efa6c5a16c1175011cb196b0f461 100644 (file)
--- 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<page *> &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 b70041b4e2e9a11cab68108532c9aba5cbf1b609..9081c558c861bfd2551b0a941887f7b32680b7a6 100644 (file)
--- 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);
index f5a08f97da4a4ccd762ca3ea21207d7bd9abfa52..f49fd7cc1e96745b94b695ac0510596b19063fab 100644 (file)
 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
index 8e7de38b3aec6a52f57a3f72bb23a98158f3aee4..5f1b1d035c119ee1a729e5f1900f1232b288e80a 100644 (file)
--- a/parse.cc
+++ b/parse.cc
@@ -493,12 +493,14 @@ static void instantiate(list<cmd *> &cmds)
 
 void parse(const char *in, list<cmd *> &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 f262f5ba6952554dde4444fbd572aaab2d4c547f..d54506e6d669071b1771fcb1a45d96dda6d19afc 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -75,7 +75,7 @@ void in_page::render(out_context *out, pdf_matrix xform)
 
 void debug_pages(vector<page *> &pages)
 {
-  if (!debug_mode)
+  if (!debug_level)
     return;
 
   for (auto pg: pages)
@@ -111,6 +111,7 @@ vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
 
 void process(list<cmd *> &cmds)
 {
+  debug("### Reading input");
   in_pdf.processFile(in_name);
   in_pdf.pushInheritedAttributesToPage();
   out_pdf.emptyPDF();
@@ -127,8 +128,10 @@ void process(list<cmd *> &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<cmd *> &cmds)
   // Write the output file
   QPDFWriter writer(out_pdf, out_name);
   writer.write();
+  debug("### Done");
 }
 
 /*** Re-calculation of bboxes ***/