From 39c38e65e5d17593f4d9cd0ed597d7f7582f4b7f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 5 Apr 2024 04:11:22 +0200 Subject: [PATCH] posix-modules: Sync auxiliary functions from gnulib-tool.sh. * posix-modules (func_exit, func_fatal_error, func_readlink, func_gnulib_dir): Move before func_usage and func_version. Incorporate improvements from gnulib-tool.sh. --- ChangeLog | 7 +++ posix-modules | 168 ++++++++++++++++++++++++++------------------------ 2 files changed, 96 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a84f5a2c7..07e1e3088a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-04-04 Bruno Haible + + posix-modules: Sync auxiliary functions from gnulib-tool.sh. + * posix-modules (func_exit, func_fatal_error, func_readlink, + func_gnulib_dir): Move before func_usage and func_version. Incorporate + improvements from gnulib-tool.sh. + 2024-04-04 Collin Funk gnulib-tool.py: Ignore 'use-dict-literal' warnings. diff --git a/posix-modules b/posix-modules index 0da6942738..ae5fb90ffd 100755 --- a/posix-modules +++ b/posix-modules @@ -19,59 +19,6 @@ progname=$0 package=gnulib -# func_usage -# outputs to stdout the --help usage message. -func_usage () -{ - echo "\ -Usage: posix-modules [option] - -Lists the gnulib modules that implement POSIX interfaces. - -Options: - - --for-mingw list only modules that work on mingw - --for-msvc list only modules that work on MSVC - -Report bugs to ." -} - -# func_version -# outputs to stdout the --version message. -func_version () -{ - func_gnulib_dir - if test -d "$gnulib_dir"/.git \ - && (git --version) >/dev/null 2>/dev/null \ - && (date --version) >/dev/null 2>/dev/null; then - # gnulib checked out from git. - sed_extract_first_date='/^Date/{ -s/^Date:[ ]*//p -q -}' - date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"` - # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600". - sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /' - date=`echo "$date" | sed -e "$sed_year_before_time"` - # Use GNU date to compute the time in GMT. - date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"` - version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'` - else - # gnulib copy without versioning information. - date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog` - version= - fi - year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'` - echo "\ -posix-modules (GNU $package $date)$version -Copyright (C) $year Free Software Foundation, Inc. -License GPLv3+: GNU GPL version 3 or later -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law. - -Written by" "Bruno Haible" -} - # func_exit STATUS # exits with a given status. # This function needs to be used, rather than 'exit', when a 'trap' handler is @@ -81,6 +28,34 @@ func_exit () (exit $1); exit $1 } +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +# Input: +# - progname name of this program +func_fatal_error () +{ + echo "$progname: *** $1" 1>&2 + echo "$progname: *** Stop." 1>&2 + func_exit 1 +} + +# func_readlink SYMLINK +# outputs the target of the given symlink. +if (type readlink) > /dev/null 2>&1; then + func_readlink () + { + # Use the readlink program from GNU coreutils. + readlink "$1" + } +else + func_readlink () + { + # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p' + # would do the wrong thing if the link target contains " -> ". + LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' + } +fi + # func_gnulib_dir # locates the directory where the gnulib repository lives # Input: @@ -91,7 +66,7 @@ func_exit () func_gnulib_dir () { case "$progname" in - /*) self_abspathname="$progname" ;; + /* | ?:*) self_abspathname="$progname" ;; */*) self_abspathname=`pwd`/"$progname" ;; *) # Look in $PATH. @@ -121,6 +96,16 @@ func_gnulib_dir () || PATH_SEPARATOR=';' } fi + if test "${PATH_SEPARATOR+set}" != set; then + # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which + # contains only /bin. Note that ksh looks also at the FPATH variable, + # so we have to set that as well for the test. + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + || PATH_SEPARATOR=';' + } + fi if test "$PATH_SEPARATOR" = ";"; then # On Windows, programs are searched in "." before $PATH. pathx=".;$PATH" @@ -154,7 +139,7 @@ func_gnulib_dir () linkval=`func_readlink "$self_abspathname"` test -n "$linkval" || break case "$linkval" in - /* ) self_abspathname="$linkval" ;; + /* | ?:* ) self_abspathname="$linkval" ;; * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;; esac done @@ -194,33 +179,58 @@ func_tmpdir () } } -# func_fatal_error message -# outputs to stderr a fatal error message, and terminates the program. -# Input: -# - progname name of this program -func_fatal_error () +# func_usage +# outputs to stdout the --help usage message. +func_usage () { - echo "$progname: *** $1" 1>&2 - echo "$progname: *** Stop." 1>&2 - func_exit 1 + echo "\ +Usage: posix-modules [option] + +Lists the gnulib modules that implement POSIX interfaces. + +Options: + + --for-mingw list only modules that work on mingw + --for-msvc list only modules that work on MSVC + +Report bugs to ." } -# func_readlink SYMLINK -# outputs the target of the given symlink. -if (type -p readlink) > /dev/null 2>&1; then - func_readlink () - { - # Use the readlink program from GNU coreutils. - readlink "$1" - } -else - func_readlink () - { - # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p' - # would do the wrong thing if the link target contains " -> ". - LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' - } -fi +# func_version +# outputs to stdout the --version message. +func_version () +{ + func_gnulib_dir + if test -d "$gnulib_dir"/.git \ + && (git --version) >/dev/null 2>/dev/null \ + && (date --version) >/dev/null 2>/dev/null; then + # gnulib checked out from git. + sed_extract_first_date='/^Date/{ +s/^Date:[ ]*//p +q +}' + date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"` + # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600". + sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /' + date=`echo "$date" | sed -e "$sed_year_before_time"` + # Use GNU date to compute the time in GMT. + date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"` + version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'` + else + # gnulib copy without versioning information. + date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog` + version= + fi + year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'` + echo "\ +posix-modules (GNU $package $date)$version +Copyright (C) $year Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + +Written by" "Bruno Haible" +} # Excludes for mingw. exclude_for_mingw= -- 2.39.5