File: genfiles.pl

package info (click to toggle)
libtext-mecab-perl 0.20016-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 380 kB
  • ctags: 275
  • sloc: perl: 2,849; ansic: 579; makefile: 8
file content (74 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

package MeCabBuild;

sub write_files {
    my $version = shift;

    write_config_const($version);
}

sub write_config_const {
    my ($version) = @_;

    my $contents;
    if ($version >= 0.99) {
        $contents = config_const_from_enum();
    } else {
        $contents = config_const_from_symbol();
    }

    open my $f, '>', 'xs/config-const.h'
        or die "Could not open file: $!";
    print $f $contents;
    close $f;
}

my @const_names = qw(
    MECAB_NOR_NODE
    MECAB_UNK_NODE
    MECAB_BOS_NODE
    MECAB_EOS_NODE
    MECAB_EON_NODE

    MECAB_SYS_DIC
    MECAB_USR_DIC
    MECAB_UNK_DIC

    MECAB_ONE_BEST
    MECAB_NBEST
    MECAB_PARTIAL
    MECAB_MARGINAL_PROB
    MECAB_ALTERNATIVE
    MECAB_ALL_MORPHS
    MECAB_ALLOCATE_SENTENCE
);

# for >= 0.99
sub config_const_from_enum {
    my $contents = "";

    foreach my $name (@const_names) {
        $contents .= <<"END_TEMPLATE";
#define HAVE_$name 1
END_TEMPLATE
    }

    return $contents;
}

# for <= 0.98
sub config_const_from_symbol {
    my $contents = "";

    foreach my $name (@const_names) {
        $contents .= <<"END_TEMPLATE";
#ifdef $name
#define HAVE_$name 1
#endif
END_TEMPLATE
    }

    return $contents;
}