##!/bin/sh
# ************************************************************************* 
#    	Source Id:	 @(#)ctlib.make	1.1.1.1		07/24/98
# *************************************************************************
### Copyright (C) 1992-2000 by UniTrends Software Corporation
### All Rights Reserved
###
### Author: Steve W. Schwartz
###








set_ECHO() { 
	[ -d /usr/5bin ] && { PATH="/usr/5bin:${PATH}"; export PATH; }
  ECHO="echo -e"; 
  echo -e "hello" | grep "e h" >/dev/null && ECHO="echo"
  OS=`uname 2>/dev/null`
  case "$OS" in
      SunOS) [ -x /usr/5bin/echo ] && ECHO=/usr/5bin/echo ;;
  esac
  unset OS; export ECHO
}

[ -z "$ECHO" ] && set_ECHO
export ECHO

if [ -z "$BPDIR" ]; then
    if [ ! -d /usr/bp ]; then
		$ECHO "ERROR: Can't determine bin directory."
		$ECHO "       Try setting the \"BPDIR\" environment variable..."
		exit 1
	else
		BPDIR="/usr/bp"
    fi
fi

SAVE_COLORS="/tmp/ctcolr.$$"
GRAPH_INIT="$BPDIR/bin/graph_init"
HOMEBIN=$BPDIR/bin

LINE="==============================================================================="
NLINE="=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
## Screen Control Variables
LINES=`tput lines` || LINES=25
CLEAR=`tput clear 2>/dev/null` ||  
	CLEAR="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
BON=`tput bold 2>/dev/null`
BOFF=`tput rmso 2>/dev/null`
REV=`tput rev 2>/dev/null || tput smso 2>/dev/null`
BLK=`tput blink 2>/dev/null`
if [ "$LINES" = 25 ] 
then
	L25="\n"   
	BOTTOM="`tput cup 24 0 2>/dev/null`" || BOTTOM="\n\n"
else
	L25=""
	BOTTOM="`tput cup 23 0 2>/dev/null || $ECHO \"\n\"`"
fi
# If your screen does not completely become the background
# then make sure this is set to NO
# NOTE: You can turn of all color by setting DO_COLOR=NO
# DO_COLOR=NO; export DO_COLOR
: ${CAN_SET_BACKGROUND:=NO}
case "$TERM" in
	AT386*|ansi|1) CAN_SET_BACKGROUND=YES;;
	*term*) CAN_SET_BACKGROUND=NO;;
esac
export CAN_SET_BACKGROUND

if [ "$CAN_SET_BACKGROUND" = YES ]
then
	if [ -x /bin/setcolor -o -x /usr/bin/setcolor ]
	then
		BKG=`setcolor white blue 2>/dev/null`
	fi
fi
ROFF="${BOFF}${BKG}"

########################################################################
##
##    GRAPHICS INIT
##
########################################################################

