#!/usr/bin/perl

# a lame attempt at xgettext for perl
# no line numbers, yet

# 5.005_02 in particular seems to have a BIG BUG
# resulting in an endless loop and a memory leak in the 
# regex machinery :(

## updated by salsaman for LiVES

exit 0 unless ( $] >= 5.005_03 || $] <= 5.005 );

undef $/;

use File::Basename;

$prefix=$ARGV[0];
shift (@ARGV);

while (<>) {
    $file = $ARGV;
    $file =~ s/\.\.\///;
    $basename = basename($file);

    while (/(?:N|print) \(?"((?:[^"\\]+|\\.)*)"\)?/sg) {
       my $s = $1;
       if($s=~/\|/){
       @temp=split(/\|/, $s);
       } else {
       $s =~ s/\\n//;
       @temp[0]=$s;
       } if ($temp[0]) {
       $e = "msgid \"$temp[0]\"\n";
       $e .= "msgstr \"\"\n";
       $fileposition = "#: $prefix/share/lives/plugins/effects/rendered/$basename:0\n";
       push @{$entry{$e}}, $fileposition;
       }
       if($temp[1] and not $temp[1]=~/[0-9]/) {
       $e = "msgid \"$temp[1]\"\n";
       $e .= "msgstr \"\"\n";
       push @{$entry{$e}}, $fileposition;              
       }
       
    }
}

foreach $e (sort keys %entry) {
    if ($e=~/layout/ or $e=~/hseparator/) {} else {
    print @{$entry{$e}};
    print $e;
    print "\n";
    }
}


