Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
     5         kx #!@INTLTOOL_PERL@ -w
     5         kx # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4  -*-
     5         kx 
     5         kx #
     5         kx #  The Intltool Message Updater
     5         kx #
     5         kx #  Copyright (C) 2000-2003 Free Software Foundation.
     5         kx #
     5         kx #  Intltool is free software; you can redistribute it and/or
     5         kx #  modify it under the terms of the GNU General Public License
     5         kx #  version 2 published by the Free Software Foundation.
     5         kx #
     5         kx #  Intltool is distributed in the hope that it will be useful,
     5         kx #  but WITHOUT ANY WARRANTY; without even the implied warranty of
     5         kx #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     5         kx #  General Public License for more details.
     5         kx #
     5         kx #  You should have received a copy of the GNU General Public License
     5         kx #  along with this program; if not, write to the Free Software
     5         kx #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     5         kx #
     5         kx #  As a special exception to the GNU General Public License, if you
     5         kx #  distribute this file as part of a program that contains a
     5         kx #  configuration script generated by Autoconf, you may include it under
     5         kx #  the same distribution terms that you use for the rest of that program.
     5         kx #
     5         kx #  Authors: Kenneth Christiansen <kenneth@gnu.org>
     5         kx #           Maciej Stachowiak
     5         kx #           Darin Adler <darin@bentspoon.com>
     5         kx 
     5         kx ## Release information
     5         kx my $PROGRAM = "intltool-update";
     5         kx my $VERSION = "@VERSION@";
     5         kx my $PACKAGE = "@PACKAGE@";
     5         kx 
     5         kx ## Loaded modules
     5         kx use strict;
     5         kx use Getopt::Long;
     5         kx use Cwd;
     5         kx use File::Copy;
     5         kx use File::Find;
     5         kx 
     5         kx ## Scalars used by the option stuff
     5         kx my $HELP_ARG 	   = 0;
     5         kx my $VERSION_ARG    = 0;
     5         kx my $DIST_ARG	   = 0;
     5         kx my $POT_ARG	   = 0;
     5         kx my $HEADERS_ARG    = 0;
     5         kx my $MAINTAIN_ARG   = 0;
     5         kx my $REPORT_ARG     = 0;
     5         kx my $VERBOSE	   = 0;
     5         kx my $GETTEXT_PACKAGE = "";
     5         kx my $OUTPUT_FILE    = "";
     5         kx 
     5         kx my @languages;
     5         kx my %varhash = ();
     5         kx my %po_files_by_lang = ();
     5         kx 
     5         kx # Regular expressions to categorize file types.
     5         kx # FIXME: Please check if the following is correct
     5         kx 
     5         kx my $xml_support =
     5         kx "xml(?:\\.in)*|".	# http://www.w3.org/XML/ (Note: .in is not required)
     5         kx "ui|".			# Bonobo specific - User Interface desc. files
     5         kx "lang|".		# ?
     5         kx "glade2?(?:\\.in)*|".	# Glade specific - User Interface desc. files (Note: .in is not required)
     5         kx "oaf(?:\\.in)+|".	# DEPRECATED: Replaces by Bonobo .server files
     5         kx "etspec|".		# ?
     5         kx "server(?:\\.in)+|".	# Bonobo specific
     5         kx "sheet(?:\\.in)+|".	# ?
     5         kx "schemas(?:\\.in)+|".	# GConf specific
     5         kx "gschema.xml|".         # GLib schema (ie: GSettings) specific
     5         kx "pong(?:\\.in)+|".	# DEPRECATED: PONG is not used [by GNOME] any longer.
     5         kx "kbd(?:\\.in)+|".	# GOK specific.
     5         kx "policy(?:\\.in)+";	# PolicyKit files
     5         kx 
     5         kx my $ini_support =
     5         kx "icon(?:\\.in)+|".	# http://www.freedesktop.org/Standards/icon-theme-spec
     5         kx "desktop(?:\\.in)+|".	# http://www.freedesktop.org/Standards/menu-spec
     5         kx "caves(?:\\.in)+|".	# GNOME Games specific
     5         kx "directory(?:\\.in)+|".	# http://www.freedesktop.org/Standards/menu-spec
     5         kx "soundlist(?:\\.in)+|".	# GNOME specific
     5         kx "keys(?:\\.in)+|".	# GNOME Mime database specific
     5         kx "theme(?:\\.in)+|".	# http://www.freedesktop.org/Standards/icon-theme-spec
     5         kx "service(?:\\.in)+";    # DBus specific
     5         kx 
     5         kx my $tlk_support =
     5         kx "tlk(?:\\.in)+";        # Bioware Aurora Talk Table Format
     5         kx 
     5         kx my $buildin_gettext_support =
     5         kx "c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py|scm(?:\\.in)*";
     5         kx 
     5         kx ## Always flush buffer when printing
     5         kx $| = 1;
     5         kx 
     5         kx ## Sometimes the source tree will be rooted somewhere else.
     5         kx my $SRCDIR = $ENV{"srcdir"} || ".";
     5         kx my $POTFILES_in;
     5         kx 
     5         kx $POTFILES_in = "<$SRCDIR/POTFILES.in";
     5         kx 
     5         kx my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
     5         kx 
     5         kx ## Handle options
     5         kx GetOptions
     5         kx (
     5         kx  "help" 	       => \$HELP_ARG,
     5         kx  "version" 	       => \$VERSION_ARG,
     5         kx  "dist|d"	       => \$DIST_ARG,
     5         kx  "pot|p"	       => \$POT_ARG,
     5         kx  "headers|s"	       => \$HEADERS_ARG,
     5         kx  "maintain|m"	       => \$MAINTAIN_ARG,
     5         kx  "report|r"	       => \$REPORT_ARG,
     5         kx  "verbose|x"	       => \$VERBOSE,
     5         kx  "gettext-package|g=s" => \$GETTEXT_PACKAGE,
     5         kx  "output-file|o=s"     => \$OUTPUT_FILE,
     5         kx  ) or &Console_WriteError_InvalidOption;
     5         kx 
     5         kx &Console_Write_IntltoolHelp if $HELP_ARG;
     5         kx &Console_Write_IntltoolVersion if $VERSION_ARG;
     5         kx 
     5         kx my $arg_count = ($DIST_ARG > 0)
     5         kx     + ($POT_ARG > 0)
     5         kx     + ($HEADERS_ARG > 0)
     5         kx     + ($MAINTAIN_ARG > 0)
     5         kx     + ($REPORT_ARG > 0);
     5         kx 
     5         kx &Console_Write_IntltoolHelp if $arg_count > 1;
     5         kx 
     5         kx my $MODULE = $GETTEXT_PACKAGE || FindPackageName() || "unknown";
     5         kx 
     5         kx if ($POT_ARG)
     5         kx {
     5         kx     &GenerateHeaders;
     5         kx     &GeneratePOTemplate;
     5         kx }
     5         kx elsif ($HEADERS_ARG)
     5         kx {
     5         kx     &GenerateHeaders;
     5         kx }
     5         kx elsif ($MAINTAIN_ARG)
     5         kx {
     5         kx     &FindLeftoutFiles;
     5         kx }
     5         kx elsif ($REPORT_ARG)
     5         kx {
     5         kx     &GenerateHeaders;
     5         kx     &GeneratePOTemplate;
     5         kx     &Console_Write_CoverageReport;
     5         kx }
     5         kx elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
     5         kx {
     5         kx     my $lang = $ARGV[0];
     5         kx 
     5         kx     ## Report error if the language file supplied
     5         kx     ## to the command line is non-existent
     5         kx     &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
     5         kx         if ! -s "$SRCDIR/$lang.po";
     5         kx 
     5         kx     if (!$DIST_ARG)
     5         kx     {
     5         kx 	print "Working, please wait..." if $VERBOSE;
     5         kx 	&GenerateHeaders;
     5         kx 	&GeneratePOTemplate;
     5         kx     }
     5         kx     &POFile_Update ($lang, $OUTPUT_FILE);
     5         kx     &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
     5         kx }
     5         kx else
     5         kx {
     5         kx     &Console_Write_IntltoolHelp;
     5         kx }
     5         kx 
     5         kx exit;
     5         kx 
     5         kx #########
     5         kx 
     5         kx sub Console_Write_IntltoolVersion
     5         kx {
     5         kx     print <<_EOF_;
     5         kx ${PROGRAM} (${PACKAGE}) $VERSION
     5         kx Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
     5         kx 
     5         kx Copyright (C) 2000-2003 Free Software Foundation, Inc.
     5         kx This is free software; see the source for copying conditions.  There is NO
     5         kx warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     5         kx _EOF_
     5         kx     exit;
     5         kx }
     5         kx 
     5         kx sub Console_Write_IntltoolHelp
     5         kx {
     5         kx     print <<_EOF_;
     5         kx Usage: ${PROGRAM} [OPTION]... LANGCODE
     5         kx Updates PO template files and merge them with the translations.
     5         kx 
     5         kx Mode of operation (only one is allowed):
     5         kx   -p, --pot                   generate the PO template only
     5         kx   -s, --headers               generate the header files in POTFILES.in
     5         kx   -m, --maintain              search for left out files from POTFILES.in
     5         kx   -r, --report                display a status report for the module
     5         kx   -d, --dist                  merge LANGCODE.po with existing PO template
     5         kx 
     5         kx Extra options:
     5         kx   -g, --gettext-package=NAME  override PO template name, useful with --pot
     5         kx   -o, --output-file=FILE      write merged translation to FILE
     5         kx   -x, --verbose               display lots of feedback
     5         kx       --help                  display this help and exit
     5         kx       --version               output version information and exit
     5         kx 
     5         kx Examples of use:
     5         kx ${PROGRAM} --pot    just create a new PO template
     5         kx ${PROGRAM} xy       create new PO template and merge xy.po with it
     5         kx 
     5         kx Report bugs to http://bugs.launchpad.net/intltool
     5         kx _EOF_
     5         kx     exit;
     5         kx }
     5         kx 
     5         kx sub echo_n
     5         kx {
     5         kx     my $str = shift;
     5         kx     my $ret = `echo "$str"`;
     5         kx 
     5         kx     $ret =~ s/\n$//; # do we need the "s" flag?
     5         kx 
     5         kx     return $ret;
     5         kx }
     5         kx 
     5         kx sub POFile_DetermineType ($)
     5         kx {
     5         kx    my $type = $_;
     5         kx    my $gettext_type;
     5         kx 
     5         kx    my $xml_regex     = "(?:" . $xml_support . ")";
     5         kx    my $ini_regex     = "(?:" . $ini_support . ")";
     5         kx    my $tlk_regex     = "(?:" . $tlk_support . ")";
     5         kx    my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
     5         kx 
     5         kx    if ($type =~ /\[type: gettext\/([^\]].*)]/)
     5         kx    {
     5         kx 	$gettext_type=$1;
     5         kx    }
     5         kx    elsif ($type =~ /gschema.xml$/)
     5         kx    {
     5         kx 	$gettext_type="gsettings";
     5         kx    }
     5         kx    elsif ($type =~ /schemas(\.in)+$/)
     5         kx    {
     5         kx 	$gettext_type="schemas";
     5         kx    }
     5         kx    elsif ($type =~ /glade2?(\.in)*$/)
     5         kx    {
     5         kx        $gettext_type="glade";
     5         kx    }
     5         kx    elsif ($type =~ /scm(\.in)*$/)
     5         kx    {
     5         kx        $gettext_type="scheme";
     5         kx    }
     5         kx    elsif ($type =~ /keys(\.in)+$/)
     5         kx    {
     5         kx        $gettext_type="keys";
     5         kx    }
     5         kx 
     5         kx    # bucket types
     5         kx 
     5         kx    elsif ($type =~ /$xml_regex$/)
     5         kx    {
     5         kx        $gettext_type="xml";
     5         kx    }
     5         kx    elsif ($type =~ /$ini_regex$/)
     5         kx    {
     5         kx        $gettext_type="ini";
     5         kx    }
     5         kx    elsif ($type =~ /$tlk_regex$/)
     5         kx    {
     5         kx        $gettext_type="tlk";
     5         kx    }
     5         kx    elsif ($type =~ /$buildin_regex$/)
     5         kx    {
     5         kx        $gettext_type="buildin";
     5         kx    }
     5         kx    else
     5         kx    {
     5         kx        $gettext_type="unknown";
     5         kx    }
     5         kx 
     5         kx    return "gettext\/$gettext_type";
     5         kx }
     5         kx 
     5         kx sub TextFile_DetermineEncoding ($)
     5         kx {
     5         kx     my $gettext_code="UTF-8"; # All files are UTF-8 by default
     5         kx     my $filetype=`file $_ | cut -d ' ' -f 2`;
     5         kx 
     5         kx     if ($? eq "0")
     5         kx     {
     5         kx 	if ($filetype =~ /^(ISO|UTF)/)
     5         kx 	{
     5         kx 	    chomp ($gettext_code = $filetype);
     5         kx 	}
     5         kx 	elsif ($filetype =~ /^XML/)
     5         kx 	{
     5         kx 	    $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     return $gettext_code;
     5         kx }
     5         kx 
     5         kx sub isNotValidMissing
     5         kx {
     5         kx     my ($file) = @_;
     5         kx     my $package_name = "";
     5         kx     my $version = "";
     5         kx     $package_name = $varhash{"PACKAGE"} if (defined $varhash{"PACKAGE"});
     5         kx     $version = $varhash{"VERSION"} if (defined $varhash{"VERSION"});
     5         kx 
     5         kx     return if $file =~ /^\{arch\}\/.*$/;
     5         kx     return if $file =~ /^$package_name-$version\/.*$/;
     5         kx }
     5         kx 
     5         kx sub removeFromArray
     5         kx {
     5         kx     my ($file, @array) = @_;
     5         kx 
     5         kx     my $i = 0;
     5         kx     foreach my $potfile (@array) {
     5         kx         delete $array[$i] if $potfile =~ m/$file/;
     5         kx         $i++;
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub AddFileToListIfMissing
     5         kx {
     5         kx     my ($file, $list) = @_;
     5         kx 
     5         kx     my $name_pattern;
     5         kx     if ($file =~ /^\.\.\//) {
     5         kx         $name_pattern = "x3 A*";
     5         kx     } else {
     5         kx         $name_pattern = "A*";
     5         kx     }
     5         kx 
     5         kx     my $file_name = unpack($name_pattern, $file);
     5         kx     if (defined isNotValidMissing ($file_name)) {
     5         kx         ## Remove the first 3 chars if needed and add newline
     5         kx         push @$list, $file_name . "\n";
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub FindLeftoutFiles
     5         kx {
     5         kx     my (@buf_i18n_plain,
     5         kx 	@buf_i18n_xml,
     5         kx 	@buf_i18n_xml_unmarked,
     5         kx 	@buf_i18n_ini,
     5         kx 	@buf_potfiles,
     5         kx 	@buf_potfiles_ignore,
     5         kx 	@buf_allfiles,
     5         kx 	@buf_allfiles_sorted,
     5         kx 	@buf_potfiles_sorted,
     5         kx         @buf_potfiles_ignore_sorted
     5         kx     );
     5         kx 
     5         kx     ## Search and find all translatable files
     5         kx     find sub {
     5         kx 	# Ignore hidden files
     5         kx 	return if "$File::Find::name" =~ /\/\./;
     5         kx 	push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
     5         kx 	push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
     5         kx 	push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
     5         kx 	push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
     5         kx 	}, "..";
     5         kx     find sub {
     5         kx 	# Ignore hidden files
     5         kx 	return if "$File::Find::name" =~ /\/\.[^.]/;
     5         kx 	push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
     5         kx 	push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
     5         kx 	push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
     5         kx 	push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
     5         kx 	}, "$SRCDIR/.." if "$SRCDIR" ne ".";
     5         kx 
     5         kx     open POTFILES, $POTFILES_in or die "$PROGRAM:  there's no POTFILES.in!\n";
     5         kx     @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
     5         kx     close POTFILES;
     5         kx 
     5         kx     foreach (@buf_potfiles) {
     5         kx 	s/^\[.*]\s*//;
     5         kx     }
     5         kx 
     5         kx     print "Searching for missing translatable files...\n" if $VERBOSE;
     5         kx 
     5         kx     ## Check if we should ignore some found files, when
     5         kx     ## comparing with POTFILES.in
     5         kx     foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
     5         kx     {
     5         kx 	(-s "$SRCDIR/$ignore") or next;
     5         kx 
     5         kx 	if ("$ignore" eq "POTFILES.ignore")
     5         kx 	{
     5         kx 	    print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
     5         kx 		  "content of this file to POTFILES.skip.\n";
     5         kx 	}
     5         kx 
     5         kx 	print "Found $ignore: Ignoring files...\n" if $VERBOSE;
     5         kx 	open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
     5         kx 
     5         kx 	while (<FILE>)
     5         kx 	{
     5         kx             next if (/^$/);
     5         kx             next if (/^(#|\s*$)/);
     5         kx 
     5         kx             my $skipdir = "../$_";
     5         kx             $skipdir = "$SRCDIR/../$_" if "$SRCDIR" ne ".";
     5         kx             $skipdir =~ s/\n//g;
     5         kx 
     5         kx             my @dirignored;
     5         kx 
     5         kx             if (-d "$skipdir")
     5         kx             {
     5         kx                 find sub {
     5         kx                     push @dirignored, "$File::Find::name" if /\.($buildin_gettext_support)$/;
     5         kx                     push @dirignored, "$File::Find::name" if /\.($xml_support)$/;
     5         kx                     push @dirignored, "$File::Find::name" if /\.($ini_support)$/;
     5         kx                     push @dirignored, "$File::Find::name" if /\.(schemas(\.in)+)$/;
     5         kx                 }, "$skipdir";
     5         kx                 foreach my $ignored (@dirignored)
     5         kx                 {
     5         kx                     $ignored =~ s/^$SRCDIR\///g;
     5         kx                     $ignored =~ s/^..\///g;
     5         kx                     $ignored =~ s/$/\n/g;
     5         kx 
     5         kx                     removeFromArray ($ignored, @buf_i18n_plain);
     5         kx                     removeFromArray ($ignored, @buf_i18n_xml);
     5         kx                     removeFromArray ($ignored, @buf_i18n_ini);
     5         kx                     removeFromArray ($ignored, @buf_i18n_xml_unmarked);
     5         kx                     push @buf_potfiles_ignore, $ignored;
     5         kx                 }
     5         kx                 next;
     5         kx             }
     5         kx             removeFromArray ($_, @buf_i18n_plain);
     5         kx             removeFromArray ($_, @buf_i18n_xml);
     5         kx             removeFromArray ($_, @buf_i18n_ini);
     5         kx             removeFromArray ($_, @buf_i18n_xml_unmarked);
     5         kx             push @buf_potfiles_ignore, $_;
     5         kx 	}
     5         kx 	close FILE;
     5         kx 
     5         kx 	@buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
     5         kx     }
     5         kx 
     5         kx     foreach my $file (@buf_i18n_plain)
     5         kx     {
     5         kx 	my $in_comment = 0;
     5         kx 	my $in_macro = 0;
     5         kx         my $in_string = 0;
     5         kx         my @multiline_quotes;
     5         kx         if ($file =~ /\.scm/) {
     5         kx             @multiline_quotes = ('"');
     5         kx         } else {
     5         kx             @multiline_quotes = ("'''", '"""');
     5         kx         }
     5         kx 
     5         kx 	open FILE, "<$file";
     5         kx 	while (<FILE>)
     5         kx 	{
     5         kx             if ($file =~ /\.scm/) {
     5         kx                 # Strip single quotes from .scm files.
     5         kx                 s-\'--g;
     5         kx             }
     5         kx 
     5         kx 	    # Handle continued multi-line comment.
     5         kx 	    if ($in_comment)
     5         kx 	    {
     5         kx 		next unless s-.*\*/--;
     5         kx 		$in_comment = 0;
     5         kx 	    }
     5         kx 
     5         kx             # Handle continued multi-line string.
     5         kx             if ($in_string)
     5         kx             {
     5         kx                 my $pattern = join '|', @multiline_quotes;
     5         kx                 if (!s/.*$pattern//) {
     5         kx                     s///s;
     5         kx                     next;
     5         kx                 };
     5         kx                 $in_string = 0;
     5         kx             }
     5         kx 
     5         kx 	    # Handle continued macro.
     5         kx 	    if ($in_macro)
     5         kx 	    {
     5         kx 		$in_macro = 0 unless /\\$/;
     5         kx 		next;
     5         kx 	    }
     5         kx 
     5         kx 	    # Handle start of macro (or any preprocessor directive).
     5         kx 	    if (/^\s*\#/)
     5         kx 	    {
     5         kx 		$in_macro = 1 if /^([^\\]|\\.)*\\$/;
     5         kx 		next;
     5         kx             }
     5         kx 
     5         kx 	    # Handle comments and quoted text.
     5         kx 	    while (m-(/\*|//|\'\'\'|\"\"\"|\'|\")-) # \' and \" keep emacs perl mode happy
     5         kx 	    {
     5         kx 		my $match = $1;
     5         kx 		if ($match eq "/*")
     5         kx 		{
     5         kx 		    if (!s-/\*.*?\*/--)
     5         kx 		    {
     5         kx 			s-/\*.*--;
     5         kx 			$in_comment = 1;
     5         kx 		    }
     5         kx 		}
     5         kx 		elsif ($match eq "//")
     5         kx 		{
     5         kx 		    s-//.*--;
     5         kx 		}
     5         kx                 elsif (grep($match, @multiline_quotes))
     5         kx                 {
     5         kx                     if (!s-$match(\\$match|[^$match])*$match-QUOTEDTEXT-g)
     5         kx                     {
     5         kx                         s-$match.*-QUOTEDTEXT-s;
     5         kx                         $in_string = 1;
     5         kx                     }
     5         kx                 }
     5         kx 		else # ' or "
     5         kx 		{
     5         kx 		    s-$match(\\$match|[^$match])*$match-QUOTEDTEXT-g;
     5         kx 
     5         kx                     # Handle inline # comments.
     5         kx                     s/^([^$match]+)\#.*/$1/;
     5         kx 
     5         kx 		    if (m-$match-)
     5         kx 		    {
     5         kx 			warn "mismatched quotes at line $. in $file\n";
     5         kx 			s-$match.*--;
     5         kx 		    }
     5         kx 		}
     5         kx 	    }
     5         kx 
     5         kx 	    if (/\w\.GetString *\(QUOTEDTEXT/)
     5         kx 	    {
     5         kx                 AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx 		last;
     5         kx 	    }
     5         kx 
     5         kx             ## C_ N_ NC_ Q_ and _ are the macros defined in gi8n.h
     5         kx 	    if (/(NC_|[NCQ]_|[^_]_|(^|$)[_]) *\(?QUOTEDTEXT/m)
     5         kx 	    {
     5         kx                 AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx 		last;
     5         kx 	    }
     5         kx 
     5         kx             # Check for direct calls to the glib gettext wrappers
     5         kx             if (/g_d[np]?gettext[2]? *\(QUOTEDTEXT/)
     5         kx             {
     5         kx                 AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx                 last;
     5         kx             }
     5         kx 	}
     5         kx 	close FILE;
     5         kx     }
     5         kx 
     5         kx     foreach my $file (@buf_i18n_xml)
     5         kx     {
     5         kx 	open FILE, "<$file";
     5         kx 
     5         kx 	while (<FILE>)
     5         kx 	{
     5         kx 	    # FIXME: share the pattern matching code with intltool-extract
     5         kx 	    if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
     5         kx 	    {
     5         kx                 AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx 		last;
     5         kx 	    }
     5         kx 	}
     5         kx 	close FILE;
     5         kx     }
     5         kx 
     5         kx     foreach my $file (@buf_i18n_ini)
     5         kx     {
     5         kx 	open FILE, "<$file";
     5         kx 	while (<FILE>)
     5         kx 	{
     5         kx 	    if (/_(.*)=/)
     5         kx 	    {
     5         kx                 AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx 		last;
     5         kx 	    }
     5         kx 	}
     5         kx 	close FILE;
     5         kx     }
     5         kx 
     5         kx     foreach my $file (@buf_i18n_xml_unmarked)
     5         kx     {
     5         kx         AddFileToListIfMissing($file, \@buf_allfiles);
     5         kx     }
     5         kx 
     5         kx 
     5         kx     @buf_allfiles_sorted = sort (@buf_allfiles);
     5         kx     @buf_potfiles_sorted = sort (@buf_potfiles);
     5         kx 
     5         kx     my %in2;
     5         kx     foreach (@buf_potfiles_sorted)
     5         kx     {
     5         kx         s#^$SRCDIR/../##;
     5         kx         s#^$SRCDIR/##;
     5         kx 	$in2{$_} = 1;
     5         kx     }
     5         kx 
     5         kx     foreach (@buf_potfiles_ignore_sorted)
     5         kx     {
     5         kx         s#^$SRCDIR/../##;
     5         kx         s#^$SRCDIR/##;
     5         kx 	$in2{$_} = 1;
     5         kx     }
     5         kx 
     5         kx     my @result;
     5         kx 
     5         kx     foreach (@buf_allfiles_sorted)
     5         kx     {
     5         kx         my $dummy = $_;
     5         kx         my $srcdir = $SRCDIR;
     5         kx 
     5         kx         $srcdir =~ s#^../##;
     5         kx         $dummy =~ s#^$srcdir/../##;
     5         kx         $dummy =~ s#^$srcdir/##;
     5         kx         $dummy =~ s#_build/##;
     5         kx 	if (!exists($in2{$dummy}))
     5         kx 	{
     5         kx 	    push @result, $dummy
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     my @buf_potfiles_notexist;
     5         kx 
     5         kx     foreach (@buf_potfiles_sorted)
     5         kx     {
     5         kx 	chomp (my $dummy = $_);
     5         kx 	if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
     5         kx 	{
     5         kx 	    push @buf_potfiles_notexist, $_;
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     ## Save file with information about the files missing
     5         kx     ## if any, and give information about this procedure.
     5         kx     if (@result + @buf_potfiles_notexist > 0)
     5         kx     {
     5         kx 	if (@result)
     5         kx 	{
     5         kx 	    print "\n" if $VERBOSE;
     5         kx 	    unlink "missing";
     5         kx 	    open OUT, ">missing";
     5         kx 	    print OUT @result;
     5         kx 	    close OUT;
     5         kx 	    warn "The following files contain translations and are currently not in use. Please\n".
     5         kx 	         "consider adding these to the POTFILES.in file, located in the po/ directory.\n\n";
     5         kx 	    print STDERR @result, "\n";
     5         kx 	    warn "If some of these files are left out on purpose then please add them to\n".
     5         kx 		 "POTFILES.skip instead of POTFILES.in. A file 'missing' containing this list\n".
     5         kx 		 "of left out files has been written in the current directory.\n";
     5         kx             warn "Please report to ". $varhash{"PACKAGE_BUGREPORT"} ."\n" if (defined $varhash{"PACKAGE_BUGREPORT"});
     5         kx 	}
     5         kx 	if (@buf_potfiles_notexist)
     5         kx 	{
     5         kx 	    unlink "notexist";
     5         kx 	    open OUT, ">notexist";
     5         kx 	    print OUT @buf_potfiles_notexist;
     5         kx 	    close OUT;
     5         kx 	    warn "\n" if ($VERBOSE or @result);
     5         kx 	    warn "The following files do not exist anymore:\n\n";
     5         kx 	    warn @buf_potfiles_notexist, "\n";
     5         kx 	    warn "Please remove them from POTFILES.in. A file 'notexist'\n".
     5         kx                 "containing this list of absent files has been written in the current directory.\n";
     5         kx             warn "Please report to ". $varhash{"PACKAGE_BUGREPORT"} ."\n" if (defined $varhash{"PACKAGE_BUGREPORT"});
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     ## If there is nothing to complain about, notify the user
     5         kx     else {
     5         kx 	print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub Console_WriteError_InvalidOption
     5         kx {
     5         kx     ## Handle invalid arguments
     5         kx     print STDERR "Try `${PROGRAM} --help' for more information.\n";
     5         kx     exit 1;
     5         kx }
     5         kx 
     5         kx sub isProgramInPath
     5         kx {
     5         kx     my ($file) = @_;
     5         kx     # If a file is executable (or exists on Windows),
     5         kx     # or when it returns 0 exit status.
     5         kx     return 1 if (
     5         kx         ((-x $file) or ($^O eq 'MSWin32' and (-e $file))) or
     5         kx         (system("$file --version >$devnull") == 0));
     5         kx     return 0;
     5         kx }
     5         kx 
     5         kx sub isGNUGettextTool
     5         kx {
     5         kx     my ($file) = @_;
     5         kx     # Check that we are using GNU gettext tools
     5         kx     if (isProgramInPath ($file))
     5         kx     {
     5         kx         my $version = `$file --version`;
     5         kx         return 1 if ($version =~ m/.*\(GNU .*\).*/);
     5         kx     }
     5         kx     return 0;
     5         kx }
     5         kx 
     5         kx sub GenerateHeaders
     5         kx {
     5         kx     my $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} || "intltool-extract";
     5         kx 
     5         kx     ## Generate the .h header files, so we can allow glade and
     5         kx     ## xml translation support
     5         kx     if (! isProgramInPath ("$EXTRACT"))
     5         kx     {
     5         kx 	print STDERR "\n *** The intltool-extract script wasn't found!"
     5         kx 	     ."\n *** Without it, intltool-update can not generate files.\n";
     5         kx 	exit;
     5         kx     }
     5         kx     else
     5         kx     {
     5         kx 	open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
     5         kx 
     5         kx 	while (<FILE>)
     5         kx 	{
     5         kx 	   chomp;
     5         kx 	   next if /^\[\s*encoding/;
     5         kx 
     5         kx 	   ## Find xml files in POTFILES.in and generate the
     5         kx 	   ## files with help from the extract script
     5         kx 
     5         kx 	   my $gettext_type= &POFile_DetermineType ($1);
     5         kx 
     5         kx 	   if (/\.($xml_support|$ini_support|$tlk_support)$/ || /^\[/)
     5         kx 	   {
     5         kx 	       s/^\[[^\[].*]\s*//;
     5         kx 
     5         kx 	       my @cmd = ($EXTRACT, "--update", "--type=$gettext_type",
     5         kx 	                  "--srcdir=$SRCDIR");
     5         kx 
     5         kx 	       unshift (@cmd, $^X) if ($^O eq 'MSWin32' && !($EXTRACT =~ /perl/));
     5         kx 
     5         kx 	       push (@cmd, "--quiet") if (! $VERBOSE);
     5         kx 	       push (@cmd, "../$_");
     5         kx 
     5         kx 	       system (@cmd);
     5         kx 	   }
     5         kx        }
     5         kx        close FILE;
     5         kx    }
     5         kx }
     5         kx 
     5         kx #
     5         kx # Generate .pot file from POTFILES.in
     5         kx #
     5         kx sub GeneratePOTemplate
     5         kx {
     5         kx     my $XGETTEXT = $ENV{"XGETTEXT"} || "xgettext";
     5         kx     my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
     5         kx     chomp $XGETTEXT;
     5         kx 
     5         kx     if (! isGNUGettextTool ("$XGETTEXT"))
     5         kx     {
     5         kx 	print STDERR " *** GNU xgettext is not found on this system!\n".
     5         kx 		     " *** Without it, intltool-update can not extract strings.\n";
     5         kx 	exit;
     5         kx     }
     5         kx 
     5         kx     print "Building $MODULE.pot...\n" if $VERBOSE;
     5         kx 
     5         kx     open INFILE, $POTFILES_in;
     5         kx     unlink "POTFILES.in.temp";
     5         kx     open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
     5         kx 
     5         kx     my $gettext_support_nonascii = 0;
     5         kx 
     5         kx     # checks for GNU gettext >= 0.12
     5         kx     my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
     5         kx     if ($? == 0)
     5         kx     {
     5         kx 	$gettext_support_nonascii = 1;
     5         kx     }
     5         kx     else
     5         kx     {
     5         kx 	# require gnu gettext >= 0.12
     5         kx 	die "$PROGRAM: GNU gettext >= 0.12 is required for intltool\n";
     5         kx     }
     5         kx 
     5         kx     my $encoding = "UTF-8";
     5         kx     my $forced_gettext_code;
     5         kx     my @temp_headers;
     5         kx     my $encoding_problem_is_reported = 0;
     5         kx 
     5         kx     while (<INFILE>)
     5         kx     {
     5         kx 	next if (/^#/ or /^\s*$/);
     5         kx 
     5         kx 	chomp;
     5         kx 
     5         kx 	my $gettext_code;
     5         kx 
     5         kx 	if (/^\[\s*encoding:\s*(.*)\s*\]/)
     5         kx 	{
     5         kx 	    $forced_gettext_code=$1;
     5         kx 	}
     5         kx 	elsif (/\.($xml_support|$ini_support|$tlk_support)$/ || /^\[/)
     5         kx 	{
     5         kx 	    s/^\[.*]\s*//;
     5         kx             print OUTFILE "../$_.h\n";
     5         kx 	    push @temp_headers, "../$_.h";
     5         kx 	    $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
     5         kx 	}
     5         kx 	else
     5         kx 	{
     5         kx             print OUTFILE "../$_\n";
     5         kx 	    $gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
     5         kx 	}
     5         kx 
     5         kx 	next if (! $gettext_support_nonascii);
     5         kx 
     5         kx 	if (defined $forced_gettext_code)
     5         kx 	{
     5         kx 	    $encoding=$forced_gettext_code;
     5         kx 	}
     5         kx 	elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
     5         kx 	{
     5         kx 	    if ($encoding eq "ASCII")
     5         kx 	    {
     5         kx 		$encoding=$gettext_code;
     5         kx 	    }
     5         kx 	    elsif ($gettext_code ne "ASCII")
     5         kx 	    {
     5         kx 		# Only report once because the message is quite long
     5         kx 		if (! $encoding_problem_is_reported)
     5         kx 		{
     5         kx 		    print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
     5         kx 				 "         but $PROGRAM thinks that most of the source files are in\n".
     5         kx 				 "         $encoding encoding, while \"$_\" is (likely) in\n".
     5         kx 		       		 "         $gettext_code encoding. If you are sure that all translatable strings\n".
     5         kx 				 "         are in same encoding (say UTF-8), please *prepend* the following\n".
     5         kx 				 "         line to POTFILES.in:\n\n".
     5         kx 				 "                 [encoding: UTF-8]\n\n".
     5         kx 				 "         and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
     5         kx 				 "(such warning message will only be reported once.)\n";
     5         kx 		    $encoding_problem_is_reported = 1;
     5         kx 		}
     5         kx 	    }
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     close OUTFILE;
     5         kx     close INFILE;
     5         kx 
     5         kx     unlink "$MODULE.pot";
     5         kx     my @xgettext_argument=("$XGETTEXT",
     5         kx 			   "--add-comments",
     5         kx 			   "--directory\=.",
     5         kx                            "--directory\=$SRCDIR",
     5         kx                            "--default-domain\=$MODULE",
     5         kx                            "--flag\=g_strdup_printf:1:c-format",
     5         kx                            "--flag\=g_string_printf:2:c-format",
     5         kx                            "--flag\=g_string_append_printf:2:c-format",
     5         kx                            "--flag\=g_error_new:3:c-format",
     5         kx                            "--flag\=g_set_error:4:c-format",
     5         kx                            "--flag\=g_markup_printf_escaped:1:c-format",
     5         kx                            "--flag\=g_log:3:c-format",
     5         kx                            "--flag\=g_print:1:c-format",
     5         kx                            "--flag\=g_printerr:1:c-format",
     5         kx                            "--flag\=g_printf:1:c-format",
     5         kx                            "--flag\=g_fprintf:2:c-format",
     5         kx                            "--flag\=g_sprintf:2:c-format",
     5         kx                            "--flag\=g_snprintf:3:c-format",
     5         kx                            "--flag\=g_scanner_error:2:c-format",
     5         kx                            "--flag\=g_scanner_warn:2:c-format",
     5         kx 			   "--output\=$MODULE\.pot",
     5         kx 			   "--files-from\=\.\/POTFILES\.in\.temp");
     5         kx     my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
     5         kx     push @xgettext_argument, $XGETTEXT_KEYWORDS;
     5         kx     my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
     5         kx     push @xgettext_argument, "--msgid-bugs-address\=\"$MSGID_BUGS_ADDRESS\"" if $MSGID_BUGS_ADDRESS;
     5         kx     push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
     5         kx     push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
     5         kx     my $xgettext_command = join ' ', @xgettext_argument;
     5         kx 
     5         kx     # intercept xgettext error message
     5         kx     print "Running $xgettext_command\n" if $VERBOSE;
     5         kx     my $xgettext_error_msg = `$xgettext_command 2>\&1`;
     5         kx     my $command_failed = $?;
     5         kx 
     5         kx     unlink "POTFILES.in.temp";
     5         kx 
     5         kx     print "Removing generated header (.h) files..." if $VERBOSE;
     5         kx     unlink foreach (@temp_headers);
     5         kx     print "done.\n" if $VERBOSE;
     5         kx 
     5         kx     if (! $command_failed)
     5         kx     {
     5         kx 	if (! -e "$MODULE.pot")
     5         kx 	{
     5         kx 	    print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
     5         kx 	}
     5         kx 	else
     5         kx 	{
     5         kx 	    print "Wrote $MODULE.pot\n" if $VERBOSE;
     5         kx 	}
     5         kx     }
     5         kx     else
     5         kx     {
     5         kx 	if ($xgettext_error_msg =~ /--from-code/)
     5         kx 	{
     5         kx             my $errlocation = "unknown";
     5         kx 
     5         kx             if ($xgettext_error_msg =~ /Non-ASCII string at (.*)\..*/)
     5         kx             {
     5         kx                 $errlocation = $1;
     5         kx             }
     5         kx             print STDERR "ERROR: xgettext failed to generate PO tempalte file because the following     \n".
     5         kx                          "       file contains strings marked for translation, not encoded in UTF-8.    \n".
     5         kx                          "       Please ensure all strings marked for translation are UTF-8 encoded.  \n\n".
     5         kx                          "           $errlocation\n\n";
     5         kx 	}
     5         kx 	else
     5         kx 	{
     5         kx 	    print STDERR "$xgettext_error_msg";
     5         kx 	    if (-e "$MODULE.pot")
     5         kx 	    {
     5         kx 		# is this possible?
     5         kx 		print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
     5         kx 			     "       Please consult error message above if there is any.\n";
     5         kx 	    }
     5         kx 	    else
     5         kx 	    {
     5         kx 		print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
     5         kx 			     "       error message above if there is any.\n";
     5         kx 	    }
     5         kx 	}
     5         kx 	exit (1);
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub POFile_Update
     5         kx {
     5         kx     -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
     5         kx 
     5         kx     my $MSGMERGE = $ENV{"MSGMERGE"} || "msgmerge";
     5         kx     my ($lang, $outfile) = @_;
     5         kx 
     5         kx     if (! isGNUGettextTool ("$MSGMERGE"))
     5         kx     {
     5         kx 	print STDERR " *** GNU msgmerge is not found on this system!\n".
     5         kx 		     " *** Without it, intltool-update can not extract strings.\n";
     5         kx 	exit;
     5         kx     }
     5         kx 
     5         kx     print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
     5         kx 
     5         kx     my $infile = "$SRCDIR/$lang.po";
     5         kx     $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
     5         kx 
     5         kx     # I think msgmerge won't overwrite old file if merge is not successful
     5         kx     system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
     5         kx }
     5         kx 
     5         kx sub Console_WriteError_NotExisting
     5         kx {
     5         kx     my ($file) = @_;
     5         kx 
     5         kx     ## Report error if supplied language file is non-existing
     5         kx     print STDERR "$PROGRAM: $file does not exist!\n";
     5         kx     print STDERR "Try '$PROGRAM --help' for more information.\n";
     5         kx     exit;
     5         kx }
     5         kx 
     5         kx sub GatherPOFiles
     5         kx {
     5         kx     my @po_files = glob ("./*.po");
     5         kx 
     5         kx     @languages = map (&POFile_GetLanguage, @po_files);
     5         kx 
     5         kx     foreach my $lang (@languages)
     5         kx     {
     5         kx 	$po_files_by_lang{$lang} = shift (@po_files);
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub POFile_GetLanguage ($)
     5         kx {
     5         kx     s/^(.*\/)?(.+)\.po$/$2/;
     5         kx     return $_;
     5         kx }
     5         kx 
     5         kx sub Console_Write_TranslationStatus
     5         kx {
     5         kx     my ($lang, $output_file) = @_;
     5         kx     my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
     5         kx 
     5         kx     if (! isGNUGettextTool ("$MSGFMT"))
     5         kx     {
     5         kx 	print STDERR " *** GNU msgfmt is not found on this system!\n".
     5         kx 		     " *** Without it, intltool-update can not extract strings.\n";
     5         kx 	exit;
     5         kx     }
     5         kx 
     5         kx     $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
     5         kx 
     5         kx     system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
     5         kx }
     5         kx 
     5         kx sub Console_Write_CoverageReport
     5         kx {
     5         kx     my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
     5         kx 
     5         kx     if (! isGNUGettextTool ("$MSGFMT"))
     5         kx     {
     5         kx 	print STDERR " *** GNU msgfmt is not found on this system!\n".
     5         kx 		     " *** Without it, intltool-update can not extract strings.\n";
     5         kx 	exit;
     5         kx     }
     5         kx 
     5         kx     &GatherPOFiles;
     5         kx 
     5         kx     foreach my $lang (@languages)
     5         kx     {
     5         kx 	print STDERR "$lang: ";
     5         kx 	&POFile_Update ($lang, "");
     5         kx     }
     5         kx 
     5         kx     print STDERR "\n\n * Current translation support in $MODULE \n\n";
     5         kx 
     5         kx     foreach my $lang (@languages)
     5         kx     {
     5         kx 	print STDERR "$lang: ";
     5         kx 	system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub SubstituteVariable
     5         kx {
     5         kx     my ($str) = @_;
     5         kx 
     5         kx     # always need to rewind file whenever it has been accessed
     5         kx     seek (CONF, 0, 0);
     5         kx 
     5         kx     # cache each variable. varhash is global to we can add
     5         kx     # variables elsewhere.
     5         kx     while (<CONF>)
     5         kx     {
     5         kx 	if (/^(\w+)=(.*)$/)
     5         kx 	{
     5         kx 	    ($varhash{$1} = $2) =~  s/^["'](.*)["']$/$1/;
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     if ($str =~ /^(.*)\$\{?([A-Z_]+)}?(.*)$/)
     5         kx     {
     5         kx 	my $rest = $3;
     5         kx 	my $untouched = $1;
     5         kx 	my $sub = "";
     5         kx         # Ignore recursive definitions of variables
     5         kx         $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
     5         kx 
     5         kx 	return SubstituteVariable ("$untouched$sub$rest");
     5         kx     }
     5         kx 
     5         kx     # We're using Perl backticks ` and "echo -n" here in order to
     5         kx     # expand any shell escapes (such as backticks themselves) in every variable
     5         kx     return echo_n ($str);
     5         kx }
     5         kx 
     5         kx sub CONF_Handle_Open
     5         kx {
     5         kx     my $base_dirname = getcwd();
     5         kx     $base_dirname =~ s@.*/@@;
     5         kx 
     5         kx     my ($conf_in, $src_dir);
     5         kx 
     5         kx     if ($base_dirname =~ /^po(-.+)?$/)
     5         kx     {
     5         kx 	if (-f "Makevars")
     5         kx 	{
     5         kx 	    my $makefile_source;
     5         kx 
     5         kx 	    local (*IN);
     5         kx 	    open (IN, "<Makevars") || die "can't open Makevars: $!";
     5         kx 
     5         kx 	    while (<IN>)
     5         kx 	    {
     5         kx 		if (/^top_builddir[ \t]*=/)
     5         kx 		{
     5         kx 		    $src_dir = $_;
     5         kx 		    $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
     5         kx 
     5         kx 		    chomp $src_dir;
     5         kx                     if (-f "$src_dir" . "/configure.ac") {
     5         kx                         $conf_in = "$src_dir" . "/configure.ac" . "\n";
     5         kx                     } else {
     5         kx                         $conf_in = "$src_dir" . "/configure.in" . "\n";
     5         kx                     }
     5         kx 		    last;
     5         kx 		}
     5         kx 	    }
     5         kx 	    close IN;
     5         kx 
     5         kx 	    $conf_in || die "Cannot find top_builddir in Makevars.";
     5         kx 	}
     5         kx 	elsif (-f "$SRCDIR/../configure.ac")
     5         kx 	{
     5         kx 	    $conf_in = "$SRCDIR/../configure.ac";
     5         kx 	}
     5         kx 	elsif (-f "$SRCDIR/../configure.in")
     5         kx 	{
     5         kx 	    $conf_in = "$SRCDIR/../configure.in";
     5         kx 	}
     5         kx 	else
     5         kx 	{
     5         kx 	    my $makefile_source;
     5         kx 
     5         kx 	    local (*IN);
     5         kx 	    open (IN, "<Makefile") || return;
     5         kx 
     5         kx 	    while (<IN>)
     5         kx 	    {
     5         kx 		if (/^top_srcdir[ \t]*=/)
     5         kx 		{
     5         kx 		    $src_dir = $_;
     5         kx 		    $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
     5         kx 
     5         kx 		    chomp $src_dir;
     5         kx 		    $conf_in = "$src_dir" . "/configure.in" . "\n";
     5         kx 
     5         kx 		    last;
     5         kx 		}
     5         kx 	    }
     5         kx 	    close IN;
     5         kx 
     5         kx 	    $conf_in || die "Cannot find top_srcdir in Makefile.";
     5         kx 	}
     5         kx 
     5         kx 	open (CONF, "<$conf_in");
     5         kx     }
     5         kx     else
     5         kx     {
     5         kx 	print STDERR "$PROGRAM: Unable to proceed.\n" .
     5         kx 		     "Make sure to run this script inside the po directory.\n";
     5         kx 	exit;
     5         kx     }
     5         kx }
     5         kx 
     5         kx sub FindPackageName
     5         kx {
     5         kx     my $version;
     5         kx     my $domain = &FindMakevarsDomain;
     5         kx     my $name = $domain || "untitled";
     5         kx     my $bugurl;
     5         kx 
     5         kx     &CONF_Handle_Open;
     5         kx 
     5         kx     my $conf_source; {
     5         kx 	local (*IN);
     5         kx 	open (IN, "<&CONF") || return $name;
     5         kx 	seek (IN, 0, 0);
     5         kx 	local $/; # slurp mode
     5         kx 	$conf_source = <IN>;
     5         kx 	close IN;
     5         kx     }
     5         kx 
     5         kx     # priority for getting package name:
     5         kx     # 1. GETTEXT_PACKAGE
     5         kx     # 2. first argument of AC_INIT (with >= 2 arguments)
     5         kx     # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
     5         kx 
     5         kx     # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m
     5         kx     # the \s makes this not work, why?
     5         kx     if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
     5         kx     {
     5         kx 	($name, $version) = ($1, $2);
     5         kx 	$name    =~ s/[\[\]\s]//g;
     5         kx 	$version =~ s/[\[\]\s]//g;
     5         kx 	$name    =~ s/\(+$//g;
     5         kx 	$version =~ s/\(+$//g;
     5         kx 
     5         kx 	$varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\$\{?AC_PACKAGE_NAME}?/);
     5         kx 	$varhash{"PACKAGE"} = $name if (not $name =~ /\$\{?PACKAGE}?/);
     5         kx 	$varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\$\{?AC_PACKAGE_VERSION}?/);
     5         kx 	$varhash{"VERSION"} = $version if (not $name =~ /\$\{?VERSION}?/);
     5         kx     }
     5         kx 
     5         kx     if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)[,]?([^,\)]+)?/m)
     5         kx     {
     5         kx 	($name, $version) = ($1, $2);
     5         kx         $bugurl = $3 if (defined $3);
     5         kx 
     5         kx         # Handle m4_esyscmd
     5         kx         # FIXME: We should do this in a more generic way that works for all vars
     5         kx         if ($version =~ /m4_esyscmd\([\[]?([^\)\]]+)/)
     5         kx         {
     5         kx             my $cwd = getcwd ();
     5         kx             chdir ("$SRCDIR/..");
     5         kx             $version = qx($1);
     5         kx             chdir ($cwd);
     5         kx         }
     5         kx 
     5         kx 
     5         kx 	$name    =~ s/[\[\]\s]//g;
     5         kx 	$version =~ s/[\[\]\s]//g;
     5         kx         $bugurl  =~ s/[\[\]\s]//g if (defined $bugurl);
     5         kx 	$name    =~ s/\(+$//g;
     5         kx 	$version =~ s/\(+$//g;
     5         kx         $bugurl  =~ s/\(+$//g if (defined $bugurl);
     5         kx 
     5         kx 	$varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\$\{?AC_PACKAGE_NAME}?/);
     5         kx 	$varhash{"PACKAGE"} = $name if (not $name =~ /\$\{?PACKAGE}?/);
     5         kx 	$varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\$\{?AC_PACKAGE_VERSION}?/);
     5         kx 	$varhash{"VERSION"} = $version if (not $name =~ /\$\{?VERSION}?/);
     5         kx         $varhash{"PACKAGE_BUGREPORT"} = $bugurl if (defined $bugurl and not $bugurl =~ /\$\{?\w+}?/);
     5         kx     }
     5         kx 
     5         kx     # \s makes this not work, why?
     5         kx     $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
     5         kx 
     5         kx     # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
     5         kx     # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
     5         kx     $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
     5         kx 
     5         kx     $name = $domain if $domain;
     5         kx 
     5         kx     $name = SubstituteVariable ($name);
     5         kx     $name =~ s/^["'](.*)["']$/$1/;
     5         kx 
     5         kx     return $name if $name;
     5         kx }
     5         kx 
     5         kx 
     5         kx sub FindPOTKeywords
     5         kx {
     5         kx 
     5         kx     my $keywords = "--keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 --keyword=Q_ --keyword=g_dgettext:2 --keyword=g_dngettext:2,3 --keyword=g_dpgettext:2 --keyword=g_dpgettext2=2c,3";
     5         kx     my $varname = "XGETTEXT_OPTIONS";
     5         kx     my $make_source; {
     5         kx 	local (*IN);
     5         kx 	open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
     5         kx 	seek (IN, 0, 0);
     5         kx 	local $/; # slurp mode
     5         kx 	$make_source = <IN>;
     5         kx 	close IN;
     5         kx     }
     5         kx 
     5         kx     # unwrap lines split with a trailing \
     5         kx     $make_source =~  s/\\ $ \n/ /mxg;
     5         kx     $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
     5         kx 
     5         kx     return $keywords;
     5         kx }
     5         kx 
     5         kx sub FindMakevarsDomain
     5         kx {
     5         kx 
     5         kx     my $domain = "";
     5         kx     my $makevars_source; {
     5         kx 	local (*IN);
     5         kx 	open (IN, "<Makevars") || return $domain;
     5         kx 	seek (IN, 0, 0);
     5         kx 	local $/; # slurp mode
     5         kx 	$makevars_source = <IN>;
     5         kx 	close IN;
     5         kx     }
     5         kx 
     5         kx     $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
     5         kx     $domain =~ s/^\s+//;
     5         kx     $domain =~ s/\s+$//;
     5         kx 
     5         kx     return $domain;
     5         kx }
     5         kx 
     5         kx sub FindMakevarsBugAddress
     5         kx {
     5         kx 
     5         kx     my $address = "";
     5         kx     my $makevars_source; {
     5         kx 	local (*IN);
     5         kx 	open (IN, "<Makevars") || return undef;
     5         kx 	seek (IN, 0, 0);
     5         kx 	local $/; # slurp mode
     5         kx 	$makevars_source = <IN>;
     5         kx 	close IN;
     5         kx     }
     5         kx 
     5         kx     $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
     5         kx     $address =~ s/^\s+//;
     5         kx     $address =~ s/\s+$//;
     5         kx 
     5         kx     return $address;
     5         kx }