Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: The default $fpath



On Mon, 08 Sep 2014 13:16:37 +0200
Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx> wrote:
> Peter Stephenson wrote:
> > Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >> I can't think of any; presumably the configure-time (?) code for this
> >> would resemble
> >> 
> >>     if [ X$ac_default_prefix != X/usr/local ]
> >>     then fixed_sitefndir=/usr/local/zsh/site-functions
> >>     elif [ X$tzsh_name != Xzsh ]
> >>     then fixed_sitefndir=/usr/local/zsh/site-functions
> >>     else fixed_sitefndir=''
> >>     fi
> >> 
> >> and then zsh.mdd would use something like
> >> 
> >>     echo '#define FIXED_FPATH_DIR "'$(fixed_sitefndir)'"' >> zshpaths.h.tmp;
> >> 
> >> and finally somewhere in Src/init.c the fpath would be prefixed with the
> >> value of FIXED_FPATH_DIR if it is non-empty.
> >
> > OK, so that's an answer to my other open question: you're suggesting (i)
> > if the prefix is /usr/local and this is a standard zsh installation
> > we keep things the way they are (ii) otherwise the new component is
> > the first thing to be tried in the default fpath.
> 
> It should probably also check if --enable-site-fndir points to the
> location in ‘/usr/local’, not just ‘prefix’.

This looks plausible, but it'll need trying out in a few different
configurations.  I'll do a sanity check after I've committed it.

diff --git a/Src/init.c b/Src/init.c
index d536978..40f46a8 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -770,7 +770,8 @@ setupvals(void)
     struct timezone dummy_tz;
     char *ptr;
     int i, j;
-#if defined(SITEFPATH_DIR) || defined(FPATH_DIR) || defined (ADDITIONAL_FPATH)
+#if defined(SITEFPATH_DIR) || defined(FPATH_DIR) || defined (ADDITIONAL_FPATH) || defined(FIXED_FPATH_DIR)
+#define FPATH_NEEDS_INIT 1
     char **fpathptr;
 # if defined(FPATH_DIR) && defined(FPATH_SUBDIRS)
     char *fpath_subdirs[] = FPATH_SUBDIRS;
@@ -779,11 +780,17 @@ setupvals(void)
     char *more_fndirs[] = ADDITIONAL_FPATH;
     int more_fndirs_len;
 # endif
+# ifdef FIXED_FPATH_DIR
+#  define FIXED_FPATH_LEN 1
+# else
+#  define FIXED_FPATH_LEN 0
+# endif
 # ifdef SITEFPATH_DIR
-    int fpathlen = 1;
+#  define SITE_FPATH_LEN 1
 # else
-    int fpathlen = 0;
+#  define SITE_FPATH_LEN 0
 # endif
+    int fpathlen = FIXED_FPATH_LEN + SITE_FPATH_LEN;
 #endif
     int close_fds[10], tmppipe[2];
 
@@ -862,23 +869,27 @@ setupvals(void)
     manpath  = mkarray(NULL);
     fignore  = mkarray(NULL);
 
-#if defined(SITEFPATH_DIR) || defined(FPATH_DIR) || defined(ADDITIONAL_FPATH)
+#ifdef FPATH_NEEDS_INIT
 # ifdef FPATH_DIR
 #  ifdef FPATH_SUBDIRS
     fpathlen += sizeof(fpath_subdirs)/sizeof(char *);
-#  else
+#  else /* FPATH_SUBDIRS */
     fpathlen++;
-#  endif
-# endif
+#  endif /* FPATH_SUBDIRS */
+# endif /* FPATH_DIR */
 # if defined(ADDITIONAL_FPATH)
     more_fndirs_len = sizeof(more_fndirs)/sizeof(char *);
     fpathlen += more_fndirs_len;
-# endif
+# endif /* ADDITONAL_FPATH */
     fpath = fpathptr = (char **)zalloc((fpathlen+1)*sizeof(char *));
+# ifdef FIXED_FPATH_DIR
+    *fpathptr++ = ztrdup(FIXED_FPATH_DIR);
+    fpathlen--;
+# endif
 # ifdef SITEFPATH_DIR
     *fpathptr++ = ztrdup(SITEFPATH_DIR);
     fpathlen--;
-# endif
+# endif /* SITEFPATH_DIR */
 # if defined(ADDITIONAL_FPATH)
     for (j = 0; j < more_fndirs_len; j++)
 	*fpathptr++ = ztrdup(more_fndirs[j]);
@@ -897,9 +908,9 @@ setupvals(void)
 #  endif
 # endif
     *fpathptr = NULL;
-#else
+#else /* FPATH_NEEDS_INIT */
     fpath    = mkarray(NULL);
-#endif
+#endif /* FPATH_NEEDS_INIT */
 
     mailpath = mkarray(NULL);
     watch    = mkarray(NULL);
diff --git a/Src/zsh.mdd b/Src/zsh.mdd
index cec3eda..9a8c923 100644
--- a/Src/zsh.mdd
+++ b/Src/zsh.mdd
@@ -73,6 +73,9 @@ zshpaths.h: Makemod $(CONFIG_INCS)
 	@if test x$(sitefndir) != xno; then \
 	  echo '#define SITEFPATH_DIR "'$(sitefndir)'"' >> zshpaths.h.tmp; \
 	fi
+	@if test x$(fixed_sitefndir) != x; then \
+	  echo '#define FIXED_FPATH_DIR "'$(fixed_sitefndir)'"' >> zshpaths.h.tmp; \
+        fi
 	@if test x$(fndir) != xno; then \
 	  echo '#define FPATH_DIR "'$(fndir)'"' >> zshpaths.h.tmp; \
 	  if test x$(FUNCTIONS_SUBDIRS) != x && \
diff --git a/configure.ac b/configure.ac
index 37f3585..68a2e91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,18 @@ else
   sitefndir="$enableval"
 fi], [sitefndir=${datadir}/${tzsh_name}/site-functions])
 
+dnl Add /usr/local/share/zsh/site-functions if not yet present.
+dnl It might be present owing to an explicit sitefndir or the install
+dnl prefix if the shell is installed under the name "zsh".
+if test X$sitefndir = X/usr/local/zsh/site-functions
+then fixed_sitefndir=''
+elif test X$ac_default_prefix != X/usr/local
+then fixed_sitefndir=/usr/local/zsh/site-functions
+elif test X$tzsh_name != Xzsh
+then fixed_sitefndir=/usr/local/zsh/site-functions
+else fixed_sitefndir=''
+fi
+
 ifdef([function_subdirs],[undefine([function_subdirs])])
 AC_ARG_ENABLE(function-subdirs,
 AC_HELP_STRING([--enable-function-subdirs], [install functions in subdirectories]))
@@ -340,6 +352,7 @@ AC_SUBST(runhelp)dnl
 AC_SUBST(additionalfpath)dnl
 AC_SUBST(fndir)dnl
 AC_SUBST(sitefndir)dnl
+AC_SUBST(fixed_sitefndir)dnl
 AC_SUBST(FUNCTIONS_SUBDIRS)dnl
 
 dnl Directories for scripts such as newuser.


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author