groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 06/10: [libgroff, troff]: Add debug diagnostic level.


From: G. Branden Robinson
Subject: [groff] 06/10: [libgroff, troff]: Add debug diagnostic level.
Date: Mon, 26 Jul 2021 20:38:49 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 93ffeffd21868f64af7302cb9574240c8354c60a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jul 26 18:04:16 2021 +1000

    [libgroff, troff]: Add debug diagnostic level.
    
    * src/include/error.h: Declare functions `debug_with_file_and_line` and
      `debug`.
    * src/libs/libgroff/error.cpp: Add `DEBUG` to enum `error_type`.
    
      (do_error_with_file_and_line): Add case for `DEBUG` in switch.
    
      (debug, debug_with_file_and_line): Add new functions.
    
    Do the same for troff since it has a private implementation of the
    diagnostic functions (thanks to `output_warning()`).
    
    * src/roff/troff/input.cpp: Add `DEBUG` to enum `error_type`.
    
      (do_error_with_file_and_line): Add case for `DEBUG` in switch.
    
      (debug, debug_with_file_and_line): Add new functions.
    
    There are no call sites for debug() and I don't plan for there to be; I
    am adding these for developer convenience because it's the second time
    I've had to do so and I told myself after the first (ripping them back
    out after they'd helped me solve a problem) that if I ever needed them
    again I'd add them permanently.
---
 ChangeLog                   | 17 +++++++++++++++++
 src/include/error.h         | 11 +++++++++++
 src/libs/libgroff/error.cpp | 23 ++++++++++++++++++++++-
 src/roff/troff/input.cpp    | 28 +++++++++++++++++++++++++++-
 4 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 65ac337..1317073 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2021-07-26  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [libgroff, troff]: Add debug diagnostic level.
+
+       * src/include/error.h: Declare functions
+       `debug_with_file_and_line` and `debug`.
+       * src/libs/libgroff/error.cpp: Add `DEBUG` to enum `error_type`.
+       (do_error_with_file_and_line): Add case for `DEBUG` in switch.
+       (debug, debug_with_file_and_line): Add new functions.
+
+       Do the same for troff since it has a private implementation of
+       the diagnostic functions (thanks to `output_warning()`).
+
+       * src/roff/troff/input.cpp: Add `DEBUG` to enum `error_type`.
+       (do_error_with_file_and_line): Add case for `DEBUG` in switch.
+       (debug, debug_with_file_and_line): Add new functions.
+
+2021-07-26  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * src/utils/hpftodit/hpftodit.cpp (hp_msl_to_ucode_name,
        unicode_to_ucode_name): Hush "format nonliteral" compiler
        warnings by using a preprocessor-defined string literal as an
diff --git a/src/include/error.h b/src/include/error.h
index 4a2aaf8..6784c51 100644
--- a/src/include/error.h
+++ b/src/include/error.h
@@ -35,6 +35,12 @@ extern void warning_with_file_and_line(const char *filename, 
int lineno,
                                     const errarg &arg2 = empty_errarg,
                                     const errarg &arg3 = empty_errarg);
 
+extern void debug_with_file_and_line(const char *filename, int lineno,
+                                    const char *format,
+                                    const errarg &arg1 = empty_errarg,
+                                    const errarg &arg2 = empty_errarg,
+                                    const errarg &arg3 = empty_errarg);
+
 extern void fatal(const char *,
                  const errarg &arg1 = empty_errarg,
                  const errarg &arg2 = empty_errarg,
@@ -50,6 +56,11 @@ extern void warning(const char *,
                    const errarg &arg2 = empty_errarg,
                    const errarg &arg3 = empty_errarg);
 
+extern void debug(const char *,
+                 const errarg &arg1 = empty_errarg,
+                 const errarg &arg2 = empty_errarg,
+                 const errarg &arg3 = empty_errarg);
+
 
 extern "C" const char *program_name;
 extern int current_lineno;
diff --git a/src/libs/libgroff/error.cpp b/src/libs/libgroff/error.cpp
index 0753149..fb76783 100644
--- a/src/libs/libgroff/error.cpp
+++ b/src/libs/libgroff/error.cpp
@@ -29,7 +29,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 extern void fatal_error_exit();
 
-enum error_type { WARNING, ERROR, FATAL };
+enum error_type { DEBUG, WARNING, ERROR, FATAL };
 
 static void do_error_with_file_and_line(const char *filename,
                                        const char *source_filename,
@@ -66,6 +66,9 @@ static void do_error_with_file_and_line(const char *filename,
   case WARNING:
     fputs("warning: ", stderr);
     break;
+  case DEBUG:
+    fputs("debug: ", stderr);
+    break;
   }
   errprint(format, arg1, arg2, arg3);
   fputc('\n', stderr);
@@ -85,6 +88,13 @@ static void do_error(error_type type,
                              current_lineno, type, format, arg1, arg2, arg3);
 }
 
+void debug(const char *format,
+          const errarg &arg1,
+          const errarg &arg2,
+          const errarg &arg3)
+{
+  do_error(DEBUG, format, arg1, arg2, arg3);
+}
 
 void error(const char *format, 
           const errarg &arg1,
@@ -110,6 +120,17 @@ void fatal(const char *format,
   do_error(FATAL, format, arg1, arg2, arg3);
 }
 
+void debug_with_file_and_line(const char *filename,
+                             int lineno,
+                             const char *format,
+                             const errarg &arg1,
+                             const errarg &arg2,
+                             const errarg &arg3)
+{
+  do_error_with_file_and_line(filename, 0, lineno,
+                             DEBUG, format, arg1, arg2, arg3);
+}
+
 void error_with_file_and_line(const char *filename,
                              int lineno,
                              const char *format, 
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 4289d4f..2a94e64 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8702,7 +8702,7 @@ static void copy_mode_error(const char *format,
     error(format, arg1, arg2, arg3);
 }
 
-enum error_type { WARNING, OUTPUT_WARNING, ERROR, FATAL };
+enum error_type { DEBUG, WARNING, OUTPUT_WARNING, ERROR, FATAL };
 
 static void do_error(error_type type,
                     const char *format,
@@ -8735,6 +8735,9 @@ static void do_error(error_type type,
   case WARNING:
     fputs("warning: ", stderr);
     break;
+  case DEBUG:
+    fputs("debug: ", stderr);
+    break;
   case OUTPUT_WARNING:
     double fromtop = topdiv->get_vertical_position().to_units() / warn_scale;
     fprintf(stderr, "warning [p %d, %.1f%c",
@@ -8755,6 +8758,14 @@ static void do_error(error_type type,
     cleanup_and_exit(1);
 }
 
+void debug(const char *format,
+          const errarg &arg1,
+          const errarg &arg2,
+          const errarg &arg3)
+{
+  do_error(DEBUG, format, arg1, arg2, arg3);
+}
+
 int warning(warning_type t,
            const char *format,
            const errarg &arg1,
@@ -8826,6 +8837,21 @@ void error_with_file_and_line(const char *filename, int 
lineno,
   fflush(stderr);
 }
 
+void debug_with_file_and_line(const char *filename,
+                             int lineno,
+                             const char *format,
+                             const errarg &arg1,
+                             const errarg &arg2,
+                             const errarg &arg3)
+{
+  if (program_name)
+    fprintf(stderr, "%s: ", program_name);
+  fprintf(stderr, "%s:%d: debug: ", filename, lineno);
+  errprint(format, arg1, arg2, arg3);
+  fputc('\n', stderr);
+  fflush(stderr);
+}
+
 dictionary charinfo_dictionary(501);
 
 charinfo *get_charinfo(symbol nm)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]