#!/usr/bin/ksh
#  report.shl	UNIX Script for SQL*Plus Code Generation        by bknox@uaex.edu
#               
/bin/clear
echo
echo
echo "To Create a New SQL*Plus Report Program"
echo
echo "Enter Start Name for SQL*Plus Report (no .sql): \c"
read ProgramName; export ProgramName
echo
echo "Enter Report Title (no single or double qoutes): \c"
read ReportTitle; export ReportTitle
echo
echo "Start Name: " $ProgramName
echo
echo "      File: " $ProgramName."sql"
echo
echo "    Report: " $ProgramName."lst"
echo
echo "     Title: " $ReportTitle
echo
 
# test for no file name specified
if [[ -z "$ProgramName" ]]
then
print No Output File Specified -- Report Create Cancelled
exit 1
fi

# preclude use of report_skeleton for name of program
if [[ "$ProgramName" = report_skeleton ]]
then
print report_skeleton Cannot Be Used for Program Name -- Report Create Cancelled
exit 1
fi

# test for .lst .lis .txt .sql already exist

file="$ProgramName.lst"

# test for file already exist
if [[ -f $file ]]
then
print $file Already Exist -- Report Create Cancelled
exit 1
fi

file="$ProgramName.lis"

# test for file already exist
if [[ -f $file ]]
then
print $file Already Exist -- Report Create Cancelled
exit 1
fi

file="$ProgramName.txt"

# test for file already exist
if [[ -f $file ]]
then
print $file Already Exist -- Report Create Cancelled
exit 1
fi

file="$ProgramName.sql"

# test for file already exist
if [[ -f $file ]]
then
print $file Already Exist -- Report Create Cancelled
exit 1
fi

today="$(date "+%m\/%d\/%y")"

# replace string example with new file name
sed -e "s/report_skeleton/$ProgramName/g" -e "s/Report_Skeleton_Description/$ReportTitle/g" -e "s/mm-dd-yy USER/$today/g" -e "s/USER/$USER/g" report_skeleton.sql > $file
chmod 644 $file

print $file Created
echo
echo
# This script is available "as is".  See Disclaimer http://www.uaex.edu/bknox/