chiark / gitweb /
fold multiple consecutive whitespace chars into single '_'
authorHannes Reinecke <hare@suse.de>
Thu, 15 Dec 2005 11:22:42 +0000 (12:22 +0100)
committerKay Sievers <kay.sievers@suse.de>
Thu, 15 Dec 2005 11:22:42 +0000 (12:22 +0100)
extras/scsi_id/scsi_id.c

index 39391f6..aa1b160 100644 (file)
@@ -677,13 +677,22 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
  */
 static void format_serial(char *serial)
 {
-       char *p = serial;
+       char *p = serial, *q;
 
+       q = p;
        while (*p != '\0') {
-               if (isspace(*p))
-                       *p = '_';
+               if (isspace(*p)) {
+                       if (q > serial && q[-1] != '_') {
+                               *q = '_';
+                               q++;
+                       }
+               } else {
+                       *q = *p;
+                       q++;
+               }
                p++;
        }
+       *q = '\0';
 }
 
 /*