graphics_init(){
: ${GRAPHICS_INIT:=NO}
if [ "$GRAPHICS_INIT" = NO ]
then
	GRAPHICS_INIT=YES; export GRAPHICS_INIT
 	## Defaults in case below routines failed to set values
	unset l v lu ll lt ru  rl rt
	: ${l:="="} ${v:="|"} ${lu:="*"} ${ll:="*"} ${lt:="|"} ${ru:="*"}
	: ${rl:="*"} ${rt:="|"} 

	if [ -x $HOMEBIN/graph_init ]
	then
		eval `$HOMEBIN/graph_init -a`   # Set graphics lines/corner chars: 
	fi
	## LINES,CLEAR,BOTTOM,ROFF,BLK,REV,BON,DIM
	## l,v,lu,ll,lt,ru,rl,rt
        ## ASC,S,E, HAS_COLORS=YES/NO
	## and save our initial colors
	v1="$S$v$E"                     # Vertical line - no background color
	## Screen Control Variables
	L25=""
	if [ "$LINES" != 25 ]; then
		L25="\n"                    # Used for spacing top of menus
	fi
	[ -z "$CLEAR" ] && 
		CLEAR="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"


	[ -n "$DISPLAY" ] && unset TERMCAP __n_elements
	export l v lu ll lt ru rl rt ACS S E ENACS     # Line drawing characters
	export LINES CLEAR BON ROFF REV BLK BOTTOM DIM # Positioning variables
	export BOFF L25                                # Generated from above


if [ "$DO_COLOR" != NO   -a "$HAS_COLORS" = YES ]
then
    ## 0      1      2     3     4    5        6      7     8
    ##black, blue, green, cyan, red,magenta, brown, white, gray
    ##  9           10        11      12       13        14      15
    ## lt. blue, lt.green, lt.cyan, lt.red,lt.magenta, yellow, hi white 
    if [ "$ANSI_COLORS" = YES ]
    then

    CURS="[=11;13C"          # Cursor to small line
    LT='[=14F'               # Highlight color for letter selections (yellow)
    WARN='[=14F[=4G'       # Warning messages (yellow on red)
    BLACKWHITE="[=7F[=0G"  # White fore/on black background
    export CONNECT_COLOR BLACKWHITE

    case "${COLOR_SET:=3}" in
    1)  # Traditional color set - {violets,cyan,blue} on black
    BG=0                       #  Black background
    SEL="[=3F[=${BG}G"     # Selection Color 1 (cyan on black)
    SE2="[=13F[=${BG}G"    # Selection Color 2 (lt_magenta on black)
    NL_FB="[=7F[=${BG}G"   # Normal fore/background (white on black)
    RV_FB='[=7H[=5I'       # Rev video fore/background (white on magenta)
    ##RV_FB='[=14H[=5I'     # Rev video fore/background (yellow on magenta)
    GR_FB='[=7J[=1K'       # Graphics fore/background (white on black)
    ##GR_FB='[=11J[=8K'     # Graphics fore/background (ltcyan on gray)
    GRPH_BG=                   # Graphic background - we are not using this
    GR_NL='[=7J[=0K'       # Graphics normal mode     (white on black)
    CONNECT_COLOR="[=7F[=1G"   # White fore/on blue background
    ;;
    #############################
    2) # COLOR_SET=2 blue letters on white background
    BG=7                       # white background 
    [ -n "$DISPLAY" ] && BG=8  # If xterm ==> must use gray background
    SEL="[=15F[=${BG}G"    # Selection Color 1 (hiwhite)
    SE2="[=4F[=${BG}G"     # Selection Color 2 (red)
    NL_FB="[=1F[=${BG}G"   # Normal fore/background (white on background)
    RV_FB='[=13H[=1I'      # Rev video fore/background (lt_magenta on blue)
    GR_FB="[=9J[=1K"       # Graphics fore/background (ltblue on blue)
    [ -n "$DISPLAY" ] && {     # Better contrast for xterm
      ##GR_FB="[=15J[=3K"    # Graphics fore/background (hiwhite on cyan)
      LT='[=6F'              # Highlight color for letter selections (brown)
	}
    GRPH_BG='[=9F[=1G'     # Graphic background - (lt_blue on blue)       
    GR_NL="[=1J[=${BG}K"   # Graphics normal mode (blue on background)
    CONNECT_COLOR="[=7F[=1G"   # White fore/on blue background
    ;;
    3) # COLOR_SET=3 Conservative white on blue
    BG=1                       # blue background 
    SEL="[=15F[=${BG}G"    # Selection Color 1 (hiwhite)
    SE2="[=13F[=${BG}G"    # Selection Color 2 (lt_magenta)
    NL_FB="[=7F[=${BG}G"   # Normal fore/background (white on background)
    RV_FB='[=1H[=7I'       # Rev video fore/background (blue on white)
    GR_FB="[=3J[=9K"       # Graphics fore/background (cyan on lt_blue)
    GRPH_BG='[=9F[=1G'     # Graphic background - (lt_blue on blue)       
    GR_NL='[=7J[=1K'       # Graphics normal mode     (white on black)
    CONNECT_COLOR="[=14F[=9G"   # Yellow on lt blue background
		BLKOFF='\033[=0E'          # SCO Ansi Blink Off -need for these colors
    [ -n "$DISPLAY" ] && {     # Better contrast for xterm
      GR_FB="[=0J[=8K"     # Graphics fore/background (black on gray )
      NL_FB="[=8F[=${BG}G" # Normal fore/background (gray on background)
      SE2="[=4F[=${BG}G"   # Selection Color 2 (red)
      CONNECT_COLOR="[=4F[=8G"   # Red on gray
		}
    ;;
    #############################
    esac

    $HOMEBIN/graph_init -s /tmp/svcolr_$$ # Save our original color scheme
    fi
		if [ "$CAN_SET_BACKGROUND" = YES ]
		then
			INIT_COLORS="${NL_FB}${RV_FB}${GR_FB}${CURS}${BLKOFF}"  
			${ECHO} "${INIT_COLORS}\c"            # Set our color scheme now
			BASE="$NL_FB"; B="$BASE"              # Set our BASE and B variables
			ROFF="${BOFF}${BASE}"                 # Turn REV video off

			export NL_FB RV_FB GR_FB BASE B GR_NL # Base NL/REV/GRAPH strings
			export INIT_COLORS BLKOFF
		else
			unset NL_FB RV_FB GR_FB GR_NL # Base NL/REV/GRAPH strings
			INIT_COLORS="${CURS}${BLKOFF}"  
			${ECHO} "${INIT_COLORS}\c"            # Set our color scheme now
			BASE="$BOFF"; B="$BASE"               # Set our BASE and B variables
			ROFF="${BOFF}"                        # Turn REV video off
			export BASE B L CURS INIT_COLORS BLKOFF
		fi
	fi
	if [ -z "$SEL" ] #If still not set, lets spiff it up a bit
	then
    unset NL_FB RV_FB GR_FB BASE B GR_NL 
		LT="$BON"
		[ -z "$BON" -a -n "$DIM" ] && LT="$DIM" # The best we can do
		WARN="$REV"; SE2="$DIM"; SEL="$LT"; B="$BOFF"; BASE="$B"
		ROFF="${BOFF}"                       
	fi
	export SEL SE2 LT WARN GRPH_BG B BASE NL_FB      # Color strings
	ROFF="${BOFF}${BASE}"                  # Turn REV video off
	v="$S$GRPH_BG$v$E${BASE}"              # Vertical line - color background
	## If graph_init sets colors, some versions don't set BASE
	[ -z "$BASE" ] && { BASE="$NL_FB"; B="$BASE"; export BASE B; }

	[ -n "$ENACS" ] && ${ECHO} "${ENACS}\c"   # Enable ACS if needed

	l10="$l$l$l$l$l$l$l$l$l$l"
	l20="$l10$l10"
	l30="$l20$l10"
	l40="$l20$l20"
	## "nice line" - used for separating list items or first 10 lines of a file
	NLINE="$GR_NL$S$l40$l30$l$l$l$l$l$l$l$l$E$GR_FB"

	## Menu line  - upper bar
	MLINE_U="            $S$GRPH_BG$lu$l40$l$l$l$l$ru$E$BASE"
	## Menu line - lower bar
	MLINE_L="            $S$GRPH_BG$ll$l40$l$l$l$l$rl$E$BASE"
	## Long Menu line - upper bar
	LMLINE_U="        $S$GRPH_BG$lu$l40$l20$l$l$l$ru$E$BASE"
	## Lone Menu line - lower bar
	LMLINE_L="        $S$GRPH_BG$ll$l40$l20$l$l$l$rl$E$BASE"
	export NLINE MLINE_U MLINE_L LMLINE_U LMLINE_L
