From: Vincent Bernat Date: Sat, 12 Mar 2016 13:03:54 +0000 (+0100) Subject: lldpcli: with key/value display, remove any newline X-Git-Tag: 0.9.2~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8755512e8b52b20a7fe48b53d2c8930d63824be7;p=thirdparty%2Flldpd.git lldpcli: with key/value display, remove any newline They make hard to parse the result. Just remove them. This happens for example with CDP. --- 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); }