commit:     2d2ee989b05556a6ba109458f2fdb605eeb596e1
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Aug 10 16:57:23 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sun Aug 10 17:04:42 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=2d2ee989

Delegate config file selection wholly to a new subroutine

This commit introduces the select_config_file() subroutine, which
relieves both the main block and the parse_opts() subroutine of their
joint responsibility in determining which config files are to be passed
to the read_config() subroutine.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/locale-gen b/locale-gen
index d1d66d7..948ee59 100755
--- a/locale-gen
+++ b/locale-gen
@@ -74,15 +74,7 @@ umask 0022;
        my @locales = ([ 'C', 'UTF-8', 'C.UTF-8' ]);
 
        # Compose a list of up to two configuration files to be read.
-       my @config_files;
-       if (exists $opt{'config'}) {
-               push @config_files, $opt{'config'};
-       } else {
-               push @config_files, (
-                       catfile($prefix, '/etc', 'locale.gen'),
-                       catfile($prefix, '/usr/share/i18n', 'SUPPORTED')
-               );
-       }
+       my @config_files = select_config_files($prefix, %opt);
 
        # Collect the locales that are being requested for installation.
        push @locales, read_config($prefix, @config_files);
@@ -196,15 +188,29 @@ sub parse_opts ($known_prefix, @args) {
        if (! exists $opt{'jobs'} || $opt{'jobs'} < 1) {
                $opt{'jobs'} = get_nprocs() || 1;
        }
-       if ($opt{'all'}) {
-               $opt{'config'} = catfile($opt{'prefix'} // $known_prefix, 
'/usr/share/i18n', 'SUPPORTED');
-       } elsif (exists $opt{'config'} && $opt{'config'} eq '-') {
+
+       # Replace the special <hyphen-minus> operand with "/dev/stdin".
+       if (exists $opt{'config'} && $opt{'config'} eq '-') {
                $opt{'config'} = '/dev/stdin';
        }
 
        return %opt;
 }
 
+sub select_config_files ($prefix, %opt) {
+       my $path1 = catfile($prefix, '/etc', 'locale.gen');
+       my $path2 = catfile($prefix, '/usr/share/i18n', 'SUPPORTED');
+       return do {
+               if (exists $opt{'config'}) {
+                       $opt{'config'};
+               } elsif (! $opt{'all'}) {
+                       $path1, $path2;
+               } else {
+                       $path2;
+               }
+       };
+}
+
 sub show_usage (@options) {
        print "Usage: locale-gen [OPTION]...\n\n";
        my $pipe;

Reply via email to