#!/bin/sh

# sam_view
# 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 210810 I changed "less" to "less -c".  I did this for
# the benefit of another script, not in the kernel, which invokes menu. 
# Hopefully, this change will do no harm.

# Joseph Rosevear 230526 I changed:

#    if [ -x "$sam_view" ]; then

# to:

#    if [[ ("$sam_view" != "") && (-x `which "$sam_view"`) ]]; then



if [[ ("$sam_view" != "") && (-x `which "$sam_view"`) ]]; then
   
   $sam_view "$@"

else

   export LESS=-MPM"Using \"less\"\.  Use arrows to scroll\.  Press q to exit\."

   #I put " around the $1 and $2 trying to make it deal better with
   #args that have spaces in them.
   if [ "$2" = "" ]; then
      less -c "$1"
   else
      less -c "+$2" -- "$1" 
   fi
fi
