home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / mail / mh / vmail / vmailtool.Z / vmailtool / vmailicon < prev    next >
Encoding:
Text File  |  1991-04-05  |  1.2 KB  |  54 lines

  1. :
  2. # NAME
  3. #    vmailicon - set the icon for /dev/tty's window
  4. #
  5. # SYNOPSIS
  6. #    vmailicon iconfile
  7. #
  8. # DESCRIPTION
  9. #    This is the tool that vmailtool uses to raise or lower the icon
  10. #    flag.  This tool exists because the method used to set the icon
  11. #    (echoing a shelltool "terminal" command string to /dev/tty)
  12. #    sometimes blocks forever due to a race condition.  This tool can
  13. #    keep trying to set the icon until it finally succeeds, and it
  14. #    can do it in the background so vmailtool doesn't hang up.
  15. #
  16. # AUTHOR
  17. #    James Perkins 6 Feb 1991
  18.  
  19. case $# in
  20.     1) icon=$1;;
  21.     *) echo "usage: $0 iconfile" >&2; exit 1;;
  22. esac
  23.  
  24. if [ ! -f $icon ]
  25. then
  26.     echo "usage: $0 iconfile" >&2
  27.     exit 1
  28. fi
  29.  
  30. # run echo and then kill it.  If the echo is finished, the kill will return a
  31. # nonzero exit code.  If the kill succeeds, the echo wasn't finished, so
  32. # loop back and try again, ad nauseum.  Give up after maxtries tries.
  33.  
  34. export iconfile
  35. (
  36.     trynum=1
  37.     maxtries=5
  38.     status=0
  39.     while [ $status -eq 0 -a $trynum -le $maxtries ]
  40.     do
  41.     echo -n "]I${icon}\\" >/dev/tty &
  42.     echopid=$!
  43.     trynum=`expr $trynum + 1`
  44.     sleep 1
  45.     kill -9 $! > /dev/null 2>&1
  46.     status=$?
  47.     done
  48.  
  49.     if [ $trynum -gt $maxtries ]
  50.     then
  51.     echo "vmailicon: icon not set after $trynum tries" >&2
  52.     fi
  53. ) &
  54.