fi

}

########################################################################
##
##    GRAPHICS END
##
########################################################################
graph_stop() {
if [ "$DO_COLOR" != NO  -a -s $SAVE_COLORS ]
then
	setcolor white black 2>/dev/null
	$GRAPH_INIT -r $SAVE_COLORS
fi
clear
USE_REAL_RM="YES"
export USE_REAL_RM
rm -f $SAVE_COLORS
unset USE_REAL_RM
}

notinuse(){
$ECHO "\nNot in use at this time!!"
}

########################################################################
##
##    PROMPT to continue
##
########################################################################
pressret() {
##WARN, protect ECHO from cpp
stty -"echo"
$ECHO "${BOTTOM}${REV}Press <RETURN> to continue ${ROFF}\c"
read rtn
stty "echo"
$ECHO "${BOTTOM}                                                        \r\c"
}
pressretm() {
stty -"echo"
$ECHO "${BOTTOM}${REV}READ the above and when ready, press <RETURN> for more ${ROFF}\c"
read rtn
stty "echo"
$ECHO "${BOTTOM}                                                         \r\c"
}
pressretq(){
$ECHO "\n\nStrike <${LT}RETURN${BASE}> to continue:
      or strike '${LT}q${BASE}' to QUIT: \c"
read rtn
[ ${rtn:=x} = q -o $rtn = Q ]  && return 1
return 0
}

