~ubuntu-branches/ubuntu/wily/console-setup/wily

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl

#     describe_unicodes -- add human readable descriptions to unicodes
#     Copyright © 2005 Anton Zinoviev <anton@lml.bas.bg>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.

#     If you have not received a copy of the GNU General Public License
#     along with this program, write to the Free Software Foundation, Inc.,
#     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use strict;

my $utf = "/usr/share/i18n/charmaps/UTF-8.gz";

sub debug {
    print STDERR "@_";
}

if ($ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
    print STDERR <<EOT;
Usage:	describe_unicodes FILE

Adds a comment lines in FILE for every substring of the form "U+NNNN",
where NNNN are hexadecimal digits.
EOT
    exit 0
}

my $file = $ARGV[0];

my $line = 0;
my %descriptions;
open UTF, "zcat $utf |" or die "$0: zcat $utf: $!\n";
while (<UTF>) {
    $line++;
    last if (/^[[:space:]]*CHARMAP[[:space:]]*$/);
}
while (<UTF>) {
    $line++;
    last if (/^[[:space:]]*END[[:space:]]*CHARMAP[[:space:]]*$/);
    /\<U([0-9a-fA-F]+)\>[[:space:]]+[^[:space:]]+[[:space:]]+(.*)/
	or die "$0: $utf: syntax error on line $line: $_\n";
    $descriptions{hex ($1)} = $2;
}
close UTF;

my @output;
open FILE, "$file" or die "$0: $file: $!\n";
while (<FILE>) {
    push (@output, $_) unless (/^\# U\+[0-9a-fA-F]+:   [^ ]/);
    s/#.*//;
    while (/^.*?U\+([0-9a-fA-F]+)(.*)/) {
	push (@output, 
	      sprintf ("# U+%s:   %s\n", $1, $descriptions{hex ($1)}));
	$_ = $2;
    }
}
close FILE;
    
open FILE, ">$file" or die "$0: $file: $!\n";
foreach (@output) {
    print FILE;
}
close FILE;