[PATCH 6/9] libmultipath: make snprint_pctable indent a variable amount

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of always indenting two tabs, which is what is needed in for
the protocol subsection of the device subsection, indent a variable
amount. This will be needed in a future patch.

Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx>
---
 libmultipath/print.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 46d231ed..093e43aa 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -1407,28 +1407,42 @@ int snprint_multipath_topology_json (struct strbuf *buff,
 }
 
 static int
-snprint_pcentry (struct strbuf *buff, const struct pcentry *pce,
+snprint_pcentry (struct strbuf *buff, int indent, const struct pcentry *pce,
 		 const struct keyword *rootkw)
 {
 	int i, rc;
 	struct keyword *kw;
 	size_t initial_len = get_strbuf_len(buff);
+	STRBUF_ON_STACK(fmt);
 
-	if ((rc = append_strbuf_str(buff, "\t\tprotocol {\n")) < 0)
+	for (i = 0; i < indent; i++)
+		if ((rc = append_strbuf_str(&fmt, "\t")) < 0)
+			return rc;
+	if ((rc = append_strbuf_str(&fmt, "\t%k %v\n")) < 0)
+			return rc;
+
+	for (i = 0; i < indent; i++)
+		if ((rc = append_strbuf_str(buff, "\t")) < 0)
+			return rc;
+	if ((rc = append_strbuf_str(buff, "protocol {\n")) < 0)
 		return rc;
 
 	iterate_sub_keywords(rootkw, kw, i) {
-		if ((rc = snprint_keyword(buff, "\t\t\t%k %v\n", kw, pce)) < 0)
+		if ((rc = snprint_keyword(buff, get_strbuf_str(&fmt), kw,
+					  pce)) < 0)
 			return rc;
 	}
 
-	if ((rc = append_strbuf_str(buff, "\t\t}\n")) < 0)
+	for (i = 0; i < indent; i++)
+		if ((rc = append_strbuf_str(buff, "\t")) < 0)
+			return rc;
+	if ((rc = append_strbuf_str(buff, "}\n")) < 0)
 		return rc;
 	return get_strbuf_len(buff) - initial_len;
 }
 
 static int
-snprint_pctable (const struct config *conf, struct strbuf *buff,
+snprint_pctable (const struct config *conf, struct strbuf *buff, int indent,
 		 const struct _vector *pctable, const struct keyword *rootkw)
 {
 	int i, rc;
@@ -1439,7 +1453,7 @@ snprint_pctable (const struct config *conf, struct strbuf *buff,
 	assert(rootkw);
 
 	vector_foreach_slot(pctable, pce, i) {
-		if ((rc = snprint_pcentry(buff, pce, rootkw)) < 0)
+		if ((rc = snprint_pcentry(buff, indent, pce, rootkw)) < 0)
 			return rc;
 	}
 	return get_strbuf_len(buff) - initial_len;
@@ -1468,7 +1482,7 @@ snprint_hwentry (const struct config *conf,
 	}
 
 	if (hwe->pctable &&
-	    (rc = snprint_pctable(conf, buff, hwe->pctable, rootkw)) < 0)
+	    (rc = snprint_pctable(conf, buff, 2, hwe->pctable, rootkw)) < 0)
 		return rc;
 
 	if ((rc = append_strbuf_str(buff, "\t}\n")) < 0)
-- 
2.17.2

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux