Debian Codegraph @

languages/collate-sbl

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 my $copyright = <<'EOF';
5 /* Copyright (C) 2007,2012,2013,2015 Olly Betts
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 EOF
22
23 use Tokeniseise;
24
25 my $srcdir = shift @ARGV;
26
27 my $all_header = 'languages/allsnowballheaders.h';
28 open ALL_HEADER, '>', "$all_header~" or die $!;
29 my $all_guard = 'XAPIAN_INCLUDED_ALLSNOWBALLHEADERS_H';
30 print ALL_HEADER <<"EOF";
31 /** \@file
32 * \@brief Include headers for all Snowball stemmers
33 */
34 /* Warning: This file is generated by $0 - do not modify directly! */
35 $copyright
36 #ifndef $all_guard
37 #define $all_guard
38
39 EOF
40
41 my $hdr = Tokeniseise->new('languages/sbl-dispatch.h', 'Map string to language code', $copyright, 'XAPIAN_INCLUDED_SBL_DISPATCH_H', 'sbl_code', 2);
42 $hdr->add('none', 'NONE');
43 my @langs;
44 foreach (sort @ARGV) {
45 m{.*/(.*)\.sbl$} or die "Failed to parse snowball source: $_\n";
46 my $lang = $1;
47 push @langs, $lang;
48 # Include the headers for all the snowball stemmers.
49 print ALL_HEADER "#include \"$lang.h\"\n";
50 my $enum = uc $lang;
51 $hdr->add($lang, $enum);
52 open SBL, '<', "$srcdir/$_" or die "Open $srcdir/$_ failed: $!\n";
53 my $l = <SBL>;
54 close SBL;
55 $l =~ s/^\W*Alias:\s*//i or die "No Alias: header in $srcdir/$_\n";
56 $l =~ s/\s*$//;
57 for (split /\s+/, $l) {
58 $hdr->add($_, $enum);
59 }
60 }
61
62 print ALL_HEADER <<"EOF";
63
64 #endif
65 EOF
66 close ALL_HEADER or die $!;
67 rename "$all_header~", $all_header or die $!;
68
69 $hdr->append("#define LANGSTRING \"" . join(" ", @langs) . "\"");
70
71 $hdr->write();