Date:2014-12-01 07:14:56 (4 years 5 months ago)
Author:Werner Almesberger
Commit:dd900189032ece666c1f102ae995e16267bf74a9
Message: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.
Files: bin/hi8 (1 diff)

Change Details

bin/hi8
1#!/usr/bin/perl
2sub usage
3{
4    print STDERR "usage: $0 [-g] [file ...]\n";
5    exit(1);
6}
7
8if ($ARGV[0] eq "-g") {
9    $grep = 1;
10    shift @ARGV;
11}
12&usage if $ARGV[0] =~ /^-/;
13
14while (<>) {
15    @c = unpack "C*";
16    for (@c) {
17        if ($_ == 10) {
18            print "$s\n" if $found || !$grep;
19            $found = 0;
20            undef $s;
21        } elsif ($_ < 0x80) {
22            $s .= pack("c", $_);
23        } else {
24            $s .= sprintf("\e[7m%02x\e[0m", $_);
25            $found = 1;
26        }
27    }
28}

Archive Download the corresponding diff file

Branches:
master



interactive