########################################################################
##
##    PROMPT FOR
##
########################################################################
promptfor()  # Usage: promptfor VARNAME Phrase
## if fails, will leave VARNAME at previous value, thus default remains
{
VARNAME=$1
PROMPT=$2
eval DEF="\$$VARNAME"

$ECHO "\n${SEL}[Default: ${LT}${DEF}${SEL} ]\n${PROMPT}\nEnter:${BASE} \c"
$ECHO "${BASE}\c"
read ans
[ -z "$ans" ]  &&  return 0  # Still success, just take the default
eval "$VARNAME=\"$ans\""
return 0
}

prompt_num() { # Usage promptnum VARNAME Phrase
## Will get a number between 0-99 (${MIN_NUM:=0} ${MAX_NUM:=99})
DEF=$1
PROMPT=$2
eval _N="\$$DEF"
export BASE
while :
do
	_NSAVE=$_N
	$ECHO "\n${SEL}[Default: ${LT}${_N}${SEL} ]\n${PROMPT}\nEnter:${BASE} \c"
	$ECHO "${BASE}\c"
	read ans junk;
	[ -n "$ans" ]  && _N=$ans
	: ${MIN_NUM:=0} ${MAX_NUM:=99} 
	case "$_N" in
	q|Q) unset _N _PHRASE _NSAVE MAX_NUM MIN_NUM; return 1;;
	[0-9]*) # this way since below prints returns true if _N non numeric - ksh 
	if [ "$_N" -ge $MIN_NUM -a "$_N" -le $MAX_NUM ] 
	then
		break
	else
		$ECHO "\n${WARN}\"$_N\" is not a number between ${MIN_NUM} and ${MAX_NUM:=99}!!${BASE}\nPlease try again."
		_N=$_NSAVE;
	fi
	;;
	*) $ECHO "\n${WARN}\"$_N\" is not a number!!${BASE}\nPlease try again."
		_N=$_NSAVE;;
   esac
   sleep 2;
done
eval "$DEF=\"$_N\""
unset _N _PHRASE _NSAVE MAX_NUM MIN_NUM
return 0

}

########################################################################
##
##    PROMPT with y/n
##
########################################################################
prompt(){ # Usage: prompt y/n QUESTION
## QUESTION will default to no answer
## Success is a 'y' answer
DEF=no
[ "$1" = y ] && DEF=yes
$ECHO "\n${SEL}[Default: ${LT}$DEF${SEL} ]\n${2:-bad_prompt_string} (${LT}y/n${SEL})${BASE}: \c"
getans $1 && return 0
return 1
}

getans() # Usage: getans (y or n)
{ DEF=${1:-n};
read ans
[  ${ans:=$DEF} = y -o $ans = yes -o $ans = Y ] && return 0
return 1
}
is_correct(){
prompt y "Is this correct?" && return 0
return 1
}
clear() { $ECHO "${CLEAR}\c" ; return 0 ; }

