xref: /PHP-5.5/build/shtool (revision f32d2ac3)
1#!/bin/sh
2##
3##  GNU shtool -- The GNU Portable Shell Tool
4##  Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>
5##
6##  See http://www.gnu.org/software/shtool/ for more information.
7##  See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
8##
9##  Version:  2.0.8 (18-Jul-2008)
10##  Contents: 5/19 available modules
11##
12
13##
14##  This program is free software; you can redistribute it and/or modify
15##  it under the terms of the GNU General Public License as published by
16##  the Free Software Foundation; either version 2 of the License, or
17##  (at your option) any later version.
18##
19##  This program is distributed in the hope that it will be useful,
20##  but WITHOUT ANY WARRANTY; without even the implied warranty of
21##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22##  General Public License for more details.
23##
24##  You should have received a copy of the GNU General Public License
25##  along with this program; if not, write to the Free Software
26##  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
28##
29##  NOTICE: Given that you include this file verbatim into your own
30##  source tree, you are justified in saying that it remains separate
31##  from your package, and that this way you are simply just using GNU
32##  shtool. So, in this situation, there is no requirement that your
33##  package itself is licensed under the GNU General Public License in
34##  order to take advantage of GNU shtool.
35##
36
37##
38##  Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
39##
40##  Available commands:
41##    echo       Print string with optional construct expansion
42##    install    Install a program, script or datafile
43##    mkdir      Make one or more directories
44##    platform   Platform Identification Utility
45##    path       Deal with program paths
46##
47##  Not available commands (because module was not built-in):
48##    mdate      Pretty-print modification time of a file or dir
49##    table      Pretty-print a field-separated list as a table
50##    prop       Display progress with a running propeller
51##    move       Move files with simultaneous substitution
52##    mkln       Make link with calculation of relative paths
53##    mkshadow   Make a shadow tree through symbolic links
54##    fixperm    Fix file permissions inside a source tree
55##    rotate     Logfile rotation
56##    tarball    Roll distribution tarballs
57##    subst      Apply sed(1) substitution operations
58##    arx        Extended archive command
59##    slo        Separate linker options by library class
60##    scpp       Sharing C Pre-Processor
61##    version    Maintain a version information file
62##
63
64#   maximum Bourne-Shell compatibility
65if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then
66    #   reconfigure zsh(1)
67    emulate sh
68    NULLCMD=:
69    alias -g '${1+"$@"}'='"$@"'
70elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then
71    #   reconfigure bash(1)
72    set -o posix
73fi
74
75#   maximum independence of NLS nuisances
76for var in \
77    LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
78    LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
79    LC_TELEPHONE LC_TIME
80do
81    if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then
82        eval $var=C; export $var
83    else
84        unset $var
85    fi
86done
87
88#   initial command line handling
89if [ $# -eq 0 ]; then
90    echo "$0:Error: invalid command line" 1>&2
91    echo "$0:Hint:  run \`$0 -h' for usage" 1>&2
92    exit 1
93fi
94if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then
95    echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)"
96    echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>'
97    echo 'Report bugs to <bug-shtool@gnu.org>'
98    echo ''
99    echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
100    echo ''
101    echo 'Available global <options>:'
102    echo '  -v, --version   display shtool version information'
103    echo '  -h, --help      display shtool usage help page (this one)'
104    echo '  -d, --debug     display shell trace information'
105    echo '  -r, --recreate  recreate this shtool script via shtoolize'
106    echo ''
107    echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
108    echo '  echo     [-n|--newline] [-e|--expand] [<string> ...]'
109    echo '  install  [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
110    echo '           [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
111    echo '           [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
112    echo '           <sed-cmd>] <file> [<file> ...] <path>'
113    echo '  mkdir    [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
114    echo '           <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
115    echo '           [<dir> ...]'
116    echo '  platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc'
117    echo '           <string>] [-L|--lower] [-U|--upper] [-v|--verbose]'
118    echo '           [-c|--concise] [-n|--no-newline] [-t|--type <type>]'
119    echo '           [-V|--version] [-h|--help]'
120    echo '  path     [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
121    echo '           [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
122    echo ''
123    echo 'Not available <cmd-name> (because module was not built-in):'
124    echo '  mdate    [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
125    echo '           [-f|--field-sep <str>] [-o|--order <spec>] <path>'
126    echo '  table    [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
127    echo '           <cols>] [-s|--strip <strip>] <str><sep><str>...'
128    echo '  prop     [-p|--prefix <str>]'
129    echo '  move     [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
130    echo '           <src-file> <dst-file>'
131    echo '  mkln     [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
132    echo '           [<src-path> ...] <dst-path>'
133    echo '  mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
134    echo '  fixperm  [-v|--verbose] [-t|--trace] <path> [<path> ...]'
135    echo '  rotate   [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
136    echo '           <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
137    echo '           [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
138    echo '           [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode'
139    echo '           <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate'
140    echo '           <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
141    echo '  tarball  [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
142    echo '           [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
143    echo '           <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
144    echo '           <path> [<path> ...]'
145    echo '  subst    [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]'
146    echo '           [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup'
147    echo '           <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]'
148    echo '           [...]'
149    echo '  arx      [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
150    echo '           ...]'
151    echo '  slo      [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
152    echo '           ...]'
153    echo '  scpp     [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
154    echo '           [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
155    echo '           <mark>] [-D|--define <dname>] [-C|--class <cname>]'
156    echo '           <file> [<file> ...]'
157    echo '  version  [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
158    echo '           <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
159    echo '           <knob>] [-d|--display <type>] <file>'
160    echo ''
161    exit 0
162fi
163if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then
164    echo "GNU shtool 2.0.8 (18-Jul-2008)"
165    exit 0
166fi
167if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then
168    shtoolize -obuild/shtool echo install mkdir platform path
169    exit 0
170fi
171if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then
172    shift
173    set -x
174fi
175name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
176case "$name" in
177    echo|install|mkdir|platform|path )
178        #   implicit tool command selection
179        tool="$name"
180        ;;
181    * )
182        #   explicit tool command selection
183        tool="$1"
184        shift
185        ;;
186esac
187arg_spec=""
188opt_spec=""
189gen_tmpfile=no
190
191##
192##  DISPATCH INTO SCRIPT PROLOG
193##
194
195case $tool in
196    echo )
197        str_tool="echo"
198        str_usage="[-n|--newline] [-e|--expand] [<string> ...]"
199        arg_spec="0+"
200        opt_spec="n.e."
201        opt_alias="n:newline,e:expand"
202        opt_n=no
203        opt_e=no
204        ;;
205    install )
206        str_tool="install"
207        str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
208        arg_spec="1+"
209        opt_spec="v.t.d.c.C.s.m:o:g:e+"
210        opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
211        opt_v=no
212        opt_t=no
213        opt_d=no
214        opt_c=no
215        opt_C=no
216        opt_s=no
217        opt_m="0755"
218        opt_o=""
219        opt_g=""
220        opt_e=""
221        ;;
222    mkdir )
223        str_tool="mkdir"
224        str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
225        arg_spec="1+"
226        opt_spec="t.f.p.m:o:g:"
227        opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
228        opt_t=no
229        opt_f=no
230        opt_p=no
231        opt_m=""
232        opt_o=""
233        opt_g=""
234        ;;
235    platform )
236        str_tool="platform"
237        str_usage="[-F|--format <format>] [-S|--sep <string>] [-C|--conc <string>] [-L|--lower] [-U|--upper] [-v|--verbose] [-c|--concise] [-n|--no-newline] [-t|--type <type>] [-V|--version] [-h|--help]"
238        arg_spec="0="
239        opt_spec="F:S:C:L.U.v.c.n.t:d.V.h."
240        opt_alias="F:format,S:sep,C:conc,L:lower,U:upper,v:verbose,c:consise,t:type,n:no-newline,V:version,h:help"
241        opt_F="%{sp} (%{ap})"
242        opt_S=" "
243        opt_C="/"
244        opt_L=no
245        opt_U=no
246        opt_t=""
247        opt_v=no
248        opt_c=no
249        opt_n=no
250        opt_V=no
251        opt_h=no
252        ;;
253    path )
254        str_tool="path"
255        str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
256        gen_tmpfile=yes
257        arg_spec="1+"
258        opt_spec="s.r.d.b.m.p:"
259        opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
260        opt_s=no
261        opt_r=no
262        opt_d=no
263        opt_b=no
264        opt_m=no
265        opt_p="$PATH"
266        ;;
267    -* )
268        echo "$0:Error: unknown option \`$tool'" 2>&1
269        echo "$0:Hint:  run \`$0 -h' for usage" 2>&1
270        exit 1
271        ;;
272    * )
273        echo "$0:Error: unknown command \`$tool'" 2>&1
274        echo "$0:Hint:  run \`$0 -h' for usage" 2>&1
275        exit 1
276        ;;
277esac
278
279##
280##  COMMON UTILITY CODE
281##
282
283#   commonly used ASCII values
284ASC_TAB="	"
285ASC_NL="
286"
287
288#   determine name of tool
289if [ ".$tool" != . ]; then
290    #   used inside shtool script
291    toolcmd="$0 $tool"
292    toolcmdhelp="shtool $tool"
293    msgprefix="shtool:$tool"
294else
295    #   used as standalone script
296    toolcmd="$0"
297    toolcmdhelp="sh $0"
298    msgprefix="$str_tool"
299fi
300
301#   parse argument specification string
302eval `echo $arg_spec |\
303      sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
304
305#   parse option specification string
306eval `echo h.$opt_spec |\
307      sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
308
309#   parse option alias string
310eval `echo h:help,$opt_alias |\
311      sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
312
313#   interate over argument line
314opt_PREV=''
315while [ $# -gt 0 ]; do
316    #   special option stops processing
317    if [ ".$1" = ".--" ]; then
318        shift
319        break
320    fi
321
322    #   determine option and argument
323    opt_ARG_OK=no
324    if [ ".$opt_PREV" != . ]; then
325        #   merge previous seen option with argument
326        opt_OPT="$opt_PREV"
327        opt_ARG="$1"
328        opt_ARG_OK=yes
329        opt_PREV=''
330    else
331        #   split argument into option and argument
332        case "$1" in
333            --[a-zA-Z0-9]*=*)
334                eval `echo "x$1" |\
335                      sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
336                opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
337                eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
338                ;;
339            --[a-zA-Z0-9]*)
340                opt_OPT=`echo "x$1" | cut -c4-`
341                opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
342                eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
343                opt_ARG=''
344                ;;
345            -[a-zA-Z0-9]*)
346                eval `echo "x$1" |\
347                      sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
348                          -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
349                ;;
350            -[a-zA-Z0-9])
351                opt_OPT=`echo "x$1" | cut -c3-`
352                opt_ARG=''
353                ;;
354            *)
355                break
356                ;;
357        esac
358    fi
359
360    #   eat up option
361    shift
362
363    #   determine whether option needs an argument
364    eval "opt_MODE=\$opt_MODE_${opt_OPT}"
365    if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then
366        if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then
367            opt_PREV="$opt_OPT"
368            continue
369        fi
370    fi
371
372    #   process option
373    case $opt_MODE in
374        '.' )
375            #   boolean option
376            eval "opt_${opt_OPT}=yes"
377            ;;
378        ':' )
379            #   option with argument (multiple occurrences override)
380            eval "opt_${opt_OPT}=\"\$opt_ARG\""
381            ;;
382        '+' )
383            #   option with argument (multiple occurrences append)
384            eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
385            ;;
386        * )
387            echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
388            echo "$msgprefix:Hint:  run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
389            exit 1
390            ;;
391    esac
392done
393if [ ".$opt_PREV" != . ]; then
394    echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
395    echo "$msgprefix:Hint:  run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
396    exit 1
397fi
398
399#   process help option
400if [ ".$opt_h" = .yes ]; then
401    echo "Usage: $toolcmdhelp $str_usage"
402    exit 0
403fi
404
405#   complain about incorrect number of arguments
406case $arg_MODE in
407    '=' )
408        if [ $# -ne $arg_NUMS ]; then
409            echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
410            echo "$msgprefix:Hint:  run \`$toolcmd -h' or \`man shtool' for details" 1>&2
411            exit 1
412        fi
413        ;;
414    '+' )
415        if [ $# -lt $arg_NUMS ]; then
416            echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
417            echo "$msgprefix:Hint:  run \`$toolcmd -h' or \`man shtool' for details" 1>&2
418            exit 1
419        fi
420        ;;
421esac
422
423#   establish a temporary file on request
424if [ ".$gen_tmpfile" = .yes ]; then
425    #   create (explicitly) secure temporary directory
426    if [ ".$TMPDIR" != . ]; then
427        tmpdir="$TMPDIR"
428    elif [ ".$TEMPDIR" != . ]; then
429        tmpdir="$TEMPDIR"
430    else
431        tmpdir="/tmp"
432    fi
433    tmpdir="$tmpdir/.shtool.$$"
434    ( umask 077
435      rm -rf "$tmpdir" >/dev/null 2>&1 || true
436      mkdir  "$tmpdir" >/dev/null 2>&1
437      if [ $? -ne 0 ]; then
438          echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
439          exit 1
440      fi
441    )
442
443    #   create (implicitly) secure temporary file
444    tmpfile="$tmpdir/shtool.tmp"
445    touch "$tmpfile"
446fi
447
448#   utility function: map string to lower case
449util_lower () {
450    echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
451}
452
453#   utility function: map string to upper case
454util_upper () {
455    echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
456}
457
458#   cleanup procedure
459shtool_exit () {
460    rc="$1"
461    if [ ".$gen_tmpfile" = .yes ]; then
462        rm -rf "$tmpdir" >/dev/null 2>&1 || true
463    fi
464    exit $rc
465}
466
467##
468##  DISPATCH INTO SCRIPT BODY
469##
470
471case $tool in
472
473echo )
474    ##
475    ##  echo -- Print string with optional construct expansion
476    ##  Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
477    ##
478
479    text="$*"
480
481    #   check for broken escape sequence expansion
482    seo=''
483    bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
484    if [ ".$bytes" != .3 ]; then
485        bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
486        if [ ".$bytes" = .3 ]; then
487            seo='-E'
488        fi
489    fi
490
491    #   check for existing -n option (to suppress newline)
492    minusn=''
493    bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
494    if [ ".$bytes" = .3 ]; then
495        minusn='-n'
496    fi
497
498    #   determine terminal bold sequence
499    term_bold=''
500    term_norm=''
501    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then
502        case $TERM in
503            #   for the most important terminal types we directly know the sequences
504            xterm|xterm*|vt220|vt220*)
505                term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
506                term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
507                ;;
508            vt100|vt100*|cygwin)
509                term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
510                term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
511                ;;
512            #   for all others, we try to use a possibly existing `tput' or `tcout' utility
513            * )
514                paths=`echo $PATH | sed -e 's/:/ /g'`
515                for tool in tput tcout; do
516                    for dir in $paths; do
517                        if [ -r "$dir/$tool" ]; then
518                            for seq in bold md smso; do # 'smso' is last
519                                bold="`$dir/$tool $seq 2>/dev/null`"
520                                if [ ".$bold" != . ]; then
521                                    term_bold="$bold"
522                                    break
523                                fi
524                            done
525                            if [ ".$term_bold" != . ]; then
526                                for seq in sgr0 me rmso init reset; do # 'reset' is last
527                                    norm="`$dir/$tool $seq 2>/dev/null`"
528                                    if [ ".$norm" != . ]; then
529                                        term_norm="$norm"
530                                        break
531                                    fi
532                                done
533                            fi
534                            break
535                        fi
536                    done
537                    if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then
538                        break;
539                    fi
540                done
541                ;;
542        esac
543        if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then
544            echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
545            term_bold=''
546            term_norm=''
547        fi
548    fi
549
550    #   determine user name
551    username=''
552    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then
553        username="`(id -un) 2>/dev/null`"
554        if [ ".$username" = . ]; then
555            str="`(id) 2>/dev/null`"
556            if [ ".`echo $str | grep '^uid[ 	]*=[ 	]*[0-9]*('`" != . ]; then
557                username=`echo $str | sed -e 's/^uid[ 	]*=[ 	]*[0-9]*(//' -e 's/).*$//'`
558            fi
559            if [ ".$username" = . ]; then
560                username="$LOGNAME"
561                if [ ".$username" = . ]; then
562                    username="$USER"
563                    if [ ".$username" = . ]; then
564                        username="`(whoami) 2>/dev/null |\
565                                   awk '{ printf("%s", $1); }'`"
566                        if [ ".$username" = . ]; then
567                            username="`(who am i) 2>/dev/null |\
568                                       awk '{ printf("%s", $1); }'`"
569                            if [ ".$username" = . ]; then
570                                username='unknown'
571                            fi
572                        fi
573                    fi
574                fi
575            fi
576        fi
577    fi
578
579    #   determine user id
580    userid=''
581    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then
582        userid="`(id -u) 2>/dev/null`"
583        if [ ".$userid" = . ]; then
584            userid="`(id -u ${username}) 2>/dev/null`"
585            if [ ".$userid" = . ]; then
586                str="`(id) 2>/dev/null`"
587                if [ ".`echo $str | grep '^uid[ 	]*=[ 	]*[0-9]*('`" != . ]; then
588                    userid=`echo $str | sed -e 's/^uid[ 	]*=[ 	]*//' -e 's/(.*$//'`
589                fi
590                if [ ".$userid" = . ]; then
591                    userid=`(getent passwd ${username}) 2>/dev/null | \
592                            sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
593                    if [ ".$userid" = . ]; then
594                        userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
595                                sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
596                        if [ ".$userid" = . ]; then
597                            userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
598                                    sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
599                            if [ ".$userid" = . ]; then
600                                userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
601                                        sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
602                                if [ ".$userid" = . ]; then
603                                    userid='?'
604                                fi
605                            fi
606                        fi
607                    fi
608                fi
609            fi
610        fi
611    fi
612
613    #   determine (primary) group id
614    groupid=''
615    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then
616        groupid="`(id -g ${username}) 2>/dev/null`"
617        if [ ".$groupid" = . ]; then
618            str="`(id) 2>/dev/null`"
619            if [ ".`echo $str | grep 'gid[ 	]*=[ 	]*[0-9]*('`" != . ]; then
620                groupid=`echo $str | sed -e 's/^.*gid[ 	]*=[ 	]*//' -e 's/(.*$//'`
621            fi
622            if [ ".$groupid" = . ]; then
623                groupid=`(getent passwd ${username}) 2>/dev/null | \
624                         sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
625                if [ ".$groupid" = . ]; then
626                    groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
627                             sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
628                    if [ ".$groupid" = . ]; then
629                        groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
630                                 sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
631                        if [ ".$groupid" = . ]; then
632                            groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
633                                     sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
634                            if [ ".$groupid" = . ]; then
635                                groupid='?'
636                            fi
637                        fi
638                    fi
639                fi
640            fi
641        fi
642    fi
643
644    #   determine (primary) group name
645    groupname=''
646    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then
647        groupname="`(id -gn ${username}) 2>/dev/null`"
648        if [ ".$groupname" = . ]; then
649            str="`(id) 2>/dev/null`"
650            if [ ".`echo $str | grep 'gid[ 	]*=[ 	]*[0-9]*('`" != . ]; then
651                groupname=`echo $str | sed -e 's/^.*gid[ 	]*=[ 	]*[0-9]*(//' -e 's/).*$//'`
652            fi
653            if [ ".$groupname" = . ]; then
654                groupname=`(getent group) 2>/dev/null | \
655                           grep "^[^:]*:[^:]*:${groupid}:" | \
656                           sed -e 's/:.*$//'`
657                if [ ".$groupname" = . ]; then
658                    groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
659                               sed -e 's/:.*$//'`
660                    if [ ".$groupname" = . ]; then
661                        groupname=`(ypcat group; niscat group) 2>/dev/null | \
662                                   sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \
663                                   sed -e 's/:.*$//'`
664                        if [ ".$groupname" = . ]; then
665                            groupname=`(nidump group .) 2>/dev/null | \
666                                       grep "^[^:]*:[^:]*:${groupid}:" | \
667                                       sed -e 's/:.*$//'`
668                            if [ ".$groupname" = . ]; then
669                                groupname='?'
670                            fi
671                        fi
672                    fi
673                fi
674            fi
675        fi
676    fi
677
678    #   determine host and domain name
679    hostname=''
680    domainname=''
681    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then
682        hostname="`(uname -n) 2>/dev/null |\
683                   awk '{ printf("%s", $1); }'`"
684        if [ ".$hostname" = . ]; then
685            hostname="`(hostname) 2>/dev/null |\
686                       awk '{ printf("%s", $1); }'`"
687            if [ ".$hostname" = . ]; then
688                hostname='unknown'
689            fi
690        fi
691        case $hostname in
692            *.* )
693                domainname=".`echo $hostname | cut -d. -f2-`"
694                hostname="`echo $hostname | cut -d. -f1`"
695                ;;
696        esac
697    fi
698    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then
699        if [ ".$domainname" = . ]; then
700            if [ -f /etc/resolv.conf ]; then
701                domainname="`grep '^[ 	]*domain' /etc/resolv.conf | sed -e 'q' |\
702                             sed -e 's/.*domain//' \
703                                 -e 's/^[ 	]*//' -e 's/^ *//' -e 's/^	*//' \
704                                 -e 's/^\.//' -e 's/^/./' |\
705                             awk '{ printf("%s", $1); }'`"
706                if [ ".$domainname" = . ]; then
707                    domainname="`grep '^[ 	]*search' /etc/resolv.conf | sed -e 'q' |\
708                                 sed -e 's/.*search//' \
709                                     -e 's/^[ 	]*//' -e 's/^ *//' -e 's/^	*//' \
710                                     -e 's/ .*//' -e 's/	.*//' \
711                                     -e 's/^\.//' -e 's/^/./' |\
712                                 awk '{ printf("%s", $1); }'`"
713                fi
714            fi
715        fi
716    fi
717
718    #   determine current time
719    time_day=''
720    time_month=''
721    time_year=''
722    time_monthname=''
723    if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then
724        time_day=`date '+%d'`
725        time_month=`date '+%m'`
726        time_year=`date '+%Y' 2>/dev/null`
727        if [ ".$time_year" = . ]; then
728            time_year=`date '+%y'`
729            case $time_year in
730                [5-9][0-9]) time_year="19$time_year" ;;
731                [0-4][0-9]) time_year="20$time_year" ;;
732            esac
733        fi
734        case $time_month in
735            1|01) time_monthname='Jan' ;;
736            2|02) time_monthname='Feb' ;;
737            3|03) time_monthname='Mar' ;;
738            4|04) time_monthname='Apr' ;;
739            5|05) time_monthname='May' ;;
740            6|06) time_monthname='Jun' ;;
741            7|07) time_monthname='Jul' ;;
742            8|08) time_monthname='Aug' ;;
743            9|09) time_monthname='Sep' ;;
744              10) time_monthname='Oct' ;;
745              11) time_monthname='Nov' ;;
746              12) time_monthname='Dec' ;;
747        esac
748    fi
749
750    #   expand special ``%x'' constructs
751    if [ ".$opt_e" = .yes ]; then
752        text=`echo $seo "$text" |\
753              sed -e "s/%B/${term_bold}/g" \
754                  -e "s/%b/${term_norm}/g" \
755                  -e "s/%u/${username}/g" \
756                  -e "s/%U/${userid}/g" \
757                  -e "s/%g/${groupname}/g" \
758                  -e "s/%G/${groupid}/g" \
759                  -e "s/%h/${hostname}/g" \
760                  -e "s/%d/${domainname}/g" \
761                  -e "s/%D/${time_day}/g" \
762                  -e "s/%M/${time_month}/g" \
763                  -e "s/%Y/${time_year}/g" \
764                  -e "s/%m/${time_monthname}/g" 2>/dev/null`
765    fi
766
767    #   create output
768    if [ .$opt_n = .no ]; then
769        echo $seo "$text"
770    else
771        #   the harder part: echo -n is best, because
772        #   awk may complain about some \xx sequences.
773        if [ ".$minusn" != . ]; then
774            echo $seo $minusn "$text"
775        else
776            echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
777        fi
778    fi
779
780    shtool_exit 0
781    ;;
782
783install )
784    ##
785    ##  install -- Install a program, script or datafile
786    ##  Copyright (c) 1997-2008 Ralf S. Engelschall <rse@engelschall.com>
787    ##
788
789    #   special case: "shtool install -d <dir> [...]" internally
790    #   maps to "shtool mkdir -f -p -m 755 <dir> [...]"
791    if [ "$opt_d" = yes ]; then
792        cmd="$0 mkdir -f -p -m 755"
793        if [ ".$opt_o" != . ]; then
794            cmd="$cmd -o '$opt_o'"
795        fi
796        if [ ".$opt_g" != . ]; then
797            cmd="$cmd -g '$opt_g'"
798        fi
799        if [ ".$opt_v" = .yes ]; then
800            cmd="$cmd -v"
801        fi
802        if [ ".$opt_t" = .yes ]; then
803            cmd="$cmd -t"
804        fi
805        for dir in "$@"; do
806            eval "$cmd $dir" || shtool_exit $?
807        done
808        shtool_exit 0
809    fi
810
811    #   determine source(s) and destination
812    argc=$#
813    srcs=""
814    while [ $# -gt 1 ]; do
815        srcs="$srcs $1"
816        shift
817    done
818    dstpath="$1"
819
820    #   type check for destination
821    dstisdir=0
822    if [ -d $dstpath ]; then
823        dstpath=`echo "$dstpath" | sed -e 's:/$::'`
824        dstisdir=1
825    fi
826
827    #   consistency check for destination
828    if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
829        echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
830        shtool_exit 1
831    fi
832
833    #   iterate over all source(s)
834    for src in $srcs; do
835        dst=$dstpath
836
837        #   if destination is a directory, append the input filename
838        if [ $dstisdir = 1 ]; then
839            dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
840            dst="$dst/$dstfile"
841        fi
842
843        #   check for correct arguments
844        if [ ".$src" = ".$dst" ]; then
845            echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
846            continue
847        fi
848        if [ -d "$src" ]; then
849            echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
850            continue
851        fi
852
853        #   make a temp file name in the destination directory
854        dsttmp=`echo $dst |\
855                sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
856                    -e "s;\$;/#INST@$$#;"`
857
858        #   verbosity
859        if [ ".$opt_v" = .yes ]; then
860            echo "$src -> $dst" 1>&2
861        fi
862
863        #   copy or move the file name to the temp name
864        #   (because we might be not allowed to change the source)
865        if [ ".$opt_C" = .yes ]; then
866            opt_c=yes
867        fi
868        if [ ".$opt_c" = .yes ]; then
869            if [ ".$opt_t" = .yes ]; then
870                echo "cp $src $dsttmp" 1>&2
871            fi
872            cp "$src" "$dsttmp" || shtool_exit $?
873        else
874            if [ ".$opt_t" = .yes ]; then
875                echo "mv $src $dsttmp" 1>&2
876            fi
877            mv "$src" "$dsttmp" || shtool_exit $?
878        fi
879
880        #   adjust the target file
881        if [ ".$opt_e" != . ]; then
882            sed='sed'
883            OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
884            for e
885            do
886                sed="$sed -e '$e'"
887            done
888            cp "$dsttmp" "$dsttmp.old"
889            chmod u+w $dsttmp
890            eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
891            rm -f $dsttmp.old
892        fi
893        if [ ".$opt_s" = .yes ]; then
894            if [ ".$opt_t" = .yes ]; then
895                echo "strip $dsttmp" 1>&2
896            fi
897            strip $dsttmp || shtool_exit $?
898        fi
899        if [ ".$opt_o" != . ]; then
900            if [ ".$opt_t" = .yes ]; then
901                echo "chown $opt_o $dsttmp" 1>&2
902            fi
903            chown $opt_o $dsttmp || shtool_exit $?
904        fi
905        if [ ".$opt_g" != . ]; then
906            if [ ".$opt_t" = .yes ]; then
907                echo "chgrp $opt_g $dsttmp" 1>&2
908            fi
909            chgrp $opt_g $dsttmp || shtool_exit $?
910        fi
911        if [ ".$opt_m" != ".-" ]; then
912            if [ ".$opt_t" = .yes ]; then
913                echo "chmod $opt_m $dsttmp" 1>&2
914            fi
915            chmod $opt_m $dsttmp || shtool_exit $?
916        fi
917
918        #   determine whether to do a quick install
919        #   (has to be done _after_ the strip was already done)
920        quick=no
921        if [ ".$opt_C" = .yes ]; then
922            if [ -r $dst ]; then
923                if cmp -s "$src" "$dst"; then
924                    quick=yes
925                fi
926            fi
927        fi
928
929        #   finally, install the file to the real destination
930        if [ $quick = yes ]; then
931            if [ ".$opt_t" = .yes ]; then
932                echo "rm -f $dsttmp" 1>&2
933            fi
934            rm -f $dsttmp
935        else
936            if [ ".$opt_t" = .yes ]; then
937                echo "rm -f $dst && mv $dsttmp $dst" 1>&2
938            fi
939            rm -f $dst && mv $dsttmp $dst
940        fi
941    done
942
943    shtool_exit 0
944    ;;
945
946mkdir )
947    ##
948    ##  mkdir -- Make one or more directories
949    ##  Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
950    ##
951
952    errstatus=0
953    for p in ${1+"$@"}; do
954        #   if the directory already exists...
955        if [ -d "$p" ]; then
956            if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
957                echo "$msgprefix:Error: directory already exists: $p" 1>&2
958                errstatus=1
959                break
960            else
961                continue
962            fi
963        fi
964        #   if the directory has to be created...
965        if [ ".$opt_p" = .no ]; then
966            if [ ".$opt_t" = .yes ]; then
967                echo "mkdir $p" 1>&2
968            fi
969            mkdir $p || errstatus=$?
970            if [ ".$opt_o" != . ]; then
971                if [ ".$opt_t" = .yes ]; then
972                    echo "chown $opt_o $p" 1>&2
973                fi
974                chown $opt_o $p || errstatus=$?
975            fi
976            if [ ".$opt_g" != . ]; then
977                if [ ".$opt_t" = .yes ]; then
978                    echo "chgrp $opt_g $p" 1>&2
979                fi
980                chgrp $opt_g $p || errstatus=$?
981            fi
982            if [ ".$opt_m" != . ]; then
983                if [ ".$opt_t" = .yes ]; then
984                    echo "chmod $opt_m $p" 1>&2
985                fi
986                chmod $opt_m $p || errstatus=$?
987            fi
988        else
989            #   the smart situation
990            set fnord `echo ":$p" |\
991                       sed -e 's/^:\//%/' \
992                           -e 's/^://' \
993                           -e 's/\// /g' \
994                           -e 's/^%/\//'`
995            shift
996            pathcomp=''
997            for d in ${1+"$@"}; do
998                pathcomp="$pathcomp$d"
999                case "$pathcomp" in
1000                    -* ) pathcomp="./$pathcomp" ;;
1001                esac
1002                if [ ! -d "$pathcomp" ]; then
1003                    if [ ".$opt_t" = .yes ]; then
1004                        echo "mkdir $pathcomp" 1>&2
1005                    fi
1006					# See https://bugs.php.net/51076
1007					# The fix is from Debian who have sent it
1008					# upstream, too; but upstream seems dead.
1009                    mkdir $pathcomp || {
1010                        _errstatus=$?
1011                        [ -d "$pathcomp" ] || errstatus=${_errstatus}
1012                        unset _errstatus
1013                    }
1014                    if [ ".$opt_o" != . ]; then
1015                        if [ ".$opt_t" = .yes ]; then
1016                            echo "chown $opt_o $pathcomp" 1>&2
1017                        fi
1018                        chown $opt_o $pathcomp || errstatus=$?
1019                    fi
1020                    if [ ".$opt_g" != . ]; then
1021                        if [ ".$opt_t" = .yes ]; then
1022                            echo "chgrp $opt_g $pathcomp" 1>&2
1023                        fi
1024                        chgrp $opt_g $pathcomp || errstatus=$?
1025                    fi
1026                    if [ ".$opt_m" != . ]; then
1027                        if [ ".$opt_t" = .yes ]; then
1028                            echo "chmod $opt_m $pathcomp" 1>&2
1029                        fi
1030                        chmod $opt_m $pathcomp || errstatus=$?
1031                    fi
1032                fi
1033                pathcomp="$pathcomp/"
1034            done
1035        fi
1036    done
1037
1038    shtool_exit $errstatus
1039    ;;
1040
1041platform )
1042    ##
1043    ##  platform -- Platform Identification Utility
1044    ##  Copyright (c) 2003-2008 Ralf S. Engelschall <rse@engelschall.com>
1045    ##
1046
1047    #   option post-processing
1048    if [ ".$opt_t" != . ]; then
1049        case "$opt_t" in
1050            binary )
1051                #   binary package id (OpenPKG RPM)
1052                opt_F="%<ap>-%<sp>"
1053                opt_L=yes
1054                opt_S=""
1055                opt_C="+"
1056                ;;
1057            build )
1058                #   build time checking (OpenPKG RPM)
1059                opt_F="%<at>-%<st>"
1060                opt_L=yes
1061                opt_S=""
1062                opt_C="+"
1063                ;;
1064            gnu )
1065                #   GNU config.guess style <arch>-<vendor>-<os><osversion>
1066                opt_F="%<at>-unknown-%<st>"
1067                opt_L=yes
1068                opt_S=""
1069                opt_C="+"
1070                ;;
1071            web )
1072                #   non-whitespace HTTP Server-header id
1073                opt_F="%<sp>-%<ap>"
1074                opt_S="/"
1075                opt_C="+"
1076                ;;
1077            summary)
1078                #   human readable verbose summary information
1079                opt_F="Class:      %[sc] (%[ac])\\nProduct:    %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
1080                opt_S=" "
1081                opt_C="/"
1082                ;;
1083            all-in-one )
1084                #   full-table all-in-one information
1085                opt_F=""
1086                opt_F="${opt_F}concise architecture class:      %<ac>\\n"
1087                opt_F="${opt_F}regular architecture class:      %{ac}\\n"
1088                opt_F="${opt_F}verbose architecture class:      %[ac]\\n"
1089                opt_F="${opt_F}concise architecture product:    %<ap>\\n"
1090                opt_F="${opt_F}regular architecture product:    %{ap}\\n"
1091                opt_F="${opt_F}verbose architecture product:    %[ap]\\n"
1092                opt_F="${opt_F}concise architecture technology: %<at>\\n"
1093                opt_F="${opt_F}regular architecture technology: %{at}\\n"
1094                opt_F="${opt_F}verbose architecture technology: %[at]\\n"
1095                opt_F="${opt_F}concise system class:            %<sc>\\n"
1096                opt_F="${opt_F}regular system class:            %{sc}\\n"
1097                opt_F="${opt_F}verbose system class:            %[sc]\\n"
1098                opt_F="${opt_F}concise system product:          %<sp>\\n"
1099                opt_F="${opt_F}regular system product:          %{sp}\\n"
1100                opt_F="${opt_F}verbose system product:          %[sp]\\n"
1101                opt_F="${opt_F}concise system technology:       %<st>\\n"
1102                opt_F="${opt_F}regular system technology:       %{st}\\n"
1103                opt_F="${opt_F}verbose system technology:       %[st]"
1104                ;;
1105            * )
1106                echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
1107                exit 1
1108                ;;
1109        esac
1110    fi
1111
1112    #   assemble initial platform information
1113    UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
1114    UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
1115    UNAME_MACHINE='unknown'
1116    UNAME_SYSTEM=`(uname -s) 2>/dev/null`  ||\
1117    UNAME_SYSTEM='unknown'
1118    UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
1119    UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
1120    UNAME_RELEASE='unknown'
1121
1122    UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
1123
1124    AC=""; AP=""; AT=""
1125    SC=""; SP=""; ST=""
1126
1127    #    dispatch into platform specific sections
1128    case "${UNAME}" in
1129
1130        #   FreeBSD
1131        *:FreeBSD:* )
1132            #   determine architecture
1133            AC="${UNAME_MACHINE}"
1134            case "${AC}" in
1135                i386 ) AC="iX86" ;;
1136            esac
1137            AP="${AC}"
1138            AT="${AP}"
1139            if [ ".${AT}" = ".iX86" ]; then
1140                case "`(/sbin/sysctl -n hw.model) 2>&1`" in
1141                    *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
1142                    *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
1143                    *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
1144                esac
1145            fi
1146            #   determine system
1147            r=`echo "${UNAME_RELEASE}" |\
1148               sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
1149            ST="FreeBSD ${r}"
1150            SP="${ST}"
1151            case "${r}" in
1152                1.* ) SC="4.3BSD" ;;
1153                *   ) SC="4.4BSD" ;;
1154            esac
1155            ;;
1156
1157        #   NetBSD
1158        *:NetBSD:* )
1159            #   determine architecture
1160            AT="${UNAME_MACHINE}"
1161            AP="${AT}"
1162            case "${AP}" in
1163                i[3-6]86 ) AP="iX86" ;;
1164            esac
1165            AC="${AP}"
1166            #   determine system
1167            r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1168            ST="NetBSD ${r}"
1169            SP="${ST}"
1170            case "${r}" in
1171                0.* ) SC="4.3BSD" ;;
1172                *   ) SC="4.4BSD" ;;
1173            esac
1174            ;;
1175
1176        #   OpenBSD
1177        *:OpenBSD:* )
1178            #   determine architecture
1179            AT="${UNAME_MACHINE}"
1180            AP="${AT}"
1181            case "${AP}" in
1182                i[3-6]86 ) AP="iX86" ;;
1183            esac
1184            AC="${AP}"
1185            #   determine system
1186            r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1187            ST="OpenBSD ${r}"
1188            SP="${ST}"
1189            SC="4.4BSD"
1190            ;;
1191
1192        #   DragonFly BSD
1193        *:DragonFly:* )
1194            #   determine architecture
1195            AT="${UNAME_MACHINE}"
1196            AP="${AT}"
1197            case "${AP}" in
1198                i[3-6]86 ) AP="iX86" ;;
1199            esac
1200            AC="${AP}"
1201            #   determine system
1202            r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1203            ST="DragonFly ${r}"
1204            SP="${ST}"
1205            SC="4.4BSD"
1206            ;;
1207
1208        #   GNU/Linux
1209        *:Linux:* )
1210            #   determine architecture
1211            AT="${UNAME_MACHINE}"
1212            case "${AT}" in
1213               ia64     ) AT="IA64"   ;;
1214               x86_64   ) AT='AMD64'  ;;
1215               parisc   ) AT="HPPA32" ;;
1216               parisc64 ) AT="HPPA64" ;;
1217            esac
1218            AP="${AT}"
1219            case "${AP}" in
1220               i[3-6]86 ) AP='iX86' ;;
1221            esac
1222            AC="${AP}"
1223            #   determine system
1224            v_kern=`echo "${UNAME_RELEASE}" |\
1225                sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
1226            v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
1227                env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
1228            ST="GNU/<Linux >${v_libc}/<${v_kern}>"
1229            if [ -f /etc/lsb-release ]; then
1230                eval `( . /etc/lsb-release
1231                    echo "SC=\"LSB${LSB_VERSION}\""
1232                    if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
1233                        echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
1234                    fi
1235                ) 2>/dev/null`
1236            fi
1237            if [ ".$SP" = . ]; then
1238                for tagfile in x \
1239                    `cd /etc && \
1240                    /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
1241                    sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
1242                    echo redhat-release lsb-release`
1243                do
1244                    [ ".${tagfile}" = .x ] && continue
1245                    [ ! -f "/etc/${tagfile}" ] && continue
1246                    n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
1247                    v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
1248                       sed -e 's/^/#/' \
1249                           -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1250                           -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1251                           -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1252                           -e 's/^#.*$//'`
1253                    case "`util_lower ${n}`" in
1254                        redhat )
1255                            if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
1256                                n="<R>ed <H>at <E>nterprise <L>inux"
1257                            else
1258                                n="<R>ed <H>at <L>inux"
1259                            fi
1260                            ;;
1261                        debian             ) n="Debian[ GNU/Linux]"        ;;
1262                        ubuntu             ) n="Ubuntu[ GNU/Linux]"        ;;
1263                        fedora             ) n="<Fedora> Core[ GNU/Linux]" ;;
1264                        suse               ) n="[Novell ]SUSE[ Linux]"     ;;
1265                        mandrake*|mandriva ) n="Mandriva[ Linux]"          ;;
1266                        gentoo             ) n="Gentoo[ GNU/Linux]"        ;;
1267                        slackware          ) n="Slackware[ Linux]"         ;;
1268                        turbolinux         ) n="TurboLinux"                ;;
1269                        unitedlinux        ) n="UnitedLinux"               ;;
1270                        *                  ) n="${n}[ GNU/Linux]"          ;;
1271                    esac
1272                    case "$n" in
1273                        *"<"*">"* ) SP="$n <$v>" ;;
1274                        *         ) SP="$n $v"   ;;
1275                    esac
1276                    break
1277                done
1278            fi
1279            [ ".$SP" = . ] && SP="${ST}"
1280            [ ".$SC" = . ] && SC="LSB"
1281            ;;
1282
1283        #   Sun Solaris
1284        *:SunOS:* )
1285            #   determine architecture
1286            AT="${UNAME_MACHINE}"
1287            case "${AT}" in
1288                i86pc )
1289                    AT="iX86"
1290                    case "`(/bin/isainfo -k) 2>&1`" in
1291                        amd64 ) AT="AMD64" ;;
1292                    esac
1293                    ;;
1294            esac
1295            AP="${AT}"
1296            case "${AP}" in
1297                sun4[cdm] ) AP="SPARC32" ;;
1298                sun4[uv]  ) AP="SPARC64" ;;
1299                sun4*     ) AP="SPARC"   ;;
1300            esac
1301            AC="${AP}"
1302            case "${AC}" in
1303                SPARC* ) AC="SPARC" ;;
1304            esac
1305            #   determine system
1306            ST="[Sun ]SunOS ${UNAME_RELEASE}"
1307            v=`echo "${UNAME_RELEASE}" |\
1308               sed -e 's;^4\.;1.;' \
1309                   -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
1310                   -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
1311            SP="[Sun ]Solaris $v"
1312            case "${UNAME_RELEASE}" in
1313                4.* ) SC="4.3BSD" ;;
1314                5.* ) SC="SVR4"   ;;
1315            esac
1316            ;;
1317
1318        #   SCO UnixWare
1319        *:UnixWare:* )
1320            #   determine architecture
1321            AT="${UNAME_MACHINE}"
1322            case "${AT}" in
1323                i[3-6]86 | ix86at ) AT="iX86" ;;
1324            esac
1325            AP="${AT}"
1326            #   determine system
1327            v=`/sbin/uname -v`
1328            ST="[SCO ]UnixWare ${v}"
1329            SP="${ST}"
1330            SC="SVR${UNAME_RELEASE}"
1331            ;;
1332
1333        #   QNX
1334        *:QNX:* )
1335            #   determine architecture
1336            AT="${UNAME_MACHINE}"
1337            case "${AT}" in
1338                x86pc ) AT="iX86" ;;
1339            esac
1340            AP="${AT}"
1341            #   determine system
1342            v="${UNAME_RELEASE}"
1343            ST="QNX[ Neutrino RTOS] ${v}"
1344            v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
1345            SP="QNX[ Neutrino RTOS] ${v}"
1346            SC="QNX"
1347            ;;
1348
1349        #   SGI IRIX
1350        *:IRIX*:* )
1351            #   determine architecture
1352            AT="${UNAME_MACHINE}"
1353            AP="${AT}"
1354            case "${AP}:${UNAME_SYSTEM}" in
1355                IP*:IRIX64 ) AP="MIPS64" ;;
1356                IP*:*      ) AP="MIPS"   ;;
1357            esac
1358            AC="${AP}"
1359            #   determine system
1360            v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
1361            ST="[SGI ]IRIX ${v}"
1362            v="${UNAME_RELEASE}"
1363            SP="[SGI ]IRIX ${v}"
1364            SC="4.2BSD/SVR3"
1365            ;;
1366
1367        #   HP HP-UX
1368        *:HP-UX:* )
1369            #   determine architecture
1370            AT="${UNAME_MACHINE}"
1371            case "${AT}" in
1372                ia64 ) AT="IA64" ;;
1373                9000/[34]?? ) AT=M68K ;;
1374                9000/[678][0-9][0-9])
1375                    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
1376                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
1377                    case "${sc_cpu_version}" in
1378                        523 ) AT="HPPA1.0" ;;
1379                        528 ) AT="HPPA1.1" ;;
1380                        532 ) AT="HPPA2.0"
1381                            case "${sc_kernel_bits}" in
1382                                32 ) AT="${AT}n" ;;
1383                                64 ) AT="${AT}w" ;;
1384                            esac
1385                            ;;
1386                    esac
1387                    ;;
1388            esac
1389            AP="${AT}"
1390            case "${AP}" in
1391                HPPA* ) AP="HPPA" ;;
1392            esac
1393            AC="${AP}"
1394            #   determine system
1395            v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
1396            ST="[HP ]<HP>-<UX ${v}>"
1397            SP="${ST}"
1398            case "${v}" in
1399                10.*   ) SC="SVR4.2" ;;
1400                [7-9]* ) SC="SVR4"   ;;
1401            esac
1402            ;;
1403
1404        #   HP Tru64 (OSF1)
1405        *:OSF1:* )
1406            #   determine architecture
1407            AP="${UNAME_MACHINE}"
1408            case "${AP}" in
1409                alpha ) AP="Alpha" ;;
1410            esac
1411            alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
1412                sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
1413            AT="${AP}${alpha_type}"
1414            AC="${AP}"
1415            #   determine system
1416            v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
1417            ST="[HP ]Tru64 ${v}"
1418            SP="${ST}"
1419            SC="OSF1"
1420            ;;
1421
1422        #   IBM AIX
1423        *:AIX:* )
1424            #   determine architecture
1425            cpu_arch=RS6000
1426            if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
1427                cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
1428                if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
1429                    cpu_arch=PPC
1430                fi
1431            elif [ -d /QOpenSys ]; then
1432                #   IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
1433                cpu_arch=PPC
1434            fi
1435            if [ -x /usr/bin/oslevel ]; then
1436                os_level=`/usr/bin/oslevel`
1437            else
1438                os_level="`uname -v`.`uname -r`"
1439            fi
1440            os_level=`echo "${os_level}" |\
1441                      sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
1442                          -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
1443            AT="${cpu_arch}"
1444            AP="${AT}"
1445            AC="${AP}"
1446            #   determine system
1447            ST="[IBM ]<AIX >${os_level}"
1448            SP="${ST}"
1449            case "${os_level}" in
1450                [12]* ) SC="SVR2" ;;
1451                *     ) SC="SVR4" ;;
1452            esac
1453            ;;
1454
1455        #   Apple Mac OS X (Darwin)
1456        *:Darwin:* )
1457            #   determine architecture
1458            AT="`uname -p`"
1459            case "${AT}" in
1460                powerpc ) AT="PPC" ;;
1461            esac
1462            AP="${AT}"
1463            case "${AP}" in
1464                i?86 ) AP="iX86" ;;
1465            esac
1466            AC="${AP}"
1467            #   determine system
1468            unset v1; unset v2; unset v3
1469            eval `echo "${UNAME_RELEASE}" |\
1470                  sed -e 's/^/#/' \
1471                      -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1472                      -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1473                      -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1474                      -e 's/^#.*$/v1="0"/'`
1475            ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
1476            SP="$ST"
1477            v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
1478            if [ ".$v" = . ]; then
1479                for name in System Server; do
1480                    if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
1481                        v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
1482                        [ ".$v" != . ] && break
1483                    fi
1484                done
1485            fi
1486            if [ ".$v" != . ]; then
1487                unset v1; unset v2; unset v3
1488                eval `echo "${v}" |\
1489                      sed -e 's/^/#/' \
1490                          -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1491                          -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1492                          -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1493                          -e 's/^#.*$/v1="0"/'`
1494                SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
1495            fi
1496            SC="4.4BSD/Mach3.0"
1497            ;;
1498
1499        #   Windows/Cygwin
1500        *:CYGWIN*:* )
1501            #   determine architecture
1502            AT="`uname -m`"
1503            AP="${AT}"
1504            case "${AP}" in
1505                i?86 ) AP="iX86" ;;
1506            esac
1507            AC="${AP}"
1508            #   determine system
1509            unset v1; unset v2; unset v3
1510            eval `echo "${UNAME_RELEASE}" |\
1511                  sed -e 's/^/#/' \
1512                      -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1513                      -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1514                      -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1515                      -e 's/^#.*$/v1="0"/'`
1516            ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}"
1517            SP="$ST"
1518            SC="Windows"
1519            v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\
1520               sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'`
1521            case "$v" in
1522                4.0 ) SC="$SC[ NT]"    ;;
1523                5.0 ) SC="$SC[ 2000]"  ;;
1524                5.1 ) SC="$SC[ XP]"    ;;
1525                6.0 ) SC="$SC[ Vista]" ;;
1526            esac
1527            ;;
1528
1529        #   TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
1530        # *:XXX:* )
1531        #   ...
1532        #   ;;
1533
1534        #   ...A STILL UNKNOWN PLATFORM...
1535        * )
1536            AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
1537            AP="${AT}"
1538            AC="${AP}"
1539            v=`echo "${UNAME_RELEASE}" |\
1540               sed -e 's/^/#/' \
1541                   -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1542                   -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1543                   -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1544                   -e 's/^#.*$/?/'`
1545            ST="${UNAME_SYSTEM} ${v}"
1546            SP="${ST}"
1547            SC="${SP}"
1548            ;;
1549
1550    esac
1551
1552    #   provide fallback values
1553    [ ".$AT" = . ] && AT="${AP:-${AC}}"
1554    [ ".$AP" = . ] && AP="${AT:-${AC}}"
1555    [ ".$AC" = . ] && AC="${AP:-${AT}}"
1556    [ ".$ST" = . ] && ST="${SP:-${SC}}"
1557    [ ".$SP" = . ] && SP="${ST:-${SC}}"
1558    [ ".$SC" = . ] && SC="${SP:-${ST}}"
1559
1560    #   support explicit enforced verbose/concise output
1561    if [ ".$opt_v" = .yes ]; then
1562        opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
1563    elif [ ".$opt_c" = .yes ]; then
1564        opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
1565    fi
1566
1567    #   provide verbose and concise variants
1568    AC_V=""; AC_N=""; AC_C=""
1569    AP_V=""; AP_N=""; AP_C=""
1570    AT_V=""; AT_N=""; AT_C=""
1571    SC_V=""; SC_N=""; SC_C=""
1572    SP_V=""; SP_N=""; SP_C=""
1573    ST_V=""; ST_N=""; ST_C=""
1574    for var_lc in at ap ac st sp sc; do
1575        case "$opt_F" in
1576            *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
1577            var_uc=`util_upper "$var_lc"`
1578            eval "val=\"\$${var_uc}\""
1579            val_V=""; val_N=""; val_C=""
1580            case "$opt_F" in
1581                *"%[${var_lc}]"* )
1582                    val_V=`echo ":$val" | \
1583                           sed -e 's/^://' \
1584                               -e 's;\[\([^]]*\)\];\1;g' \
1585                               -e 's;<\([^>]*\)>;\1;g' \
1586                               -e "s; ;��;g" \
1587                               -e "s;/;%%;g" \
1588                               -e "s;��;${opt_S};g" \
1589                               -e "s;%%;${opt_C};g"`
1590                    eval "${var_uc}_V=\"\${val_V}\""
1591                    ;;
1592            esac
1593            case "$opt_F" in
1594                *"%{${var_lc}}"* | *"%${var_lc}"* )
1595                    val_N=`echo ":$val" | \
1596                           sed -e 's/^://' \
1597                               -e 's;\[\([^]]*\)\];;g' \
1598                               -e 's;<\([^>]*\)>;\1;g' \
1599                               -e "s; ;��;g" \
1600                               -e "s;/;%%;g" \
1601                               -e "s;��;${opt_S};g" \
1602                               -e "s;%%;${opt_C};g"`
1603                    eval "${var_uc}_N=\"\${val_N}\""
1604                    ;;
1605            esac
1606            case "$opt_F" in
1607                *"%<${var_lc}>"* )
1608                    val_C=`echo ":$val" | \
1609                           sed -e 's/^://' \
1610                               -e 's;\[\([^]]*\)\];;g' \
1611                               -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
1612                               -e "s; ;��;g" \
1613                               -e "s;/;%%;g" \
1614                               -e "s;��;${opt_S};g" \
1615                               -e "s;%%;${opt_C};g"`
1616                    eval "${var_uc}_C=\"\${val_C}\""
1617                    ;;
1618            esac
1619            ;;
1620        esac
1621    done
1622
1623    #   create output string
1624    output=`echo ":$opt_F" |\
1625            sed -e "s/^://" \
1626                -e "s;%\\[ac\\];${AC_V};g" \
1627                -e "s;%{ac};${AC_N};g" \
1628                -e "s;%ac;${AC_N};g" \
1629                -e "s;%<ac>;${AC_C};g" \
1630                -e "s;%\\[ap\\];${AP_V};g" \
1631                -e "s;%{ap};${AP_N};g" \
1632                -e "s;%ap;${AP_N};g" \
1633                -e "s;%<ap>;${AP_C};g" \
1634                -e "s;%\\[at\\];${AT_V};g" \
1635                -e "s;%{at};${AT_N};g" \
1636                -e "s;%at;${AT_N};g" \
1637                -e "s;%<at>;${AT_C};g" \
1638                -e "s;%\\[sc\\];${SC_V};g" \
1639                -e "s;%{sc};${SC_N};g" \
1640                -e "s;%sc;${SC_N};g" \
1641                -e "s;%<sc>;${SC_C};g" \
1642                -e "s;%\\[sp\\];${SP_V};g" \
1643                -e "s;%{sp};${SP_N};g" \
1644                -e "s;%sp;${SP_N};g" \
1645                -e "s;%<sp>;${SP_C};g" \
1646                -e "s;%\\[st\\];${ST_V};g" \
1647                -e "s;%{st};${ST_N};g" \
1648                -e "s;%st;${ST_N};g" \
1649                -e "s;%<st>;${ST_C};g" \
1650                -e 's/\\\\n/^/g' |\
1651             tr '^' '\012'`
1652
1653    #   support lower/upper-case mapping
1654    if [ ".$opt_L" = .yes ]; then
1655        output=`util_lower "$output"`
1656    elif [ ".$opt_U" = .yes ]; then
1657        output=`util_upper "$output"`
1658    fi
1659
1660    #   display output string
1661    if [ ".$opt_n" = .yes ]; then
1662        echo . | awk '{ printf("%s", output); }' output="$output"
1663    else
1664        echo "$output"
1665    fi
1666
1667    shtool_exit 0
1668    ;;
1669
1670path )
1671    ##
1672    ##  path -- Deal with program paths
1673    ##  Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
1674    ##
1675
1676    namelist="$*"
1677
1678    #   check whether the test command supports the -x option
1679    if [ -x /bin/sh ] 2>/dev/null; then
1680        minusx="-x"
1681    else
1682        minusx="-r"
1683    fi
1684
1685    #   split path string
1686    paths="`echo $opt_p |\
1687            sed -e 's/^:/.:/' \
1688                -e 's/::/:.:/g' \
1689                -e 's/:$/:./' \
1690                -e 's/:/ /g'`"
1691
1692    #   SPECIAL REQUEST
1693    #   translate forward to reverse path
1694    if [ ".$opt_r" = .yes ]; then
1695        if [ "x$namelist" = "x." ]; then
1696            rp='.'
1697        else
1698            rp=''
1699            for pe in `IFS="$IFS/"; echo $namelist`; do
1700                rp="../$rp"
1701            done
1702        fi
1703        echo $rp | sed -e 's:/$::'
1704        shtool_exit 0
1705    fi
1706
1707    #   SPECIAL REQUEST
1708    #   strip out directory or base name
1709    if [ ".$opt_d" = .yes ]; then
1710        echo "$namelist" |\
1711        sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
1712        shtool_exit 0
1713    fi
1714    if [ ".$opt_b" = .yes ]; then
1715        echo "$namelist" |\
1716        sed -e 's;.*/\([^/]*\)$;\1;'
1717        shtool_exit 0
1718    fi
1719
1720    #   MAGIC SITUATION
1721    #   Perl Interpreter (perl)
1722    if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
1723        rm -f $tmpfile >/dev/null 2>&1
1724        touch $tmpfile
1725        found=0
1726        pc=99
1727        for dir in $paths; do
1728            dir=`echo $dir | sed -e 's;/*$;;'`
1729            nc=99
1730            for name in perl perl5 miniperl; do
1731                 if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
1732                     perl="$dir/$name"
1733                     pv=`$perl -e 'printf("%.3f", $]);'`
1734                     echo "$pv:$pc:$nc:$perl" >>$tmpfile
1735                     found=1
1736                 fi
1737                 nc=`expr $nc - 1`
1738            done
1739            pc=`expr $pc - 1`
1740        done
1741        if [ $found = 1 ]; then
1742            perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
1743            rm -f $tmpfile >/dev/null 2>&1
1744            echo "$perl"
1745            shtool_exit 0
1746        fi
1747        rm -f $tmpfile >/dev/null 2>&1
1748        shtool_exit 1
1749    fi
1750
1751    #   MAGIC SITUATION
1752    #   C pre-processor (cpp)
1753    if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
1754        echo >$tmpfile.c "#include <assert.h>"
1755        echo >>$tmpfile.c "Syntax Error"
1756        #   1. try the standard cc -E approach
1757        cpp="${CC-cc} -E"
1758        (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1759        my_error=`grep -v '^ *+' $tmpfile.out`
1760        if [ ".$my_error" != . ]; then
1761            #   2. try the cc -E approach and GCC's -traditional-ccp option
1762            cpp="${CC-cc} -E -traditional-cpp"
1763            (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1764            my_error=`grep -v '^ *+' $tmpfile.out`
1765            if [ ".$my_error" != . ]; then
1766                #   3. try a standalone cpp command in path and lib dirs
1767                for path in $paths /lib /usr/lib /usr/local/lib; do
1768                    path=`echo $path | sed -e 's;/*$;;'`
1769                    if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
1770                        cpp="$path/cpp"
1771                        break
1772                    fi
1773                done
1774                if [ ".$cpp" != . ]; then
1775                    (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1776                    my_error=`grep -v '^ *+' $tmpfile.out`
1777                    if [ ".$my_error" != . ]; then
1778                        #   ok, we gave up...
1779                        cpp=''
1780                    fi
1781                fi
1782            fi
1783        fi
1784        rm -f $tmpfile >/dev/null 2>&1
1785        rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
1786        if [ ".$cpp" != . ]; then
1787            echo "$cpp"
1788            shtool_exit 0
1789        fi
1790        shtool_exit 1
1791    fi
1792
1793    #   STANDARD SITUATION
1794    #   iterate over names
1795    for name in $namelist; do
1796        #   iterate over paths
1797        for path in $paths; do
1798            path=`echo $path | sed -e 's;/*$;;'`
1799            if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
1800                if [ ".$opt_s" != .yes ]; then
1801                    echo "$path/$name"
1802                fi
1803                shtool_exit 0
1804            fi
1805        done
1806    done
1807
1808    shtool_exit 1
1809    ;;
1810
1811esac
1812
1813shtool_exit 0
1814
1815