home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / vidtype < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  3.3 KB  |  124 lines

  1. #!/bin/ksh
  2. # @(#) vidtype.ksh 1.0 93/04/01
  3. # 93/04/01 John H. DuBois III (john@armory.com)
  4. # vidtype: tell video adapter type.
  5.  
  6. name=${0##*/}
  7.  
  8. Usage="Usage: $name [-acht] [ttyname ...]"
  9.  
  10. typeset -i typeonly=0
  11.  
  12. alias istrue="test 0 -ne"
  13. alias isfalse="test 0 -eq"
  14.  
  15. set -A AdaptNames vga ega cga mono
  16. set -A TestFont font{8x16,8x14,8x8}
  17.  
  18. # Sets global Adapters[] to the types of adapters present
  19. function FindAdapters {
  20.     typeset Name
  21.     typeset -i i=0 j=0
  22.     while [ i -lt ${#AdaptNames[*]} ]; do
  23.     ( < /dev/${AdaptNames[i]} ) > /dev/null 2>&1 &&
  24.     Adapters[i]=${AdaptNames[i]}
  25.     let i+=1
  26.     done
  27.     [ ${#Adapters[*]} -gt 2 ] &&
  28.     echo "Invalid result: more than two adapters present?!"
  29. }
  30.  
  31. while getopts :acht opt; do
  32.     case $opt in
  33.     h) echo \
  34. "$name: tell video adapter type.
  35. $Usage
  36. For each ttyname given, a line is printed giving the tty name and the type of
  37. adapter the tty is associated with.
  38. If no tty name is given, the standard input is used.
  39. The adapter type will be one of mono, cga, ega, or vga, '-' if the
  40. tty is not associated with any of them, 'nontty' if the device name
  41. given is not a tty, or 'noopen' if the device could not be opened.
  42. If a mono adapter and a non-mono/cga/ega/vga adapter are both present,
  43. it is possible for ttys associated with the non-mono adapter to be
  44. reported as being associated with the mono adapter.
  45. Options:
  46. -a: print the adapter types present.
  47. -c: print the types for all of the console ttys (tty01..tty12).
  48. -h: print this help.
  49. -t: print only the adapter types, not the tty names."
  50.        exit 0;;
  51.      a)
  52.     FindAdapters
  53.     echo ${Adapters[*]}
  54.     exit 0
  55.     ;;
  56.      c)
  57.     ctty="tty0{1,2,3,4,5,6,7,8,9} tty1{0,1,2}"
  58.     ;;
  59.      t)
  60.     typeonly=1
  61.     ;;
  62. #    f) files="$files $OPTARG";;    # add arg to list of address files
  63.     +?) echo "$name: options should not be preceded by a '+'."; exit 1;;
  64.     :) 
  65.     print -r -u2 -- \
  66.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  67.     exit 1
  68.     ;;
  69.     ?) echo "$name: $OPTARG: bad option.  Use -h for help."; exit 1;;
  70.     esac
  71. done
  72.  
  73. # remove args that were options
  74. let OPTIND=OPTIND-1
  75. shift $OPTIND
  76.  
  77. set -- $ctty "$@"
  78.  
  79. [ $# -lt 1 ] && set -- `tty`
  80.  
  81. FindAdapters
  82. isfalse ${#Adapters[*]} && set -A Adapters ${AdaptNames[*]}
  83. typeset -i i
  84.  
  85. for tty; do
  86.     tty="/dev/${tty#/dev/}" 
  87.     isfalse typeonly && echo -n "${tty#/dev/} "
  88.     if [ ! -r "$tty" ]; then
  89.     echo noopen
  90.     continue
  91.     fi
  92.     if [ ! -t 0 ] < "$tty"; then
  93.     echo nontty
  94.     continue
  95.     fi
  96.     i=0
  97.     while [ i -lt ${#AdaptNames[*]} ]; do
  98.     if [ -n "${Adapters[i]}" ]; then
  99.         [ -z "${TestFont[i]}" ] && break
  100.         # vidi -d font   exits:
  101.         # nonzero on a color adapter if the named font is invalid
  102.         # nonzero if the standard input is not a known video adapter
  103.         # zero but emits all zeros if the input is a mono adapter
  104.         (vidi -d ${TestFont[i]} < "$tty" 2>/dev/null || echo "") |
  105.         tr | wc | read l w c
  106.         # c (number of non-null chars emitted by vidi) will be
  107.         # 0 if the input was a mono adapter
  108.         # 1 (the echoed newline) if vidi exits nonzero
  109.         # >1 if the font was valid
  110.         case $c in
  111.         0) ;;    # probably a mono adapter; continue
  112.         1)
  113.         # The font was invalid; this is not a known adapter
  114.         let i=${#AdaptNames[*]}+1
  115.         break ;;
  116.         *)    # Found adapter type
  117.         break ;;
  118.         esac
  119.     fi
  120.     let i+=1
  121.     done
  122.     [ -n "${AdaptNames[i]}" ] && echo ${AdaptNames[i]} || echo -
  123. done
  124.