texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Use XDG Base Directory Specification for director


From: Patrice Dumas
Subject: branch master updated: Use XDG Base Directory Specification for directory lookups
Date: Thu, 29 Aug 2024 02:18:21 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 7ba5100639 Use XDG Base Directory Specification for directory lookups
7ba5100639 is described below

commit 7ba51006395793fe6bdfdd2fc195cba27c6f758b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Aug 29 08:17:59 2024 +0200

    Use XDG Base Directory Specification for directory lookups
    
    * tp/Texinfo/Common.pm (locate_file_in_dirs), tp/t/test_utils.pl
    (test), tp/texi2any.pl (locate_and_load_init_file)
    (locate_and_load_extension_file): add deprecated directories argument
    and return deprecated directories used.  Update callers.
    
    * tp/texi2any.pl (add_config_paths): add function to setup directories
    using XDG Base Directory Specification environment variable,
    installation directory and default XDG Base Directory Specification
    directories.  The default XDG Base Directory Specification directories
    are added (last) even if the environment variable is set, such as to
    always have directories searched implementation and user-configuration
    independent.
    
    * tp/texi2any.pl (set_subdir_directories): set all the directories
    where files are searched for in a subdirectory.  In current directory,
    in HOME, following the XDG Base Directory Specification and by calling
    add_config_paths.  Set deprecated_dirs information with dot directory
    directly found in HOME that is deprecated by XDG Base Directory
    Specification HOME directories.  Use set_subdir_directories to set
    @texinfo_language_config_dirs, @program_config_dirs.
    
    * tp/texi2any.pl (_warn_deprecated_dirs, $config_init_files)
    (locate_and_load_init_file): warn for deprecated directories.
    
    * tp/Texinfo/Convert/Converter.pm (%common_converters_defaults),
    tp/texi2any.pl: pass main program deprecated directories information
    to converter through deprecated_config_directories key value.
    
    * tp/Texinfo/Convert/HTML.pm (_parse_htmlxref_files): pass
    deprecated_config_directories to locate_file_in_dirs and warn about
    deprecated directories used.
    
    * NEWS, doc/texi2any_api.texi (Loading Init Files), doc/texinfo.texi
    (HTML Xref Configuration): update directory lookup descriptions.
---
 ChangeLog                       |  39 +++++++++
 NEWS                            |   6 ++
 doc/texi2any_api.texi           |  76 +++++++++++++++--
 doc/texinfo.texi                |  41 ++++++++--
 tp/Texinfo/Common.pm            |  36 +++++---
 tp/Texinfo/Convert/Converter.pm |   1 +
 tp/Texinfo/Convert/HTML.pm      |  30 ++++++-
 tp/t/test_utils.pl              |   8 +-
 tp/texi2any.pl                  | 177 ++++++++++++++++++++++++++++++++++------
 9 files changed, 361 insertions(+), 53 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 67d0a5042e..a7d684a432 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2024-08-28  Patrice Dumas  <pertusus@free.fr>
