#!/bin/sh
 
 # l_save
 # ======
 
 # This file is part of Gerolf Markup Shredder,
 # written by G. D. Brettschneider (1999-2006).
  
 GMSdateL_SAVE=20060927
 
 # Prologue: ==================================================================
 
 # Not running:
 
 if [ "$GMS_SHELL" = "" ]; then
   echo "This is Gerolf Markup Shredder (l_save)."
   exit
 fi 
 
 # Debug: ---------------------------------------------------------------------
   
 if [ "$GMS_DEBUG" = "X" -o "$GMS_DEBUG" = "Y" ]; then
   source "$GMS_SHELL/l_banner" -debug l_save $1 $2 $3 $4
 elif  [ "$GMS_DEBUG" = "Z" ]; then
   echo " l_save ($1) ($2) ($3) ($4) ($5) ($6) ($7) ($8) ($9)" >> "$Z"
 fi 
 
 # Chapters: ==================================================================
 
 # Not defined:
 
 if [ "$1" = "" ]; then source "$GMS_SHELL/l_banner" -no_action l_save
 
 # Update: --------------------------------------------------------------------
 
 elif [ $1 = -update ]; then
   if [ -f "$GMS_FOLDER/$GMS_FILE" ]; then
   
   # There exists an old file that can be overwritten:
     ""$GMS_REPLY"" -item 8 "Overwrite existing file" O 3
   # Cold state:
     if [ "$3 " = "" ]; then
     source "$GMS_SHELL/l_banner" -no_cold l_save
     elif [ $3 = Q ]; then "$GMS_REPLY" -item 5 "Quit dialog" Q 1
     elif [ $3 = C ]; then "$GMS_REPLY" -item 7 "Cancel file creation" C 2
     elif [ $3 = O ]; then "$GMS_REPLY" -item 8 "Overwrite existing file" O 3
     elif [ $3 = N ]; then "$GMS_REPLY" -item 10 "$GMS_FILE" N 4
     else
       source "$GMS_SHELL/l_banner" -no_cold l_save $3
     fi
   # Hot state:
     if [ "$2 " = "" ]; then
       source "$GMS_SHELL/l_banner" -no_hot l_save
     elif [ $2 = Q ]; then "$GMS_REPLY" -item 5 "Quit dialog" QQ 1
     elif [ $2 = C ]; then "$GMS_REPLY" -item 7 "Cancel file creation" CC 2
     elif [ $2 = O ]; then "$GMS_REPLY" -item 8 "Overwrite existing file" OO 3
     elif [ $2 = N ]; then
       setterm -cursor on
         "$GMS_REPLY" -question 10 "$GMS_FILE" NN 4
       setterm -cursor off 
     else
       source "$GMS_SHELL/l_banner" -no_hot l_save $2
     fi
   else
   
   # There does not exist an old file that can be overwritten:
   # Cold state:
     if [ "$3 " = "" ]; then
       source "$GMS_SHELL/l_banner" -no_cold l_save
     elif [ $3 = Q ]; then "$GMS_REPLY" -item 5 "Quit dialog" Q 1
     elif [ $3 = C ]; then "$GMS_REPLY" -item 7 "Cancel file creation" C 2
     elif [ $3 = O ]; then "$GMS_REPLY" -item 8 " " " " 3
     elif [ $3 = N ]; then "$GMS_REPLY" -item 10 "$GMS_FILE" N 4
     else
       source "$GMS_SHELL/l_banner" -no_cold l_save $3
     fi
   # Hot state:
     if [ "$2 " = "" ]; then
       source "$GMS_SHELL/l_banner" -no_hot l_save
     elif [ $2 = Q ]; then "$GMS_REPLY" -item 5 "Quit dialog" QQ 1
     elif [ $2 = C ]; then "$GMS_REPLY" -item 7 "Cancel file creation" CC 2
     elif [ $2 = O ]; then "$GMS_REPLY" -item 8 " " OO 3
     elif [ $2 = N ]; then
       setterm -cursor on
         "$GMS_REPLY" -question 10 "$GMS_FILE" NN 4
       setterm -cursor off 
     else
       source "$GMS_SHELL/l_banner" -no_hot l_save $2
     fi
   fi
 
 # Build: ---------------------------------------------------------------------
 
 elif [ $1 = -build ]; then 
   "$GMS_REPLY" -top 3 "$GMS_FILEBOX" 
   "$GMS_REPLY" -item 4 " " " " 
   "$GMS_REPLY" -item 5 "Quit dialog" Q 1
   "$GMS_REPLY" -item 6 " " " " 
   "$GMS_REPLY" -item 7 "Cancel file creation" C 2
   "$GMS_REPLY" -item 8 "O" O 3 
   "$GMS_REPLY" -item 8 " " " " 
   "$GMS_REPLY" -item 9 " " " " 
   "$GMS_REPLY" -item 10 "$GMS_FILE" N 4
   "$GMS_REPLY" -item 11 " " " " 
   "$GMS_REPLY" -bottom 12 
   "$GMS_REPLY" -shadow 13 
 
 # Not found: -----------------------------------------------------------------
 
 else
   source "$GMS_SHELL/l_banner" -no_action l_save $1   
 fi
