From ff1efc0901a57a846aa1ebc90c2a11daa5ab9967 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Wed, 1 Aug 2012 03:28:28 -0400 Subject: [PATCH] conf: simplify Buffer Indentation in virDomainNetDefFormat This function has several calls to increase the buffer indent by 6, then decrease it again, then increase, then decrease. Additionally, there were several printfs that had 6 spaces at the beginning of the line. virDomainActualNetDefFormat, which is called by virDomainNetDefFormat, had similar ugliness. This patch changes both functions to just increase the indent at the beginning, decrease it at (well, just before*) the end, and remove all of the occurences of 6/8 spaces at the beginning of lines. *The indent had to be reset before the end of the function because virDomainDeviceInfoFormat assumes a 0 indent and is called from many other places, and I didn't want to do an overhaul of every caller of that function. A separate patch to switch all of domain_conf.c would be a useful exercise, but my current goal is unrelated to that, so I'll leave it for another day. --- src/conf/domain_conf.c | 73 +++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e3830803f1..b10ffe3216 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11559,21 +11559,22 @@ virDomainActualNetDefFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, " type == VIR_DOMAIN_NET_TYPE_HOSTDEV && def->data.hostdev.def.managed) { virBufferAddLit(buf, " managed='yes'"); } virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); switch (def->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", def->data.bridge.brname); break; case VIR_DOMAIN_NET_TYPE_DIRECT: - virBufferAddLit(buf, " data.direct.linkdev) virBufferEscapeString(buf, " dev='%s'", def->data.direct.linkdev); @@ -11589,12 +11590,10 @@ virDomainActualNetDefFormat(virBufferPtr buf, break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: - virBufferAdjustIndent(buf, 8); if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def, flags, true) < 0) { return -1; } - virBufferAdjustIndent(buf, -8); break; case VIR_DOMAIN_NET_TYPE_NETWORK: @@ -11605,14 +11604,13 @@ virDomainActualNetDefFormat(virBufferPtr buf, return -1; } - virBufferAdjustIndent(buf, 8); if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) return -1; if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0) return -1; - virBufferAdjustIndent(buf, -8); - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); return 0; } @@ -11636,14 +11634,15 @@ virDomainNetDefFormat(virBufferPtr buf, } virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 6); virBufferAsprintf(buf, - " \n", + "\n", def->mac.addr[0], def->mac.addr[1], def->mac.addr[2], def->mac.addr[3], def->mac.addr[4], def->mac.addr[5]); switch (def->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: - virBufferEscapeString(buf, " data.network.name); virBufferEscapeString(buf, " portgroup='%s'", def->data.network.portgroup); @@ -11654,39 +11653,41 @@ virDomainNetDefFormat(virBufferPtr buf, break; case VIR_DOMAIN_NET_TYPE_ETHERNET: - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", def->data.ethernet.dev); if (def->data.ethernet.ipaddr) - virBufferAsprintf(buf, " \n", + virBufferAsprintf(buf, "\n", def->data.ethernet.ipaddr); break; case VIR_DOMAIN_NET_TYPE_BRIDGE: - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", def->data.bridge.brname); - if (def->data.bridge.ipaddr) - virBufferAsprintf(buf, " \n", + if (def->data.bridge.ipaddr) { + virBufferAsprintf(buf, "\n", def->data.bridge.ipaddr); + } break; case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: - if (def->data.socket.address) - virBufferAsprintf(buf, " \n", + if (def->data.socket.address) { + virBufferAsprintf(buf, "\n", def->data.socket.address, def->data.socket.port); - else - virBufferAsprintf(buf, " \n", + } else { + virBufferAsprintf(buf, "\n", def->data.socket.port); + } break; case VIR_DOMAIN_NET_TYPE_INTERNAL: - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", def->data.internal.name); break; case VIR_DOMAIN_NET_TYPE_DIRECT: - virBufferEscapeString(buf, " data.direct.linkdev); virBufferAsprintf(buf, " mode='%s'", virNetDevMacVLanModeTypeToString(def->data.direct.mode)); @@ -11694,12 +11695,10 @@ virDomainNetDefFormat(virBufferPtr buf, break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: - virBufferAdjustIndent(buf, 6); if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def, flags, true) < 0) { return -1; } - virBufferAdjustIndent(buf, -6); break; case VIR_DOMAIN_NET_TYPE_USER: @@ -11707,26 +11706,22 @@ virDomainNetDefFormat(virBufferPtr buf, break; } - virBufferAdjustIndent(buf, 6); if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) return -1; - virBufferAdjustIndent(buf, -6); - - virBufferEscapeString(buf, "