-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaml2txt.pl
executable file
·55 lines (44 loc) · 1.44 KB
/
naml2txt.pl
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
48
49
50
51
52
53
54
#!/usr/bin/perl
#
# this script is released under the Fair License (see LICENSE)
#
# copyright, 2014, Armin Stebich ([email protected])
use Getopt::Std;
my $eol = "\n";
getopts('hi:o:');
my $help = defined($opt_h) ? 1 : 0;
my $infile = defined($opt_i) ? $opt_i : "";
my $outfile = defined($opt_o) ? $opt_o : "";
help() if( $help or "" eq $infile or "" eq $outfile);
open(TXTFILE, ">$outfile") or die "Could not open $outfile for writing! ($!)\n";
open(NAMLFILE, "<$infile") or die "Could not open $infile for reading! ($!)\n";
while( <NAMLFILE>) {
chomp( $_);
# find all lines of this kind:
# <translation><from>Source</from><to>Translation</to></translation>
# or commnet lines, starting with #
if( m'\s*<translation>\s*<from>.*</from>\s*<to>(.*)</to>\s*</translation>\s*'i
or m'(#.*)'i) {
print TXTFILE $1.$eol;
}
# add comment tags to txt file
elsif (m'(\s*<!--.*-->)'i) {
print TXTFILE '# '.$1.$eol;
}
# add newlines to txt file
elsif (m'^\s*$'i) {
print TXTFILE $eol;
}
}
close(NAMLFILE);
close(TXTFILE);
exit 0;
sub help()
{
print "\n$0, create a text file from nabble.com NAML file to check spellings\n\n";
print "Usage: $0 [options] -i NAMLFILE -o TXTFILE\n";
print " options: -h this help message\n";
print " -i path/name of the NAML file (input)\n";
print " -o path/name of the TXT file (output)\n\n";
exit -1;
}