#!/bin/sh
 
 # l_box
 # =====

 # This file is part of Gerolf Markup Shredder,
 # written by G. D. Brettschneider (1999-2006).
 
 GMSdateL_BOX=20060927
 
 # Prologue: ==================================================================
 
 # Not running:
 
 if [ "$GMS_SHELL" = "" ]; then
   echo "This is Gerolf Markup Shredder (l_box)."
   exit
 fi 
 
 # Debug: ---------------------------------------------------------------------
   
 if [ "$GMS_DEBUG" = "X" -o "$GMS_DEBUG" = "Y" ]; then
   source "$GMS_SHELL/l_banner" -debug l_box $1 $2 $3 $4
 elif  [ "$GMS_DEBUG" = "Z" ]; then
   echo " l_box ($1) ($2) ($3) ($4) ($5) ($6) ($7) ($8) ($9)" >> "$Z"
 fi 
  
 # Box cycle: -----------------------------------------------------------------
 
 function l_box_cycle { 
   if [ $1 = -build ]; then 
     if [ "$2" != "0" ]; then "$GMS_REPLY" -top $2; fi
     if [ "$3" != "0" ]; then "$GMS_REPLY" -item $3; fi
     if [ "$4" != "0" ]; then "$GMS_REPLY" -shadow $4; fi
     if [ "$5" != "0" ]; then "$GMS_REPLY" -bottom $5; fi
     if [ "$6" != "0" ]; then "$GMS_REPLY" -item $6; fi   
   elif [ $1 = -remove ]; then 
     if [ "$2" != "0" ]; then "$GMS_REPLY" -bottom $2; fi
     if [ "$3" != "0" ]; then "$GMS_REPLY" -shadow $3; fi
     if [ "$4" != "0" ]; then
       "$GMS_REPLY" -stripe $4 $REPLY_PATTERN $REPLY_LETTER 
     fi
     if [ "$5" != "0" ]; then "$GMS_REPLY" -top $5; fi
     if [ "$6" != "0" ]; then
       "$GMS_REPLY" -stripe $6 $REPLY_PATTERN $REPLY_LETTER 
     fi
   fi; }
   
 # Chapters: ==================================================================
 
 # Not defined:
 
 if [ "$1" = "" ]; then source "$GMS_SHELL/l_banner" -no_action l_box
 
 # Idle: ----------------------------------------------------------------------
 
 elif [ $1 = -idle ]; then 
   "$GMS_REPLY" -item 4 " " " "
   
 # Build: =====================================================================
    
 # Box, y-offset = 13:
 
 elif [ $1 = -build ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then
     #                        ,- Offset
     l_box_cycle -build 12 0 13 0 0
     l_box_cycle -build 11 12 14 13 12
     l_box_cycle -build 10 11 15 14 13
     l_box_cycle -build 9 10 16 15 14
     l_box_cycle -build 8 9 17 16 15
     l_box_cycle -build 7 8 18 17 16
     l_box_cycle -build 6 7 19 18 17
     l_box_cycle -build 5 6 20 19 18
     l_box_cycle -build 4 5 21 20 19
     l_box_cycle -build 3 4 22 21 20
   fi
   
 # Top box, y-offset = 12: ----------------------------------------------------
 
 elif [ $1 = -t12_build ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     #                        ,- Offset 
     l_box_cycle -build 11 0 12 0 0
     l_box_cycle -build 10 11 13 12 11
     l_box_cycle -build 9 10 14 13 12
     l_box_cycle -build 8 9 15 14 13
     l_box_cycle -build 7 8 16 15 14
     l_box_cycle -build 6 7 17 16 15
     l_box_cycle -build 5 6 18 17 16
     l_box_cycle -build 4 5 19 18 17 
     l_box_cycle -build 3 4 20 19 18 
   fi 
   
 # Top box, y-offset = 11: ----------------------------------------------------
 
 elif [ $1 = -t11_build ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     #                        ,- Offset 
     l_box_cycle -build 10 0 11 0 0
     l_box_cycle -build 9 10 12 11 10
     l_box_cycle -build 8 9 13 12 11
     l_box_cycle -build 7 8 14 13 12
     l_box_cycle -build 6 7 15 14 13
     l_box_cycle -build 5 6 16 15 14
     l_box_cycle -build 4 5 17 16 15
     l_box_cycle -build 3 4 18 17 16 
   fi 
   
 # Top box, y-offset = 8: -----------------------------------------------------
 
 elif [ $1 = -t8_build ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     #                       ,- Offset 
     l_box_cycle -build 7 0 8 0 0
     l_box_cycle -build 6 7 9 8 7
     l_box_cycle -build 5 6 10 9 8
     l_box_cycle -build 4 5 11 10 9
     l_box_cycle -build 3 4 12 11 10
     l_box_cycle -build 0 0 13 12 11
   fi 
   
 # Remove: ====================================================================
 
 # Box cycle:
 
 elif [ $1 = -cyc_remove ]; then 
   if [ "$2" != "0" ]; then "$GMS_REPLY" -bottom $2; fi
   if [ "$3" != "0" ]; then "$GMS_REPLY" -shadow $3; fi
   if [ "$4" != "0" ]; then
     "$GMS_REPLY" -stripe $4 $REPLY_PATTERN $REPLY_LETTER 
   fi
   if [ "$5" != "0" ]; then "$GMS_REPLY" -top $5; fi
   if [ "$6" != "0" ]; then
     "$GMS_REPLY" -stripe $6 $REPLY_PATTERN $REPLY_LETTER 
   fi
 
 # Box, y-offset = 13: --------------------------------------------------------
 
 elif [ $1 = -remove ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
   # Animation:
     l_box_cycle -remove 20 21 22 4 3
     l_box_cycle -remove 19 20 21 5 4
     l_box_cycle -remove 18 19 20 6 5
     l_box_cycle -remove 17 18 19 7 6
     l_box_cycle -remove 16 17 18 8 7
     l_box_cycle -remove 15 16 17 9 8
     l_box_cycle -remove 14 15 16 10 9
     l_box_cycle -remove 13 14 15 11 10
     l_box_cycle -remove 12 13 14 12 11
     l_box_cycle -remove 0 12 13 0 12
   else #                      `- Offset
   # Erasure:
     for i in 3 22 4 21 5 20; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 6 19 7 18 8 17; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 9 16 10 15 11 14; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 12 13; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
   fi
   
 # Top box, y-offset = 12: ----------------------------------------------------
 
 elif [ $1 = -t12_remove ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     l_box_cycle -remove 18 19 20 4 3
     l_box_cycle -remove 17 18 19 5 4
     l_box_cycle -remove 16 17 18 6 5
     l_box_cycle -remove 15 16 17 7 6
     l_box_cycle -remove 14 15 16 8 7
     l_box_cycle -remove 13 14 15 9 8
     l_box_cycle -remove 12 13 14 10 9
     l_box_cycle -remove 11 12 13 11 10
     l_box_cycle -remove 0 11 12 0 11
   else #                      `- Offset
   # Erasure:
     for i in 3 20 4 19 5 18 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 6 17 7 16 8 15 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 9 14 10 13 11 12 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
   fi
   
 # Top box, y-offset = 11: ----------------------------------------------------
 
 elif [ $1 = -t11_remove ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     l_box_cycle -remove 16 17 18 4 3
     l_box_cycle -remove 15 16 17 5 4
     l_box_cycle -remove 14 15 16 6 5
     l_box_cycle -remove 13 14 15 7 6
     l_box_cycle -remove 12 13 14 8 7
     l_box_cycle -remove 11 12 13 9 8
     l_box_cycle -remove 10 11 12 10 9
     l_box_cycle -remove 0 10 11 0 10
   else #                      `- Offset
   # Erasure:
     for i in 3 18 4 17 5 16 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 6 15 7 14 8 13 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 9 12 10 11 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
   fi
   
 # Top box, y-offset = 8: -----------------------------------------------------
 
 elif [ $1 = -t8_remove ]; then 
   if [ "$GMS_ANIMATE" = "on" ]; then 
     l_box_cycle -remove 13 0 0 0 0
     l_box_cycle -remove 12 13 0 0 0
     l_box_cycle -remove 11 12 13 3 0
     l_box_cycle -remove 10 11 12 4 3
     l_box_cycle -remove 9 10 11 5 4
     l_box_cycle -remove 8 9 10 6 5
     l_box_cycle -remove 7 8 9 7 6
     l_box_cycle -remove 0 7 8 0 7
   else #                    `- Offset
   # Erasure:
     for i in 3 13 4 12 5 11 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
     for i in 6 10 7 9 8 ; do
       "$GMS_REPLY" -stripe $i $REPLY_PATTERN $REPLY_LETTER; done
   fi
   
 # Not found: -----------------------------------------------------------------
 
 else
   source "$GMS_SHELL/l_banner" -no_action l_box $1   
 fi
