kettext.pl now has proper usage screen. Also allows for convertor specification via --convert/--convertTo=HTML. Other stuff too!
parent
1f19efe295
commit
9cb4f36ee4
49
kettext.pl
49
kettext.pl
|
|
@ -2,24 +2,65 @@
|
||||||
require kettext;
|
require kettext;
|
||||||
# arg check / usage
|
# arg check / usage
|
||||||
if ($#ARGV+1 == 0) {
|
if ($#ARGV+1 == 0) {
|
||||||
printf "Usage: kettext.pl file_name.ktx\n";
|
showUsage();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
my @files;
|
||||||
my $file_name;
|
my $file_name;
|
||||||
|
my $output = 0;
|
||||||
|
my $output_file;
|
||||||
|
my $converter = "HTML";
|
||||||
my %cmd_settings = ();
|
my %cmd_settings = ();
|
||||||
for (my $arg_i = 0; $arg_i < $#ARGV+1; $arg_i++) {
|
for (my $arg_i = 0; $arg_i < $#ARGV+1; $arg_i++) {
|
||||||
if ($ARGV[$arg_i] =~ m/^-(-|)(.*)/) {
|
if ($ARGV[$arg_i] =~ m/^-(-|)(.*)/) {
|
||||||
if ($2 =~ m/^(h(elp|))$/) {
|
if ($2 =~ m/^(h(elp|))$/) {
|
||||||
printf "Usage: kettext.pl file_name.ktx\n";
|
showUsage();
|
||||||
exit;
|
exit;
|
||||||
|
} elsif ($2 =~ m/^(o(ut|utput|))$/) {
|
||||||
|
$output = 1;
|
||||||
|
} elsif ($2 =~ m/^(convert(To|))=(.*)$/) {
|
||||||
|
$converter = $3;
|
||||||
} else {
|
} else {
|
||||||
if ($2 =~ m/^(.[^\=]*)(\=|)(.*|)/) {
|
if ($2 =~ m/^(.[^\=]*)(\=|)(.*|)/) {
|
||||||
$cmd_settings{$1} = (length($3) ? $3 : 1);
|
$cmd_settings{$1} = (length($3) ? $3 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($output == 1) {
|
||||||
|
$output_file = $ARGV[$arg_i];
|
||||||
|
$output = 2;
|
||||||
|
} else {
|
||||||
|
push @files, $ARGV[$arg_i];
|
||||||
$file_name = $ARGV[$arg_i];
|
$file_name = $ARGV[$arg_i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my %parsed_file = kettext::parseFile($file_name, \%cmd_settings);
|
}
|
||||||
kettext::convertTo::HTML(%parsed_file);
|
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\n";
|
||||||
|
print " set parse/convert setting (e.g., \"--header.numbering\")\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";
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue