File: flagdoc.pl

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (47 lines) | stat: -rwxr-xr-x 1,087 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
#!/usr/bin/env perl

use warnings;
use strict;
use 5.014;

use JSON;
use File::Basename;
use File::Spec::Functions qw(catfile);

my $config;
for( open my $fh, '<', catfile(dirname(__FILE__), 'sections.conf'); <$fh>; ) {
    chomp;
    do {} while( s/#.*|^\s+|\s+$//g );
    next unless length;
    my ($section, $context) = ( split '=' );
    foreach( split ',', $context ) {
        $config->{$_} = $section;
    }
}

my $json = JSON->new->allow_nonref;

sub output($$) {
    my $flags = (shift)->{(shift)};
    foreach (sort keys %{$flags}) {
        print "- `$_` $flags->{$_}\n";
    }
}

my $parsed;
foreach (@{($json->decode(do { local $/; <> }))}) {
    next if $_->{pseudo};

    my $id = $_->{id};
    my $msg = $_->{description} // ($_->{info} =~ s/<.+?>//gr);

    foreach (@{$_->{context}}) {
        my $section = $config->{$_};
        $parsed->{$section} = {} unless exists $parsed->{$section};
        $parsed->{$section}->{$id} = $msg;
    }
}

for( open my $fh, '<', catfile(dirname(__FILE__), 'template.in'); <$fh>; ) {
    print s/@([^@]+)@/output($parsed,$1)/egr;
}