#!/bin/sh
 
 # g_launch
 # ========
 
 # This file is part of Gerolf Markup Shredder,
 # written by G. D. Brettschneider (1999-2006).
 
 GMSdateG_LAUNCH=20060927
 
 # Prologue: ==================================================================
 
 line="====================================="
 dash="---------------------"
 
 # Not running: ---------------------------------------------------------------
 
 if [ "$GMS_ROOT" = "" ]; then
   echo "This is Gerolf Markup Shredder (g_launch)."
   exit
 fi 
 
 # Debug: ---------------------------------------------------------------------
   
 if [ "$GMS_DEBUG" = "X" -o "$GMS_DEBUG" = "Y" ]; then
   source "$GMS_SHELL/l_banner" -debug g_launch $1 $2 $3 $4
 elif  [ "$GMS_DEBUG" = "Z" ]; then
   echo " g_launch ($1) ($2) ($3) ($4) ($5) ($6) ($7) ($8) ($9)" >> "$Z"
 fi 
 
 # Chapters: ==================================================================
 
 # Not defined:
 
 if [ "$1" = "" ]; then source "$GMS_SHELL/l_banner" -no_action g_launch 
 
 # Build 'gerolf' launcher script: --------------------------------------------
 
 # Fixme: check "$HOME" not equal to "/root" ]; 
 
 elif [ $1 = -build ]; then
   if [ "$HOME" = "/root" ]; then l="gerolf"
   else l="$HOME/gms_user"; fi
   cd "$GMS_SETTING" 
   echo "#!/bin/sh" > $l
   echo >> $l
   if [ "$HOME" = "/root" ]; then
     echo " # gerolf" >> $l
     echo " # ======" >> $l
     echo >> $l
     echo " # Launcher script for Gerolf Markup Shredder (Unix)." >> $l
   else
     echo " # gms_user" >> $l
     echo " # ========" >> $l
     echo >> $l
     echo " User setting script for Gerolf Markup Shredder (Unix)." >> $l
   fi
   echo " # Web: www.Gerolf.org, eMail: MarkupShredder@Gerolf.org" >> $l
   echo -n " # Generated on ">> $l
   date >> $l
   echo >> $l
   echo " # ==$line$line" >> $l
   echo >> $l
   echo " # 0) Start shell: $dash---------------------------------------" >> $l
   echo >> $l
   echo "   if [ \"\$1\" != \"-passive\" ]; then" >> $l
   echo "     if [ \"\$1\" = \"-shell\" ]; then" >> $l
   echo "       shift" >> $l
   echo "     else" >> $l
   echo "       xterm -fg black -bg white -e \"\$0\" -shell" \
                 "\$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9" >> $l
   echo "       exit" >> $l
   echo "     fi" >> $l
   echo "   fi" >> $l
   echo >> $l
   echo " # 1) General settings: $dash----------------------------------" >> $l
   echo >> $l
   if [ "$HOME" = "/root" ]; then
     echo " # Setting directory:" >> $l
     echo "     export GMS_SETTING=\"$GMS_SETTING\"" >> $l
     echo "     if [ \"\$GMS_MODE\" != \"quiet\" ]; then" >> $l
     echo "       setterm -clear -reset; fi" >> $l ###
     echo "     if [ \"\$1\" != \"-passive\" ]; then" >> $l
     echo "       cat \"\$GMS_SETTING/launch_1.scn\"" >> $l
     echo "     fi" >> $l
     echo >> $l
     echo " # Main directories (can be web server subfolders):" >> $l
     echo "     export GMS_ROOT=\"$GMS_ROOT\"" >> $l
     echo "     export GMS_BODY=\"$GMS_BODY\"" >> $l
     echo >> $l
   fi
   echo " # Debugging mode (0, 1, 2, 3, ... or X, Y, Z)" >> $l
   echo "     export GMS_DEBUG=$GMS_DEBUG" >> $l
   echo >> $l
   echo " # Rewrite gmsdebug log file (do not change):" >> $l
   echo "     export Z=\"\$GMS_SETTING/gmsdebug.log\"" >> $l
   echo "     if [ \"\$4\" != \"gmssetup\" ]; then" >> $l
   echo "      if [ \"\$GMS_MODE\" != \"quiet\" ]; then" >> $l
   echo "       if [ -f \"\$Z\" ]; then rm \"\$Z\"" >> $l
   echo "         gmshead=\"\$GMS_SETTING/_gmshead.txt\"" >> $l
   echo \
  "           if [ -f \"\$gmshead\" ]; then mv \"\$gmshead\" \"\$Z\"; fi" >> $l
   echo "         unset gmshead" >> $l
   echo -n "         echo \" gerolf (\$1) (\$2) (\$3) (\$4) (\$5)" >> $l
   echo " (\$6) (\$7) (\$8) (\$9)\" >> \"\$Z\"" >> $l
   echo "       fi" >> $l
   echo "      fi" >> $l
   echo "     fi" >> $l
   echo >> $l
   echo " # Main codepage name:" >> $l
   echo "     export GMS_CODEPAGE=$GMS_CODEPAGE" >> $l
   echo >> $l
   echo " # 2) Programs in search path (binary names): $dash------------" >> $l
   echo >> $l
   echo " #   Plain text viewer and editor:" >> $l
   echo "       export GMS_VIEWER=\"$GMS_VIEWER\"" >> $l
   echo "       export GMS_EDITOR=\"$GMS_EDITOR\"" >> $l
   echo " #   HTML browser, syntax checker, typesetting engine:" >> $l
   echo "       export GMS_BROWSER=\"$GMS_BROWSER\"" >> $l
   echo "       export GMS_ANALYST=\"$GMS_ANALYST\"" >> $l
   echo "       export GMS_TSETTER=\"$GMS_TSETTER\"" >> $l
   echo " #   PDF reader:" >> $l
   echo "       export GMS_READER=\"$GMS_READER\"" >> $l
   echo >> $l
   echo " # 3) Textmode interface variables: $dash----------------------" >> $l
   echo >> $l
   echo " #   Menu animation ('on' or 'off'):" >> $l
   echo "       export GMS_ANIMATE=$GMS_ANIMATE" >> $l
   echo " #   Colors and pattern ('R' = 'Random'):" >> $l
   echo " #     Foreground colors (0 to 15):" >> $l
   echo "         export GMS_TEXT=$GMS_TEXT" >> $l
   echo "         export GMS_HOTKEY=$GMS_HOTKEY" >> $l
   echo "         export GMS_PATTERN=$GMS_PATTERN" >> $l
   echo " #     Background colors (0 to 7):" >> $l
   echo "         export GMS_BANNER=$GMS_BANNER" >> $l
   echo "         export GMS_SHADE=$GMS_SHADE" >> $l
   echo "         export GMS_DESKTOP=$GMS_DESKTOP" >> $l
   echo " #   Fill character (ASCII code 32 to 126)" >> $l
   echo "       export GMS_LETTER=$GMS_LETTER" >> $l
   echo >> $l
   echo " # 4) Browser interface variables: $dash-----------------------" >> $l
   echo >> $l
   echo " #   Maximal size and number of files:" >> $l
   echo "       export GMS_MAXSIZE=$GMS_MAXSIZE" >> $l
   echo "       export GMS_MAXFILES=$GMS_MAXFILES" >> $l
   echo " #   Width of text area (join/split):" >> $l
   echo "       export GMS_WIDTH_ONE=$GMS_WIDTH_ONE" >> $l
   echo "       export GMS_WIDTH_TWO=$GMS_WIDTH_TWO" >> $l
   echo " #   Height of text area (join/split):" >> $l
   echo "       export GMS_HEIGHT_ONE=$GMS_HEIGHT_ONE" >> $l
   echo "       export GMS_HEIGHT_TWO=$GMS_HEIGHT_TWO" >> $l
   echo " #   Font size, in point (join/split):" >> $l
   echo "       export GMS_SIZE_ONE=$GMS_SIZE_ONE" >> $l
   echo "       export GMS_SIZE_TWO=$GMS_SIZE_TWO" >> $l
   echo " #   Linking to internal or external target:" >> $l
   echo "       export GMS_LINKS=$GMS_LINKS" >> $l
   echo >> $l
   if [ "$HOME" = "/root" ]; then
     echo " # 5) Start program: $dash-------------------------------------">>$l
     echo >> $l
     echo " # Do not change the rest of this file:" >> $l
     echo >> $l
     echo " #   Set version number and date:" >> $l
     echo "       export GMS_VERSION=$GMS_VERSION" >> $l
     echo "       export GMS_DATE=$GMS_DATE" >> $l
     echo " #   Get folder structure:" >> $l
     echo "       source \"\$GMS_SETTING/folder\" called_by gerolf">> $l    
     echo "       if [ \"\$GMS_MODE\" != \"quiet\" ]; then" >> $l
     echo "         setterm -clear -reset; fi" >> $l ###
     echo "       if [ \"\$1\" != \"-passive\" ]; then" >> $l
     echo "         cat \"\$GMS_SETTING/launch_2.scn\"" >> $l
     echo "       fi" >> $l
     echo " #   Get work file:" >> $l
     echo "       if [ \"\$GMS_MODE\" != \"quiet\" ]; then" >> $l
     arg="called_by gerolf \$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9"
       echo "         source \"\$GMS_SHELL/g_vars\" -ini_file"\\>> $l
       echo "           $arg" >> $l
     unset arg
     echo "       fi" >> $l 
     echo "       if [ \"\$GMS_MODE\" != \"quiet\" ]; then" >> $l
     echo "         setterm -clear -reset; fi" >> $l ###
     echo " #   Launch textmode interface:" >> $l
     echo "       if [ \"\$1\" != \"-passive\" ]; then" >> $l
     echo "         cat \"\$GMS_SETTING/launch_3.scn\"" >> $l
     echo "         source \"\$GMS_SHELL/shredder\" called_by gerolf" >> $l
     echo "       fi" >> $l
   fi   
   chmod 755 $l
   unset l
 
 # Not found: -----------------------------------------------------------------
 
 else
   source "$GMS_SHELL/l_banner" -no_action g_launch $1   
 fi
