]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: indent multiline texts (like system description)
authorVincent Bernat <vincent@bernat.im>
Tue, 12 Aug 2014 18:03:09 +0000 (20:03 +0200)
committerVincent Bernat <vincent@bernat.im>
Tue, 12 Aug 2014 18:03:09 +0000 (20:03 +0200)
This should fix #73 in an alternate way.

src/client/text_writer.c

index 0f0c515b83e437e08544bdf5c08bd0c040b62d35..208211cc8ec3a76dd35fa56d2d4e5551a2f17732 100644 (file)
@@ -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