<commit_before>#!/usr/bin/env perl

use strict;
use warnings;
use autodie qw( :all );

use FindBin qw( $Bin );

use File::Path qw( mkpath );
use File::Slurp qw( edit_file read_file write_file );
use File::Temp qw( tempdir );
use File::Which qw( which );

sub main {
    my $target = shift || "$Bin/..";

    my @translators = qw ( pandoc lowdown );
    my $translator;
    foreach my $p ( @translators ) {
        if (defined which($p)) {
            $translator = $p;
            last;
        }
    }
    unless ( defined $translator ) {
        die
        "\n  You must install one of " . join(', ', @translators) .
        " in order to generate the man pages.\n\n";
    }

    _make_man( $translator, $target, 'libmaxminddb', 3 );
    _make_lib_man_links($target);

    _make_man( $translator, $target, 'mmdblookup', 1 );
}

sub _make_man {
    my $translator = shift;
    my $target     = shift;
    my $name       = shift;
    my $section    = shift;

    my $man_dir = "$target/man/man$section";
    mkpath($man_dir);

    my $tempdir = tempdir( CLEANUP => 1 );

    my $markdown = <<"EOF";
title: $name
section: $section

EOF
    $markdown .= read_file("$Bin/../doc/$name.md");

    my $tempfile = "$tempdir/$name.$section.md";
    write_file( $tempfile, $markdown );

    my $man_file = "$man_dir/$name.$section";

    if ( $translator eq 'pandoc' ) {
        system( qw( pandoc -s -f markdown+mmd_title_block -t man ), $tempfile, '-o', $man_file );
        _pandoc_postprocess($man_file);
    } elsif ( $translator eq 'lowdown' ) {
        system( qw( lowdown -s -Tman ), $tempfile, '-o', $man_file );
    }
}

sub _make_lib_man_links {
    my $target = shift;

    my $header = read_file("$Bin/../include/maxminddb.h");
    for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) {
        open my $fh, '>', "$target/man/man3/$proto.3";
        print {$fh} ".so man3/libmaxminddb.3\n";
        close $fh;
    }
}<commit_msg>Disable "smarty" filters from manpage generation<commit_after>#!/usr/bin/env perl

use strict;
use warnings;
use autodie qw( :all );

use FindBin qw( $Bin );

use File::Path qw( mkpath );
use File::Slurp qw( edit_file read_file write_file );
use File::Temp qw( tempdir );
use File::Which qw( which );

sub main {
    my $target = shift || "$Bin/..";

    my @translators = qw ( pandoc lowdown );
    my $translator;
    foreach my $p ( @translators ) {
        if (defined which($p)) {
            $translator = $p;
            last;
        }
    }
    unless ( defined $translator ) {
        die
        "\n  You must install one of " . join(', ', @translators) .
        " in order to generate the man pages.\n\n";
    }

    _make_man( $translator, $target, 'libmaxminddb', 3 );
    _make_lib_man_links($target);

    _make_man( $translator, $target, 'mmdblookup', 1 );
}

sub _make_man {
    my $translator = shift;
    my $target     = shift;
    my $name       = shift;
    my $section    = shift;

    my $man_dir = "$target/man/man$section";
    mkpath($man_dir);

    my $tempdir = tempdir( CLEANUP => 1 );

    my $markdown = <<"EOF";
title: $name
section: $section

EOF
    $markdown .= read_file("$Bin/../doc/$name.md");

    my $tempfile = "$tempdir/$name.$section.md";
    write_file( $tempfile, $markdown );

    my $man_file = "$man_dir/$name.$section";

    if ( $translator eq 'pandoc' ) {
        system( qw( pandoc -s -f markdown+mmd_title_block-smart -t man ), $tempfile, '-o', $man_file );
        _pandoc_postprocess($man_file);
    } elsif ( $translator eq 'lowdown' ) {
        system( qw( lowdown --out-no-smarty -s -Tman ), $tempfile, '-o', $man_file );
    }
}

sub _make_lib_man_links {
    my $target = shift;

    my $header = read_file("$Bin/../include/maxminddb.h");
    for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) {
        open my $fh, '>', "$target/man/man3/$proto.3";
        print {$fh} ".so man3/libmaxminddb.3\n";
        close $fh;
    }
}
{'fraction_non_alphanumeric': 0.16840233680467362, 'fraction_numerical': 0.003556007112014224, 'mean_word_length': 2.497335701598579, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '781418', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1435, 'n_words': 362}