[WIP 1/3] util: move chomp_newline to string-util.h

Subject: [WIP 1/3] util: move chomp_newline to string-util.h

Date: Sun, 28 Sep 2014 20:28:17 +0200

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


This allows it to be called from functions in the library, if needed.

Instead of making all of string-util available to everywhere
notmuch-client.h is included, just add an extra include to the three
places chomp_newline was needed (and string-util.h not yet included).
---
 notmuch-client.h   | 7 -------
 notmuch-count.c    | 1 +
 notmuch-setup.c    | 1 +
 test/hex-xcode.c   | 2 ++
 util/string-util.h | 7 +++++++
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e1efbe0..bd01005 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -111,13 +111,6 @@ typedef struct notmuch_show_params {
 #define STRNCMP_LITERAL(var, literal) \
     strncmp ((var), (literal), sizeof (literal) - 1)
 
-static inline void
-chomp_newline (char *str)
-{
-    if (str && str[strlen(str)-1] == '\n')
-	str[strlen(str)-1] = '\0';
-}
-
 /* Exit status code indicating the requested format version is too old
  * (support for that version has been dropped).  CLI code should use
  * notmuch_exit_if_unsupported_format rather than directly exiting
diff --git a/notmuch-count.c b/notmuch-count.c
index 6058f7c..c3f4b54 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -20,6 +20,7 @@
  */
 
 #include "notmuch-client.h"
+#include "string-util.h"
 
 enum {
     OUTPUT_THREADS,
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 36a6171..eb91179 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -19,6 +19,7 @@
  */
 
 #include "notmuch-client.h"
+#include "string-util.h"
 
 static const char *
 make_path_absolute (void *ctx, const char *path)
diff --git a/test/hex-xcode.c b/test/hex-xcode.c
index 65d4956..20d0a68 100644
--- a/test/hex-xcode.c
+++ b/test/hex-xcode.c
@@ -9,6 +9,8 @@
 
 #include "notmuch-client.h"
 #include "hex-escape.h"
+#include "string-util.h"
+
 #include <assert.h>
 
 enum direction {
diff --git a/util/string-util.h b/util/string-util.h
index e409cb3..9337770 100644
--- a/util/string-util.h
+++ b/util/string-util.h
@@ -64,6 +64,13 @@ int
 parse_boolean_term (void *ctx, const char *str,
 		    char **prefix_out, char **term_out);
 
+static inline void
+chomp_newline (char *str)
+{
+    if (str && str[strlen(str)-1] == '\n')
+	str[strlen(str)-1] = '\0';
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.1.0


Thread: