From dd900189032ece666c1f102ae995e16267bf74a9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 1 Dec 2014 03:14:56 -0300 Subject: [PATCH] bin/hi8: highlight 8-bit chars; -g for "grep" mode: show only lines with 8-bit This is useful for cleaning files from 8-bit contamination obtained through copy & paste, etc. --- bin/hi8 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 bin/hi8 diff --git a/bin/hi8 b/bin/hi8 new file mode 100755 index 0000000..9e14729 --- /dev/null +++ b/bin/hi8 @@ -0,0 +1,28 @@ +#!/usr/bin/perl +sub usage +{ + print STDERR "usage: $0 [-g] [file ...]\n"; + exit(1); +} + +if ($ARGV[0] eq "-g") { + $grep = 1; + shift @ARGV; +} +&usage if $ARGV[0] =~ /^-/; + +while (<>) { + @c = unpack "C*"; + for (@c) { + if ($_ == 10) { + print "$s\n" if $found || !$grep; + $found = 0; + undef $s; + } elsif ($_ < 0x80) { + $s .= pack("c", $_); + } else { + $s .= sprintf("\e[7m%02x\e[0m", $_); + $found = 1; + } + } +}