#!/etc/bin/sh
#
# Telnet menu child, dless-Xwin toolkit, (C) 1997 Roman Dolejsi - roman@sorry.vse.cz
#

CNT=1
OUT=$1
TMP1=`echo $1 | cut -f2 -d:`
if [ "$TMP1" != "$1" ]; then
  CNT=`echo $TMP1 | cut -f1 -d\ `
  OUT=`echo $1 | cut -f1 -d:`
  TMP2=`echo $TMP1 | cut -f2- -d\ ` 
  if [ "$TMP2" != "$TMP1" ]; then
    OUT="$OUT `echo $TMP1 | cut -f2- -d\ `"
  fi
fi
if [ -z "$OUT" ]; then
  OUT=$DEFAULT
fi
while [ -f "/tmp/.tty$CNT" -a "$CNT" -lt "$MAX_TTY" ]; do
  CNT=`expr $CNT + 1`
done
if [ "$CNT" = "$MAX_TTY" ]; then
  dialog --backtitle "$L_COPY" --title "Telnet" --msgbox "$L_TELERR" 5 46
else
  echo "$$ tel $OUT $2" > /tmp/.tty$CNT
  export CNT
  doprog /dev/tty$CNT runtel2 $OUT $2
  dialog --backtitle "$L_COPY" --title "Telnet" --msgbox "$L_TELRUN tty$CNT." 5 46
  if [ -f "/tmp/.tty$CNT" ]; then
    echo "0 tel $OUT $2" > /tmp/.tty$CNT
  fi
fi