show_list() # Usage: show_list "Name of List"  elem1 elem2 elem3 elem4 ...
{
	LISTNAME=$1
	shift
	LIST="$*"
## Return if  passed NULL list
	[ -z "$LIST" ] && return 1
	set $LIST >/dev/null
	$ECHO "\nCurrent $LISTNAME List is:\n${LINE}"
	if [ $# -le  20 ]
	then
		$ECHO "${LIST}\c"|tr ' ' '\012'
		$ECHO "\n${LINE}"
	else
		sleep 2  # So user can see above message briefly
		$ECHO "${LIST}\c"|tr ' ' '\012'| $PAGER
		$ECHO "\n${LINE}"
	fi

}
insert_tape(){
if [ "$TAPE_IN_DRIVE" = "NO" ]
then
	$ECHO "\nPlease put MEDIA in drive and \nPress [${LT}Enter${BASE}] when ready\c"
	read rtn
	TAPE_IN_DRIVE="YES"
	$ECHO
fi
}

editor() #Usage: editor filename
{
EDIT_FILE="$1"  # Only 1 file at a time
$ECHO "\nYou can use your own editor or the default system editor"
$ECHO "\n[Default Editor: $EDITOR ]"
$ECHO "Enter the name of Editor to use: \c"
read EDIT_CMD
[ -z "$EDIT_CMD" ]  && EDIT_CMD="$EDITOR"
if [ -f "$EDIT_FILE" ]
then
	BAK=`bakname $EDIT_FILE`
	$ECHO "\nMaking a backup copy in '${BAK}' ..."
	cp ${EDIT_FILE} ${BAK} || pressret
fi
if [ "$EDIT_CMD" =  vi ] 
then
	$ECHO "\nWhen done with editing Strike <SHIFT> ZZ to exit 'vi' editor"
	pressret
else
	$ECHO "\nWhen you are done editing, please be sure to save the 
file in \"Ascii Text\" format"
fi
$EDIT_CMD $EDIT_FILE 
}
showstatus(){ # Status code
_STATUS=$?
[ -n "$1" ] && _STATUS="$1"
if [ "$_STATUS" -eq 0 ] ; then $ECHO "Success!" ;return 0; 
else $ECHO "Failed!"; return 1; fi
}

isdir(){ # Usage isdir DIRECTORY
[ ! -d "$1" ] && { $ECHO "$1 is not a directory!!"; pressret; return 1; }
return 0
}

prompt_dir() { # Usage prompt_dir DIRECTORY PROMPT
DIR=$1
PROMPT=$2
: ${PROMPT:="\nEnter directory name: \c"}
	while :
	do
		eval TDIR="\$$DIR"
		promptfor TDIR "$PROMPT"
		isdir $TDIR && break
	done
eval "$DIR=\"$TDIR\""
}

bakname() { # Usage: bakname NAME
## Converts NAME to /tmp file eg. doggy ==> /tmp/doggy.bk
_BNAME=`basename $1`
export _BNAME
if [ `$ECHO  $_BNAME|wc -c` -ge  12 ]
then
	_BNAME=`expr $_BNAME : "\(...........\).*"`
fi
_BNAME="${_BNAME}.bk"
$ECHO "/tmp/${_BNAME}"
unset _BNAME
}

count() { #  Usage: count FILE
	wc -l 2>/dev/null <  $1 | tr -d " "
}

show_top() {  #Usage: show_top filename
	$ECHO "\nFirst 10 lines of this file are:"
	$ECHO "$NLINE"
	sed -n '1,10p;11q' $1
	$ECHO "$NLINE"
}
view_file() { #Usage: view TITLE filename [NEEDLINES]
TITLE=$1
TFILE=$2
NEEDLINES=$3
: ${NEEDLINES:=20}
export TFILE
NUM=`wc -l < $TFILE`
if [ "$NUM" -gt "$NEEDLINES" ]
then
	$PAGER  $TFILE
	$ECHO "$NLINE"
	$ECHO "$TITLE"
else
	$ECHO "$TITLE\n$NLINE"
	cat $TFILE
	$ECHO $NLINE
fi
unset TITLE TFILE NEEDLINES
}


file_select() { # Usage: file_select DIR PATTERN CONTAINER [PROMPT]
DIR=${1:-/}
PATTERN=$2
CONTAINER=$3
PROMPT=$4
FLIST=
TMP=/tmp/ls.$$
TMP2=/tmp/Rm.$$
isdir $DIR || return 1
SELECTED=NO

while [ $SELECTED = NO ]
do
clear
export DIR PATTERN
( cd $DIR; ls $PATTERN 2>/dev/null ) > $TMP2
if [ -s $TMP2 ]
then
##ifdef COHERENT
## pr - set lines to 1, sed to replace : with ), remove leading blanks
## pr -t -n -l1 $TMP2 | sed -n 's/^  *//g;/[0-9]:/s/:/)/p'|tee $TMP| pr -t -4 -l1 -w80
	pr -t -n\)1 $TMP2 | sed -n '/[0-9])/s/)/) /p'|tee $TMP| pr -t -4 -w80
else
	$ECHO "\nThere are no files in $DIR"
	$ECHO "that match the selection pattern \"$PATTERN\""
	pressret
	return 1
fi

if [ -z "$PROMPT" ]
then
$ECHO "\nEnter choices separated by spaces.  You can enter by number\nor name or both.  Wild cards '*' and '?' are allowed. Enter '${LT}q${BASE}' to quit"
$ECHO "\nEnter Selection(s): \c"
else
	$ECHO "$PROMPT \c"
fi
read TSEL ; : ${TSEL:=q}
SELECTIONS=`$ECHO "$TSEL" | sed '/\./s//\\\\./g;/\*/s//.*/g;/?/s//./g'`
set -f # Disable filename expansion
for sel in $SELECTIONS
do
set +f  # Re-enable filename expansion
case "${sel}" in
	q|Q) break 2;;
	"\\.") 
	[ -n "$FLIST" ]  && FLIST="${FLIST}\n"
	FLIST="${FLIST}."
	;;
	[0-9]*) 
	[ -n "$FLIST" ]  && FLIST="${FLIST}\n"
	FLIST="${FLIST}`sed -n "${sel}p" $TMP | sed 's/[0-9].*) //'`"
	;;
	[A-z\*\?\.]*) 
	grep -y ") $sel\$" $TMP 2>/dev/null >/dev/null
	if [ $? -eq 0 ]
	then
		grep -y ") $sel\$" $TMP 2>/dev/null | sed 's/[0-9].* //' > $TMP2
		[ -n "$FLIST" ]  && FLIST="${FLIST}\n"
		FLIST="${FLIST}`cat $TMP2`"
	else
		rm -f $TMP2
		$ECHO "\nYour selection: \"$sel\" does not match anything"
		$ECHO "Please try again!"
		sleep 2
		continue 2
	fi
	;;
