From 36a74e1b450f95767671df44bee9c73f21e2dec5 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 29 Mar 2011 11:44:29 +0200 Subject: [PATCH] blkid: add -d option to print non-printable chars Reported-by: laborer2008 laborer Signed-off-by: Karel Zak --- misc-utils/blkid.8 | 7 ++++++- misc-utils/blkid.c | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8 index 1dbb20b07..92fd3854f 100644 --- a/misc-utils/blkid.8 +++ b/misc-utils/blkid.8 @@ -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. diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index ca8083bfa..c8c95b6b1 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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 ] [-o ] ...\n\n" "Options:\n" " -c 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 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);