#!/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/>.



# Joseph Rosevear 111231 I changed #!/bin/sh to #!/bin/bash.

# Joseph Rosevear 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.

# Joseph Rosevear 230517 I changed the code to use shoparts to display
# the contents of sam_add

# I removed the code which displays the other, non-level, parts of the
# menu.

# I revised the menu format.



### 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 -e "added:\n\n`shoparts sam_add`"          >> $sam_temp_dir/view.dat
      echo ""                                         >> $sam_temp_dir/view.dat
   fi

   ### "$1" IS ""
   if [ "$1" = "" ]; then
      echo -e "${level}:\n"                           >> $sam_temp_dir/view.dat
   fi

   ### "$1" is NOT ""
   if [ "$1" != "" ]; then
      echo -e "${1}:\n"                               >> $sam_temp_dir/view.dat
   fi

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

   ### "$1" IS ""
   if [ "$1" = "" ]; then
      cat $level/menu.dat                             >> $sam_temp_dir/view.dat
   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     
