#!/bin/ksh
# pubmusicbookcatalog - Author: Edwin Arneson - $Revision: 1.1 $ - $Date: 2007/03/10 18:52:41 $
#	Q&D script to publish the music book catalog HTML files to the web server.
# FORMAT:	pubmusicbookcatalog
# CHANGE HISTORY:
#	070310 EJA 1.1	- Created
# CALLED BY:
# CALLS:
# SEE ALSO:
# SCRIPTS:
# PERMISSIONS:
# HOSTS THIS FILE IS IDENTICAL ON:
# FILES:
# GLOBALS:
# LOCALS:
# COMMANDS:
# INPUT:
# OUTPUT:
# OUTPUT USED BY:
# EXAMPLES:
# HINTS:
# RESTRICTIONS:
# BUGS:
# WARNINGS:
#	40 - The localize script could not be found. Global machine settings can not be set.
# ERROR CODES:
#	51 - An unknown option was passed to the script, or syntax of the parameters is wrong.
#	56 - The USAGE was requested using -z or -?.
# DIAGNOSTICS:
# RCS.SH VERSION: 00010
# RCS INFORMATION:
#         $Id: pubmusicbookcatalog,v 1.1 2007/03/10 18:52:41 earneson Exp $
#     $Author: earneson $
#       $Date: 2007/03/10 18:52:41 $
#   $Revision: 1.1 $
#     $Source: /Users/cvs/scripts/all/Users/earneson/bin/pubmusicbookcatalog,v $
#      $State: Exp $

#######
####### Initialization
#######
# Special check for first parameter of "-x" to turn on tracing of the script execution
if [[ "$1" = "-x" ]] ; then
	set -x
fi

# Find and execute the localization script designed to set common environment variables based name characteristics of the executing computer
binDir=`dirname $0` # get the directory this script is in and check for localize there
if [[ -r "$binDir/localize" ]] ; then
	. $binDir/localize
else
	echo "$0: WARNING 40 - The localize script could not be found. Global machine settings can not be set."
fi

# Ensure these three are set
if [[ -z "$localhost" ]] ; then	localhost="`uname -n`"	; export localhost ; fi
if [[ -z "$awkname" ]] ; then	if [[ -x "/usr/bin/nawk" ]] ; then awkname="nawk" ; else awkname="awk" ; export awkname ; fi ; fi 
if [[ -z "$OStype" ]] ; then	OStype="`uname -s`"		; export OStype ; fi
#######
####### Functions
#######

#######
####### Other variables
#######
basename=`basename $0`
USAGE="$basename
	\$Revision: 1.1 $ - \$Date: 2007/03/10 18:52:41 $
usage: $basename [-d] [-x]* [-X]*
	<-d> diff the before and after files (passed through to touchvi)
	<-x> does 'set -x' (may be used in functions and external script calls)
	<-X> sets debugging level--the number of times -X is specified"
debuglevel=0	# -X: stores the number of times -X is specified (debugging level)
xlevel=0		# -x: stores the number of times -x is specified (for optional "set -x" call in functions) and does 'set -x'
dflag=""		# -d:

#######
####### Parse parameters.
#######
while getopts :dxXz optchar ; do
	if [[ $debuglevel -ge 1 ]] ; then echo ">optchar=$optchar< >OPTARG=$OPTARG> >OPTIND=$OPTIND<" ; fi
	case $optchar in
		d)	dflag="-d" ;;
		x)	xcmd="$xcmd -x" ; ${xcmd:+set -x} ; let "xlevel=$xlevel + 1" ;;	# xcmd stores any -x parameters for passing to other scripts
		X)	Xcmd="$Xcmd -X " ; let "debuglevel=$debuglevel + 1" ;;			# Xcmd stores any -X parameters for passing to other scripts
		\?|z)	echo "$USAGE" >&2 ; exit 56 ;;
		*)	if [[ -z "$OPTARG" ]] ; then
				case "$optchar" in
					?)	errflag="-$optchar" ;;
					+?)	errflag="$optchar" ;;
					*)	errflag="unknown1" ;;
				esac
			else
				errflag="$OPTARG"
			fi
			echo "$basename: ERROR 51 - Unknown option >$errflag<" >&2
			echo "$USAGE" >&2
			exit 51
			;;
	esac
done
shift `expr $OPTIND - 1`

#######
####### Additional checks
#######

#######
####### Main processing
#######
# First, open the Excel file /Data/Excel/music_book_catalog:xl6
# Sort by Title/Book/Number and save the sheet as music_book_catalog-by_title.html
# Sort by Book/Number/Title and save the sheet as music_book_catalog-by_book.html
cd /Data/Excel
# Change the CR characters to NL characters
for f in music_book_catalog-by_book.html music_book_catalog-by_title.html ; do
	echo $echoflag "$basename: changing CR characters to NL characters in $f...\c"
	touchvi $dflag -e fixmus1 $f
	echo "done."
done


#######
####### Cleanup
#######

#######
####### The end.
#######
exit
