gbranden pushed a commit to branch master
in repository groff.

commit 80a7b8f8c7cdc2ccad4ac62cb9b10d885fea7db9
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Sun Feb 23 21:06:23 2025 -0600

    [eqn,preconv,refer,tbl]: Trivially refactor.
    
    * src/preproc/eqn/main.cpp (do_file):
    * src/preproc/preconv/preconv.cpp (do_file):
    * src/preproc/refer/refer.cpp (do_file):
    * src/preproc/tbl/main.cpp (main): Use a consistent pattern when writing
      `lf` requests to output; employ an {f,}printf(3) call parameterized in
      the line number and file name, explicitly discard its return value,
      and assign to the globals `current_lineno` and `current_filename`
      beforehand.
---
 ChangeLog                       | 13 +++++++++++++
 src/preproc/eqn/main.cpp        |  4 ++--
 src/preproc/preconv/preconv.cpp |  2 +-
 src/preproc/refer/refer.cpp     |  5 +++--
 src/preproc/tbl/main.cpp        | 14 ++++++++------
 5 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cffd7a755..1b53c48ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-02-23  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       [eqn,preconv,refer,tbl]: Trivially refactor.
+
+       * src/preproc/eqn/main.cpp (do_file):
+       * src/preproc/preconv/preconv.cpp (do_file):
+       * src/preproc/refer/refer.cpp (do_file):
+       * src/preproc/tbl/main.cpp (main): Use a consistent pattern when
+       writing `lf` requests to output; employ an {f,}printf(3) call
+       parameterized in the line number and file name, explicitly
+       discard its return value, and assign to the globals
+       `current_lineno` and `current_filename` beforehand.
+
 2025-02-23  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        [eqn,pic,preconv,refer,soelim,tbl]: Use `lf` requests more
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 9e78c85c7..e537d206a 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -103,10 +103,10 @@ void do_file(FILE *fp, const char *filename)
   string fn(filename);
   fn += '\0';
   normalize_for_lf(fn);
+  current_lineno = 1;
   current_filename = fn.contents();
   if (output_format == troff)
-    printf(".lf 1 \"%s\n", current_filename);
-  current_lineno = 1;
+    (void) printf(".lf %d \"%s\n", current_lineno, current_filename);
   while (read_line(fp, &linebuf)) {
     if (linebuf.length() >= 4
        && linebuf[0] == '.' && linebuf[1] == 'l' && linebuf[2] == 'f'
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index ca9d43983..cd3d34a2a 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -1197,7 +1197,7 @@ do_file(const char *filename)
     string fn(filename);
     fn += '\0';
     normalize_for_lf(fn);
-    printf(".lf 1 \"%s\n", fn.contents());
+    (void) printf(".lf 1 \"%s\n", fn.contents());
   }
   int success = 1;
   // Call converter (converters write to stdout).
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index 38a74d61a..a51518360 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -473,9 +473,10 @@ static void do_file(const char *filename)
   string fn(filename);
   fn += '\0';
   normalize_for_lf(fn);
-  current_filename = fn.contents();
-  fprintf(outfp, ".lf 1 \"%s\n", current_filename);
   current_lineno = 1;
+  current_filename = fn.contents();
+  (void) fprintf(outfp, ".lf %d \"%s\n", current_lineno,
+                current_filename);
   string line;
   for (;;) {
     line.clear();
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 17d4fca0b..d068d1f08 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1706,9 +1706,10 @@ int main(int argc, char **argv)
   if (argc > optind) {
     for (int i = optind; i < argc; i++)
       if (argv[i][0] == '-' && argv[i][1] == '\0') {
-       current_filename = "-";
        current_lineno = 1;
-       printf(".lf 1 -\n");
+       current_filename = "-";
+       (void) printf(".lf %d \"\%s\n", current_lineno,
+                     current_filename);
        process_input_file(stdin);
       }
       else {
@@ -1719,20 +1720,21 @@ int main(int argc, char **argv)
          fatal("cannot open '%1': %2", argv[i], strerror(errno));
        }
        else {
-         current_lineno = 1;
          string fn(argv[i]);
          fn += '\0';
          normalize_for_lf(fn);
+         current_lineno = 1;
          current_filename = fn.contents();
-         printf(".lf 1 \"%s\n", current_filename);
+         (void) printf(".lf %d \"\%s\n", current_lineno,
+                       current_filename);
          process_input_file(fp);
        }
       }
   }
   else {
-    current_filename = "-";
     current_lineno = 1;
-    printf(".lf 1 -\n");
+    current_filename = "-";
+    (void) printf(".lf %d \"\%s\n", current_lineno, current_filename);
     process_input_file(stdin);
   }
   if (ferror(stdout))

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to