From 8755512e8b52b20a7fe48b53d2c8930d63824be7 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 12 Mar 2016 14:03:54 +0100 Subject: [PATCH] lldpcli: with key/value display, remove any newline They make hard to parse the result. Just remove them. This happens for example with CDP. --- src/client/kv_writer.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/client/kv_writer.c b/src/client/kv_writer.c index 2983288e..dcbfa097 100644 --- a/src/client/kv_writer.c +++ b/src/client/kv_writer.c @@ -53,10 +53,19 @@ kv_data(struct writer *w, const char *data) { struct kv_writer_private *p = w->priv; char *key = strdup(p->prefix); - char *dot; + char *value = data?strdup(data):NULL; + char *dot, *nl; if (!key) fatal(NULL, NULL); - while ((dot = strchr(key, '\1')) != NULL) *dot=SEP; - fprintf(p->fh, "%s=%s\n", key, data?data:""); + while ((dot = strchr(key, '\1')) != NULL) + *dot = SEP; + if (value) { + nl = value; + while ((nl = strchr(nl, '\n'))) { + *nl = ' '; + nl++; + } + } + fprintf(p->fh, "%s=%s\n", key, value?value:""); free(key); } -- 2.39.5