groff-commit
[Top][All Lists]
Advanced

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

[groff] 15/19: [libgroff, troff]: Further boolify.


From: G. Branden Robinson
Subject: [groff] 15/19: [libgroff, troff]: Further boolify.
Date: Thu, 16 Sep 2021 08:59:04 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 4662bbb7d60e2842cbee4fbe8616fb40f24dd9cb
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Sep 15 12:06:30 2021 +1000

    [libgroff, troff]: Further boolify.
    
    * src/include/font.h (load_font, font): Demote parameters from {pointer
      to} `int` to `bool` and update default literal from integer to Boolean
      (except for the pointer).  Update comment.
    * src/libs/libgroff/font.cpp (load_font, load): Similarly.
    
    * src/roff/troff/node.h (mount_font):
    * src/roff/troff/node.cpp (mount_font): Demote return type from `int` to
      `bool`.
    
    * src/roff/troff/node.h (mount_style):
    * src/roff/troff/node.cpp (mount_style): Promote return type from `void`
      to `bool`.
    
    * src/roff/troff/node.cpp (mount_font_no_translate): Demote return type
      and `check_only` parameter from `int` to `bool` and use Boolean rather
      than integer literals with them.
    
      (check_font): Update call site of `mount_font_no_translate` to use
      Boolean literal.
    
      (font_position): Indicate that "error" is ignored by casting return
      value of `mount_font` to void instead of using a comment.
    
      (style): Cast return value of `mount_style` to `void`.
    
    The return value of `mount_style` will be used elsewhere in a
    forthcoming commit.
---
 ChangeLog                  | 26 ++++++++++++++++++++++++++
 src/include/font.h         | 25 +++++++++++++------------
 src/libs/libgroff/font.cpp |  4 ++--
 src/roff/troff/node.cpp    | 37 +++++++++++++++++++++----------------
 src/roff/troff/node.h      |  4 ++--
 5 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f971653..beefddd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
 2021-09-15  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       * [libgroff, troff]: Further boolify.
+
+       * src/include/font.h (load_font, font): Demote parameters from
+       {pointer to} `int` to `bool` and update default literal from
+       integer to Boolean (except for the pointer).  Update comment.
+       * src/libs/libgroff/font.cpp (load_font, load): Similarly.
+
+       * src/roff/troff/node.h (mount_font):
+       * src/roff/troff/node.cpp (mount_font): Demote return type from
+       `int` to `bool`.
+
+       * src/roff/troff/node.h (mount_style):
+       * src/roff/troff/node.cpp (mount_style): Promote return type
+       from `void` to `bool`.
+
+       * src/roff/troff/node.cpp (mount_font_no_translate): Demote
+       return type and `check_only` parameter from `int` to `bool` and
+       use Boolean rather than integer literals with them.
+       (check_font): Update call site of `mount_font_no_translate` to
+       use Boolean literal.
+       (font_position): Indicate that "error" is ignored by casting
+       return value of `mount_font` to void instead of using a comment.
+       (style): Cast return value of `mount_style` to `void`.
+
+2021-09-15  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * Makefile.am: Add `.DELETE_ON_ERROR` special target; both GNU
        and FreeBSD make(1)s support it so maybe it will be portable
        enough.  This avoids, among other problems, a target appearing
diff --git a/src/include/font.h b/src/include/font.h
index dda72d6..1eb3460 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -200,16 +200,17 @@ public:
                        // 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 font *load_font(const char *, int * = 0, int = 0);    // Load the
-                       // font description file with the given name (arg1)
-                       // and return it as a 'font' class.  If arg2 points
-                       // to an integer variable, set it to 1 if the file
-                       // is not found, without emitting an error message.
-                       // If arg2 is NULL, print an error message if the
-                       // file is not found.  If arg3 is nonzero, only the
-                       // part of the font description file before the
-                       // 'charset' and 'kernpairs' sections is loaded.
-                       // Return NULL in case of failure.
+  static font *load_font(const char *, int * = 0, bool = false); // Load
+                       // the font description file with the given name
+                       // (arg1) and return it as a 'font' class.  If
+                       // arg2 points to an integer variable, set it to
+                       // 1 if the file is not found, without emitting
+                       // an error message.  If arg2 is NULL, print an
+                       // error message if the file is not found.  If
+                       // arg3 is true, only the part of the font
+                       // description file before the 'charset' and
+                       // 'kernpairs' sections is loaded.  Return NULL
+                       // in case of failure.
   static void command_line_font_dir(const char *);     // Prepend given
                        // path (arg1) to the list of directories in which
                        // to look up fonts.
@@ -333,10 +334,10 @@ protected:
   // `name` into this object.  If arg1 points to an integer variable,
   // set it to 1 if the file is not found and do not emit an error
   // message.  If arg1 is 0, print an error message if the file is not
-  // found.  If arg2 is nonzero, only the part of the font description
+  // found.  If arg2 is true, only the part of the font description
   // file before the 'charset' and 'kernpairs' sections is loaded.
   // Return success/failure status of load.
-  bool load(int * = 0, int = 0);
+  bool load(int * = 0, bool = false);
 };
 
 // Local Variables:
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 9c50930..861b04c 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -680,7 +680,7 @@ void font::copy_entry(glyph *new_glyph, glyph *old_glyph)
   ch_index[new_index] = ch_index[old_index];
 }
 
