poke-devel
[Top][All Lists]
Advanced

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

[PATCH v1] libpoke: refactoring NULL check


From: Vincenzo Palazzo
Subject: [PATCH v1] libpoke: refactoring NULL check
Date: Sat, 3 Feb 2024 11:31:46 +0100

This simple commit just clean up some C code
that I found while reading the compiler code.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
---
 libpoke/libpoke.c |  6 +-----
 libpoke/libpoke.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index 6aa23e02..2533ef3b 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -59,11 +59,7 @@ pk_compiler_new_with_flags (struct pk_term_if *term_if, 
uint32_t flags)
   if (!term_if)
     return NULL;
 
-  if (!term_if->flush_fn || !term_if->puts_fn || !term_if->printf_fn
-      || !term_if->indent_fn || !term_if->class_fn || !term_if->end_class_fn
-      || !term_if->hyperlink_fn || !term_if->end_hyperlink_fn
-      || !term_if->get_color_fn || !term_if->get_bgcolor_fn
-      || !term_if->set_color_fn || !term_if->set_bgcolor_fn)
+  if (term_if_is_null(term_if))
     return NULL;
 
   pkc = calloc (1, sizeof (struct _pk_compiler));
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index baee3b91..d40aaec6 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -125,6 +125,18 @@ struct pk_term_if
   void (*set_bgcolor_fn) (pk_compiler pkc, struct pk_color color);
 };
 
+/* term_if_is_null - Helper function that check if the term_if is NULL */
+inline bool term_if_is_null(struct pk_term_if *term_if)
+{
+  if (!term_if->flush_fn || !term_if->puts_fn || !term_if->printf_fn
+      || !term_if->indent_fn || !term_if->class_fn || !term_if->end_class_fn
+      || !term_if->hyperlink_fn || !term_if->end_hyperlink_fn
+      || !term_if->get_color_fn || !term_if->get_bgcolor_fn
+      || !term_if->set_color_fn || !term_if->set_bgcolor_fn)
+    return true;
+  return false;
+}
+
 /* Create and return a new Poke incremental compiler.
 
    TERM_IF is a pointer to a struct pk_term_if containing pointers to
-- 
2.43.0




reply via email to

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