#	#  * means [Enter] was hit or another character
	*)  $ECHO "Bad response"
		sleep 2
		continue 2
	;;
esac
$ECHO ".\c"
done  #  Read and process each arg loop 

set +f  # Re-enable filename expansion
	show_list Selection "$FLIST" || continue
	if is_correct 
	then
		SELECTED=YES
	else
		FLIST=
	fi
done
rm -f $TMP $TMP2

$ECHO "\n${BLK}Working . . .$ROFF\c"
FLIST="`$ECHO "$FLIST" | tr '\012' ' '`"
LFLIST=
for file in $FLIST
do
	[ -n "$LFLIST" ]  && LFLIST="${LFLIST} "
	LFLIST="${LFLIST}${DIR}/$file"
done
$ECHO "\r                          "
[ $SELECTED = YES ] && { eval "$CONTAINER=\"$LFLIST\"" ; return 0; }
return 1
}
list_select() { # Usage: list_select Filename Outlist [Converted]
FILENAME=$1
OUT_LST=$2
IS_CONVERTED=${3:-NO}  # YES or NO
ADDL="" 
while
clear
show_top $FILENAME
$ECHO "\nWild-cards allowable:
                '*' - matches any number of characters or numbers
                '?' - matches a single character or number
                [a-f] - matches any single character in the range a-f"
$ECHO "
Enter the ${ADDL}name(s) of the file you want to restore\nEnter: \c"
do
read PATTERN ; : ${PATTERN:=*}

## * => .*
## ? => .
## . => \.
PATTERN=`$ECHO "$PATTERN" | sed '/\./s//\\\\./g;/\*/s//.*/g;/?/s//./g'`
clear
$ECHO "Searching $FILENAME  " 
$ECHO "\n${BLK}Working . . .$ROFF\c"
[ -z "$ADDL" ] && cp /dev/null $OUT_LST
set -f # Disable filename expansion
for P in $PATTERN
do
## Unset here in case they hit <DEL> while processing
	set +f  # Re-enable filename expansion
	if [ "$IS_CONVERTED" != YES ]
	then
		grep "$P" $FILENAME | $HOMEBASE/filecnvt >> $OUT_LST
	else
		grep "$P" $FILENAME >> $OUT_LST
	fi
done
$ECHO "\r                     " 

while
NUM=`count $OUT_LST`
$ECHO "\n$NUM total file(s) found"
do
if [ "$NUM" -le 12 ]
then
	$ECHO "$NLINE"
	sed  -n 1,12p $OUT_LST
	$ECHO "$NLINE"
else
	prompt y "Do you wish to view the list?" && $PAGER $OUT_LST
fi
$ECHO "
Please select:
    '${LT}a${BASE}' - ${LT}a${BASE}ccept as is
    '${LT}r${BASE}' - ${LT}r${BASE}eject and try again
    '${LT}s${BASE}' - ${LT}s${BASE}earch for more files to add to list
    '${LT}e${BASE}' - ${LT}e${BASE}dit (using \"$EDITOR\" editor)
    '${LT}q${BASE}' - ${LT}q${BASE}uit entirely
Enter: \c"
read ans
case "$ans" in
	a|A) break 2;;
	r|R) ADDL=""; continue 2;;
	s|S) ADDL="additional "; break 1;;
	e|E) editor $OUT_LST; clear;;
	q|Q) cp /dev/null $OUT_LST; break 2;;
	*) continue  2;;
esac
done  
done
[ -s "$OUT_LST" ] && return 0
return 1
}
canwrite(){ #Usage: canwrite filname English_description
CHKFILE=$1
DESC=$2
if [ ! -w  "$CHKFILE" ]
then
	$ECHO "\nYou do not have permission to modify $DESC "
	$ECHO "\nThe permissions on $DESC \"$CHKFILE\" are:"
	ls -l $CHKFILE 2>/dev/null || $ECHO "No access permission either"
	$ECHO "\nAgain, Sorry..."
	pressret
	return 1
fi
return 0
}
trim() { #Usage: trim 80
## Replacement for cut which is not on all systems
	awk -F\| "NR == 1 { printf \"%.${1-80}s\n\", \$1 } "
}
is_wild() { #Usage: is_wild expression
	expr "${1:-a}" : '.*\([\*?]\).*' 2>/dev/null 1>&2
	return $?
}
runit() { # Usage: runit program arg1 arg2 arg3
if [ -x $1 ] 
then $*
	return $?
else 
	$ECHO "\n\nNot in use at this time!!"
	$ECHO "\n\007You don't have \"$1\" on the system"
	return 9  # Internal code
fi
}

_SPIN_NDX=1
SPIN_STR='-\|/'
: ${KBS:=''}	# should come from graph_init
spin()
{
    c=`$ECHO $SPIN_STR | cut -c${_SPIN_NDX}`
    $ECHO "${c}${KBS}\c"
    if [ $_SPIN_NDX -eq 4 ]; then
        _SPIN_NDX=1
    else
        _SPIN_NDX=`expr $_SPIN_NDX + 1`
    fi
}

##@CT_LIB_END()
