#################################################################################################
# .profile_sub_strg		(c) R. H. Reepe 12th December 1996	Version 1.0		#
#################################################################################################
# 961212 RHR Genesis

#===========================================================================================
s_version()			# (c) R. H. Reepe. Returns integer arg count of arg list
#===========================================================================================
# Arg_1 = File containing version information
{
	head -3 $1 | tail -1 | /bin/nawk '{print($11)}'
}

#===========================================================================================
s_arg_count()			# (c) R. H. Reepe. Returns integer arg count of arg list
#===========================================================================================
# Arg_List = List of arguments to count
{
	echo $#
}

#===========================================================================================
s_line_count()			# (c) R. H. Reepe. Returns integer line count of File
#===========================================================================================
# Arg_1 = FILENAME
{
	_line_count=`wc -l $1 | cut -c1-8`
	expr $_line_count + 0   
}

#===========================================================================================
s_length()			# (c) R. H. Reepe. Returns integer char count of String
#===========================================================================================
# Arg_1 = STRING
{
	_length=`echo "$1" | wc -c | cut -c1-8`
	expr $_length - 1   
}

#===========================================================================================
s_in_string_all()		# (c) R. H. Reepe. Returns ALL positions of CHAR in STRING
#===========================================================================================
# Arg_1 = char
# Arg_2 = string
{
	echo $@ | cut -f2- -d\ | sed -e 's/./&\
	/g' | grep -n $1 | cut -f1 -d:
}

#===========================================================================================
s_in_string()			# (c) R. H. Reepe. Returns FIRST position of CHAR in STRING
#===========================================================================================
# Arg_1 = char
# Arg_2 = string
{
	s_in_string_all $@ | head -1
}

#===========================================================================================
s_find_string_all()		# (c) R. H. Reepe. Returns location of word in string
#===========================================================================================
# Arg_1 = WORD to find
# Arg_n = STRING to search along
{
	echo $@ | cut -f2- -d\ | $ORACLE_BASE/bin/new_tr | grep -n $1 | cut -f1 -d:
}

#===========================================================================================
s_find_string()		# (c) R. H. Reepe. Returns location of word in string
#===========================================================================================
# Arg_1 = WORD to find
# Arg_n = STRING to search along
{
	s_find_string_all $@ | head -1
}

#===========================================================================================
s_get_string()			# (c) R. H. Reepe. Returns word at location in string
#===========================================================================================
# Arg_1 = START_LOCATION of word to get
# Arg_2 = STRING to search along
{
	echo "$@" | cut -f2- -d\  | cut -f$1-$1 -d\ 
}

#===========================================================================================
s_upper_case()			# (c) R. H. Reepe. Changes text to upper case
#===========================================================================================
# Arg_1 = INPUT_STRING
{
	echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
}

#===========================================================================================
s_lower_case()			# (c) R. H. Reepe. Changes text to lower case
#===========================================================================================
# Arg_1 = INPUT_STRING
{
	echo $1 | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
}

#===========================================================================================
s_right_pad()			# (c) R. H. Reepe. Blank pads a string to right
#===========================================================================================
# Arg_1 = INPUT_STRING
# Arg_2 = PAD_WIDTH (INT)
{
	_string=$1"                                                                              "
	echo "$_string" | cut -c1-$2
}

#===========================================================================================
s_left_pad()			# (c) R. H. Reepe. Blank pads a string to left
#===========================================================================================
# Arg_1 = INPUT_STRING
# Arg_2 = PAD_WIDTH (INT)
{
	_string="                                                                              "$1
	_length=`s_length "$_string"`
	echo "$_string" | cut -c`expr $_length - $2 + 1`-
}

#===========================================================================================
s_join()			# (c) R. H. Reepe. Joins words into one string
#===========================================================================================
# Arg_list = INPUT_STRING
{
	echo $@ | tr ' ' '_'
}

#===========================================================================================
s_initials()		# (c) Richard Reepe Returns Initials of input Words
#===========================================================================================
# Arg_@ = Word_List
{
	_initials=""
	for _word in "$@"
	do
		_initials="$_initials `echo $_word | cut -c1`"
	done
	echo $_initials
}