+
+       Use XDG Base Directory Specification for directory lookups
+
+       * tp/Texinfo/Common.pm (locate_file_in_dirs), tp/t/test_utils.pl
+       (test), tp/texi2any.pl (locate_and_load_init_file)
+       (locate_and_load_extension_file): add deprecated directories argument
+       and return deprecated directories used.  Update callers.
+
+       * tp/texi2any.pl (add_config_paths): add function to setup directories
+       using XDG Base Directory Specification environment variable,
+       installation directory and default XDG Base Directory Specification
+       directories.  The default XDG Base Directory Specification directories
+       are added (last) even if the environment variable is set, such as to
+       always have directories searched implementation and user-configuration
+       independent.
+
+       * tp/texi2any.pl (set_subdir_directories): set all the directories
+       where files are searched for in a subdirectory.  In current directory,
+       in HOME, following the XDG Base Directory Specification and by calling
+       add_config_paths.  Set deprecated_dirs information with dot directory
+       directly found in HOME that is deprecated by XDG Base Directory
+       Specification HOME directories.  Use set_subdir_directories to set
+       @texinfo_language_config_dirs, @program_config_dirs.
+
+       * tp/texi2any.pl (_warn_deprecated_dirs, $config_init_files)
+       (locate_and_load_init_file): warn for deprecated directories.
+
+       * tp/Texinfo/Convert/Converter.pm (%common_converters_defaults),
+       tp/texi2any.pl: pass main program deprecated directories information
+       to converter through deprecated_config_directories key value.
+
+       * tp/Texinfo/Convert/HTML.pm (_parse_htmlxref_files): pass
+       deprecated_config_directories to locate_file_in_dirs and warn about
+       deprecated directories used.
+
+       * NEWS, doc/texi2any_api.texi (Loading Init Files), doc/texinfo.texi
+       (HTML Xref Configuration): update directory lookup descriptions.
+
 2024-08-28  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texi2any_api.texi (Simple Navigation Panel Customization): the
diff --git a/NEWS b/NEWS
index 23b993fccd..7fd3b72f51 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,12 @@ See the manual for detailed information.
    the linguistic tailoring of index sorting
  . new variable USE_UNICODE_COLLATION to allow turning off the slower
    use of Unicode collation when sorting indices
+ . Add XDG Base Directory Specification support for search paths.
+   The dot directories directly found in users home, ~/.texinfo and
+   ~/.texi2any are deprecated and should be replaced by texinfo or
+   texi2any directories in XDG_CONFIG_HOME or in ~/.config/.  In future
+   versions the ~/.texinfo and ~/.texi2any directories will not be
+   in search paths.
  . remove SIMPLE_MENU customization option and tree transformation.
  . remove FRAMES and FRAMESET_DOCTYPE customization options.
  . remove AVOID_MENU_REDUNDANCY, NO_USE_SETFILENAME and
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 7696263448..4770fa2f50 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -107,18 +107,45 @@ of @file{texi2any-config.pm} files is not definitive.
 You can write so-called @dfn{initialization files}, or @dfn{init
 files} for short, to modify almost every aspect of output formatting.
 The program loads init files named @file{texi2any-config.pm} each time it
-is run.  Those files are looked for in the following directories:
+is run.  The directories lookup is based on the 
@url{https://specifications.freedesktop.org/basedir-spec/latest/, XDG Base
+Directory Specification} with additional possibilities.
+The @file{texi2any-config.pm} files are looked for in the
+following directories:
 
 @table @file
+@item /usr/share/texi2any/
+(with @file{/usr/share/} the second default directory for @env{XDG_DATA_DIRS}
+in the XDG Base Directory Specification)
+
+@item /usr/local/share/texi2any/
+(with @file{/usr/local/share} the first default directory for
+@env{XDG_DATA_DIRS} in the XDG Base Directory Specification)
+
 @item @var{datadir}/texi2any/
 (where @var{datadir} is the system data directory specified at
 compile-time, e.g., @file{/usr/local/share})
 
+@item @env{XDG_DATA_DIRS}/texi2any
+(for each directory in the @code{:} delimited @env{XDG_DATA_DIRS} environment
+variable, in reverse order)
+
+@item /etc/xdg/texi2any/
+(with @file{/etc/xdg} the default directory for @env{XDG_CONFIG_DIRS}
+in the XDG Base Directory Specification)
+
 @item @var{sysconfdir}/texi2any/
-(likewise specified at compile time, e.g., @file{/usr/local/etc})
+(specified at compile time, e.g., @file{/usr/local/etc})
+
+@item @env{XDG_CONFIG_DIRS}/texi2any
+(for each directory in the @code{:} delimited @env{XDG_CONFIG_DIRS}
+environment variable, in reverse order)
 
