summaryrefslogtreecommitdiff
path: root/renumber.pl
blob: bc2b6abd3e5c3eb9f00443f209fc8d192d723953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env perl

use v5.36;
use warnings;
use diagnostics;
use strict;
use utf8;
use open qw(:std :encoding(UTF-8));
use charnames ':full';

my $width  = 12;
my $height = 22;
my $dblwidth = 2 * $width;

my $lnr = 0;
my $n   = $height;
while (<>) {
  chop;
  ++$lnr;
  if (/^STARTCHAR\s+[Uu]\+([[:xdigit:]]+)/) {
    my $cp   = hex $1;
    my $name = charnames::viacode ($cp) // '<no name>';
    $_ = sprintf "STARTCHAR U+%04x %s", $cp, $name;
  }
  elsif (/^[[:digit:]]+ \|(.{$width})\|/) {
    $_ = sprintf "%02d |%s|", $n--, $1;
  }
  elsif (/^[[:digit:]]+ \|(.{$dblwidth})\|/) {
    $_ = sprintf "%02d |%s|", $n--, $1;
  }
  elsif (/^ENDCHAR$/) {
    if ($n != 0) {
      my $N = 22 - $n;
      print STDERR
        "line $lnr: ENDCHAR after $N bitmap rows, expected $height\n";
      exit 1;
    }
    $n = $height;
  }
  else {
    print STDERR "line $lnr: unrecognized input: '$_'\n";
    exit 1;
  }
  print "$_\n";
}

# vi: set tabstop=2 shiftwidth=2 expandtab fileformat=unix: