Debian Codegraph @

unicode/gen_c_istab

raw
1 #!/usr/bin/perl
2 # Copyright (C) 2015 Olly Betts
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 use strict;
19 use warnings;
20
21 @ARGV == 1 or die "Syntax: $0 OUTFILE\n";
22
23 my $out = shift @ARGV;
24
25 open OUT, '>', "$out.tmp" or die $!;
26
27 print OUT "/* Generated by $0 */\n\n";
28
29 print OUT "{\n";
30 for my $ch (0 .. 255) {
31 $_ = chr($ch);
32 if (/[ -~]/) {
33 print OUT " /* '$_' */ ";
34 } else {
35 printf OUT " /* 0x%02x */ ", $ch;
36 }
37 my @a;
38 if (/[0-9a-fA-F]/) {
39 push @a, sprintf "0x%02x", hex($_);
40 }
41 if (/[A-Za-z]/) {
42 push @a, 'Xapian::Internal::IS_ALPHA';
43 }
44 if (/[A-Z]/) {
45 push @a, 'Xapian::Internal::IS_UPPER';
46 }
47 if (/[0-9]/) {
48 push @a, 'Xapian::Internal::IS_DIGIT';
49 }
50 if (/[\t\n\f\r ]/) {
51 push @a, 'Xapian::Internal::IS_SPACE';
52 }
53 @a > 0 or @a = (0);
54 print OUT join ' | ', @a;
55 print OUT ",\n";
56 }
57 print OUT "},\n";
58
59 close OUT or die $!;
60
61 rename "$out.tmp", $out or die $!;