sysinfo: delete unnecessary white space of sysinfo.

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

 



sysinfo: delete unnecessary white space of sysinfo.

  * Add virSkipSpacesBackwards() to src/util/util.[ch]
  * Trim each element and delete null entry of sysinfo by virSkipSpacesBackwards().

Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx>
---
 src/util/sysinfo.c |   34 +++++++++++++++++++++++++---------
 src/util/util.c    |   27 +++++++++++++++++++++++++++
 src/util/util.h    |    1 +
 3 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c
index bff1cb8..2ebd34c 100644
--- a/src/util/sysinfo.c
+++ b/src/util/sysinfo.c
@@ -238,6 +238,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Socket Designation: ")) != NULL) {
             cur += 20;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_socket_destination = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -245,6 +246,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Type: ")) != NULL) {
             cur += 6;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_type = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -252,6 +254,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Family: ")) != NULL) {
             cur += 8;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -259,6 +262,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_manufacturer = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -266,6 +270,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Signature: ")) != NULL) {
             cur += 11;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_signature = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -273,6 +278,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Version: ")) != NULL) {
             cur += 9;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -280,6 +286,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "External Clock: ")) != NULL) {
             cur += 16;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_external_clock = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -287,6 +294,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Max Speed: ")) != NULL) {
             cur += 11;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_max_speed = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -294,6 +302,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Status: ")) != NULL) {
             cur += 8;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_status = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -301,6 +310,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Serial Number: ")) != NULL) {
             cur += 15;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -308,12 +318,13 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Part Number: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((processor->processor_part_number = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
         }
 
-        base = eol + 1;
+        base += strlen("Processor Information");
     }
 
     return base;
@@ -342,6 +353,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
             if (STREQLEN(cur, "No Module Installed", eol - cur))
                 goto next;
 
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_size = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -349,6 +361,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Form Factor: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_form_factor = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -356,6 +369,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Locator: ")) != NULL) {
             cur += 9;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_locator = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -363,6 +377,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Bank Locator: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_bank_locator = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -370,6 +385,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Type: ")) != NULL) {
             cur += 6;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_type = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -377,6 +393,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Type Detail: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_type_detail = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -384,6 +401,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Speed: ")) != NULL) {
             cur += 7;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_speed = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -391,6 +409,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_manufacturer = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -398,6 +417,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Serial Number: ")) != NULL) {
             cur += 15;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_serial_number = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
@@ -405,13 +425,14 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
         if ((cur = strstr(base, "Part Number: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if ((eol) &&
                 ((memory->memory_part_number = strndup(cur, eol - cur)) == NULL))
                 goto no_memory;
         }
 
     next:
-        base = eol + 1;
+        base += strlen("Memory Device");
     }
 
     return base;

diff --git a/src/util/util.c b/src/util/util.c
index 463d2b8..c5c1a89 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1550,6 +1550,33 @@ virSkipSpaces(const char **str)
 }
 
 /**
+ * virSkipSpacesBackwards:
+ * @str : pointer to the target strings
+ * @endp: pointer to the end of @str
+ *
+ * Skip potential blanks backwards.
+ */
+void
+virSkipSpacesBackwards(const char *str, char **endp)
+{
+    char *cur;
+
+    if (!endp || !*endp)
+        return;
+
+    cur = *endp - 1;
+    while (cur >= str) {
+        if ((*cur == ' ') || (*cur == '\t') || (*cur == '\n') ||
+            (*cur == '\r') || (*cur == '\\'))
+            cur--;
+        else
+            break;
+    }
+
+    *endp = (cur >= str) ? cur + 1 : NULL;
+}
+
+/**
  * virParseNumber:
  * @str: pointer to the char pointer used
  *
diff --git a/src/util/util.h b/src/util/util.h
index 0c43f7a..ae74c30 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -167,6 +167,7 @@ int virHexToBin(unsigned char c);
 int virMacAddrCompare (const char *mac1, const char *mac2);
 
 void virSkipSpaces(const char **str);
+void virSkipSpacesBackwards(const char *str, char **endp);
 int virParseNumber(const char **str);
 int virParseVersionString(const char *str, unsigned long *version);
 int virAsprintf(char **strp, const char *fmt, ...)
-- 
1.7.1

-- 
Minoru Usui <usui@xxxxxxxxxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]