#!/bin/sh

# menu
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 2011, 2012, 2023
# Joseph Rosevear

# This file is part of The SAM Kernel.

# The SAM Kernel is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.

# The SAM Kernel is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.



# JHR 111231 I changed #!/bin/sh to #!/bin/bash.

# JHR 120808 I changed the prgama back to #!/bin/sh, because due to
# changes in SAM the sh shell will work fine.

# Joseph Rosevear 230502 I added an echo of $1 at the beginning.

# Joseph Rosevear 230512 I removed the above adding of an echo. 
# Apparently, it wasn't needed.



### This is for use of SAM as an invisible backbone.
### "$sam_menu" is NOT ""
if [ -x "$sam_menu" ]; then

   $sam_menu $*

else

   if [ "$1" = "" ]; then if [ -x $level/setcolor ]; then $level/setcolor; fi; fi

   echo ""                                             > $sam_temp_dir/view.dat
   
   ### $sam_add is NOT "" and "$1" IS ""
   if [ "$sam_add" != "" ] && [ "$1" = "" ]; then
      echo "(added: $sam_add)"                        >> $sam_temp_dir/view.dat
      echo ""                                         >> $sam_temp_dir/view.dat
   fi

   ### "$1" IS ""
   if [ "$1" = "" ]; then
      echo $level                                     >> $sam_temp_dir/view.dat
   fi

   ### "$1" is NOT ""
   if [ "$1" != "" ]; then
      echo $1                                         >> $sam_temp_dir/view.dat
   fi

   echo ""                                            >> $sam_temp_dir/view.dat
   echo "local  {"                                    >> $sam_temp_dir/view.dat

   echo  " COMMAND       DESCRIPTION"                 >> $sam_temp_dir/view.dat

   ### "$1" IS ""
   if [ "$1" = "" ]; then
      cat $level/menu.dat                             >> $sam_temp_dir/view.dat
      echo ""                                         >> $sam_temp_dir/view.dat
      echo "global {"                                 >> $sam_temp_dir/view.dat
      echo  " COMMAND       DESCRIPTION"              >> $sam_temp_dir/view.dat
      echo "Builtin     --"                           >> $sam_temp_dir/view.dat
      echo "    exit       Closes the current shell.  If SAM was started in the" >> $sam_temp_dir/view.dat
      echo "                current shell, then exit will terminate SAM."        >> $sam_temp_dir/view.dat
      echo "in \$sam     --"                          >> $sam_temp_dir/view.dat
      cat $sam/menu.dat                               >> $sam_temp_dir/view.dat

      ### $sam_tool/menu.dat DOES exist
      if [ -a $sam_tool/menu.dat ]; then
         echo "in \$sam_tool--"                       >> $sam_temp_dir/view.dat
         cat $sam_tool/menu.dat                       >> $sam_temp_dir/view.dat
      fi
   fi

   ### "$1" is NOT ""
   if [ "$1" != "" ]; then
       cat $1/menu.dat                                >> $sam_temp_dir/view.dat
   fi

   echo ""                                            >> $sam_temp_dir/view.dat
   cat $sam_root/main/about/data/copyr.dat            >> $sam_temp_dir/view.dat
   echo ""                                            >> $sam_temp_dir/view.dat
   sam_view $sam_temp_dir/view.dat
   echo ""
fi     
