#*************************************************************************
#
#  Set up variables and flags
#
#*************************************************************************

options  +lEeFscC

PS1         = '$_ANSI_P3[$PWD]: $_ANSI_P1'
PS2         = '$_ANSI_P3> $_ANSI_P1'
PNPC        = 21
LOGOUT      = 'echo "\nBye!\n"'
LLMIN       = 4
MAXDIST     = 5
ROOT        = ':'

_ANSI_BS    = "^[[1m"
_ANSI_BE    = "^[[m"
_ANSI_IS    = "^[[3m"
_ANSI_IE    = "^[[m"
_ANSI_US    = "^[[4m"
_ANSI_UE    = "^[[m"
_ANSI_P1    = "^[[0;31;40m"
_ANSI_P2    = "^[[0;32;40m"
_ANSI_P3    = "^[[0;33;40m"
_ANSI_CLEAR = "^[[H^[[2J"

_DIR_S      = "$_ANSI_P3"
_DIR_E      = "$_ANSI_P1"

#*************************************************************************
#
#  Set up sksh aliases
#
#*************************************************************************

alias    unalias   = 'unset -a'
alias    unfunc    = 'unset -f'
alias    aliases   = 'set -a'
alias    functions = 'set -f'
alias    variables = 'set -v'
alias    builtins  = 'set -b'
alias    help      = 'set -bfa'
alias    logout    = 'exit 0'
alias    pwd       = 'echo "$PWD"'
alias    clear     = 'echo -n $_ANSI_CLEAR'
alias    cls       = 'echo -n $_ANSI_CLEAR'
alias    ctpri     = 'ChangeTaskPri'
alias    '.'       = 'source'
alias    quit      = 'LOGOUT=""; exit'

if [ "$SIZE" = 'normal' ]    # large version only...
then
   alias makedir   = 'mkdir'
   alias delete    = 'rm'
   alias remove    = 'rm'
   alias '!'       = 'history -e'
   alias '!!'      = 'history -e -1'
   alias ll        = 'ls -lbF'
   alias dir       = 'ls -bF'
fi


#*************************************************************************
#
#  Set up sksh functions
#
#*************************************************************************

function path {   # set or examine path

    local component;

    if [ $# -eq 0 ]
    then
        echo "$PATH";
    elif [ "$1" = "-add" -o "$1" = "add" ]
    then
        shift
        for component in $* do

            if [ $( expr index "$PATH," "$component," ) -eq 0 ]
            then
                PATH = "$PATH,$component"
            fi

        done
    else
        PATH = "$1"
    fi

    export PATH
}

function run {  # run a program, searching the SKsh $PATH
    local prog loc

    prog = $1
    shift

    loc = $(which -s $prog)

    if [ -z "$loc" ]
    then
       echo "$prog not found."
    else 
       c:run $loc $*
    fi
}

function stack {  # set or change stack size

    if [ $# -eq 0 ]
    then
       c:stack
       return
    fi

    if [ $1 -lt 4000 -o $1 -gt 128000 ]
    then
       echo "Invalid stack size.  Use 4000 to 128000"
       return
    fi

    c:stack $(expr $1 + 10000)
}