-@item ~/.texi2any/
-(where @code{~} is the current user's home directory)
+@item ~/.config/texi2any/
+(where @code{~} is the current user's home directory, only if
+@env{XDG_CONFIG_HOME} is not set)
+
+@item @env{XDG_CONFIG_HOME}/texi2any
+(with @env{XDG_CONFIG_HOME} an environment variable)
 
 @item ./.texi2any/
 (under the current directory)
@@ -129,7 +156,7 @@ compile-time, e.g., @file{/usr/local/share})
 
 All @file{texi2any-config.pm} files found are loaded, in the above order.
 Thus, @file{./texi2any-config.pm} can override entries in, say,
-@file{/usr/local/share/makeinfo/texi2any-config.pm}.
+@file{/usr/local/share/texi2any/texi2any-config.pm}.
 
 @c @opindex --init-file
 @cindex @option{--init-file}
@@ -145,25 +172,58 @@ file found is used:
 
 @item @file{./.texi2any/} under the current directory;
 
-@item @file{~/.texi2any/}
-where @code{~} is the current user's home directory;
+@item @env{XDG_CONFIG_HOME}/texi2any if the @env{XDG_CONFIG_HOME} environment 
+is set, otherwise ~/.config/texi2any/ where @code{~} is the current user's home
+directory;
+
+@item if the environment variable @env{XDG_CONFIG_DIRS} is set,
+@var{directory}/texi2any for each @var{directory} in the
+@code{:} delimited @env{XDG_CONFIG_DIRS} environment variable value;
 
 @item @file{@var{sysconfdir}/texi2any/}
 where @var{sysconfdir} is the system configuration directory
 specified at compile-time, e.g., @file{/usr/local/etc};
 
+@item @file{/etc/xdg/texi2any/}
+
+@item if the environment variable @env{XDG_DATA_DIRS} is set,
+@var{directory}/texi2any for each @var{directory} in the
+@code{:} delimited @env{XDG_DATA_DIRS} environment variable value;
+
 @item @file{@var{datadir}/texi2any/}
-Where @var{datadir} is the system data directory likewise specified at
+Where @var{datadir} is the system data directory specified at
 compile time, e.g., @file{/usr/local/share};
 
+@item @file{/usr/local/share/texi2any/}
+
+@item @file{/usr/share/texi2any/}
+
 @item @file{./.texinfo/init/} under the current directory;
 
 @item @file{~/.texinfo/init/} under the current home directory;
 
+@item @env{XDG_CONFIG_HOME}/texinfo/init if the @env{XDG_CONFIG_HOME}
+environment is set, otherwise ~/.config/texinfo/init/ where @code{~} is the
+current user's home directory;
+
+@item if the environment variable @env{XDG_CONFIG_DIRS} is set,
+@var{directory}/texinfo/init for each @var{directory} in the
+@code{:} delimited @env{XDG_CONFIG_DIRS} environment variable value;
+
 @item @file{@var{sysconfdir}/texinfo/init/} with @var{sysconfdir} as above;
 
+@item @file{/etc/xdg/texinfo/init/}
+
+@item if the environment variable @env{XDG_DATA_DIRS} is set,
+@var{directory}/texinfo/init for each @var{directory} in the
+@code{:} delimited @env{XDG_DATA_DIRS} environment variable value;
+
 @item @file{@var{datadir}/texinfo/init/} with @var{datadir} as above.
 
+@item @file{/usr/local/share/texinfo/init/}
+
+@item @file{/usr/share/texinfo/init/}
+
 @item @file{@var{datadir}/texinfo/ext/} with @var{datadir} as above.
 @end enumerate
 
diff --git a/doc/texinfo.texi b/doc/texinfo.texi
index cc772d93ad..e68e744d79 100644
--- a/doc/texinfo.texi
+++ b/doc/texinfo.texi
@@ -17832,7 +17832,9 @@ web.
 
 @command{texi2any} reads a file named @file{htmlxref.cnf} to gather
 information for cross-references to other manuals in HTML output.  It
