#!/bin/ksh
###
# Display a naff Christmas tree in a highlighted box on a UNIX terminal without any fancy graphic capabilities.
# Reuses the boxit function posted with pension.ksh to this website in July 2006. Place boxit in your $PATH.
# Substitute the instance, database alias and single partition tablespace of your choice.
# Bah Humbug.
# Alex Levy, Sustainable Software Ltd. http://www.sustainablesoftware.net
# December 2006

function boxit {
# An ancient piece of code written in 1997 by an unknown author.
# This function displays its argument to stdout inside a highlighted box.
clear 

cud=$(tput cud1) ; cud=$(echo "\033[B\c")
cuu=$(tput cuu1)  
cur=$(tput cuf1)
sbox=$(tput smso)$(tput smcup)$(tput font1)
ebox=$(tput rmcup)$(tput font0)
tidy=$(tput rmso)
boxset=$(tput box2)
for char in 1 2 3 4 5 6 
do
	eval b$char=$(print $boxset | cut -c$char,$char)
done
	
function repeat
{
typeset char=$1
typeset -i i=0 length=$2
print "$(while(((i=i+1)<=$length));do print "$char\c";done)\c"
}
	
typeset -i right=0 down=0 length char
typeset message=$@ line cdwn crht cend
((length=${#message}+4))

line=$(repeat $b2 $length)
cdwn=$(repeat $cud $down)
crht=$(repeat $cur $right)
cend=$(repeat $cur $length)
        
print "$crht$sbox$b1$line$b3$ebox"
print "$crht$sbox$b4$ebox  $message  $sbox$b4$ebox"
print "$crht$sbox$b6$line$b5$ebox"

print "$cuu$cuu$crht$cend$tidy\n\n"

}

. /home/$INSTANCE/sqllib/db2profile
db2 "connect to $DBALIAS" > /dev/null
db2 "select '1' from syscat.tables where tabschema = CURRENT USER and tabname = 'XMAS_TREE'" > /dev/null
if [[ $? -eq 1 ]]
then
   cat > xmas.del << END
01,"         *             ,                            "
02,"                       _/^\_                        "
03,"                      <     >                       "
04,"     *                 /.-.\         *              "
05,"              *        \`/&\`                   *   "
06,"                      ,@.*;@,                       "
07,"                     /_o.I %_\    *                 "
08,"        *           (\`'--:o(_@;                    "
09,"                   /\`;--.,__ \`')             *    "
10,"                  ;@\`o % O,*\`'\`&\                "
11,"            *    (\`'--)_@ ;o %'()\      *          "
12,"                 /\`;--._\`''--._O'@;               "
13,"                /&*,()~o\`;-.,_ \`""\`)             "
14,"     *          /\`,@ ;+& () o*\`;-';\              "
15,"               (\`""--.,_0 +% @' &()\               "
16,"               /-.,_    \`\`''--....-'\`)  *        "
17,"          *    /@%;o\`:;'--,.__   __.'\             "
18,"              ;*,&(); @ % &^;~\`-\`o;@();         * "
19,"              /(); o^~; & ().o@*&\`;&%O\            "
20,"              \`'='==''==,,,.,='=='==='\`           "
21,"           __.----.(\-''#####---...___...-----._    "
22,"         '\`         \)_\`'""""\`                   "
23,"                 .--' ')                            "
24,"               o(  )_-\                             "
25,"                 \`'""\` \`o                        "
END
# set char length for the santa column to the display width of your terminal session - 7.
   db2 "create table xmas_tree (position smallint not null, santa char(130) not null) in userspace1" > /dev/null
   db2 "commit" > /dev/null
   db2 "import from xmas.del of del replace into xmas_tree" > /dev/null
   db2 "commit" > /dev/null
fi
x=$(db2 -x "select santa from xmas_tree order by position")
db2 terminate > /dev/null

boxit "$x"
