#! /bin/ksh # # Author: Mike Fleming mike@tauzero.co.uk # # View a file using COBOL viewer # Possible alternative location for file viewer FVIEWOBJ=$OBJ # Get filename in upper and lower case if [[ $# > 0 ]] then FN=$(echo $1 | tr [a-z] [A-Z]) fn=$(echo $FN | tr [A-Z] [a-z]) shift 1 # Have we got a COBOL file viewer? # If we have one on COBPATH, it would probably be the best bet to # match the file definition for a in . $(echo $COBPATH | tr : ' ') do if [[ -f $a/fview$fn.int || -f $a/fview$fn.gnt ]] then cobrun fview$fn $* return fi done # If not, check a possible alternative location if [[ -f $FVIEWOBJ/fview$fn.int ]] then cobrun $FVIEWOBJ/fview$fn.int $* fi return fi # Find available file viewers and put them into menu COBPROGS=$(echo $COBPATH | sed 's/:/\/fview*.int /g') COBPROGS=$COBPROGS/fview*.int if [[ $(echo $COBPROGS | cut -c5) == /fview ]] then COBPROGS=./$COBPROGS fi LIST=$(ls $COBPROGS $FVIEWOBJ/fview*.int 2> /dev/null) SLIST=$(for a in $LIST;do echo $(basename $a .int) | cut -c6-;done | sort -u) set -A names $SLIST if [[ "${names[0]}" == "" ]] then echo No viewer programs found return 1 fi # Is the menu program available? if type menu >/dev/null 2>&1 then while true do menu "File viewers" "${names[@]}" ptr=$? if (( ptr > 127 || ptr < 1 )) then break fi ptr=$((ptr - 1)) cobrun fview${names[$ptr]} done return 0 fi PGLEN=25 # page = current page (starts at 0) # index = screen array pointer for display (starts at 0) # line = display line number (starts at 1) # ptr = pointer to file to display typeset -i page=0 typeset -i index typeset -i line typeset -i ptr while [[ "$REPLY" != "Q" && "$REPLY" != "q" ]] do lastline=$((PGLEN - 1)) line=1 index=$((page * lastline)) while [[ -n "${names[$index]}" && $line -le $lastline ]] do if (( line < 10 )) then lno=" "$line else lno=$line fi echo "$lno" ${names[$index]} index=$((index + 1)) line=$((line + 1)) done FURTHER="" if [[ -n "${names[$index]}" ]] then FURTHER=$FURTHER" [N]ext page," fi if (( page > 0 )) then FURTHER=$FURTHER" [P]revious," fi read REPLY?"No. of file to view,$FURTHER [Q]uit " if [[ "$REPLY" == "" ]] then REPLY="X" fi if (( $(echo $REPLY | grep -c "^[0-9]*$") > 0 )) then if (( REPLY > 0 && REPLY <= lastline )) then ptr=$(((page * lastline) + (REPLY - 1))) if [[ -n "${names[$ptr]}" ]] then cobrun fview${names[$ptr]} fi fi else case $REPLY in P | p) if (( page > 0 )) then page=$((page - 1)) fi;; N | n) if [[ -n "${names[$index]}" ]] then page=$((page + 1)) fi;; esac fi done