#!/bin/sh
#
# chk_prtr
#
# By: A.Corbera
#
# Purpose: Get Printer's Port and Software types from files:
#  1. /etc/printers (Port Types)
#  2. /usr/fox/sp/IIF.prm (Software Types) from System Cfg
#  3. /usr/fox/sp/files/PMlbug.CS (Comm files)
#  for debugging purposes.
#
cd /opt/ac
echo "\n=============== VALID COMBOS ==================="
echo "     (SysCfg)  (/etc/printers)"
echo "    (IIF.prm)"
echo "     (PxDEV)"
echo " LP   PortTyp SoftwType   Device Description"
echo "----- ------   -------  -----------------------------------------"
echo "LPxx    0x       0000    Dot-Matrix Printer 80 Color (on PC/AP10)"
echo "LPxx    0x       0001    Dot-Matrix Printer 80 Color (on COMM)"
echo "LPxx    02       0002    Dot-Matrix Printer 80 B/W (on PC/AP10)"
echo "LPxx    03       0003    Dot-Matrix Printer 80 B/W (on COMM)"
echo "LPxx    0x       0004    Dot-Matrix Printer 132 (P136CS) (on PC/AP10)"
echo "LPxx    05       0005    Dot-Matrix Printer 132 (P136CS) (on COMM)"
echo "LPxx    07       0007    600 LPM Line Printer (GeniCom)"
echo "LPxx    08       N/A     Kanji Dot-Matrix Printer 132"
echo "LPxx    02       0006    Color Ink_jet (PaintJet) Printer"
echo "LPxx    02       0006    PS PostScript Prtr (w/Comm10)"
echo "LPxx    09       0010    PS PostScript Prtr (Serial direct)"
echo "LPxx    10 (0a)  0010    PS PostScript Prtr (Parall direct)"
echo "LPxx    02 (0b)  0006    HP870Cxi Prtr (on COMM10, v4.1.1)"
echo "TTxx    04       0004    VT100 Terminal (Wyse)"
echo "TTxx    06       0006    Modem"
echo "\n======== COMMON FILE: /etc/printers ============"
echo " LP:  SoftwTyp:   Printer:"
sort /etc/printers
echo "\n==== COMBO INFO:  IIF.prm/.dat  /etc/printers ====="
#echo "Combined data from /etc/printers and IIF.prm/.dat :"
echo "Lpxx  Host/Port     PortTyp:      SoftwTyp:"
PRM="/usr/fox/sp/IIF.prm"
DAT="/usr/fox/sp/IIF.dat"
LPS=`sort /etc/printers | awk '{print $1}'`
for x in $LPS
do
 PRTR_SOFT=`grep $x /etc/printers | awk '{print $2}'`
 sta=`grep $x $PRM | egrep 'P1LN|P2LN|P3LN|P4LN' | awk '{print $2}'`
 port=`grep $x $PRM | egrep 'P1LN|P2LN|P3LN|P4LN' | awk '{print substr($4,1,2)}'`
 IIF_PORT=`awk '{print $2,$4,$6}' $PRM| grep $sta | grep $port | grep DEV | awk '{print $3}'`
 DAT_PORT=`awk '{print $2,$4,$6}' $DAT| grep $sta | grep $port | grep DEV | awk '{print $3}'`
 echo "$x: $sta/$port\tIIF.prm/dat=$IIF_PORT-$DAT_PORT\tetc/prtrs=$PRTR_SOFT"
done
#
COMMS=`awk ' $2 == "101" {print $1}' /usr/fox/sp/hldb`
echo "\n======== COMM CONNECTED PRINTERS ==============="
echo "Comm processors in /usr/fox/sp/hldb:  \c"
echo $COMMS
echo "Port TYPES from /usr/fox/sp/files/PMxxxxxx.CS:"
ls /usr/fox/sp/files/PM*.CS |grep .CS > /dev/null
if [ $? -eq 0 ]
then
   for x in $COMMS
   do
     if [ -f /usr/fox/sp/files/PM$x.CS ]
     then
        /usr/foxbin/bpatch -d /usr/fox/sp/files/PM$x.CS > z 2>/dev/null
        P1=`grep 00: z | awk '{print $4}'`
        P2=`grep 01: z | awk '{print $8}'`
        P3=`grep 02: z | awk '{print $12}'`
        P4=`grep 03: z | awk '{print $16}'`
        echo "$x: P1=$P1\tP2=$P2\tP3=$P3\tP4=$P4"
     fi
   done
else
   echo "This station does NOT host any COMM processors!"
fi
echo "\n========== DIRECT CONNECTED PRINTERS ==========="
if [ -f /usr/fox/sp/files/cs_cfg.pars ]
then
  echo " LP:    Device:         Port Type:"
  DIR="/usr/fox/sp/files/cs_cfg.pars"
  egrep 'NAME|TYPE' $DIR | sed -e 's/=/ = /'|sed -e 's/#/ # /'|awk '
    $1 == "LPNAME" {printf "%-0s\t",$3}
    $1 == "PTNAME" {printf "%-0s\t",$3}
    $1 == "LPTYPE" {printf "%-0s\n",$3}'
fi
echo "\n========== /etc/printscreen.options ============"
if [ -f /etc/printscreen.options ]
then
   cat /etc/printscreen.options | grep -v LPxx
else
   echo "File does NOT exist!"
fi
echo "================================================"
echo "Press 'c' to show printscreen files, 'q' to quit: (c/q)?"
read answer
if test $answer = "c"
then
ls -l /usr/fox/wp/bin/jettool
ls -l /usr/fox/wp/bin/r2grab
ls -l /usr/fox/wp/bin/foxwd
ls -l /usr/fox/wp/bin/foxpr
ls -l /usr/fox/wp/bin/xwd2ps
ls -l /usr/fox/exten/standard
ls -l /usr/fox/exten/pjet_graphics
ls -l /etc/printscreen.printers
ls -l /etc/printscreen.options
else
  exit 1
fi
