69 lines
1.6 KiB
Perl
Executable File
69 lines
1.6 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/";
|
|
require kettext;
|
|
|
|
if ($#ARGV+1 == 0) {
|
|
showUsage();
|
|
exit;
|
|
}
|
|
my @files;
|
|
my $file_name;
|
|
my $output = 0;
|
|
my $output_file;
|
|
my $converter = "HTML";
|
|
my %cmd_settings = ();
|
|
for (my $arg_i = 0; $arg_i < $#ARGV+1; $arg_i++) {
|
|
if ($ARGV[$arg_i] =~ m/^-(-|)(.*)/) {
|
|
if ($2 =~ m/^(h(elp|))$/) {
|
|
showUsage();
|
|
exit;
|
|
} elsif ($2 =~ m/^(o(ut|utput|))$/) {
|
|
$output = 1;
|
|
} elsif ($2 =~ m/^(convert(To|))=(.*)$/) {
|
|
$converter = $3;
|
|
} else {
|
|
if ($2 =~ m/^(.[^\=]*)(\=|)(.*|)/) {
|
|
$cmd_settings{$1} = (length($3) ? $3 : 1);
|
|
}
|
|
}
|
|
} else {
|
|
if ($output == 1) {
|
|
$output_file = $ARGV[$arg_i];
|
|
$output = 2;
|
|
} else {
|
|
push @files, $ARGV[$arg_i];
|
|
$file_name = $ARGV[$arg_i];
|
|
}
|
|
}
|
|
}
|
|
if ($output > 0) {
|
|
if (!$output_file) {
|
|
print "No output file specified!\n";
|
|
exit 1;
|
|
} else {
|
|
open STDOUT, '>', $output_file;
|
|
}
|
|
}
|
|
if (my $sub_ref = kettext::convertTo->can($converter)) {
|
|
foreach (@files) {
|
|
my %parsed_file = kettext::parseFile($_, \%cmd_settings);
|
|
$sub_ref->(%parsed_file);
|
|
}
|
|
} else {
|
|
print "Converter \"$converter\" could not be found!\n";
|
|
exit 2;
|
|
}
|
|
|
|
sub showUsage {
|
|
print "Usage: kettext.pl *.ktx [options]\n";
|
|
print " --help\n";
|
|
print " show this help screen\n";
|
|
print " --group.setting=val\n";
|
|
print " set parse/convert setting (e.g., \"--header.numbering\", \"--header.depth=2\")\n";
|
|
print " --convert=, --convertTo=OUTPUT\n";
|
|
print " sets the output converter. Default: HTML\n";
|
|
print " --o, --out, --output filename\n";
|
|
print " sets the output file. Default: stdout\n";
|
|
}
|