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.
This commit is contained in:
Werner Almesberger 2014-12-01 03:14:56 -03:00
parent 29ac553f82
commit dd90018903
1 changed files with 28 additions and 0 deletions

28
bin/hi8 Executable file
View File

@ -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;
}
}
}