I tried to to parse the output of calling nibtool with the -L option, in the backtick operator.
Nibtool defaults to utf-16.

Attempting to do a split with the pattern /=/ failed, by not splitting the input string.

This could be fixed by either;
1) Passing the --utf8 option to nibtool,
    and in the perl script specifying
use utf8
2) Pass the -R  (macroman encoding option) to nibtool.

Are there any ways to parse nibtool output generated by the backtick operation, that don't require hardcoding character encoding used by the perl script, and don't require hardcoding the output character encoding of the nibtool -L command

My Perl script is as follows in the latest version:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;

if ( @ARGV !=2) {
    die "Usage: nibfixup Nibfile Applicationname\n" ;
}

my $nibfile = $ARGV[0];
my $appname = $ARGV[1];

my ($nibdir,$nibname) = ($nibfile =~ /^(.*\/)?([A-Za-z]+\.nib)$/);
$nibdir = '' unless $nibdir;

#call Nibtool, reading the userinterface strings of the nibfile into dictionary.
my $dictionary = `/usr/bin/nibtool --utf8 -L $nibfile`;

my @dictionary = split(/\n/,$dictionary);

open (DICT,'>','temp.strings') or die "Could not open dictionary file \n";

#replace the word NewApplication by the second comman line parameter
#in the localized strings whereever it occurs.
for my $i (@dictionary) {
    my @i = split /=/ , $i;
    if (1 ==  scalar @i) {
        print DICT $i,"\n";
    } else {
        if (scalar @i) {
            my $j = shift @i;
            print DICT "$j=";
            $j = shift @i;
            $j =~ s/NewApplication/$appname/o;
            print DICT $j;
            for $j (@i) {
                print DICT "=$j";
            }
        }
        print DICT "\n";
    }
}

close DICT;

#rename the nib file
system ('/bin/mv' ,$nibfile ,"${nibdir}old.$nibname")==0 or die "Could not rename nib file\n";

#use Nibtool to set The application name to correct value in the user interface system ('/usr/bin/nibtool' ,'--utf8','-w',$nibfile,'- d','temp.strings',"${nibdir}old.$nibname")
    == 0 or die "Could not update nibfile\n";

#remove old nib, and temporary dictionary.
system ('/bin/rm', '-rf', "${nibdir}old.$nibname") == 0 or die "Could not remove nib copy\n"; system ('/bin/rm', 'temp.strings') == 0 or die "Could not remove temporary dictionary\n";

-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
[EMAIL PROTECTED]



Reply via email to