quote: fuse into quotearg
[gnulib.git] / posix-modules
blob0d663eb298711fd6db35f5412401ea6709779a6c
1 #!/bin/sh
3 # Copyright (C) 2002-2008, 2010-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 progname=$0
20 package=gnulib
22 # func_usage
23 # outputs to stdout the --help usage message.
24 func_usage ()
26 echo "\
27 Usage: posix-modules
29 Lists the gnulib modules that implement POSIX interfaces.
31 Report bugs to <bug-gnulib@gnu.org>."
34 # func_version
35 # outputs to stdout the --version message.
36 func_version ()
38 func_gnulib_dir
39 if test -d "$gnulib_dir"/.git \
40 && (git --version) >/dev/null 2>/dev/null \
41 && (date --version) >/dev/null 2>/dev/null; then
42 # gnulib checked out from git.
43 sed_extract_first_date='/^Date/{
44 s/^Date:[ ]*//p
47 date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
48 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
49 sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
50 date=`echo "$date" | sed -e "$sed_year_before_time"`
51 # Use GNU date to compute the time in GMT.
52 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
53 version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
54 else
55 if test -d "$gnulib_dir"/CVS \
56 && (cvs --version) >/dev/null 2>/dev/null; then
57 # gnulib checked out from CVS.
58 sed_extract_first_date='/^date: /{
59 s/^date: \([0-9][0-9][0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1-\2-\3 \4/p
62 date=`cd "$gnulib_dir" && cvs log -N ChangeLog 2>/dev/null | sed -n -e "$sed_extract_first_date"`
63 else
64 # gnulib copy without versioning information.
65 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
67 version=
69 year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
70 echo "\
71 posix-modules (GNU $package $date)$version
72 Copyright (C) $year Free Software Foundation, Inc.
73 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
74 This is free software: you are free to change and redistribute it.
75 There is NO WARRANTY, to the extent permitted by law.
77 Written by" "Bruno Haible"
80 # func_exit STATUS
81 # exits with a given status.
82 # This function needs to be used, rather than 'exit', when a 'trap' handler is
83 # in effect that refers to $?.
84 func_exit ()
86 (exit $1); exit $1
89 # func_gnulib_dir
90 # locates the directory where the gnulib repository lives
91 # Input:
92 # - progname name of this program
93 # Sets variables
94 # - self_abspathname absolute pathname of this program
95 # - gnulib_dir absolute pathname of gnulib repository
96 func_gnulib_dir ()
98 case "$progname" in
99 /*) self_abspathname="$progname" ;;
100 */*) self_abspathname=`pwd`/"$progname" ;;
102 # Look in $PATH.
103 # Iterate through the elements of $PATH.
104 # We use IFS=: instead of
105 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
106 # because the latter does not work when some PATH element contains spaces.
107 # We use a canonicalized $pathx instead of $PATH, because empty PATH
108 # elements are by definition equivalent to '.', however field splitting
109 # according to IFS=: loses empty fields in many shells:
110 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
111 # beginning, at the end, and in the middle),
112 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
113 # at the beginning and at the end,
114 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
115 # Solaris lose empty fields at the end.
116 # The 'case' statement is an optimization, to avoid evaluating the
117 # explicit canonicalization command when $PATH contains no empty fields.
118 self_abspathname=
119 if test "${PATH_SEPARATOR+set}" != set; then
120 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
121 # contains only /bin. Note that ksh looks also at the FPATH variable,
122 # so we have to set that as well for the test.
123 PATH_SEPARATOR=:
124 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
125 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
126 || PATH_SEPARATOR=';'
129 if test "$PATH_SEPARATOR" = ";"; then
130 # On Windows, programs are searched in "." before $PATH.
131 pathx=".;$PATH"
132 else
133 # On Unix, we have to convert empty PATH elements to ".".
134 pathx="$PATH"
135 case :$PATH: in
136 *::*)
137 pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
139 esac
141 save_IFS="$IFS"
142 IFS="$PATH_SEPARATOR"
143 for d in $pathx; do
144 IFS="$save_IFS"
145 test -z "$d" && d=.
146 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
147 self_abspathname="$d/$progname"
148 break
150 done
151 IFS="$save_IFS"
152 if test -z "$self_abspathname"; then
153 func_fatal_error "could not locate the posix-modules program - how did you invoke it?"
156 esac
157 while test -h "$self_abspathname"; do
158 # Resolve symbolic link.
159 linkval=`func_readlink "$self_abspathname"`
160 test -n "$linkval" || break
161 case "$linkval" in
162 /* ) self_abspathname="$linkval" ;;
163 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
164 esac
165 done
166 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
169 # func_tmpdir
170 # creates a temporary directory.
171 # Input:
172 # - progname name of this program
173 # Sets variable
174 # - tmp pathname of freshly created temporary directory
175 func_tmpdir ()
177 # Use the environment variable TMPDIR, falling back to /tmp. This allows
178 # users to specify a different temporary directory, for example, if their
179 # /tmp is filled up or too small.
180 : ${TMPDIR=/tmp}
182 # Use the mktemp program if available. If not available, hide the error
183 # message.
184 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
185 test -n "$tmp" && test -d "$tmp"
186 } ||
188 # Use a simple mkdir command. It is guaranteed to fail if the directory
189 # already exists. $RANDOM is bash specific and expands to empty in shells
190 # other than bash, ksh and zsh. Its use does not increase security;
191 # rather, it minimizes the probability of failure in a very cluttered /tmp
192 # directory.
193 tmp=$TMPDIR/gl$$-$RANDOM
194 (umask 077 && mkdir "$tmp")
195 } ||
197 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
198 func_exit 1
202 # func_fatal_error message
203 # outputs to stderr a fatal error message, and terminates the program.
204 # Input:
205 # - progname name of this program
206 func_fatal_error ()
208 echo "$progname: *** $1" 1>&2
209 echo "$progname: *** Stop." 1>&2
210 func_exit 1
213 # func_readlink SYMLINK
214 # outputs the target of the given symlink.
215 if (type -p readlink) > /dev/null 2>&1; then
216 func_readlink ()
218 # Use the readlink program from GNU coreutils.
219 readlink "$1"
221 else
222 func_readlink ()
224 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
225 # would do the wrong thing if the link target contains " -> ".
226 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
230 # Command-line option processing.
231 while test $# -gt 0; do
232 case "$1" in
233 --help | --hel | --he | --h )
234 func_usage
235 exit $? ;;
236 --version | --versio | --versi | --vers | --ver | --ve | --v )
237 func_version
238 exit $? ;;
239 -* )
240 echo "posix-modules: unknown option $1" 1>&2
241 echo "Try 'posix-modules --help' for more information." 1>&2
242 exit 1 ;;
244 echo "posix-modules: too many arguments" 1>&2
245 echo "Try 'posix-modules --help' for more information." 1>&2
246 exit 1 ;;
247 esac
248 done
250 func_gnulib_dir
252 # Get the header modules.
253 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-headers/*.texi 2>/dev/null \
254 | sed -e 's,^Gnulib module: ,,'
255 # Get the function modules.
256 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-functions/*.texi 2>/dev/null \
257 | sed -e 's,^Gnulib module: ,,'
258 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
259 ) | sed -e 's/,/ /g' | LC_ALL=C sort | LC_ALL=C uniq \
260 | { # Then filter out the words "---", "and", "or" and remove *-gnu modules.
261 tr ' ' '\012' | sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
263 | LC_ALL=C sort | LC_ALL=C uniq
265 # Local Variables:
266 # indent-tabs-mode: nil
267 # whitespace-check-buffer-indent: nil
268 # End: