#! /bin/ksh # # Author: Mike Fleming mike@tauzero.co.uk # # Search in a file using COBOL search tool # 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 search program? # 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/fsrch$fn.int || -f $a/fsrch$fn.gnt ]] then cobrun fsrch$fn $* return fi done # If not, check a possible alternative location if [[ -f $FSRCHOBJ/fsrch$fn.int ]] then cobrun $FSRCHOBJ/fsrch$fn.int $* return fi echo "No search program available for $1" fi # Find available file searchers and put them into menu COBPROGS=$(echo $COBPATH | sed 's/:/\/fsrch*.int /g') COBPROGS=$COBPROGS/fsrch*.int if [[ $(echo $COBPROGS | cut -c5) == /fsrch ]] then COBPROGS=./$COBPROGS fi LIST=$(ls $COBPROGS $FSRCHOBJ/fsrch*.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 search programs found return 1 fi # Is the menu program available? if type menu >/dev/null 2>&1 then while true do menu "File search" "${names[@]}" ptr=$? if (( ptr > 127 || ptr < 1 )) then break fi ptr=$((ptr - 1)) cobrun fsrch${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 search,$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 fsrch${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