home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / nmap254b.zip / shtool < prev    next >
Text File  |  1999-12-22  |  62KB  |  1,998 lines

  1. #!/bin/sh
  2. ##
  3. ##  shtool -- Portable Shell Tool
  4. ##  Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. 
  5. ##  Version 1.2.3 (06-May-1999)
  6. ##
  7.  
  8. ##
  9. ##  LICENSE
  10. ##  =======
  11. ##
  12. ##  ====================================================================
  13. ##  Copyright (c) 1994-1999 Ralf S. Engelschall. All rights reserved.
  14. ## 
  15. ##  Redistribution and use in source and binary forms, with or without
  16. ##  modification, are permitted provided that the following conditions
  17. ##  are met:
  18. ## 
  19. ##  1. Redistributions of source code must retain the above copyright
  20. ##     notice, this list of conditions and the following disclaimer. 
  21. ## 
  22. ##  2. Redistributions in binary form must reproduce the above copyright
  23. ##     notice, this list of conditions and the following disclaimer in
  24. ##     the documentation and/or other materials provided with the
  25. ##     distribution.
  26. ## 
  27. ##  3. All advertising materials mentioning features or use of this
  28. ##     software must display the following acknowledgment:
  29. ##     "This product includes software developed by
  30. ##      Ralf S. Engelschall <rse@engelschall.com>."
  31. ## 
  32. ##  4. Redistributions of any form whatsoever must retain the following
  33. ##     acknowledgment:
  34. ##     "This product includes software developed by
  35. ##      Ralf S. Engelschall <rse@engelschall.com>."
  36. ## 
  37. ##  THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
  38. ##  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. ##  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40. ##  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL RALF S. ENGELSCHALL OR
  41. ##  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. ##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43. ##  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44. ##  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. ##  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  46. ##  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47. ##  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  48. ##  OF THE POSSIBILITY OF SUCH DAMAGE.
  49. ##  ====================================================================
  50. ##
  51. ##  This product includes software developed by the Apache Group
  52. ##  for use in the Apache HTTP server project (http://www.apache.org/)
  53. ##
  54.  
  55. ##
  56. ##  Usage: shtool <command> [<options>] [<args>]
  57. ##
  58. ##  Available commands:
  59. ##  echo         Print command with optional construct expansion
  60. ##  table        Pretty print a field-sperarated list as a table
  61. ##  prop         Display a process indication though a running propeller
  62. ##  move         Move files with simultan substitution and optimized movement
  63. ##  install      Install a program, script or datafile
  64. ##  mkdir        Make a directory
  65. ##  mkln         Extended ln(1) command which calculates relative links
  66. ##  mkshadow     Create a shadow tree
  67. ##  fixperm      Fix file permission inside a source tree
  68. ##  guessos      Simple OS/Platform guesser
  69. ##  arx          Archive (ar) wrapper command.
  70. ##  slo          Separate Linker Options by library class
  71. ##  version      Generate and maintain a version information file
  72. ##  path         Deal with $PATH variables
  73. ##
  74.  
  75. if [ $# -eq 0 ]; then
  76.     echo "$0:Error: Invalid command line" 1>&2
  77. fi
  78. if [ $# -eq 0 -o ".$1" = .-h ]; then
  79.     echo "$0:Usage: shtool <command> [<options>] [<args>]" 
  80.     echo ""
  81.     echo "Available commands are:"
  82.     echo ""
  83.     echo '  echo       [-n] [-e] <string> [<string> ...]'
  84.     echo '  table      [-F <sep>] [-w <width>] [-c <cols>] [-s <strip>]'
  85.     echo '             <str><sep><str><sep><str>...'
  86.     echo '  prop       [-p <prefix>]'
  87.     echo '  move       [-e] [-p] <src> <dst>'
  88.     echo '  install    [-c] [-m <mode>] [-o <owner>] [-g <group>]'
  89.     echo '             [-s] [-S <stripflags>] [-e <extension>] <file> <dir-or-file>'
  90.     echo '  mkdir      [-f] [-p] [-m <mode>] <dir> [<dir> ...]'
  91.     echo '  mkln       [-v] [-f] [-s] <src> [<src> ...] <dst>'
  92.     echo '  mkshadow   <srcdir> <dstdir>'
  93.     echo '  fixperm    <file-or-dir> [<file-or-dir> ...]'
  94.     echo '  guessos    '
  95.     echo '  arx        [-v] <ar-prg> <ar-cmd> <archive> <file> [<file>'
  96.     echo '             ...]'
  97.     echo '  slo        -Lxx -lxx [ -Lxx -lxx ... ]'
  98.     echo '  version    [-l <lang>] [-n <name>] [-p <prefix>] [-s'
  99.     echo '             <version>] [-i <knob>] [-d <type>] <file>'
  100.     echo '  path       [-s] [-r] [-d] [-b] [-m] [-p <path>] <string>'
  101.     echo '             [<string> ...]'
  102.     echo ""
  103.     exit 1
  104. fi
  105. if [ ".$1" = .-v ]; then
  106.     echo "shtool 1.2.3 (06-May-1999)"
  107.     exit 0
  108. fi
  109. util=$1
  110. shift
  111. case $util in
  112.  
  113. echo )
  114.     #
  115.     #   command line parsing
  116.     #
  117.     newline="\n"
  118.     expand=no
  119.     while [ ".$1" != . ]; do
  120.         case $1 in
  121.             -n ) newline=""; shift; continue ;;
  122.             -e ) expand=yes; shift; continue ;;
  123.             *  ) break ;;
  124.         esac
  125.     done
  126.     text="$*"
  127.     
  128.     #
  129.     #   check for broken escape sequence expansion
  130.     #
  131.     seo=''
  132.     bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
  133.     if [ ".$bytes" != .3 ]; then
  134.         bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
  135.         if [ ".$bytes" = .3 ]; then
  136.             seo='-E'
  137.         fi
  138.     fi
  139.     
  140.     #
  141.     #   determine terminal bold sequence
  142.     #
  143.     term_bold='' 
  144.     tern_norm=''
  145.     if [ $expand = yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then
  146.         case $TERM in
  147.             xterm|xterm*|vt220|vt220*)
  148.                 term_bold=`echo dummy | awk '{ printf("%c%c%c%c", 27, 91, 49, 109); }'`
  149.                 term_norm=`echo dummy | awk '{ printf("%c%c%c", 27, 91, 109); }'`
  150.                 ;;
  151.             vt100|vt100*)
  152.                 term_bold=`echo dummy | awk '{ printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }'`
  153.                 term_norm=`echo dummy | awk '{ printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }'`
  154.                 ;;
  155.         esac
  156.         if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
  157.             md="`tput md 2>/dev/null`"
  158.             me="`tput me 2>/dev/null`"
  159.             if [ ".$md" != . -a ".$me" != . ]; then
  160.                 term_bold="$xmd" 
  161.                 term_norm="$xme"
  162.             fi
  163.         fi
  164.         if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
  165.             echo "$0:Warning: unable to determine terminal sequence for bold mode" 1>&2
  166.         fi
  167.     fi
  168.     
  169.     #
  170.     #   determine user name
  171.     #
  172.     username=''
  173.     if [ $expand = yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then
  174.         username="$LOGNAME"
  175.         if [ ".$username" = . ]; then
  176.             username="$USER"
  177.             if [ ".$username" = . ]; then
  178.                 username="`(whoami) 2>/dev/null |\
  179.                            awk '{ printf("%s", $1); }'`"
  180.                 if [ ".$username" = . ]; then
  181.                     username="`(who am i) 2>/dev/null |\
  182.                                awk '{ printf("%s", $1); }'`"
  183.                     if [ ".$username" = . ]; then
  184.                         username='unknown'
  185.                     fi
  186.                 fi
  187.             fi
  188.         fi
  189.     fi
  190.     
  191.     #
  192.     #   determine user id
  193.     #
  194.     userid=''
  195.     if [ $expand = yes -a ".`echo $text | egrep '%U'`" != . ]; then
  196.         userid="`(id -u) 2>/dev/null`"
  197.         if [ ".$userid" = . ]; then
  198.             str="`(id) 2>/dev/null`"
  199.             if [ ".`echo $str | grep '^uid[     ]*=[     ]*[0-9]*('`" != . ]; then
  200.                 userid=`echo $str | sed -e 's/^uid[     ]*=[     ]*//' -e 's/(.*//'`
  201.             fi
  202.             if [ ".$userid" = . ]; then
  203.                 userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
  204.                         sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  205.                 if [ ".$userid" = . ]; then
  206.                     userid=`(ypcat passwd) 2>/dev/null |
  207.                             egrep "^${username}:" | \
  208.                             sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  209.                     if [ ".$userid" = . ]; then
  210.                         userid='?'
  211.                     fi
  212.                 fi
  213.             fi
  214.         fi
  215.     fi
  216.     
  217.     #
  218.     #   determine host name
  219.     #
  220.     hostname=''
  221.     if [ $expand = yes -a ".`echo $text | egrep '%h'`" != . ]; then
  222.         hostname="`(uname -n) 2>/dev/null |\
  223.                    awk '{ printf("%s", $1); }'`"
  224.         if [ ".$hostname" = . ]; then
  225.             hostname="`(hostname) 2>/dev/null |\
  226.                        awk '{ printf("%s", $1); }'`"
  227.             if [ ".$hostname" = . ]; then
  228.                 hostname='unknown'
  229.             fi
  230.         fi
  231.         case $hostname in
  232.             *.* )
  233.                 domainname=".`echo $hostname | cut -d. -f2-`"
  234.                 hostname="`echo $hostname | cut -d. -f1`"
  235.                 ;;
  236.         esac
  237.     fi
  238.     
  239.     #
  240.     #   determine domain name
  241.     #
  242.     domainname=''
  243.     if [ $expand = yes -a ".`echo $text | egrep '%d'`" != . ]; then
  244.         if [ ".$domainname" = . ]; then
  245.             if [ -f /etc/resolv.conf ]; then
  246.                 domainname="`egrep '^[     ]*domain' /etc/resolv.conf | head -1 |\
  247.                              sed -e 's/.*domain//' \
  248.                                  -e 's/^[     ]*//' -e 's/^ *//' -e 's/^    *//' \
  249.                                  -e 's/^\.//' -e 's/^/./' |\
  250.                              awk '{ printf("%s", $1); }'`"
  251.                 if [ ".$domainname" = . ]; then
  252.                     domainname="`egrep '^[     ]*search' /etc/resolv.conf | head -1 |\
  253.                                  sed -e 's/.*search//' \
  254.                                      -e 's/^[     ]*//' -e 's/^ *//' -e 's/^    *//' \
  255.                                      -e 's/ .*//' -e 's/    .*//' \
  256.                                      -e 's/^\.//' -e 's/^/./' |\
  257.                                  awk '{ printf("%s", $1); }'`"
  258.                 fi
  259.             fi
  260.         fi
  261.     fi
  262.     
  263.     #
  264.     #   determine current time
  265.     #
  266.     time_day=''
  267.     time_month=''
  268.     time_year=''
  269.     time_monthname=''
  270.     if [ $expand = yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then
  271.         time_day="`date '+%d' | awk '{ printf("%s", $1); }'`"
  272.         time_month="`date '+%m' | awk '{ printf("%s", $1); }'`"
  273.         time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
  274.         if test ".$time_year" = .; then
  275.             time_year="`date '+%y' | awk '{ printf("%s", $1); }'`"
  276.             case $time_year in
  277.                 9[0-9]*) time_year="19$time_year" ;;
  278.                       *) time_year="20$time_year" ;;
  279.             esac
  280.         fi
  281.         case $time_month in
  282.             1|01) time_monthname='Jan' ;;
  283.             2|02) time_monthname='Feb' ;;
  284.             3|03) time_monthname='Mar' ;;
  285.             4|04) time_monthname='Apr' ;;
  286.             5|05) time_monthname='May' ;;
  287.             6|06) time_monthname='Jun' ;;
  288.             7|07) time_monthname='Jul' ;;
  289.             8|08) time_monthname='Aug' ;;
  290.             9|09) time_monthname='Sep' ;;
  291.               10) time_monthname='Oct' ;;
  292.               11) time_monthname='Nov' ;;
  293.               12) time_monthname='Dec' ;;
  294.         esac
  295.     fi
  296.     
  297.     #
  298.     #   expand special ``%x'' constructs
  299.     #
  300.     if [ $expand = yes ]; then
  301.         text=`echo $seo "$text" |\
  302.               sed -e "s;%B;${term_bold};g" \
  303.                   -e "s;%b;${term_norm};g" \
  304.                   -e "s;%u;${username};g" \
  305.                   -e "s;%U;${userid};g" \
  306.                   -e "s;%h;${hostname};g" \
  307.                   -e "s;%d;${domainname};g" \
  308.                   -e "s;%D;${time_day};g" \
  309.                   -e "s;%M;${time_month};g" \
  310.                   -e "s;%Y;${time_year};g" \
  311.                   -e "s;%m;${time_monthname};g"`
  312.     fi
  313.     
  314.     #
  315.     #   create output
  316.     #
  317.     echo dummy |\
  318.     awk '{ printf("%s%s", TEXT, NEWLINE); }' \
  319.         TEXT="$text" NEWLINE="$newline"
  320. ;;
  321.  
  322. table )
  323.     #
  324.     #   command line parsing
  325.     #
  326.     width=15
  327.     cols=3
  328.     sep=':'
  329.     strip=79
  330.     while [ ".$1" != . ]; do
  331.         case $1 in
  332.             -F ) sep="$2";   shift; shift; continue ;;
  333.             -w ) width="$2"; shift; shift; continue ;;
  334.             -c ) cols="$2";  shift; shift; continue ;;
  335.             -s ) strip="$2";   shift; shift; continue ;;
  336.             *  ) break ;;
  337.         esac
  338.     done
  339.     case x$sep in
  340.         x? ) ;;
  341.         *  ) echo "$0:Error: Invalid seperator (one char allowed only)" 1>&2; exit 1 ;;
  342.     esac
  343.     if [ $cols -gt 4 ]; then
  344.         echo "$0:Error: Invalid number of colums (1..4 allowed only)" 1>&2
  345.         exit 1
  346.     fi
  347.     
  348.     #
  349.     #   split the list into a table
  350.     #
  351.     list=`
  352.         IFS="$sep"
  353.         for entry in $*; do
  354.             if [ ".$entry" != . ]; then
  355.                 echo "$entry"
  356.             fi
  357.         done |\
  358.         awk "
  359.             BEGIN { list = \"\"; n = 0; }
  360.             { 
  361.                 list = list \\$1;
  362.                 n = n + 1;
  363.                 if (n < $cols) {
  364.                     list = list \":\";
  365.                 }
  366.                 if (n == $cols) {
  367.                     list = list \"\\n\";
  368.                     n = 0;
  369.                 }
  370.             }
  371.             END { print list; }
  372.          "
  373.     `
  374.     
  375.     #
  376.     #   format table cells and make sure table 
  377.     #   doesn't exceed maximum width
  378.     #
  379.     IFS='
  380.     '
  381.     for entry in $list; do
  382.         case $cols in
  383.             1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s\\n\", \$1); }'" ;;
  384.             2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s\\n\", \$1, \$2); }'" ;;
  385.             3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s %-${width}s\\n\", \$1, \$2, \$3); }'" ;;
  386.             4 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s %-${width}s %-${width}s\\n\", \$1, \$2, \$3, \$4); }'" ;;
  387.         esac
  388.     done |\
  389.     awk "{ 
  390.         if (length(\$0) > $strip) { 
  391.             printf(\"%s\\n\", substr(\$0, 0, $strip-1));
  392.         } else { 
  393.             print \$0; 
  394.         }
  395.     }"
  396. ;;
  397.  
  398. prop )
  399.     #
  400.     #   command line parsing
  401.     #
  402.     prefix=""
  403.     while [ ".$1" != . ]; do
  404.         case $1 in
  405.             -p ) prefix="$2"; shift; shift; continue ;;
  406.             *  ) break ;;
  407.         esac
  408.     done
  409.     if [ $# -gt 0 ]; then
  410.         echo "$0:Error: too much arguments" 1>&2
  411.         exit 1
  412.     fi
  413.     
  414.     perl=''
  415.     for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
  416.         if [ -f "$dir/perl" ]; then
  417.             perl="$dir/perl"
  418.             break
  419.         fi
  420.     done
  421.     if [ ".$perl" != . ]; then
  422.         #   Perl is preferred because writing to STDERR in
  423.         #   Perl really writes immediately as one would expect
  424.         $perl -e '
  425.             @p = ("|","/","-","\\"); 
  426.             $i = 0; 
  427.             while (<STDIN>) { 
  428.                 printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]);
  429.                 $i = 0 if ($i > 3); 
  430.             }
  431.             printf(STDERR "\r%s    \n", $ARGV[0]);
  432.         ' "$prefix"
  433.     else
  434.         #   But when Perl doesn't exists we use Awk even
  435.         #   some Awk's buffer even the /dev/stderr writing :-(
  436.         awk '
  437.             BEGIN { 
  438.                 split("|#/#-#\\", p, "#");
  439.                 i = 1; 
  440.             } 
  441.             { 
  442.                 printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr"; 
  443.                 if (i > 4) { i = 1; } 
  444.             }
  445.             END {
  446.                 printf("\r%s    \n", prefix) > "/dev/stderr";
  447.             }
  448.         ' "prefix=$prefix" 
  449.     fi
  450. ;;
  451.  
  452. move )
  453.     #
  454.     #   command line parsing
  455.     #
  456.     expand=no
  457.     preserve=no
  458.     while [ ".$1" != . ]; do
  459.         case $1 in
  460.             -e ) expand=yes ; shift; continue ;;
  461.             -p ) preserve=yes ; shift; continue ;;
  462.             *  ) break ;;
  463.         esac
  464.     done
  465.     if [ $# -ne 2 ]; then
  466.         echo "$0:Usage: move [-e] [-p] <src> <dst>" 1>&2
  467.         exit 1
  468.     fi
  469.     src=$1
  470.     dst=$2
  471.     
  472.     #
  473.     #   consistency checks
  474.     #
  475.     if [ ".$src" = . -o ".$dst" = . ]; then
  476.         echo "$0:Error: Invalid arguments" 1>&2
  477.         exit 1
  478.     fi
  479.     if [ ".$src" = ".$dst" ]; then
  480.         echo "$0:Error: Source and destination files are the same" 1>&2
  481.         exit 1
  482.     fi
  483.     expsrc="$src"
  484.     if [ $expand = yes ]; then
  485.         expsrc="`echo $expsrc`"
  486.     fi
  487.     if [ $expand = yes ]; then
  488.         if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then
  489.             echo "$0:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2
  490.             exit 1
  491.         fi
  492.         if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then
  493.             echo "$0:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2
  494.             exit 1
  495.         fi
  496.         if [ ".$expsrc" = ".$src" ]; then
  497.             echo "$0:Error: Sources not found or no asterisk : $src" 1>&2
  498.             exit 1
  499.         fi
  500.     else
  501.         if [ ! -r "$src" ]; then
  502.             echo "$0:Error: Source not found: $src" 1>&2
  503.             exit 1
  504.         fi
  505.     fi
  506.     
  507.     #
  508.     #   determine substitution patterns
  509.     #
  510.     if [ $expand = yes ]; then
  511.         srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'`
  512.         dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'`
  513.     fi
  514.     
  515.     #
  516.     #   iterate over source(s)
  517.     #
  518.     for onesrc in $expsrc; do
  519.         if [ $expand = yes ]; then
  520.             onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"`
  521.         else
  522.             onedst="$dst"
  523.         fi
  524.         errorstatus=0
  525.         if [ -r $onedst ]; then
  526.             if cmp -s $onesrc $onedst; then
  527.                 rm -f $onesrc || errstatus=$?
  528.             else
  529.                 mv -f $onesrc $onedst || errstatus=$?
  530.             fi
  531.         else
  532.             mv -f $onesrc $onedst || errstatus=$?
  533.         fi
  534.         if [ $errorstatus -ne 0 ]; then
  535.             break;
  536.         fi
  537.     done
  538.     
  539.     #   die gracefully
  540.     exit $errorstatus
  541. ;;
  542.  
  543. install )
  544.     #
  545.     #   put in absolute paths if you don't have them in your path; 
  546.     #   or use env. vars.
  547.     #
  548.     mvprog="${MVPROG-mv}"
  549.     cpprog="${CPPROG-cp}"
  550.     chmodprog="${CHMODPROG-chmod}"
  551.     chownprog="${CHOWNPROG-chown}"
  552.     chgrpprog="${CHGRPPROG-chgrp}"
  553.     stripprog="${STRIPPROG-strip}"
  554.     rmprog="${RMPROG-rm}"
  555.     
  556.     #
  557.     #   parse argument line
  558.     #
  559.     instcmd="$mvprog"
  560.     chmodcmd=""
  561.     chowncmd=""
  562.     chgrpcmd=""
  563.     stripcmd=""
  564.     rmcmd="$rmprog -f"
  565.     mvcmd="$mvprog"
  566.     ext=""
  567.     src=""
  568.     dst=""
  569.     while [ ".$1" != . ]; do
  570.         case $1 in
  571.             -c) instcmd="$cpprog"
  572.                 shift; continue
  573.                 ;;
  574.             -m) chmodcmd="$chmodprog $2"
  575.                 shift; shift; continue
  576.                 ;;
  577.             -o) chowncmd="$chownprog $2"
  578.                 shift; shift; continue
  579.                 ;;
  580.             -g) chgrpcmd="$chgrpprog $2"
  581.                 shift; shift; continue
  582.                 ;;
  583.             -s) stripcmd="$stripprog"
  584.                 shift; continue;;
  585.             -S) stripcmd="$stripprog $2"
  586.                 shift; shift; continue ;;
  587.             -e) ext="$2"
  588.                 shift; shift; continue
  589.                 ;;
  590.             *)  if [ ".$src" = . ]; then
  591.                     src=$1
  592.                 else
  593.                     dst=$1
  594.                 fi
  595.                 shift; continue
  596.                 ;;
  597.         esac
  598.     done
  599.     if [ ".$src" = . ]; then
  600.          echo "install.sh: no input file specified"
  601.          exit 1
  602.     fi
  603.     if [ ".$dst" = . ]; then
  604.          echo "install.sh: no destination specified"
  605.          exit 1
  606.     fi
  607.     
  608.     #
  609.     #  If destination is a directory, append the input filename; if
  610.     #  your system does not like double slashes in filenames, you may
  611.     #  need to add some logic
  612.     #
  613.     if [ -d $dst ]; then
  614.         dst="$dst/`basename $src`"
  615.     fi
  616.     
  617.     #  Add a possible extension (such as ".exe") to src and dst
  618.     src="$src$ext"
  619.     dst="$dst$ext"
  620.     
  621.     #  Make a temp file name in the proper directory.
  622.     dstdir=`dirname $dst`
  623.     dsttmp=$dstdir/#inst.$$#
  624.     
  625.     #  Move or copy the file name to the temp name
  626.     $instcmd $src $dsttmp
  627.     
  628.     #  And set any options; do chmod last to preserve setuid bits
  629.     if [ ".$chowncmd" != . ]; then $chowncmd $dsttmp; fi
  630.     if [ ".$chgrpcmd" != . ]; then $chgrpcmd $dsttmp; fi
  631.     if [ ".$stripcmd" != . ]; then $stripcmd $dsttmp; fi
  632.     if [ ".$chmodcmd" != . ]; then $chmodcmd $dsttmp; fi
  633.     
  634.     #  Now rename the file to the real destination.
  635.     $rmcmd $dst
  636.     $mvcmd $dsttmp $dst
  637.     
  638.     exit 0
  639. ;;
  640.  
  641. mkdir )
  642.     #   command line parsing
  643.     mode=""
  644.     force=0
  645.     parent=0
  646.     while [ ".$1" != . ]; do
  647.         case $1 in
  648.             -f)  force=1;          shift; continue ;; 
  649.             -p)  parent=1;         shift; continue ;;
  650.             -m)  mode="$2"; shift; shift; continue ;;
  651.              *)  break ;;
  652.         esac
  653.     done
  654.     if [ $# -eq 0 ]; then
  655.         echo "$0:Usage: mkdir [-f] [-p] [-m <mode>] <dir> [<dir> ...]" 1>&2
  656.         exit 1
  657.     fi
  658.     
  659.     errstatus=0
  660.     for p in ${1+"$@"}; do 
  661.         #   when the directory already exists...
  662.         if [ -d "$p" ]; then
  663.             if [ $force = 0 ]; then
  664.                 echo "$0:Error: file exists: $p" 1>&2
  665.                 errstatus=1
  666.                 break
  667.             else
  668.                 continue
  669.             fi
  670.         fi
  671.         #   when the directory has to be created
  672.         if [ $parent = 0 ]; then
  673.             mkdir $p || errstatus=$?
  674.         else
  675.             #   the smart situation
  676.             set fnord `echo ":$p" |\
  677.                        sed -e 's/^:\//%/' \
  678.                            -e 's/^://' \
  679.                            -e 's/\// /g' \
  680.                            -e 's/^%/\//'`
  681.             shift
  682.             pathcomp=
  683.             for d in ${1+"$@"}; do
  684.                 pathcomp="$pathcomp$d"
  685.                 case "$pathcomp" in
  686.                     -* ) pathcomp="./$pathcomp" ;;
  687.                 esac
  688.                 if [ ! -d "$pathcomp" ]; then
  689.                     mkdir $pathcomp || errstatus=$?
  690.                     if [ ".$mode" != . ]; then
  691.                         chmod $mode $pathcomp || errstatus=$?
  692.                     fi
  693.                 fi
  694.                 pathcomp="$pathcomp/"
  695.             done
  696.         fi
  697.     done
  698.     exit $errstatus
  699. ;;
  700.  
  701. mkln )
  702.     #
  703.     #   command line parsing
  704.     #
  705.     verbose=no
  706.     force=no
  707.     symbolic=no
  708.     while [ ".$1" != . ]; do
  709.         case $1 in
  710.             -v)  verbose=yes; shift; continue ;; 
  711.             -f)  force=yes; shift; continue ;; 
  712.             -s)  symbolic=yes; shift; continue ;; 
  713.              *)  break ;;
  714.         esac
  715.     done
  716.     if [ $# -lt 2 ]; then
  717.         echo "$0:Usage: mkln [-v] [-f] [-s] <from> [<from> ...] <to>" 1>&2
  718.         exit 1
  719.     fi
  720.     args=$?
  721.     srcs=""
  722.     while [ $# -gt 1 ]; do
  723.         srcs="$srcs $1"
  724.         shift
  725.     done
  726.     dst="$1"
  727.     if [ ! -d $dst ]; then
  728.         if [ $args -gt 2 ]; then
  729.             echo "$0:Error: multiple sources not allowed when destination isn't a directory" 1>&2
  730.             exit 1
  731.         fi
  732.     fi
  733.     
  734.     #
  735.     #   determine link options
  736.     #
  737.     lnopt=""
  738.     if [ $force = yes ]; then
  739.         lnopt="$lnopt -f"
  740.     fi
  741.     if [ $symbolic = yes ]; then
  742.         lnopt="$lnopt -s"
  743.     fi
  744.     
  745.     #
  746.     #   iterate over sources
  747.     #
  748.     for src in $srcs; do
  749.         #   debugging
  750.         if [ $verbose = yes ]; then
  751.             echo "src=\"$src\" dst=\"$dst\":"
  752.         fi
  753.     
  754.         #   determine if one of the paths is an absolute path,
  755.         #   because then we _have_ to use an absolute symlink
  756.         oneisabs=0
  757.         srcisabs=0
  758.         dstisabs=0
  759.         case $src in
  760.             /* ) oneisabs=1; srcisabs=1 ;;
  761.         esac
  762.         case $dst in
  763.             /* ) oneisabs=1; dstisabs=1 ;;
  764.         esac
  765.     
  766.         #   split source and destination into dir and base name
  767.         if [ -d $src ]; then
  768.             srcdir=`echo $src | sed -e 's;/*$;;'`
  769.             srcbase=""
  770.         else
  771.             srcdir=`echo  $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  772.             srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`
  773.         fi
  774.         if [ -d $dst ]; then
  775.             dstdir=`echo $dst | sed -e 's;/*$;;'`
  776.             dstbase=""
  777.         else
  778.             dstdir=`echo  $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  779.             dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`
  780.         fi
  781.     
  782.         #   debugging
  783.         if [ $verbose = yes ]; then
  784.             echo "  STATE 1:"
  785.             echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
  786.             echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
  787.             echo "  oneisabs=$oneisabs"
  788.         fi
  789.     
  790.         #   consistency check
  791.         if [ ".$dstdir" != . ]; then
  792.             if [ ! -d $dstdir ]; then
  793.                 echo "$0:Error: destination directory not found: $dstdir" 1>&2
  794.                 exit 1
  795.             fi
  796.         fi
  797.     
  798.         #   make sure the source is reachable from the destination
  799.         if [ $dstisabs = 1 ]; then
  800.             if [ $srcisabs = 0 ]; then
  801.                 if [ -d $srcdir ]; then
  802.                     srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"
  803.                     srcisabs=1
  804.                     oneisabs=1
  805.                     #   debugging
  806.                     if [ $verbose = yes ]; then
  807.                         echo "  STATE 2:"
  808.                         echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
  809.                         echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
  810.                         echo "  oneisabs=$oneisabs"
  811.                     fi
  812.                 fi
  813.             fi
  814.         fi
  815.     
  816.         #   split away a common prefix
  817.         prefix=""
  818.         if [ ".$srcdir" = ".$dstdir" ] && [ ".$srcdir" != . ]; then
  819.             prefix="$srcdir/"
  820.             srcdir=""
  821.             dstdir=""
  822.         else
  823.             while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do
  824.                 presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  825.                 predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  826.                 if [ ".$presrc" != ".$predst" ]; then
  827.                     break
  828.                 fi
  829.                 prefix="$prefix$presrc/"
  830.                 srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`
  831.                 dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`
  832.             done
  833.         fi
  834.     
  835.         #   debugging
  836.         if [ $verbose = yes ]; then
  837.             echo "  STATE 3:"
  838.             echo "  prefix=$prefix"
  839.             echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
  840.             echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
  841.             echo "  oneisabs=$oneisabs"
  842.         fi
  843.     
  844.         #   destination prefix is just the common prefix
  845.         dstpre="$prefix"
  846.     
  847.         #   determine source prefix which is the reverse directory
  848.         #   step-up corresponding to the destination directory
  849.         srcpre=""
  850.         if [ $oneisabs = 0 ] || [ ".$prefix" != . -a ".$prefix" != ./ ]; then
  851.             pl="$dstdir/"
  852.             OIFS="$IFS"; IFS='/'
  853.             for pe in $pl; do
  854.                 [ ".$pe" = . ] && continue
  855.                 srcpre="../$srcpre"
  856.             done
  857.             IFS="$OIFS"
  858.         else
  859.             if [ $srcisabs = 1 ]; then
  860.                 srcpre="$prefix"
  861.             fi
  862.         fi
  863.     
  864.         #   debugging
  865.         if [ $verbose = yes ]; then
  866.             echo "  STATE 4:"
  867.             echo "  prefix=$prefix"
  868.             echo "  srcisabs=$srcisabs srcpre=\"$srcpre\" srcdir=\"$srcdir\" srcbase=\"$srcbase\""
  869.             echo "  dstisabs=$dstisabs dstpre=\"$dstpre\" dstdir=\"$dstdir\" dstbase=\"$dstbase\""
  870.             echo "  oneisabs=$oneisabs"
  871.         fi
  872.     
  873.         #   determine destination symlink name
  874.         if [ ".$dstbase" = . ]; then
  875.             if [ ".$srcbase" != . ]; then
  876.                 dstbase="$srcbase"
  877.             else
  878.                 dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`
  879.             fi
  880.         fi
  881.     
  882.         #   now finalize source and destination directory paths
  883.         srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
  884.         dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
  885.     
  886.         #   debugging
  887.         if [ $verbose = yes ]; then
  888.             echo "  STATE 5:"
  889.             echo "  prefix=$prefix"
  890.             echo "  srcisabs=$srcisabs srcpre=\"$srcpre\" srcdir=\"$srcdir\" srcbase=\"$srcbase\""
  891.             echo "  dstisabs=$dstisabs dstpre=\"$dstpre\" dstdir=\"$dstdir\" dstbase=\"$dstbase\""
  892.             echo "  oneisabs=$oneisabs"
  893.         fi
  894.     
  895.         #   run the final link command
  896.         if [ $verbose = yes ]; then
  897.             echo "  RESULT:"
  898.             echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
  899.         fi
  900.         eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
  901.     done
  902.     exit 0
  903. ;;
  904.  
  905. mkshadow )
  906.     #   default IFS
  907.     DIFS='     
  908.     '
  909.     
  910.     #   command line check
  911.     if [ $# -ne 2 ]; then
  912.         echo "$0:Error: Invalid aruments" 1>&2
  913.         exit 1
  914.     fi
  915.     
  916.     #   source and destination directory
  917.     src=`echo $1 | sed -e 's:/$::'`
  918.     dst=`echo $2 | sed -e 's:/$::'`
  919.     
  920.     #   check whether source exists
  921.     if [ ! -d $src ]; then
  922.         echo "$0:Error: source directory not found" 1>&2
  923.         exit 1
  924.     fi
  925.     
  926.     #   determine if one of the paths is an absolute path,
  927.     #   because then we have to use an absolute symlink
  928.     oneisabs=0
  929.     case $src in
  930.         /* ) oneisabs=1 ;;
  931.     esac
  932.     case $dst in
  933.         /* ) oneisabs=1 ;;
  934.     esac
  935.     
  936.     #   determine reverse directory for destination directory
  937.     dstrevdir=''
  938.     if [ $oneisabs = 0 ]; then
  939.         #   (inlined fp2rp)
  940.         OIFS="$IFS"; IFS='/'
  941.         for pe in $dst; do
  942.             dstrevdir="../$dstrevdir"
  943.         done
  944.         IFS="$OIFS"
  945.     else
  946.         src="`cd $src; pwd`";
  947.     fi
  948.     
  949.     #   create directory tree at destination
  950.     if [ ! -d $dst ]; then
  951.         mkdir $dst
  952.     fi
  953.     DIRS="`cd $src
  954.            find . -type d -print |\
  955.            sed -e '/\/CVS/d' \
  956.                -e '/^\.$/d' \
  957.                -e 's:^\./::'`"
  958.     OIFS="$IFS" IFS="$DIFS"
  959.     for dir in $DIRS; do
  960.         mkdir $dst/$dir
  961.     done
  962.     IFS="$OIFS"
  963.     
  964.     #   fill directory tree with symlinks to files
  965.     FILES="`cd $src
  966.             find . -depth -print |\
  967.             sed -e '/\.o$/d' \
  968.                 -e '/\.a$/d' \
  969.                 -e '/\.so$/d' \
  970.                 -e '/\.so-o$/d' \
  971.                 -e '/\.cvsignore$/d' \
  972.                 -e '/\/CVS/d' \
  973.                 -e '/\.indent\.pro$/d' \
  974.                 -e '/\.apaci.*/d' \
  975.                 -e '/Makefile$/d' \
  976.                 -e '/\/\.#/d' \
  977.                 -e '/\.orig$/d' \
  978.                 -e 's/^\.\///'`"
  979.     OIFS="$IFS" IFS="$DIFS"
  980.     for file in $FILES; do
  981.          #  don't use `-type f' above for find because of symlinks
  982.          if [ -d $file ]; then
  983.              continue
  984.          fi
  985.          basename=`echo $file | sed -e 's:^.*/::'`
  986.          dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
  987.          from="$src/$file"
  988.          to="$dst/$dir$basename"
  989.          if [ $oneisabs = 0 ]; then
  990.              if [ ".$dir" != . ]; then
  991.                  subdir=`echo $dir | sed -e 's:/$::'`
  992.                  #   (inlined fp2rp)
  993.                  revdir=''
  994.                  OIFS2="$IFS"; IFS='/'
  995.                  for pe in $subdir; do
  996.                      revdir="../$revdir"
  997.                  done
  998.                  IFS="$OIFS2"
  999.                  #   finalize from
  1000.                  from="$revdir$from"
  1001.              fi
  1002.              from="$dstrevdir$from"
  1003.          fi
  1004.          echo "    $to"
  1005.          ln -s $from $to
  1006.     done
  1007.     IFS="$OIFS"
  1008. ;;
  1009.  
  1010. fixperm )
  1011.     for p in $*; do
  1012.         for file in `find $p -depth -print`; do
  1013.             if [ -f $file ]; then
  1014.                 if [ -x $file ]; then
  1015.                     echo "    $file (FILE/EXEC)"
  1016.                     chmod 775 $file
  1017.                 else
  1018.                     echo "    $file (FILE/REGULAR)"
  1019.                     chmod 664 $file
  1020.                 fi
  1021.                 continue
  1022.             fi
  1023.             if [ -d $file ]; then
  1024.                 echo "    $file (DIR)"
  1025.                 chmod 775 $file
  1026.                 continue
  1027.             fi
  1028.             echo "    $file (UNKNOWN)"
  1029.         done
  1030.     done
  1031. ;;
  1032.  
  1033. guessos )
  1034.     MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
  1035.     RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
  1036.      SYSTEM=`(uname -s) 2>/dev/null` ||  SYSTEM="unknown"
  1037.     VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
  1038.     
  1039.     XREL=`(uname -X) 2>/dev/null | grep "^Release" | awk '{print $3}'`
  1040.     if [ "x$XREL" != "x" ]; then
  1041.         if [ -f /etc/kconfig ]; then
  1042.             case "$XREL" in
  1043.                 4.0|4.1) echo "${MACHINE}-whatever-isc4"; exit 0 ;;
  1044.             esac
  1045.         else
  1046.         case "$XREL" in
  1047.             3.2v4.2) 
  1048.                 echo "whatever-whatever-sco3"; exit 0 
  1049.                 ;;
  1050.             3.2v5.0*) 
  1051.                 echo "whatever-whatever-sco5"; exit 0 
  1052.                 ;;
  1053.             4.2MP)
  1054.                 if [ "x$VERSION" = "x2.1.1" ]; then
  1055.                     echo "${MACHINE}-whatever-unixware211"; exit 0
  1056.                 elif [ "x$VERSION" = "x2.1.2" ]; then
  1057.                     echo "${MACHINE}-whatever-unixware212"; exit 0
  1058.                 else
  1059.                     echo "${MACHINE}-whatever-unixware2"; exit 0
  1060.                 fi
  1061.                 ;;
  1062.             4.2) 
  1063.                 echo "whatever-whatever-unixware1"; exit 0 
  1064.                 ;;
  1065.             5)
  1066.                 case "$VERSION" in
  1067.                     7*) echo "${MACHINE}-whatever-unixware7"; exit 0 ;;
  1068.                 esac
  1069.                 ;;
  1070.         esac
  1071.         fi
  1072.     fi
  1073.     case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
  1074.         MiNT:*)
  1075.             echo "m68k-atari-mint"; exit 0
  1076.             ;;
  1077.         A/UX:*)
  1078.             echo "m68k-apple-aux3"; exit 0
  1079.             ;;
  1080.         AIX:*)
  1081.             echo "${MACHINE}-ibm-aix${VERSION}.${RELEASE}"; exit 0
  1082.             ;;
  1083.         dgux:*)
  1084.             echo "${MACHINE}-dg-dgux"; exit 0
  1085.             ;;
  1086.         HI-UX:*)
  1087.             echo "${MACHINE}-hi-hiux"; exit 0
  1088.             ;;
  1089.         HP-UX:*)
  1090.             HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
  1091.             echo "${MACHINE}-hp-hpux${HPUXVER}"; exit 0
  1092.             ;;
  1093.         IRIX:*)
  1094.             if [ -f /usr/lib32/mips4/libm.so ]; then
  1095.                 echo "${MACHINE}-sgi-irix32"; exit 0
  1096.             else
  1097.                 echo "${MACHINE}-sgi-irix"; exit 0
  1098.             fi
  1099.             ;;
  1100.         IRIX64:*)
  1101.             echo "${MACHINE}-sgi-irix64"; exit 0
  1102.             ;;
  1103.         Linux:[2-9].*)
  1104.             echo "${MACHINE}-whatever-linux2"; exit 0
  1105.             ;;
  1106.         Linux:1.*)
  1107.             echo "${MACHINE}-whatever-linux1"; exit 0
  1108.             ;;
  1109.         LynxOS:*)
  1110.             echo "${MACHINE}-lynx-lynxos"; exit 0
  1111.             ;;
  1112.         BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
  1113.             echo "i486-whatever-bsdi"; exit 0
  1114.             ;;
  1115.         BSD/386:*|BSD/OS:*)
  1116.             echo "${MACHINE}-whatever-bsdi"; exit 0
  1117.             ;;
  1118.         FreeBSD:*)
  1119.             VERS=`echo ${RELEASE} | sed -e 's/[-(].*//'`
  1120.             MACH=`sysctl -n hw.model`
  1121.             ARCH='whatever'
  1122.             case ${MACH} in
  1123.                *386*       ) MACH="i386"     ;;
  1124.                *486*       ) MACH="i486"     ;;
  1125.                Pentium\ II*) MACH="i686"     ;;
  1126.                Pentium*    ) MACH="i586"     ;;
  1127.                Alpha*      ) MACH="alpha"    ;;
  1128.                *           ) MACH="$MACHINE" ;;
  1129.             esac
  1130.             case ${MACH} in
  1131.                i[0-9]86 ) ARCH="pc" ;;
  1132.             esac
  1133.             echo "${MACH}-${ARCH}-freebsd${VERS}"; exit 0
  1134.             ;;
  1135.         NetBSD:*:*:*486*)
  1136.             echo "i486-whatever-netbsd"; exit 0
  1137.             ;;
  1138.         NetBSD:*)
  1139.             echo "${MACHINE}-whatever-netbsd"; exit 0
  1140.             ;;
  1141.         OpenBSD:*)
  1142.             echo "${MACHINE}-whatever-openbsd"; exit 0
  1143.             ;;
  1144.         OSF1:*:*:*alpha*)
  1145.             echo "${MACHINE}-dec-osf"; exit 0
  1146.             ;;
  1147.         QNX:*)
  1148.             if [ "$VERSION" -gt 422 ]; then
  1149.                 echo "${MACHINE}-qssl-qnx32"
  1150.             else
  1151.                 echo "${MACHINE}-qssl-qnx"
  1152.             fi
  1153.             exit 0
  1154.             ;;
  1155.         Paragon*:*:*:*)
  1156.             echo "i860-intel-osf1"; exit 0
  1157.             ;;
  1158.         SunOS:5.*)
  1159.             SOLVER=`echo ${RELEASE}|awk -F. '{
  1160.             if (NF < 3)
  1161.                 printf "2%s0\n",$2
  1162.             else
  1163.                 printf "2%s%s\n",$2,$3
  1164.             }'`
  1165.             echo "${MACHINE}-sun-solaris2.${SOLVER}"; exit 0
  1166.             ;;
  1167.         SunOS:*)
  1168.             echo "${MACHINE}-sun-sunos4"; exit 0
  1169.             ;;
  1170.         UNIX_System_V:4.*:*)
  1171.             echo "${MACHINE}-whatever-sysv4"; exit 0
  1172.             ;;
  1173.         unix:3.0.9*:*:88k)
  1174.             echo "${MACHINE}-encore-sysv4"; exit 0
  1175.             ;;
  1176.         *:4*:R4*:m88k)
  1177.             echo "${MACHINE}-whatever-sysv4"; exit 0
  1178.             ;;
  1179.         UnixWare:5:99*:*)
  1180.             # Gemini, beta release of next rev of unixware
  1181.             echo "${MACHINE}-whatever-unixware212"; exit 0
  1182.             ;;
  1183.         DYNIX/ptx:4*:*)
  1184.             echo "${MACHINE}-whatever-sysv4"; exit 0
  1185.             ;;
  1186.         *:4.0:3.0:[345][0-9]?? | *:4.0:3.0:3[34]??[/,]* | library:*)
  1187.             echo "x86-ncr-sysv4"; exit 0
  1188.             ;;
  1189.         ULTRIX:*)
  1190.             echo "${MACHINE}-unknown-ultrix"; exit 0
  1191.             ;;
  1192.         SINIX-?:* | ReliantUNIX-?:*)
  1193.             echo "${MACHINE}-siemens-sysv4"; exit 0
  1194.             ;;
  1195.         POSIX*BS2000)
  1196.             echo "${MACHINE}-siemens-sysv4"; exit 0
  1197.             ;;
  1198.         machten:*)
  1199.            echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
  1200.            ;;
  1201.         ConvexOS:*:11.*:*)
  1202.            echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
  1203.            ;;
  1204.         UNIX_SV:*:*:maxion)
  1205.            echo "${MACHINE}-ccur-sysv4"; exit 0;
  1206.            ;;
  1207.         PowerMAX_OS:*:*:Night_Hawk)
  1208.            MACHINE=`uname -p`
  1209.            echo "${MACHINE}-concurrent-powermax"; exit 0;
  1210.            ;;
  1211.         UNIX_SV:*)
  1212.            if [ -d /usr/nec ];then
  1213.                echo "mips-nec-sysv4"; exit 0;
  1214.            fi
  1215.            ;;
  1216.         NonStop-UX:4.[02]*:[BC]*:*)
  1217.            echo "${MACHINE}-tandem-sysv4"; exit 0;
  1218.            ;;
  1219.         Rhapsody:*:*:*)
  1220.            case "${MACHINE}" in
  1221.                Power*) MACHINE=powerpc ;;
  1222.            esac
  1223.            echo "${MACHINE}-apple-rhapsody${RELEASE}"; exit 0
  1224.            ;;
  1225.         "RISC iX":*)
  1226.            echo "arm-whatever-riscix"; exit 0;
  1227.            ;;
  1228.         *:4.0:2:*)
  1229.            echo "whatever-unisys-sysv4"; exit 0;
  1230.            ;;
  1231.         *:*:dcosx:NILE*)
  1232.            echo "pyramid-pyramid-svr4"; exit 0;
  1233.            ;;
  1234.         *:*:*:"DRS 6000")
  1235.            echo "drs6000-whatever-whatever"; exit 0;
  1236.            ;;
  1237.     esac
  1238.     # existance of the /usr/apollo directory is proof enough for Apollo
  1239.     if [ -d /usr/apollo ]; then
  1240.         echo "whatever-apollo-whatever"
  1241.         exit 0
  1242.     fi
  1243.     # Now NeXT
  1244.     ISNEXT=`hostinfo 2>/dev/null`
  1245.     case "$ISNEXT" in
  1246.         *NeXT*)
  1247.              # Swiped from a friendly uname clone for NEXT/OPEN Step.
  1248.              NEXTOSVER="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`"
  1249.              if [ "$NEXTOSVER" -gt 3.3 ]; then
  1250.                  NEXTOS="openstep"
  1251.              else
  1252.                  NEXTOS="nextstep"
  1253.              fi
  1254.              NEXTREL="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`" 
  1255.              NEXTARCH=`arch`
  1256.              echo "${NEXTARCH}-next-${NEXTOS}${NEXTREL}" ; exit 0
  1257.              ;;
  1258.     esac
  1259.     
  1260.     echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}"
  1261. ;;
  1262.  
  1263. arx )
  1264.     #
  1265.     #   command line parsing
  1266.     #
  1267.     verbose=no
  1268.     while [ ".$1" != . ]; do
  1269.         case $1 in
  1270.             -v)  verbose=yes; shift; continue ;; 
  1271.              *)  break ;;
  1272.         esac
  1273.     done
  1274.     if [ $# -le 4 ]; then
  1275.         echo "$0:Usage: arx [-v] <ar-prg> <ar-cmd> <archive> <file> [<file> ...]" 1>&2
  1276.         exit 1
  1277.     fi
  1278.     ar_prg=$1;  shift
  1279.     ar_cmd=$1;  shift
  1280.     archive=$1; shift
  1281.     files="$*"
  1282.     
  1283.     #
  1284.     #   walk through the file list and expand archives members
  1285.     #
  1286.     tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
  1287.     nfiles=""
  1288.     for file in $files; do
  1289.         if [ ! -f $file ]; then
  1290.             echo "$0:Error: input file not found: $file" 1>&2
  1291.             exit 1
  1292.         fi
  1293.         case $file in
  1294.             *.a ) 
  1295.                 if [ ! -d $tmpdir ]; then
  1296.                     if [ $verbose = yes ]; then
  1297.                         echo "mkdir $tmpdir"
  1298.                     fi
  1299.                     mkdir $tmpdir
  1300.                 fi
  1301.                 case $tmpdir in
  1302.                      .arx ) 
  1303.                          from="../$file"
  1304.                          ;;
  1305.                      * )
  1306.                          dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
  1307.                          base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
  1308.                          from="`cd $dir; pwd`/$base"
  1309.                          ;;
  1310.                 esac
  1311.                 if [ $verbose = yes ]; then
  1312.                     echo "(cd $tmpdir && $ar_prg x $from)"
  1313.                 fi
  1314.                 (cd $tmpdir && eval $ar_prg x $from)
  1315.                 if [ $? -ne 0 ]; then
  1316.                     echo "$0:Error: member extraction failed for archive: $file" 1>&2
  1317.                     exit 1
  1318.                 fi
  1319.                 for member in - `eval $ar_prg t $file`; do
  1320.                     [ ".$member" = .- ] && continue
  1321.                     nfiles="$nfiles $tmpdir/$member"
  1322.                 done
  1323.                 ;;
  1324.             * )
  1325.                 nfiles="$nfiles $file"
  1326.                 ;;
  1327.         esac
  1328.     done
  1329.     
  1330.     #
  1331.     #   run the final archive command
  1332.     #
  1333.     if [ $verbose = yes ]; then
  1334.         echo "$ar_prg $ar_cmd $archive $nfiles"
  1335.     fi
  1336.     eval $ar_prg $ar_cmd $archive $nfiles
  1337.     if [ $? -ne 0 ]; then
  1338.         echo "$0:Error: archive command failed" 1>&2
  1339.         exit $?
  1340.     fi
  1341.     
  1342.     #
  1343.     #   cleanup and die gracefully
  1344.     #
  1345.     if [ -d $tmpdir ]; then
  1346.         if [ $verbose = yes ]; then
  1347.             echo "rm -rf $tmpdir"
  1348.         fi
  1349.         rm -rf $tmpdir
  1350.     fi
  1351.     exit 0
  1352. ;;
  1353.  
  1354. slo )
  1355.     DIFS='     
  1356.     '
  1357.     
  1358.     #   
  1359.     #   parse out -L and -l options from command line
  1360.     #
  1361.     DIRS=''
  1362.     LIBS=''
  1363.     ARGV=''
  1364.     optprev=""
  1365.     OIFS="$IFS" IFS="$DIFS"
  1366.     for opt
  1367.     do
  1368.         #   concatenate with previous option if exists
  1369.         if [ ".$optprev" != . ]; then
  1370.             opt="${optprev}${opt}";
  1371.             optprev=''
  1372.         fi
  1373.         #   remember options for arg when used stand-alone
  1374.         if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then
  1375.             optprev="$opt"
  1376.             continue;
  1377.         fi
  1378.         #   split argument into option plus option argument
  1379.         arg="`echo $opt | cut -c3-`"
  1380.         opt="`echo $opt | cut -c1-2`"
  1381.         #   store into containers
  1382.         case $opt in
  1383.             -L) DIRS="$DIRS:$arg" ;;
  1384.             -l) LIBS="$LIBS:$arg" ;;
  1385.              *) ARGV="$ARGV $opt" ;;
  1386.         esac
  1387.     done
  1388.     IFS="$OIFS"
  1389.     
  1390.     #
  1391.     #   set linker default directories
  1392.     #
  1393.     DIRS_DEFAULT='/lib:/usr/lib'
  1394.     if [ ".$LD_LIBRARY_PATH" != . ]; then
  1395.         DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
  1396.     fi
  1397.     
  1398.     #
  1399.     #   sort options by class
  1400.     #
  1401.     DIRS_OBJ=''
  1402.     LIBS_OBJ=''
  1403.     DIRS_PIC=''
  1404.     LIBS_PIC=''
  1405.     DIRS_DSO=''
  1406.     LIBS_DSO=''
  1407.     
  1408.     #    for each library...
  1409.     OIFS="$IFS" IFS=':'
  1410.     for lib in $LIBS; do
  1411.         [ ".$lib" = . ] && continue
  1412.     
  1413.         found='no'
  1414.         found_indefdir='no'
  1415.         found_type=''
  1416.         found_dir=''
  1417.     
  1418.         #    for each directory...
  1419.         OIFS2="$IFS" IFS=":$DIFS"
  1420.         for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
  1421.             [ ".$dir" = . ] && continue
  1422.             [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
  1423.             [ ! -d $dir ] && continue
  1424.     
  1425.             #    search the file
  1426.             OIFS3="$IFS" IFS="$DIFS"
  1427.             for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do
  1428.                  [ ".$file" = . ] && continue
  1429.                  case $file in
  1430.                      *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
  1431.                           found=yes;
  1432.                           found_type=DSO; 
  1433.                           break 
  1434.                           ;;
  1435.                      *.lo|*.la )
  1436.                           found=yes;
  1437.                           found_type=PIC 
  1438.                           ;;
  1439.                      *.a )
  1440.                           if [ ".$found_type" = . ]; then
  1441.                               found=yes
  1442.                               found_type=OBJ 
  1443.                           fi
  1444.                           ;;
  1445.                  esac
  1446.             done
  1447.             IFS="$OIFS3"
  1448.             if [ ".$found" = .yes ]; then
  1449.                 found_dir="$dir"
  1450.                 break
  1451.             fi
  1452.         done
  1453.         IFS="$OIFS2"
  1454.     
  1455.         if [ ".$found" = .yes ]; then
  1456.             if [ ".$found_indefdir" != .yes ]; then
  1457.                 eval "dirlist=\"\${DIRS_${found_type}}:\""
  1458.                 if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then
  1459.                     eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\""
  1460.                 fi
  1461.                 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  1462.             else
  1463.                 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  1464.             fi
  1465.         else
  1466.             LIBS_OBJ="$LIBS_OBJ:$lib"
  1467.             #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
  1468.             #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
  1469.             #echo "slo:Warning: $dirlist" 1>&1
  1470.         fi
  1471.     done
  1472.     IFS="$OIFS"
  1473.     
  1474.     #
  1475.     #   also pass-through unused dirs even if it's useless
  1476.     #
  1477.     OIFS="$IFS" IFS=':'
  1478.     for dir in $DIRS; do
  1479.         dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
  1480.         if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then
  1481.             DIRS_OBJ="$DIRS_OBJ:$dir"
  1482.         fi
  1483.     done
  1484.     IFS="$OIFS"
  1485.     
  1486.     #
  1487.     #   reassemble the options but seperated by type
  1488.     #
  1489.     OIFS="$IFS" IFS="$DIFS"
  1490.     for type in OBJ PIC DSO; do
  1491.         OIFS2="$IFS" IFS=':'
  1492.         eval "libs=\"\$LIBS_${type}\""
  1493.         opts=''
  1494.         for lib in $libs; do
  1495.             [ ".$lib" = . ] && continue
  1496.             opts="$opts -l$lib"
  1497.         done
  1498.         eval "LIBS_${type}=\"$opts\""
  1499.     
  1500.         eval "dirs=\"\$DIRS_${type}\""
  1501.         opts=''
  1502.         for dir in $dirs; do
  1503.             [ ".$dir" = . ] && continue
  1504.             opts="$opts -L$dir"
  1505.         done
  1506.         eval "DIRS_${type}=\"$opts\""
  1507.         IFS="$OIFS2"
  1508.     done
  1509.     IFS="$OIFS"
  1510.     
  1511.     #
  1512.     #   give back results
  1513.     #
  1514.     OIFS="$IFS" IFS="$DIFS"
  1515.     for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
  1516.         eval "val=\"\$${var}\""
  1517.         val="`echo $val | sed -e 's/^ *//'`"
  1518.         echo "SLO_${var}=\"${val}\""
  1519.     done
  1520.     IFS="$OIFS"
  1521. ;;
  1522.  
  1523. version )
  1524.     LANGUAGE=txt
  1525.     NAME=unknown
  1526.     PREFIX=unknown
  1527.     FULLVERSION=unknown
  1528.     REPORT=NO
  1529.     INCREASE=P
  1530.     USAGE=NO
  1531.     FILE=""
  1532.     while [ ".$1" != . ]; do
  1533.         case $1 in
  1534.             -l) LANGUAGE=$2; shift; shift; continue ;;
  1535.             -n) NAME=$2; shift; shift; continue ;;
  1536.             -p) PREFIX=$2; shift; shift; continue ;;
  1537.             -s) FULLVERSION=$2; shift; shift; continue ;;
  1538.             -i) INCREASE=$2; shift; shift; continue ;;
  1539.             -d) REPORT=$2; shift; shift; continue ;;
  1540.             -h) USAGE=YES; shift; continue ;;
  1541.              *) break;
  1542.         esac
  1543.     done
  1544.     if [ $# -ne 1 ]; then
  1545.         USAGE=YES
  1546.     else
  1547.         FILE=$1
  1548.     fi
  1549.     
  1550.     if [ ".$USAGE" = .YES ]; then
  1551.         echo "$0:Usage: version [options] file"
  1552.         echo "Options are:"
  1553.         echo "-l <lang>                 set language to one of 'txt', 'c' or 'perl'" 
  1554.         echo "-n <name>                 set program name"
  1555.         echo "-p <prefix>               set symbol prefix"
  1556.         echo "-s <v>.<r>[.pb]<p>        set version string"
  1557.         echo "-i v|r|P|p|b|a|s          increase version, revision or {alpha,batch,patch,snap} level"
  1558.         echo "-d short|long|libtool|hex display current version only"
  1559.         echo "-h                        print this page"
  1560.         exit 0
  1561.     fi
  1562.     
  1563.     #   determine language
  1564.     if [ ".$LANGUAGE" = .unknown ]; then
  1565.         case $FILE in
  1566.             *.txt )       LANGUAGE=txt  ;;
  1567.             *.c )         LANGUAGE=c    ;;
  1568.             *.pl | *.pm ) LANGUAGE=perl ;;
  1569.             * )           echo "$0:Error: Unknown language type" 1>&2; exit 1 ;;
  1570.         esac
  1571.     fi
  1572.     
  1573.     #   determine prefix from name and vice versa
  1574.     if [ ".$PREFIX" = . -o ".$PREFIX" = .unknown ]; then
  1575.         if [ ".$NAME" != . -a ".$NAME" != .unknown ]; then
  1576.             PREFIX="$NAME"
  1577.         fi
  1578.     fi
  1579.     if [ ".$NAME" = . -o ".$NAME" = .unknown ]; then
  1580.         if [ ".$PREFIX" != . -a ".$PREFIX" != .unknown ]; then
  1581.             NAME="$PREFIX"
  1582.         fi
  1583.     fi
  1584.     
  1585.     #   determine version
  1586.     date=unknown
  1587.     if [ ".$FULLVERSION" = .unknown ]; then
  1588.         if [ -r "$FILE" ]; then
  1589.             #   grep out current information
  1590.             id=`grep 'Version [0-9]*.[0-9]*[.abps][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $FILE | \
  1591.                 head -1 | \
  1592.                 sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\1:\2:\3:\4:\5%'`
  1593.             version=`echo $id | awk -F: '{ print $1 }'`
  1594.             revision=`echo $id | awk -F: '{ print $2 }'`
  1595.             bptype=`echo $id | awk -F: '{ print $3 }'`
  1596.             bplevel=`echo $id | awk -F: '{ print $4 }'`
  1597.             date=`echo $id | awk -F: '{ print $5 }'`
  1598.             if [ .$REPORT = .NO ]; then
  1599.                 case $INCREASE in
  1600.                     b ) bplevel=`expr $bplevel + 1`
  1601.                         bptype=b
  1602.                         ;;
  1603.                     a ) bplevel=`expr $bplevel + 1`
  1604.                         bptype=a
  1605.                         ;;
  1606.                     s ) bplevel=`expr $bplevel + 1`
  1607.                         bptype=s
  1608.                         ;;
  1609.                     P ) bplevel=`expr $bplevel + 1`
  1610.                         bptype=.
  1611.                         ;;
  1612.                     p ) bplevel=`expr $bplevel + 1`
  1613.                         bptype=p
  1614.                         ;;
  1615.                     r ) revision=`expr $revision + 1`
  1616.                         bplevel=0
  1617.                         ;;
  1618.                     v ) version=`expr $version + 1`
  1619.                         revision=0
  1620.                         bplevel=0
  1621.                         ;;
  1622.                 esac
  1623.                 date=calc
  1624.             fi
  1625.             FULLVERSION="$version.$revision$bptype$bplevel"
  1626.         else
  1627.             #   intialise to first version
  1628.             version=0
  1629.             revision=5
  1630.             bptype=b
  1631.             bplevel=0
  1632.             date=calc
  1633.         fi
  1634.     else
  1635.         #   take given version
  1636.         V=`echo $FULLVERSION | sed -e 's%\([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\).*%\1:\2:\3:\4%'`
  1637.         version=`echo $V | awk -F: '{ print $1 }'`
  1638.         revision=`echo $V | awk -F: '{ print $2 }'`
  1639.         bptype=`echo $V | awk -F: '{ print $3 }'`
  1640.         bplevel=`echo $V | awk -F: '{ print $4 }'`
  1641.         date=calc
  1642.     fi
  1643.     
  1644.     #   determine hex value of version
  1645.     case $FULLVERSION in
  1646.         *.*a* )
  1647.             HEX=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
  1648.                  echo "$FULLVERSION" | sed -e 's/.*a//' | awk '{ printf("0%02d", $1); }'`
  1649.             ;;
  1650.         *.*b* )
  1651.             HEX=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
  1652.                  echo "$FULLVERSION" | sed -e 's/.*b//' | awk '{ printf("1%02d", $1); }'`
  1653.             ;;
  1654.         *.*.* )
  1655.             HEX=`echo "$FULLVERSION" | awk -F. '{ printf("%d%02d2%02d", $1, $2, $3); }'`
  1656.             ;;
  1657.     esac
  1658.     
  1659.     #   determine libtool version
  1660.     case $FULLVERSION in
  1661.         *.*a* )
  1662.             LTV=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
  1663.             ;;
  1664.         *.*b* )
  1665.             LTV=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
  1666.             ;;
  1667.         *.*.* )
  1668.             LTV=`echo "$FULLVERSION" | awk -F. '{ printf("%d:%d", $1*10+$2, $3); }'`
  1669.             ;;
  1670.     esac
  1671.     
  1672.     #   determine string out of filename
  1673.     FILESTR=`echo "$FILE" | tr 'abcdefghijklmnopqrstuvwxyz./%+-' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_____'`
  1674.     
  1675.     #   determine date
  1676.     if [ ".$date" = .calc ]; then
  1677.         day="`date '+%d' | awk '{ printf("%s", $1); }'`"
  1678.         month="`date '+%m' | awk '{ printf("%s", $1); }'`"
  1679.         year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
  1680.         if test ".$time_year" = .; then
  1681.             year="`date '+%y' | awk '{ printf("%s", $1); }'`"
  1682.             case $year in
  1683.                 9[0-9]*) year="19$year" ;;
  1684.                       *) year="20$year" ;;
  1685.             esac
  1686.         fi
  1687.         case $month in
  1688.             1|01) month='Jan' ;;
  1689.             2|02) month='Feb' ;;
  1690.             3|03) month='Mar' ;;
  1691.             4|04) month='Apr' ;;
  1692.             5|05) month='May' ;;
  1693.             6|06) month='Jun' ;;
  1694.             7|07) month='Jul' ;;
  1695.             8|08) month='Aug' ;;
  1696.             9|09) month='Sep' ;;
  1697.               10) month='Oct' ;;
  1698.               11) month='Nov' ;;
  1699.               12) month='Dec' ;;
  1700.         esac
  1701.         date="${day}-${month}-${year}"
  1702.     fi
  1703.     
  1704.     if [ .$REPORT != .NO ]; then
  1705.         case $REPORT in
  1706.             long )
  1707.                 echo "$version.$revision$bptype$bplevel ($date)"
  1708.                 ;;
  1709.             short )
  1710.                 echo "$version.$revision$bptype$bplevel"
  1711.                 ;;
  1712.             libtool )
  1713.                 echo "$LTV"
  1714.                 ;;
  1715.             hex )
  1716.                 echo "0x$HEX"
  1717.                 ;;
  1718.         esac
  1719.         exit 0
  1720.     fi
  1721.     
  1722.     #   create the version file according the the selected language  
  1723.     echo "new version: $version.$revision$bptype$bplevel ($date)"
  1724.     tmpfile="/tmp/version.tmp.$$"
  1725.     rm -f $tmpfile >/dev/null 2>&1
  1726.     case $LANGUAGE in
  1727.         txt )
  1728.             cat >$tmpfile <<'EOT'
  1729.     
  1730.   This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)
  1731. EOT
  1732.             ;;
  1733.         c )
  1734.             cat >$tmpfile <<'EOT'
  1735. /*
  1736. **  @FILE@ -- Version File (automatically generated and maintained by shtool)
  1737. */
  1738.  
  1739. #ifdef AS_HEADER
  1740.  
  1741. #ifndef @FILESTR@
  1742. #define @FILESTR@
  1743. #define @PREFIX@_VERSION 0x@HEX@
  1744. extern const int  @PREFIX@_Version;
  1745. extern const char @PREFIX@_VersionStr[];
  1746. extern const char @PREFIX@_Hello[];
  1747. extern const char @PREFIX@_GNUVersion[];
  1748. extern const char @PREFIX@_WhatID[];
  1749. extern const char @PREFIX@_RCSIdentID[];
  1750. extern const char @PREFIX@_WebID[];
  1751. extern const char @PREFIX@_PlainID[];
  1752. #endif
  1753.  
  1754. #else
  1755.  
  1756. const int  @PREFIX@_Version      = 0x@HEX@;
  1757. const char @PREFIX@_VersionStr[] = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1758. const char @PREFIX@_Hello[]      = "This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1759. const char @PREFIX@_GNUVersion[] = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1760. const char @PREFIX@_WhatID[]     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1761. const char @PREFIX@_RCSIdentID[] = "$Id: shtool,v 1.1 1999/12/22 05:04:11 fyodor Exp $";
  1762. const char @PREFIX@_WebID[]      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1763. const char @PREFIX@_PlainID[]    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1764.  
  1765. #endif
  1766. EOT
  1767.             ;;
  1768.         perl )
  1769.             cat >$tmpfile <<'EOT'
  1770. ##
  1771. ##  @FILE@ -- Version File (automatically generated and maintained by shtool)
  1772. ##
  1773.  
  1774. $@PREFIX@_Version    = 0x@HEX@;
  1775. $@PREFIX@_VersionStr = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1776. $@PREFIX@_Hello      = "This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1777. $@PREFIX@_GNUVersion = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1778. $@PREFIX@_WhatID     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
  1779. $@PREFIX@_RCSIdentID = "\$Id: shtool,v 1.1 1999/12/22 05:04:11 fyodor Exp $";
  1780. $@PREFIX@_WebID      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1781. $@PREFIX@_PlainID    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
  1782.  
  1783. 1;
  1784. EOT
  1785.             ;;
  1786.     esac
  1787.     
  1788.     #   now create the version file
  1789.     rm -f $FILE >/dev/null 2>&1
  1790.     sed \
  1791.         -e "s|@FILE@|$FILE|g" \
  1792.         -e "s|@FILESTR@|$FILESTR|g" \
  1793.         -e "s|@PREFIX@|$PREFIX|g" \
  1794.         -e "s|@NAME@|$NAME|g" \
  1795.         -e "s|@HEX@|$HEX|g" \
  1796.         -e "s|@VERSION@|$version|g" \
  1797.         -e "s|@REVISION@|$revision|g" \
  1798.         -e "s|@BPTYPE@|$bptype|g" \
  1799.         -e "s|@BPLEVEL@|$bplevel|g" \
  1800.         -e "s|@YEAR@|$year|g" \
  1801.         -e "s|@MONTH@|$month|g" \
  1802.         -e "s|@DAY@|$day|g" <$tmpfile >$FILE
  1803.     rm -f $tmpfile >/dev/null 2>&1
  1804.     exit 0
  1805. ;;
  1806.  
  1807. path )
  1808.     #
  1809.     #   parse argument line
  1810.     #
  1811.     silent=no
  1812.     reverse=no
  1813.     magic=no
  1814.     dirname=no
  1815.     basename=no
  1816.     pathlist="$PATH"
  1817.     namelist=""
  1818.     tmpfile="/tmp/path.tmp.$$"
  1819.     while [ ".$1" != . ]; do
  1820.         case $1 in
  1821.             -s ) silent=yes   ; shift; continue ;;
  1822.             -r ) reverse=yes  ; shift; continue ;;
  1823.             -d ) dirname=yes  ; shift; continue ;;
  1824.             -b ) basename=yes ; shift; continue ;;
  1825.             -m ) magic=yes    ; shift; continue ;;
  1826.             -p ) pathlist="$2"; shift; shift; continue ;;
  1827.             *  ) break ;;
  1828.         esac
  1829.     done
  1830.     if [ $# -eq 0 ]; then
  1831.         echo "$0:Usage: path [-s] [-r] [-d] [-b] [-p <path>] <string> [<string> ...]" 1>&2
  1832.         exit 1
  1833.     fi
  1834.     namelist="$*"
  1835.     
  1836.     #
  1837.     #   check whether the test command supports the -x option
  1838.     #
  1839.     cat >$tmpfile <<EOT
  1840. if [ -x / ] || [ -x /bin ] || [ -x /bin/ls ]; then
  1841.     exit 0
  1842. fi
  1843. exit 1
  1844. EOT
  1845.     if sh $tmpfile 2>/dev/null; then
  1846.         minusx="-x"
  1847.     else
  1848.         minusx="-r"
  1849.     fi
  1850.     rm -f $tmpfile
  1851.     
  1852.     #
  1853.     #   split path string
  1854.     #
  1855.     paths="`echo $pathlist |\
  1856.             sed -e 's/^:/.:/' \
  1857.                 -e 's/::/:.:/g' \
  1858.                 -e 's/:$/:./' \
  1859.                 -e 's/:/ /g'`"
  1860.     
  1861.     #
  1862.     #   SPECIAL REQUEST
  1863.     #   translate forward to reverse path
  1864.     #
  1865.     if [ $reverse = yes ]; then
  1866.         if [ "x$namelist" = "x." ]; then
  1867.             rp='.'
  1868.         else
  1869.             rp=''
  1870.             for pe in `IFS="$IFS/"; echo $namelist`; do
  1871.                 rp="../$rp"
  1872.             done
  1873.         fi
  1874.         echo $rp | sed -e 's:/$::'
  1875.         exit 0
  1876.     fi
  1877.     
  1878.     #
  1879.     #   SPECIAL REQUEST
  1880.     #   strip out directory or base name
  1881.     #
  1882.     if [ $dirname = yes ]; then
  1883.         echo "$namelist" |\
  1884.         sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
  1885.         exit 0
  1886.     fi
  1887.     if [ $basename = yes ]; then
  1888.         echo "$namelist" |\
  1889.         sed -e 's;.*/\([^/]*\)$;\1;'
  1890.         exit 0
  1891.     fi
  1892.     
  1893.     #
  1894.     #   MAGIC SITUATION
  1895.     #   Perl Interpreter (perl)
  1896.     #
  1897.     if [ ".$magic" = .yes ] && [ ".$namelist" = .perl ]; then
  1898.         rm -f $tmpfile
  1899.         touch $tmpfile
  1900.         c=0
  1901.         found=0
  1902.         for dir in $paths; do
  1903.             dir=`echo $dir | sed -e 's;/*$;;'`
  1904.             for perl in perl5 perl miniperl; do
  1905.                  if [ $minusx "$dir/$perl" ]; then
  1906.                      perl="$dir/$perl"
  1907.                      version=`$perl -v | grep version |\
  1908.                               sed -e 's/.* version //' -e 's/ built.*//' -e 's/ with.*//'`
  1909.                      versionnum="`echo $version | sed -e 's/\.//g' -e 's/_//g'`"
  1910.                      versionnum=`expr $versionnum - $c`
  1911.                      echo "$versionnum $perl" >>$tmpfile
  1912.                      found=1
  1913.                  fi
  1914.             done
  1915.             c=`expr $c + 1`
  1916.         done
  1917.         if [ $found = 1 ]; then
  1918.             perl="`cat $tmpfile | sort -u | tail -1 | cut '-d ' -f2`"
  1919.             rm -f $tmpfile
  1920.             echo "$perl"
  1921.             exit 0
  1922.         fi
  1923.         exit 1
  1924.     fi
  1925.     
  1926.     #
  1927.     #   MAGIC SITUATION
  1928.     #   C pre-processor (cpp)
  1929.     #
  1930.     if [ ".$magic" = .yes ] && [ ".$namelist" = .cpp ]; then
  1931.         cat >$tmpfile.c <<EOT
  1932. #include <assert.h>
  1933.     Syntax Error
  1934. EOT
  1935.         #   1. try the standard cc -E approach
  1936.         cpp="${CC-cc} -E"
  1937.         (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1938.         my_error=`grep -v '^ *+' $tmpfile.out`
  1939.         if [ ".$my_error" != . ]; then
  1940.             #   2. try the cc -E approach and GCC's -traditional-ccp option
  1941.             cpp="${CC-cc} -E -traditional-cpp"
  1942.             (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1943.             my_error=`grep -v '^ *+' $tmpfile.out`
  1944.             if [ ".$my_error" != . ]; then
  1945.                 #   3. try a standalone cpp command in path and lib dirs
  1946.                 for path in $paths /lib /usr/lib /usr/local/lib; do
  1947.                     path=`echo $path | sed -e 's;/*$;;'`
  1948.                     if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
  1949.                         cpp="$path/cpp"
  1950.                         break
  1951.                     fi
  1952.                 done
  1953.                 if [ ".$cpp" != . ]; then
  1954.                     (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1955.                     my_error=`grep -v '^ *+' $tmpfile.out`
  1956.                     if [ ".$my_error" != . ]; then
  1957.                         #   ok, we gave up...
  1958.                         cpp=''
  1959.                     fi
  1960.                 fi
  1961.             fi
  1962.         fi
  1963.         rm -f $tmpfile.c $tmpfile.out
  1964.         if [ ".$cpp" != . ]; then
  1965.             echo "$cpp"
  1966.             exit 0
  1967.         fi
  1968.         exit 1
  1969.     fi
  1970.     
  1971.     #
  1972.     #   STANDARD SITUATION
  1973.     #   iterate over names
  1974.     #
  1975.     for name in $namelist; do
  1976.         #   iterate over paths
  1977.         for path in $paths; do
  1978.             path=`echo $path | sed -e 's;/*$;;'`
  1979.             if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
  1980.                 if [ "$silent" != "yes" ]; then
  1981.                     echo "$path/$name"
  1982.                 fi
  1983.                 exit 0
  1984.             fi
  1985.         done
  1986.     done
  1987.     exit 1
  1988. ;;
  1989.  
  1990. * )
  1991.     echo "$0:Error: Unknown command" 2>&1
  1992.     echo "$0:Hint:  Run 'shtool.gen -h' for usage" 2>&1
  1993.     exit 1
  1994.     ;;
  1995. esac
  1996.  
  1997. ##EOF##
  1998.