]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: add -d option to print non-printable chars
authorKarel Zak <kzak@redhat.com>
Tue, 29 Mar 2011 09:44:29 +0000 (11:44 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Mar 2011 09:44:29 +0000 (11:44 +0200)
Reported-by: laborer2008 laborer <laborer2008@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.8
misc-utils/blkid.c

index 1dbb20b07233f8434dd5e13302a97bfe8d959620..92fd3854faf2a8d3bbfe0713fbb5c462ea6a9569 100644 (file)
@@ -16,7 +16,7 @@ blkid \- locate/print block device attributes
 .IR uuid
 
 .B blkid
-.RB [ \-ghlv ]
+.RB [ \-dghlv ]
 .RB [ \-c
 .IR file ]
 .RB [ \-w
@@ -84,6 +84,11 @@ If you want to start with a clean cache (i.e. don't report devices previously
 scanned but not necessarily available at this time), specify
 .IR /dev/null .
 .TP
+.B \-d
+Don't encode non-printing characters. The non-printing characters are encoded
+by ^ and M- notation by default. Note that \fB-o udev\fR output format uses
+a diffrent encoding and this encoding cannot be disabled.
+.TP
 .B \-g
 Perform a garbage collection pass on the blkid cache to remove
 devices which no longer exist.
index ca8083bfa55c28bcf9ab4a23102932ae7e93959f..c8c95b6b109e74bf633869a6662262df1dcf0927 100644 (file)
@@ -45,6 +45,8 @@ extern int optind;
 
 const char *progname = "blkid";
 
+int raw_chars;
+
 static void print_version(FILE *out)
 {
        fprintf(out, "%s from %s (libblkid %s, %s)\n",
@@ -66,6 +68,7 @@ static void usage(int error)
                "  %1$s -i [-s <tag>] [-o <format>] <dev> ...\n\n"
                "Options:\n"
                "  -c <file>   cache file (default: /etc/blkid.tab, /dev/null = none)\n"
+               "  -d          don't encode non-printing characters\n"
                "  -h          print this usage message and exit\n"
                "  -g          garbage collect the blkid cache\n"
                "  -o <format> output format; can be one of:\n"
@@ -104,13 +107,15 @@ static void safe_print(const char *cp, int len)
 
        while (len--) {
                ch = *cp++;
-               if (ch > 128) {
-                       fputs("M-", stdout);
-                       ch -= 128;
-               }
-               if ((ch < 32) || (ch == 0x7f)) {
-                       fputc('^', stdout);
-                       ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
+               if (!raw_chars) {
+                       if (ch > 128) {
+                               fputs("M-", stdout);
+                               ch -= 128;
+                       }
+                       if ((ch < 32) || (ch == 0x7f)) {
+                               fputc('^', stdout);
+                               ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
+                       }
                }
                fputc(ch, stdout);
        }
@@ -685,7 +690,7 @@ int main(int argc, char **argv)
 
        show[0] = NULL;
 
-       while ((c = getopt (argc, argv, "c:f:ghilL:n:o:O:ps:S:t:u:U:w:v")) != EOF)
+       while ((c = getopt (argc, argv, "c:df:ghilL:n:o:O:ps:S:t:u:U:w:v")) != EOF)
                switch (c) {
                case 'c':
                        if (optarg && !*optarg)
@@ -695,6 +700,9 @@ int main(int argc, char **argv)
                        if (!write)
                                write = read;
                        break;
+               case 'd':
+                       raw_chars = 1;
+                       break;
                case 'L':
                        eval++;
                        search_value = strdup(optarg);