From: Vincent Bernat Date: Tue, 12 Aug 2014 18:03:09 +0000 (+0200) Subject: lldpcli: indent multiline texts (like system description) X-Git-Tag: 0.7.11~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8d641ab478fc675e2362461cc5fe62e8bc7c0a82;p=thirdparty%2Flldpd.git lldpcli: indent multiline texts (like system description) This should fix #73 in an alternate way. --- diff --git a/src/client/text_writer.c b/src/client/text_writer.c index 0f0c515b..208211cc 100644 --- a/src/client/text_writer.c +++ b/src/client/text_writer.c @@ -72,7 +72,29 @@ txt_attr(struct writer *w, const char *tag, const char *descr, const char *value static void txt_data(struct writer *w, const char *data) { struct txt_writer_private *p = w->priv; - fprintf( p->fh, " %s", data ); + char *nl, *begin; + char *v = begin = strdup(data); + + if (v == NULL) { + fprintf(p->fh, " %s", data); + return; + } + + fprintf(p->fh, " "); + while ((nl = strchr(v, '\n')) != NULL) { + *nl = '\0'; + fprintf(p->fh, "%s\n", v); + v = nl + 1; + + /* Indent */ + int i; + for (i = 1; i < p->level - 1; i++) { + fprintf(p->fh, " "); + } + fprintf(p->fh, "%-14s", " "); + } + fprintf(p->fh, "%s", v); + free(begin); } static void