-font *font::load_font(const char *s, int *not_found, int head_only)
+font *font::load_font(const char *s, int *not_found, bool head_only)
 {
   font *f = new font(s);
   if (!f->load(not_found, head_only)) {
@@ -760,7 +760,7 @@ again:
 // If the font can't be found, then if not_found is non-NULL, it will be
 // set to 1 otherwise a message will be printed.
 
-bool font::load(int *not_found, int head_only)
+bool font::load(int *not_found, bool head_only)
 {
   if (strcmp(name, "DESC") == 0) {
     if (not_found)
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 39a2502..e0d7e5a 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -5929,8 +5929,9 @@ static symbol get_font_translation(symbol nm)
 
 dictionary font_dictionary(50);
 
-static int mount_font_no_translate(int n, symbol name, symbol external_name,
-                                  int check_only = 0)
+static bool mount_font_no_translate(int n, symbol name,
+                                   symbol external_name,
+                                   bool check_only = false)
 {
   assert(n >= 0);
   // We store the address of this char in font_dictionary to indicate
@@ -5940,14 +5941,16 @@ static int mount_font_no_translate(int n, symbol name, 
symbol external_name,
   void *p = font_dictionary.lookup(external_name);
   if (p == 0) {
     int not_found;
-    fm = font::load_font(external_name.contents(), &not_found, check_only);
+    fm = font::load_font(external_name.contents(), &not_found,
+                        check_only);
     if (check_only)
       return fm != 0;
     if (!fm) {
       if (not_found)
-       warning(WARN_FONT, "can't find font '%1'", external_name.contents());
+       warning(WARN_FONT, "can't find font '%1'",
+               external_name.contents());
       (void)font_dictionary.lookup(external_name, &a_char);
-      return 0;
+      return false;
     }
     (void)font_dictionary.lookup(name, fm);
   }
@@ -5955,16 +5958,16 @@ static int mount_font_no_translate(int n, symbol name, 
symbol external_name,
 #if 0
     error("invalid font '%1'", external_name.contents());
 #endif
-    return 0;
+    return false;
   }
   else
     fm = (font*)p;
   if (check_only)
-    return 1;
+    return true;
   if (n >= font_table_size) {
     if (n - font_table_size > 1000) {
       error("font position too much larger than first unused position");
-      return 0;
+      return false;
     }
     grow_font_table(n);
   }
@@ -5972,10 +5975,10 @@ static int mount_font_no_translate(int n, symbol name, 
symbol external_name,
     delete font_table[n];
   font_table[n] = new font_info(name, n, external_name, fm);
   font_family::invalidate_fontno(n);
-  return 1;
+  return true;
 }
 
-int mount_font(int n, symbol name, symbol external_name)
+bool mount_font(int n, symbol name, symbol external_name)
 {
   assert(n >= 0);
   name = get_font_translation(name);
@@ -5990,7 +5993,7 @@ int check_font(symbol fam, symbol name)
 {
   if (check_style(name))
     name = concat(fam, name);
-  return mount_font_no_translate(0, name, name, 1);
+  return mount_font_no_translate(0, name, name, true /* check only */);
 }
 
 int check_style(symbol s)
@@ -5999,20 +6002,22 @@ int check_style(symbol s)
   return i < 0 ? 0 : font_table[i]->is_style();
 }
 
-void mount_style(int n, symbol name)
+bool mount_style(int n, symbol name)
 {
   assert(n >= 0);
   if (n >= font_table_size) {
     if (n - font_table_size > 1000) {
       error("font position too much larger than first unused position");
-      return;
+      return false;
     }
     grow_font_table(n);
   }
   else if (font_table[n] != 0)
     delete font_table[n];
-  font_table[n] = new font_info(get_font_translation(name), n, NULL_SYMBOL, 0);
+  font_table[n] = new font_info(get_font_translation(name), n,
+                               NULL_SYMBOL, 0);
   font_family::invalidate_fontno(n);
+  return true;
 }
 
 /* global functions */
@@ -6040,7 +6045,7 @@ void font_position()
       symbol internal_name = get_name(true /* required */);
       if (!internal_name.is_null()) {
        symbol external_name = get_long_name();
-       mount_font(n, internal_name, external_name); // ignore error
+       (void) mount_font(n, internal_name, external_name);
       }
     }
   }
@@ -6145,7 +6150,7 @@ void style()
     else {
       symbol internal_name = get_name(true /* required */);
       if (!internal_name.is_null())
-       mount_style(n, internal_name);
+       (void) mount_style(n, internal_name);
     }
   }
   skip_line();
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 702520c..9b566a0 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -612,10 +612,10 @@ inline hyphen_list::hyphen_list(unsigned char code, 
hyphen_list *p)
 }
 
 extern void read_desc();
-extern int mount_font(int, symbol, symbol = NULL_SYMBOL);
+extern bool mount_font(int, symbol, symbol = NULL_SYMBOL);
 extern int check_font(symbol, symbol);
 extern int check_style(symbol);
-extern void mount_style(int, symbol);
+extern bool mount_style(int, symbol);
 extern int is_good_fontno(int);
 extern int symbol_fontno(symbol);
 extern int next_available_font_position();



reply via email to

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