#!/bin/sh

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

# This file is part of an application of SAM for GNU/Linux Slackware
# known as SAM-GLS.

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

# (Slackware is a registered trademark of Patrick Volkerding and
# Slackware Linux, Inc.)



### Here are some configuration instructions and code.  In it I tell
### you what you can and can't change.  I need to clarify.
###
### Comments such as "Don't touch", "DT" or "OK to change" in this file
### are not meant affect your rights in the manner of a license. 
### Instead these comments are a guide.  They are meant as an aid to
### help you find success in your use of SAM.
###
### SAM can be used "as is" or, alternatively, you can make changes on
### different levels. 
###
### What I mean is that if you were to "peel off" the outer layers of
### code (embodied in /opt/SAM/begin and /opt/SAM/go/sam1) what is
### under it would still work.  In other words you could invoke this
### script directly.  You would have to export some variables and maybe
### make some other preparations by hand, but it would work.  I know
### that, because that's how SAM worked at one point in the past.
###
### Having peeled off those layers, you could proceed to modify SAM
### further.  This could involve making the changes I've suggested in
### here.  Although this is not something that you should consider in
### the normal use of SAM, it was my intention that daring souls would
### succeed in making changes if my advice was followed.  To do this
### would be to revert to a time when SAM had not yet congealed and was
### somewhat jelly-like.  Please be aware that in going on such an
### adventure, fruitful as it may be, you are blazing a trail in the
### wilderness.  If you try such a thing, please let me know how it
### goes.



# Joseph Rosevear 100112 I made this (called "sam") from sam1 with a
# bit of generalization.  It now uses ${1} to represent the "sam
# number" (e.g., sam 1, sam 2, etc.).  Because this is essentially the
# same file as sam1, I kept the previous dates in the copyright notice.

# In particular there were four changes:  The title "sam" (was sam1),
# "export sam_file=sam $1" (was "sam1"), "export
# sam_temp_dir=$sam_temp_base/temp${1}" (was "$sam_temp_base/temp1"),
# and "shift" at the end of this file (there was no shift before).

# Joseph Rosevear 110112 I changed some comments.  Before I encouraged
# the user to make changes to this file.  I qualified those
# encouragements with warning and explanation.

# Joseph Rosevear 110114 I removed the definition of sam_env from this
# file.  It is now the user's resposibility to set and export this
# variable before running this script.

# Joseph Rosevear 110115 I fixed a bug.  I put in quotes around a
# variable evaluation, and for consistancy I quoted the variable again
# in the next line.  The code now reads like this:

#    if [ -r "$sam_env" ]; then
#        source "$sam_env"
#    fi

# Without the change the evaluation was coming up true when it
# shouldn't.

# Joseph Rosevear 110818 I replaced "source" with "." to improve POSIX
# compliance.

# Joseph Rosevear 111231 I replaced #!/bin/sh with #!/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 180407 I made minor edits to comments.

# Joseph Rosevear 180407 I removed $sam_temp_dir from the definition of
# pold.

# This

#    export pold=$sam:$sam_temp_dir:$sam_tool:$glos

# became this

#    export pold=$sam:$sam_tool:$glos

# I did this, because I decided that I hadn't been making use of
# $sam_temp_dir being in PATH.  Furthermore, it doesn't seem to me
# (today) like a good idea to have it in the path.  What was I
# thinking?  I hope I haven't broken any existing scripts by doing
# this.



###############################################################################
### Please set this to the name of this file, followed as shown by "$1".      #
export sam_file="sam $1"                 # This file is also called a Go file #
###############################################################################
### First, since SAM can be used recursively, we need to prepare for the      #
### chance that this is a nested invocation of SAM.  SAM uses functions for   #
### its own purposes and it defines functions for you from $level (menus) and #
### from $sam_tool.                                                           #
###                                                                           #
### (SAM's own functions are "dofun" and functions that end in ".f".  The     #
### functions of $sam_tool should also end in ".f".  The functions from       #
### $level should end in ".sam".)                                             #
###                                                                           #
### A nested invocation of SAM (starting SAM from inside SAM) will inherit    #
### all these functions.  This is bad.  SAM's functions should correspond to  #
### the SAM program, $sam_tool, and $level.  Inherited functions did          #
### correspond in the previous session, but this is not necessarily so in the #
### nested session.  So we need to wipe them clean.  This is done by funtions #
### $sam_temp_dir/unfun and $sam_temp_dir/funfun.  (unfun wipes ".sam" and    #
### funfun wipes ".f".  Nothing wipes dofun.) This wiping is done by          #
### referencing sam_temp_dir, so we need its current value.  That is why I    #
### say this:                                                                 #
###                                                                           #
###    Please do not change sam_temp_dir before this point in the invocation  #
###    of SAM.  If you do, the correct unfun and funfun won't be found, the   #
###    wiping won't be done correctly, and nested SAM sessions could inherit  #
###    stray functions. It's OK to define sam_temp_dir below.  It has a       #
###    section in this file.                                                  #
###                                                                           #
### Let's wipe:                                                               #
###                                                                           #
if [ -r $sam_temp_dir/unfun ]; then                                           #
. $sam_temp_dir/unfun; fi                                                     #
###                                                                           #
if [ -r $sam_temp_dir/funfun ]; then                                          #
. $sam_temp_dir/funfun; fi                                                    #
###                                                                           #
unset dofun                                                                   #
###############################################################################
### This section is for you to define the four directories used by SAM. It is #
### your responsibility to see that these directories exist and contain the   #
### right stuff.                                                              #
###                                                                           #
export sam=$sam_distro/sam                # where SAM lives,    OK to change  #
export sam_go=$sam_distro/go              # contains this file, OK to change  #
###                                                                           #
### Note that sam_temp_base must defined by you (before this script runs) in  #
### your .profile or where ever you like.                                     #
###                                                                           #
### Checking sam_temp_base a default value ...                                #
if [ ! -d "$sam_temp_base" ]; then                           #   Don't touch  #
   echo "$sam_file: \$sam_temp_base ($sam_temp_base) is not a directory" #DT  #
   exit                                                      #   Don't touch  #
