Root/bin/hi8

Source at commit dd900189032ece666c1f102ae995e16267bf74a9 created 4 years 6 months ago.
By Werner Almesberger, bin/hi8: highlight 8-bit chars; -g for "grep" mode: show only lines with 8-bit
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}
29

Archive Download this file

Branches:
master



interactive