groff-commit
[Top][All Lists]
Advanced

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

[groff] 01/23: [libgroff]: Slightly refactor `scan_papersize`.


From: G. Branden Robinson
Subject: [groff] 01/23: [libgroff]: Slightly refactor `scan_papersize`.
Date: Thu, 23 Sep 2021 08:12:30 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 66b45cef887999fbd1b20cb4c36f2f4f029caf82
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Sep 19 08:00:33 2021 +1000

    [libgroff]: Slightly refactor `scan_papersize`.
    
    * src/include/font.h (font::scan_papersize): Demote return type from
      `int` to `bool`.
    * src/libs/libgroff/font.cpp (font::scan_papersize): As above.  Use
      Boolean instead of integer literals.  Also rename `FILE` stream
      pointer from `f` to `fp` and perform an explicit comparison against
      the idiomatic C++98 null pointer constant.
---
 ChangeLog                  | 11 +++++++++++
 src/include/font.h         | 13 +++++++------
 src/libs/libgroff/font.cpp | 18 +++++++++---------
 3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0c965d4..fd7dba8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2021-09-19  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [libgroff]: Slightly refactor.
+
+       * src/include/font.h (font::scan_papersize): Demote return type
+       from `int` to `bool`.
+       * src/libs/libgroff/font.cpp (font::scan_papersize): As above.
+       Use Boolean instead of integer literals.  Also rename `FILE`
+       stream pointer from `f` to `fp` and perform an explicit
+       comparison against the idiomatic C++98 null pointer constant.
+
 2021-09-17  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [libgroff, troff]: Slightly refactor device and font description
diff --git a/src/include/font.h b/src/include/font.h
index f0e294a..f5c07c9 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -194,12 +194,13 @@ public:
   const char *get_image_generator();   // Return the 'image_generator'
                        // attribute of this font.  Return NULL if it has
                        // none.
-  static int scan_papersize(const char *, const char **,
-                           double *, double *);        // Parse the
-                       // 'papersize' attribute in a DESC file (given in
-                       // arg1).  Return the name of the size (in arg2),
-                       // and the length and width (in arg3 and arg4).
-                       // Return 1 in case of success, 0 otherwise.
+  static bool scan_papersize(const char *, const char **,
+                            double *, double *); // Parse the
+                       // 'papersize' directive in the DESC file name
+                       // given in arg1.  Update arg2 with the name
+                       // of the paper format and arg3 and arg4 with
+                       // its length and width, respectively.  Return
+                       // whether paper size was successfully set.
   static font *load_font(const char *, bool = false); // Load the font
                        // description file with the given name (arg1)
                        // and return a pointer to a 'font' object.  If
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index a501c71..0514e4e 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -704,8 +704,8 @@ static char *trim_arg(char *p)
   return p;
 }
 
-int font::scan_papersize(const char *p,
-                        const char **size, double *length, double *width)
+bool font::scan_papersize(const char *p, const char **size,
+                         double *length, double *width)
 {
   double l, w;
   char lu[2], wu[2];
@@ -723,7 +723,7 @@ again:
        *width = w;
       if (size)
        *size = "custom";
-      return 1;
+      return true;
     }
   }
   else {
@@ -736,12 +736,12 @@ again:
          *width = papersizes[i].width;
        if (size)
          *size = papersizes[i].name;
-       return 1;
+       return true;
       }
     if (attempt_file_open) {
-      FILE *f = fopen(p, "r");
-      if (f) {
-       if (fgets(line, 254, f)) {
+      FILE *fp = fopen(p, "r");
+      if (fp != 0) {
+       if (fgets(line, 254, fp)) {
          // Don't recurse on file names.
          attempt_file_open = false;
          char *linep = strchr(line, '\0');
@@ -750,12 +750,12 @@ again:
            *linep = '\0';
          pp = line;
        }
-       fclose(f);
+       fclose(fp);
        goto again;
       }
     }
   }
-  return 0;
+  return false;
 }
 
 bool font::load(bool load_header_only)



reply via email to

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