-is looked for in the following directories:
+is looked for in the following directories, based on the
+@url{https://specifications.freedesktop.org/basedir-spec/latest/, XDG Base
+Directory Specification} with additional possibilities:
 
 @table @file
 @item ./
@@ -17846,21 +17848,48 @@ For example, if the input file is 
@file{some/dir/mymanual.texi},
 @item ./.texinfo/
 (under the current directory)
 
-@item ~/.texinfo/
-(where @code{~} is the current user's home directory)
+@item @env{XDG_CONFIG_HOME}/texinfo
+(with @env{XDG_CONFIG_HOME} an environment variable)
+
+@item ~/.config/texinfo/
+(where @code{~} is the current user's home directory, only if
+@env{XDG_CONFIG_HOME} is not set)
+
+@item @env{XDG_CONFIG_DIRS}/texinfo
+(for each directory in the @code{:} delimited @env{XDG_CONFIG_DIRS}
+environment variable)
 
 @item @var{sysconfdir}/texinfo/
 (where @var{sysconfdir} is the system configuration directory
 specified at compile-time, e.g., @file{/usr/local/etc})
 
+@item /etc/xdg/texinfo/
+(with @file{/etc/xdg} the default directory for @env{XDG_CONFIG_DIRS}
+in the XDG Base Directory Specification)
+
+@item @env{XDG_DATA_DIRS}/texinfo
+(for each directory in the @code{:} delimited @env{XDG_DATA_DIRS} environment
+variable)
+
 @item @var{datadir}/texinfo/
-(likewise specified at compile time, e.g., @file{/usr/local/share})
+(specified at compile time, e.g., @file{/usr/local/share})
+
+@item /usr/local/share/texinfo/
+(with @file{/usr/local/share} the first default directory for
+@env{XDG_DATA_DIRS} in the XDG Base Directory Specification)
+
+@item /usr/share/texinfo/
+(with @file{/usr/share/} the second default directory for @env{XDG_DATA_DIRS}
+in the XDG Base Directory Specification)
 @end table
 
+A directory appearing more than once, for example if @file{/usr/share/} is
+in @env{XDG_DATA_DIRS}, is only looked up once.
+
 All files found are used, with earlier entries overriding later ones.
 The Texinfo distribution includes a default file which handles many
-GNU manuals; it is installed in the last of the above directories,
-i.e., @file{@var{datadir}/texinfo/htmlxref.cnf}.
+GNU manuals; it is installed in @file{@var{datadir}/texinfo/htmlxref.cnf},
+one of the last of the above directories.
 
 The @code{HTMLXREF_MODE} customization variable can be set to modify how the
 files are found.  For instance, if set to @samp{none}, no external information
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 6af9bc4ae2..3a27ff02ce 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1147,14 +1147,23 @@ sub output_files_unclosed_files($)
 #               search the file in. Binary strings.
 # $ALL_FILES:   if true collect all the files with that name, otherwise stop
 #               at first match.
-sub locate_file_in_dirs($$$)
+# $DEPRECATED_DIRS:  optional argument.  If set, associates deprecated 
directory
+#                    names with the directory name that should be used
+#
+# Return an array reference with the files found, only one if $ALL_FILES
+# is false, and an array reference with the deprecated directories used.
+sub locate_file_in_dirs($$$;$)
 {
   my $input_file_path = shift;
   my $directories = shift;
   my $all_files = shift;
+  my $deprecated_dirs = shift;
+
+  my $deprecated_dirs_used;
 
   if (File::Spec->file_name_is_absolute($input_file_path)) {
-    return $input_file_path if (-e $input_file_path and -r $input_file_path);
+    return ([$input_file_path], undef)
+       if (-e $input_file_path and -r $input_file_path);
   } else {
     my ($volume, $path_directories, $file)
        = File::Spec->splitpath($input_file_path);
@@ -1162,23 +1171,30 @@ sub locate_file_in_dirs($$$)
     if (scalar(@path_directories) > 0) {
       # do not search in directories if the file name already contains
       # directories.
-      return $input_file_path if (-e $input_file_path and -r $input_file_path);
+      return ([$input_file_path], undef)
+         if (-e $input_file_path and -r $input_file_path);
     } else {
       my @files;
       foreach my $dir (@$directories) {
         next unless (-d $dir);
         my $possible_file = File::Spec->catfile($dir, $input_file_path);
-        if ($all_files) {
-          push (@files, $possible_file)
-            if (-e $possible_file and -r $possible_file);
-        } else {
-          return $possible_file if (-e $possible_file and -r $possible_file);
+        if (-e $possible_file and -r $possible_file) {
+          if ($deprecated_dirs->{$dir}) {
+            $deprecated_dirs_used = [] if (!defined($deprecated_dirs_used));
+            push @$deprecated_dirs_used, $dir;
+          }
+          if ($all_files) {
+            push (@files, $possible_file);
+          } else {
+            return [$possible_file], $deprecated_dirs_used;
+          }
         }
       }
-      return @files if ($all_files);
+      return (\@files, $deprecated_dirs_used)
+        if ($all_files and scalar(@files));
     }
   }
-  return undef;
+  return undef, undef;
 }
 
 sub element_associated_processing_encoding($)
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index dad3c6687c..5b5af91fd3 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -145,6 +145,7 @@ my %common_converters_defaults = (
   # can be different from the converted_format, for example, epub3
   # output format converted format is html.
   'output_format'        => undef,
+  'deprecated_config_directories' => undef,
 
   # Not set in the main program
   'translated_commands'  => {'error' => 'error@arrow{}',},
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 4a22f87f20..c304b89c88 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -8695,6 +8695,8 @@ sub _parse_htmlxref_files($$)
 sub _load_htmlxref_files {
   my ($self) = @_;
 
+  my $deprecated_dirs = $self->{'deprecated_config_directories'};
+
   my @htmlxref_files;
   my $htmlxref_mode = $self->get_conf('HTMLXREF_MODE');
   return if (defined($htmlxref_mode) and $htmlxref_mode eq 'none');
@@ -8744,9 +8746,30 @@ sub _load_htmlxref_files {
     if (defined($htmlxref_file_name)) {
       my ($encoded_htmlxref_file_name, $htmlxref_file_encoding)
         = $self->encoded_output_file_name($htmlxref_file_name);
-      @htmlxref_files
+      my ($htmlxref_files_array_ref, $deprecated_dirs_used)
         = Texinfo::Common::locate_file_in_dirs($encoded_htmlxref_file_name,
-                                               \@htmlxref_dirs, 1);
+                                               \@htmlxref_dirs, 1,
+                                               $deprecated_dirs);
+      if (defined($htmlxref_files_array_ref)) {
+        @htmlxref_files = @$htmlxref_files_array_ref;
+
+        if (defined($deprecated_dirs_used)) {
+          foreach my $dir (@$deprecated_dirs_used) {
+            my $encoding = $self->get_conf('COMMAND_LINE_ENCODING');
+            my ($dir_name, $replacement_dir);
+            if (defined($encoding)) {
+              $dir_name = decode($encoding, $dir);
+              $replacement_dir = decode($encoding, $deprecated_dirs->{$dir})
+            } else {
+              $dir_name = $dir;
+              $replacement_dir = $deprecated_dirs->{$dir};
+            }
+            $self->converter_document_warn(sprintf(__(
+                      "%s directory is deprecated. Use %s instead"),
+                             $dir_name, $replacement_dir));
+          }
+        }
+      }
     }
   }
 
@@ -8759,6 +8782,9 @@ sub _load_htmlxref_files {
 
 # converter state
 #
+#   No API
+#  deprecated_config_directories
+#
 #  output_init_conf
 #
 #     API exists
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 53e4b50af6..39a67351f1 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -891,9 +891,11 @@ sub test($$)
       $symbols_before_init_file->{$symbol} = 1;
     }
     foreach my $filename (@{$parser_options->{'init_files'}}) {
-      my $file = Texinfo::Common::locate_file_in_dirs($filename,
-                                            $init_file_directories, 0);
-      if (defined($file)) {
+      my ($files, $deprecated_dirs_used)
+          = Texinfo::Common::locate_file_in_dirs($filename,
+                                                 $init_file_directories, 0);
+      if (defined($files)) {
+        my $file = $files->[0];
         Texinfo::Config::GNUT_load_init_file($file);
       } else {
         warn (sprintf("could not read init file %s", $filename));
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index a968e6dd48..9a6fdb29b8 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -381,33 +381,122 @@ my $main_program_default_options = {
 # used as part of binary strings
 my $conf_file_name = 'texi2any-config.pm';
 
+# When we replace a directory, we emit a warning for some time,
+# using %deprecated_directories to match to the directory that
+# should be used.
+# In 2024 we switched to using the XDG Base Directory Specification,
+# https://specifications.freedesktop.org/basedir-spec/latest/index.html
+#  $HOME/texinfo should be $XDG_CONFIG_HOME default: $HOME/.config/texinfo
+my %deprecated_directories;
+
+# We use first the environment variable, then the installation directory
+# and last the SDG basedir specification default, even if the environment
+# variable was set, to be sure to have implementation independent locations
+# used.
+sub add_config_paths($$$$) {
+  my $env_string = shift;
+  my $subdir = shift;
+  my $default_base_dirs = shift;
+  my $installation_dir = shift;
+
+  my @result_dirs;
+  my %used_base_dirs;
+  if (defined($ENV{$env_string}) and $ENV{$env_string} ne '') {
+    foreach my $dir (split(':', $ENV{$env_string})) {
+      if ($dir ne '') {
+        push @result_dirs, File::Spec->catdir($dir, $subdir);
+        $used_base_dirs{$dir} = 1;
+      }
+    }
+  }
+  if (defined($installation_dir)
+      and not $used_base_dirs{$installation_dir}) {
+    my $install_result_dir = File::Spec->catdir($installation_dir, $subdir);
+    push @result_dirs, $install_result_dir;
+    $used_base_dirs{$installation_dir} = 1;
+  }
+
+  foreach my $dir (@$default_base_dirs) {
+    if (!$used_base_dirs{$dir}) {
+      push @result_dirs, File::Spec->catdir($dir, $subdir);
+    }
+  }
+  return \@result_dirs;
+}
+
+sub set_subdir_directories($$) {
+  my $subdir = shift;
+  my $deprecated_dirs = shift;
+
+  my @result = File::Spec->catdir('.'.$subdir);
+
+  my $config_home;
+  my $deprecated_config_home;
+  if (defined($ENV{'XDG_CONFIG_HOME'}) and $ENV{'XDG_CONFIG_HOME'} ne '') {
+    $config_home = File::Spec->catdir($ENV{'XDG_CONFIG_HOME'}, $subdir);
+  } else {
+    if (defined($ENV{'HOME'})) {
+      $config_home = File::Spec->catdir($ENV{'HOME'}, '.config', $subdir);
+      $deprecated_config_home = File::Spec->catdir($ENV{'HOME'}, '.'.$subdir);
+      $deprecated_dirs->{$deprecated_config_home} = $config_home;
+    }
+  }
+  push @result, $config_home
+    if (defined($config_home));
+
+  push @result, $deprecated_config_home
+    if (defined($deprecated_config_home));
+
+  my $config_dirs = add_config_paths('XDG_CONFIG_DIRS', $subdir,
+                       ['/etc/xdg'], $sysconfdir);
+  push @result, @$config_dirs;
+
+  my $data_dirs = add_config_paths('XDG_DATA_DIRS', 'texinfo',
+      ['/usr/local/share/', '/usr/share/'], $datadir);
+
+  push @result, @$data_dirs;
+
+  return \@result;
+}
+
 # directories for Texinfo configuration files, as far as possible
 # implementation independent.  Used as part of binary strings.
 # curdir and the input file path directory are prepended later on.
-my @texinfo_language_config_dirs = File::Spec->catdir('.texinfo');
-push @texinfo_language_config_dirs, File::Spec->catdir($ENV{'HOME'}, 
'.texinfo')
-                                if (defined($ENV{'HOME'}));
-push @texinfo_language_config_dirs, File::Spec->catdir($sysconfdir, 'texinfo')
-                               if (defined($sysconfdir));
-push @texinfo_language_config_dirs, File::Spec->catdir($datadir, 'texinfo')
-                               if (defined($datadir));
+my $language_config_dirs
+  = set_subdir_directories('texinfo', \%deprecated_directories);
+my @texinfo_language_config_dirs = @$language_config_dirs;
+
+#push @texinfo_language_config_dirs, File::Spec->catdir($sysconfdir, 'texinfo')
+#                               if (defined($sysconfdir));
+#push @texinfo_language_config_dirs, File::Spec->catdir($datadir, 'texinfo')
+#                               if (defined($datadir));
 
 # these variables are used as part of binary strings.
 my @program_config_dirs;
 my @program_init_dirs;
 
 my $program_name = 'texi2any';
-@program_config_dirs = ($curdir, File::Spec->catdir($curdir, 
".$program_name"));
-push @program_config_dirs, File::Spec->catdir($ENV{'HOME'}, ".$program_name")
-       if (defined($ENV{'HOME'}));
-push @program_config_dirs, File::Spec->catdir($sysconfdir, $program_name)
-       if (defined($sysconfdir));
-push @program_config_dirs, File::Spec->catdir($datadir, $program_name)
-  if (defined($datadir));
+my $program_config_dirs_array_ref
+  = set_subdir_directories($program_name, \%deprecated_directories);
+
+@program_config_dirs = ($curdir, @$program_config_dirs_array_ref);
+
+#@program_config_dirs = ($curdir, File::Spec->catdir($curdir, 
".$program_name"));
+#push @program_config_dirs, File::Spec->catdir($ENV{'HOME'}, ".$program_name")
+#       if (defined($ENV{'HOME'}));
+#push @program_config_dirs, File::Spec->catdir($sysconfdir, $program_name)
+#       if (defined($sysconfdir));
+#push @program_config_dirs, File::Spec->catdir($datadir, $program_name)
+#  if (defined($datadir));
 
 @program_init_dirs = @program_config_dirs;
 foreach my $texinfo_config_dir ($curdir, @texinfo_language_config_dirs) {
-  push @program_init_dirs, File::Spec->catdir($texinfo_config_dir, 'init');
+  my $init_dir = File::Spec->catdir($texinfo_config_dir, 'init');
+  push @program_init_dirs, $init_dir;
+  if ($deprecated_directories{$texinfo_config_dir}) {
+    $deprecated_directories{$init_dir}
+   = File::Spec->catdir($deprecated_directories{$texinfo_config_dir}, 'init');
+  }
 }
 
 # add texi2any extensions dir too, such as the init files there
@@ -454,20 +543,45 @@ sub _decode_input($)
   }
 }
 
+sub _warn_deprecated_dirs($$)
+{
+  my $deprecated_dirs = shift;
+  my $deprecated_dirs_used = shift;
+
+  if (defined($deprecated_dirs_used)) {
+    foreach my $dir (@$deprecated_dirs_used) {
+      my $dir_name = _decode_input($dir);
+      my $replacement_dir = _decode_input($deprecated_dirs->{$dir});
+
+      document_warn(sprintf(__(
+                      "%s directory is deprecated. Use %s instead"),
+                             $dir_name, $replacement_dir));
+    }
+  }
+}
+
 # arguments are binary strings.
-sub locate_and_load_init_file($$)
+sub locate_and_load_init_file($$;$)
 {
   my $filename = shift;
   my $directories = shift;
+  my $deprecated_dirs = shift;
 
-  my $file = Texinfo::Common::locate_file_in_dirs($filename, $directories, 0);
-  if (defined($file)) {
+  my ($files, $deprecated_dirs_used)
+     = Texinfo::Common::locate_file_in_dirs($filename, $directories, 0,
+                                            $deprecated_dirs);
+  if (defined($files)) {
+    my $file = $files->[0];
     # evaluate the code in the Texinfo::Config namespace
     Texinfo::Config::GNUT_load_init_file($file);
   } else {
     document_warn(sprintf(__("could not read init file %s"),
                           _decode_input($filename)));
   }
+
+  if ($deprecated_dirs and $deprecated_dirs_used) {
+    _warn_deprecated_dirs($deprecated_dirs, $deprecated_dirs_used);
+  }
 }
 
 # arguments are binary strings.
@@ -478,9 +592,12 @@ sub locate_and_load_extension_file($$)
   my $filename = shift;
   my $directories = shift;
 
-  my $file = Texinfo::Common::locate_file_in_dirs($filename, $directories, 0);
-  if (defined($file)) {
+  # no possible deprecated dirs with the path passed to this sub
+  my ($files, $deprecated_dirs_used)
+     = Texinfo::Common::locate_file_in_dirs($filename, $directories, 0);
+  if (defined($files)) {
     # evaluate the code in the Texinfo::Config namespace
+    my $file = $files->[0];
     Texinfo::Config::GNUT_load_init_file($file);
   } else {
     die _encode_message(sprintf(__("could not read extension file %s"),
@@ -580,9 +697,18 @@ set_translations_encoding($translations_encoding);
 # read initialization files.  Better to do that after
 # Texinfo::Config::GNUT_initialize_customization() in case loaded
 # files replace default options.
-foreach my $file (Texinfo::Common::locate_file_in_dirs($conf_file_name,
-                  [ reverse(@program_config_dirs) ], 1)) {
-  Texinfo::Config::GNUT_load_init_file($file);
+my ($config_init_files, $deprecated_dirs_for_config_init)
+ = Texinfo::Common::locate_file_in_dirs($conf_file_name,
+                             [ reverse(@program_config_dirs) ], 1,
+                                        \%deprecated_directories);
+if (defined($config_init_files)) {
+  foreach my $file (@$config_init_files) {
+    Texinfo::Config::GNUT_load_init_file($file);
+  }
+}
+if ($deprecated_dirs_for_config_init) {
+  _warn_deprecated_dirs(\%deprecated_directories,
+                        $deprecated_dirs_for_config_init);
 }
 
 # reset translations encodings if COMMAND_LINE_ENCODING was reset
@@ -1064,7 +1190,8 @@ There is NO WARRANTY, to the extent permitted by 
law.\n"), "2024");
     if (get_conf('TEST')) {
       locate_and_load_init_file($_[1], [ @conf_dirs ]);
     } else {
-      locate_and_load_init_file($_[1], [ @conf_dirs, @program_init_dirs ]);
+      locate_and_load_init_file($_[1], [ @conf_dirs, @program_init_dirs ],
+                                \%deprecated_directories);
     }
  },
  'set-customization-variable|c=s' => sub {
@@ -1782,6 +1909,8 @@ while(@input_files) {
   # and Converters.
   $converter_options->{'output_format'} = $format;
   $converter_options->{'converted_format'} = $converted_format;
+  $converter_options->{'deprecated_config_directories'}
+     = \%deprecated_directories;
   unshift @{$converter_options->{'INCLUDE_DIRECTORIES'}},
           @prepended_include_directories;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]