#!/bin/sh

# menu
# Copyright (C) 2025 Joseph Rosevear, San Diego CA, USA.

# This file is part of a distribution SAM.

# SAM 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.

# SAM 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 I wrote this script.

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

# I removed the code for the "invisible backbone".

# Joseph Rosevear 230517 I changed the name of this script from menu to
# menu0.

# Joseph Rosevear 230517 I changed the code so the contents of sam_add
# are always displayed, instead of conditionally.

# Joseph Rosevear 230522 I changed the path to copyr.dat.

# Joseph Rosevear 230522 I changed the name of this script back to
# "menu".

# Joseph Rosevear 230526 I removed some comented-out lines.

# I added code so "cat $menu/menu.dat" won't be executed when
# "$menu/menu.dat" doesn't exist as a readable file.



# Definitions.
request="$1"

if [ "$request" = "" ]; then

   menu="$level"

else

   menu="$request"
fi

(
   echo ""

   echo -e "added:\n\n`shoparts sam_add`"
   echo ""
   
   echo -e "${menu}:\n"
   
   echo  " COMMAND       DESCRIPTION"
   
   if [ -r "$menu/menu.dat" ]; then
   
      cat $menu/menu.dat
   fi
   
   echo ""
   cat $sam_root/kernel/data/copyr.dat
   echo ""
) > $sam_temp_dir/view.dat

sam_view $sam_temp_dir/view.dat
echo ""