fi                                                           #   Don't touch  #
if [ ! -w "$sam_temp_base" ]; then                           #   Don't touch  #
   echo "$sam_file: \$sam_temp_base ($sam_temp_base) is not writeable"   #DT  #
   exit                                                      #   Don't touch  #
fi                                                           #   Don't touch  #
###                                                                           #
export sam_temp_dir=$sam_temp_base/temp${1}  # used by SAM      OK to change  #
export sam_tool=$sam_distro/tool             # always in $PATH  OK to change  #
###############################################################################
### These three variables have special meanings as noted.  They should be     #
### either "unset" or "exported".  For example...                             #
###         unset sam_menu         or...                                      #
###         export sam_menu=/opt/SAM/go/custom                                #
### In the first case above the default ($sam/menu) code will be used         #
### In the second case /opt/SAM/go/custom will be assumed to be the menu      #
### code.                                                                     #
###                                                                           #
### sam_message works the same way.  This is the message that SAM gives on    #
### exiting.  The default is coded into $sam/sam_core.                        #
###                                                                           #
### If $sam_view exists and is readable, then it is run by the script (also   #
### named) sam_view.  If $sam_view does not exist, then the script sam_view   #
### knows what to do.                                                         #
unset  sam_menu                                                               #
unset  sam_message                                                            #
unset  sam_view                                                               #
###############################################################################
### This is an important variable.  The letters "glos" mean GNU/Linux         #
### Operating System.  It is the path you provide to GNU/Linux so it can find #
### what it needs. You may set it to whatever you choose, but a good choice   #
### is just $PATH which is the path GNU/Linux was using before you started    #
### SAM.  SAM will add to this some other places to create pold (old path),   #
### and then it will later use pold dynamically to modify the path in a way   #
### that really is the heart of what SAM does.                                #
###                                                                           #
### You may leave the code below as is if you desire.  There is no need to    #
### change it.  The way it is now SAM will inherit whatever PATH was in use   #
### before the first instance of SAM was started.  Subsequent instances will  #
### get the same PATH.                                                        #
###                                                                           #
### If you want to change the line below, go ahead--you're on your own.       #
if [ "$glos" = "" ]; then export glos=$PATH; fi                               #
###############################################################################
### Do not change anything here.  If you want to change the script which will #
### run below, do so by changing the definition of sam_env above.             #
###                                                                           #
### This script, $sam_env, is meant as an easy, non-invasive way to modify    #
### the above variables (except for sam_env) or do other start up tasks.  If  #
### the script exists as a readable file, then any values given to variables  #
### in it will replace the values given above.                                #
if [ -r "$sam_env" ]; then                                                    #
    . "$sam_env"                                                              #
fi                                                                            #
###############################################################################
### Here's some more stuff which is mostly don't touch...                     #
###                                                                           #
export pold=$sam:$sam_tool:$glos                           # Don't touch      #
export PATH=$pold                                          # Don't touch      #
export sam_symbol=":)"                                     # OK, if you must  #
export sam_bye_command=exit                                # Don't touch      #
unset  level                                               # Don't touch      #
unset  sam_add                                             # Don't touch      #
export sam_env_num=0                                       # Don't touch      #
###                                                                           #
if [ "$sh_flag" = "sh" ]; then export sam_symbol=:x; fi    # OK, if you must, #
# but make a corresponding change to $sam_tool/love.f                         #
###                                                                           #
export PS1="\n$sam_file:$level $sam_env_num$sam_symbol\n\u@\h:\w\$ " # OK,    #
# if you must, but make the same change in $sam/sam_shel.f and $sam/push.f    #
###############################################################################
### Don't change these lines.                                                 #
shift                                                                         #
. $sam/sam_core                                                               #
###############################################################################
