From ebaeb8fb2340ace64565a8e56c9ab9010e8dd6d9 Mon Sep 17 00:00:00 2001
From: Felix Buehler <account@buehler.rocks>
Date: Tue, 31 Mar 2020 14:52:34 +0200
Subject: use format_placeholder for ipv6_addr

---
 src/print_ipv6_addr.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

(limited to 'src')

diff --git a/src/print_ipv6_addr.c b/src/print_ipv6_addr.c
index 5a0c38d..8fd8669 100644
--- a/src/print_ipv6_addr.c
+++ b/src/print_ipv6_addr.c
@@ -118,7 +118,6 @@ static char *get_ipv6_addr(void) {
 }
 
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down) {
-    const char *walk;
     char *addr_string = get_ipv6_addr();
     char *outwalk = buffer;
 
@@ -131,18 +130,13 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
     }
 
     START_COLOR("color_good");
-    for (walk = format_up; *walk != '\0'; walk++) {
-        if (*walk != '%') {
-            *(outwalk++) = *walk;
 
-        } else if (BEGINS_WITH(walk + 1, "ip")) {
-            outwalk += sprintf(outwalk, "%s", addr_string);
-            walk += strlen("ip");
+    placeholder_t placeholders[] = {
+        {.name = "%ip", .value = addr_string}};
 
-        } else {
-            *(outwalk++) = '%';
-        }
-    }
+    const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
+    buffer = format_placeholders(format_up, &placeholders[0], num);
     END_COLOR;
     OUTPUT_FULL_TEXT(buffer);
+    free(buffer);
 }
-- 
cgit v1.2.3