#!/usr/bin/env perl
#
#
=pod

=head1 NAME

bookshelf-mkfontsel - a script to populate C<fontsel> directory and create C<pickfont.tex> file for I<bookshelf> package

=head1 SYNOPSIS

bookshelf-mkfontsel FONTFILE

=head1 DESCRIPTION

Create and populate fontsel directory from the file
produced by L<listallfonts.pl(1)> script, and create
C<pickfont.tex> file.  Used by
I<bookshelf> package.

=head1 OPTIONS

=over 4

=item B<-v>

Print version information

=item B<-h>

Print usage information

=item B<-m>

Print manual page

=back

=head1 AUTHOR

Boris Veytsman, 2024

=head1 LICENSE

LPPL 1.3c

=cut


use strict;
use Getopt::Long;
use Pod::Usage;
use open qw( :std :encoding(UTF-8) );
my $VERSION = "1.0";

my $help=0;
my $man=0;
my $vrs=0;

GetOptions(
    "help|?" => \$help,
    "man" => \$man,
    "version" => \$vrs
    ) or pod2usage(2);

pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose=>2) if $man;
die ("$0, version $VERSION, License: LPPL 1.3c\n") if $vrs;




`mkdir -p fontsel`;
my $i=1;
while(<>) {
    chomp;
    if (/^.*#/) {
	next;
    }
    my ($name, $command) = split /\t/;
    open(RES, ">fontsel/$i.tex");
    print RES "\\font\\SILmfont={$command}\\SILmfont\n";
    print RES "\\def\\SILmfontname{$name}%\n";
    close RES;
    $i++;    	       
}
$i--;
open(RES, ">pickfont.tex");
print RES "\\setcounter{SIL\@maxfont}{$i}\n";
close RES;