Merry Xmas (special present inside)


 
Thread Tools Search this Thread
The Lounge What is on Your Mind? Merry Xmas (special present inside)
# 1  
Old 12-23-2017
Merry Xmas (special present inside)

A Merry Xmas to all of you.

And, as a special present to vbe (he knows why) a little exercise:

Code:
#! /bin/ksh

pPrintSnow ()
{
typeset -i iLen=$1
while (( iLen )) ; do
     if ! (( RANDOM % 31 )) ; then
          printf "%1s" "."
     else
          printf "%1s" " "
     fi
     (( iLen -= 1 ))
done
return 0
}



pPrintTreeLine ()
{
typeset -i iWidth=$1
typeset -i iTermWidth=$COLUMNS
typeset -i iOffset=$(( (iTermWidth - iWidth)/2 ))

pPrintSnow $iOffset
while [ $iWidth -gt 0 ] ; do
     if !   (( RANDOM % 11 )) ; then
          printf "%s" "$(tput sgr0;tput bold)i$(tput sgr0;tput dim)"
     elif ! (( RANDOM %  7 )) ; then
          printf "%s" "O"
     elif ! (( RANDOM % 13 )) ; then
          printf "%s" "O"
     else
          printf "%s" "*"
     fi
     (( iWidth -= 1 ))
done
pPrintSnow $iOffset
printf "\n"

return 0
}



pPrintTrunk ()
{
typeset -i iTrunkWidth=$(( $1 - 2 ))
typeset -i iTrunkHeight=$2
typeset -i iTermWidth=$COLUMNS
typeset -i iOffset=$(( (iTermWidth - iTrunkWidth)/2 ))
typeset -i iCnt=0

if [ $iTrunkWidth -lt 1 ] ; then
     (( iTrunkWidth = 1 ))
     (( iOffset = (iTermWidth - iTrunkWidth ) / 2 ))
fi

while (( iTrunkHeight )) ; do
     if (( iTrunkHeight == 1 )) ; then
          printf "%${iOffset}s/" " "
     else
          printf "%${iOffset}s " " "
     fi
     (( iCnt = iTrunkWidth ))
     while (( iCnt )) ; do
          printf "%s" "|"
          (( iCnt -= 1 ))
     done
     if (( iTrunkHeight == 1 )) ; then
          printf '\\ \n'
     else
          printf '\n'
     fi
     (( iTrunkHeight -= 1 ))
done
return 0
}



# main ()
typeset -i iHeight=$1
typeset -i iCnt=0

eval $(resize)
tput dim
(( iCnt = 1 ))
while [ $iCnt -le $(( iHeight *2 )) ] ; do
     pPrintTreeLine $iCnt
     (( iCnt += 2 ))
done
pPrintTrunk $(( iHeight / 2 )) $(( iHeight / 5 ))
tput sgr0

exit 0

bakunin

Last edited by bakunin; 12-24-2017 at 01:31 AM..
This User Gave Thanks to bakunin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. What is on Your Mind?

Merry XMAS, happy holidays etc. everybody...

Have a laugh... https://www.youtube.com/watch?v=HZWQcl1C-c8 Bazza... (4 Replies)
Discussion started by: wisecracker
4 Replies

2. Shell Programming and Scripting

Replace Special Character With Next Present Byte

Hi, First find the special character, from the special character take next two bytes convert the bytes to decimal and replace with next present byte of decimal value times. E.g. Input: 302619ú1A? Output: 302619(3 spaces for ú1A)?????????????????????????? Thanks, Dines (27 Replies)
Discussion started by: dineshnak
27 Replies

3. Shell Programming and Scripting

want to remove comma present inside double qoute

Hi friends... I have a dat file like below:- test_file.dat abc,ttt,"""123,89.98",yyu,opp vvv,"23,76.68",w564,"54,98.87",985 i need the remove the comma present inside the double qoute as output:- out_test_file.dat abc,ttt,"""12389.98",yyu,opp vvv,"2376.68",w564,"5498.87",985... (6 Replies)
Discussion started by: gani_85
6 Replies

4. What is on Your Mind?

Merry Christmas

Merry Christmas and all best wishes to all fox in this forum salute from Croatia (0 Replies)
Discussion started by: solaris_user
0 Replies

5. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies
Login or Register to Ask a Question