home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / axeneoffice / live / linux-2.0 / xallwrite < prev    next >
Text File  |  1998-02-09  |  4KB  |  154 lines

  1. #!/bin/sh
  2. # XAllWrite
  3. # XAllWrite script
  4. # Copyright (c)1996. All Rights reserved Axene.
  5. # EMail: <xcalibur@axene.com>
  6. # Started on  Fri Nov 17 17:34:10 1995 Nucleus
  7. # Last update Sun Jan 18 19:25:34 1998 Xibios 2
  8. #
  9.  
  10. #--- Init global variables
  11. SkipLine() { echo " "; }
  12. Fatal() { echo "${progname}: error: ${1}" 1>&2 ; exit 1; }
  13.  
  14. progname=`basename $0`
  15. bin_list=
  16. name_base=XAllWrite
  17.  
  18. # ---------------------------------------------------------------------- # 
  19. # AskOneFromList - Let the user choose an item among a list              # 
  20. #                  <text> <default-index> <var > <choice-1>...<choice-n> #
  21. # ---------------------------------------------------------------------- #
  22. AskOneFromList()
  23. {
  24.   _ask_text=$1
  25.   _ask_default=$2
  26.   _ask_var=$3
  27.   shift 3
  28.   _arg_all=$@
  29.   _arg_num=$#
  30.  
  31.   while :; do
  32.     if [ "$force_flag" = "yes" ]; then
  33.       return $_ask_default
  34.     else
  35.       echo $_ask_text
  36.       _ask_count=0
  37.       while [ $_ask_count -lt $_arg_num ]; do
  38.         if [ $_ask_count -eq $_ask_default ]; then
  39.           _ask_reply="(DEFAULT)"
  40.         else
  41.           _ask_reply=
  42.         fi
  43.         _ask_count=`expr $_ask_count + 1`
  44.         eval "echo \"  \$_ask_count. \$1 $_ask_reply\""
  45.     shift 1
  46.       done
  47.       read _ask_reply
  48.       if [ -z "$_ask_reply" ]; then
  49.     _arg_cnt=0
  50.         for _ask_phrase in $_arg_all; do
  51.          if [ $_arg_cnt -eq $_ask_default ]; then
  52.           eval "$_ask_var=\"\$_ask_phrase\""
  53.           break
  54.         fi
  55.         _arg_cnt=`expr $_arg_cnt + 1`
  56.         done        
  57.     return $_ask_default
  58.       fi
  59.       if [ $_ask_reply -gt 0 -a $_ask_reply -le $_arg_num ]; then
  60.         SkipLine
  61.     _arg_cnt=1
  62.         for _ask_phrase in $_arg_all; do
  63.          if [ $_arg_cnt -eq $_ask_reply ]; then
  64.           eval "$_ask_var=\"\$_ask_phrase\""
  65.           break
  66.          fi
  67.          _arg_cnt=`expr $_arg_cnt + 1`
  68.         done
  69.         return `expr $_ask_reply - 1`
  70.       fi
  71.       echo "ERROR: You must enter a number between 1 and $_arg_num"
  72.       exit 1
  73.     fi
  74.   done
  75.  
  76. # ---------------------------------------------------------------------- # 
  77. # ---------------------------------------------------------------------- #
  78. TestInHostList()
  79. {
  80.  _Host=xibios.xibios.net
  81.  _HostsDB=$ZHOME/lib/locale/axene.hosts
  82.  
  83.  _count_exec=0
  84.  for _file in $ZHOME/bin/${name_base}*; do
  85.   if [ -x $_file ]; then
  86.    _count_exec=`expr $_count_exec + 1`
  87.   fi
  88.  done
  89.  
  90.  if [ "$_count_exec" -eq "0" ]; then
  91.    Fatal "No executable found in $ZHOME/bin/"
  92.  fi
  93.  
  94.  if [ "$_count_exec" -eq "1" ]; then
  95.   bin_list=$ZHOME/bin/${name_base}*
  96.  else
  97.   _No_Host=0
  98.   _Bin_ok=0
  99.   test -r $_HostsDB || _No_Host=1
  100.   if [ "$_No_Host" -eq "0" ]; then
  101.    exec 5<$_HostsDB
  102.    while read _v_host <&5 ; do
  103.      if [ "$_v_host" = "$_Host" ]; then
  104.       read bin_list <&5
  105.       bin_list=$ZHOME/bin/${name_base}.${bin_list}
  106.       _Bin_ok=1
  107.       while read _v_host <&5 ; do
  108.       echo flush > /dev/null
  109.       done
  110.      else
  111.       read _v_burk <&5
  112.       read _v_burk <&5
  113.      fi
  114.    done
  115.    exec 5<&-
  116.   else
  117.    echo "No $_HostsDB defined."
  118.    if [ -w $ZHOME/lib/locale/ ]; then
  119.     touch $_HostsDB
  120.    else
  121.     echo "Not authorized to write into directory $ZHOME/lib/locale/"
  122.    fi
  123.   fi
  124.      
  125.   if [ "$_Bin_ok" -eq "0" ]; then
  126.    AskOneFromList "Please select the program to execute on $_Host" 0 bin_list $ZHOME/bin/${name_base}*
  127.    if [ ! -w $_HostsDB ]; then
  128.     echo "Could not add this entry to $_HostsDB"
  129.    else
  130.     echo "host \`$_Host\' is now associated with program :"
  131.     echo "\`$bin_list\'."
  132.     echo "(if error, edit or delete $_HostsDB)" 
  133.     echo $_Host >> $_HostsDB
  134.     echo $bin_list | cut -d"." -f2- >> $_HostsDB
  135.     echo ----- >> $_HostsDB
  136.    fi
  137.   fi
  138.  fi
  139. }
  140.  
  141. ZHOME=`dirname $0`
  142. AXENE_LIB=$ZHOME/lib
  143. XALLWRITE_LIB=$ZHOME/lib
  144. XAPPLRESDIR=$ZHOME/app-defaults
  145. export AXENE_LIB XALLWRITE_LIB XAPPLRESDIR
  146.  
  147. TestInHostList
  148. exec $bin_list $@
  149.  
  150.