### Copyright (C) 1996 Per Zacho
### This program 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 2 of the License, or
### (at your option) any later version.
###
### This program 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, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc errorHandling {} {
    # System<->Bash interface / Error handling

    Desc "This configuration page will help you to setup how Bash is to react upon certain"\
	"exceptions like unknown variables, failing to execute a command/program, etc."

    ShortDesc "Error handling"

    ### Error handling ###

    Header head1 -text "Error handling"\
	-background gray\
	-help "Setup of how Bash is to handle certain exceptions."

    CheckBox nounset -text "Treat undefined variables as errors"\
	-help "If you (or a script) try to read an undefined variable, Bash normally"\
	"expand the variable to a null-string. If this option is checked, reading"\
	"undefined variables will cause Bash to halt with a message \"unbound variable\""

    CheckBox exitOnFail -text "Non-interactive shell exit if 'exec'-call fails"\
	-default 1\
	-help "If the built-in call \"exec\" fails, Bash will not exit in an"\
	"interactive shell (e.g. your login-shell). But if you call shell scripts"\
	"you can specify if the shell is to exit if the \"exec\"-call fails. It can"\
	"be usefull to keep the shell when debugging shell scripts, but normally"\
	"you would leave this option checked."

    CheckBox errExit -text "Exit shell if 'simple' command fails"\
	-help "A simple command is a command not part of a \"while\", \"until\" or \"if\";"\
	"or part of a \"&&\" or \"||\"; or a command whose return value is inverted by \"!\"."

    CheckBox shiftErr -text "Halt if 'shift'-ing exceeds number of arguments"\
	-help "If checked, the \"shift\" built-in prints an error message when the shift"\
	"count exceeds the number of positional parameters. (This option is available"\
	"in Bash version 2.0 only)"

    ShowPage {
	if {[set version@bash(index)]} {
	    Enable shiftErr
	} {
	    Disable shiftErr
	}
    }

    Save {
	### Error handling ###
	if {$nounset || $generateDefault} {
	    print "set [pick $nounset - +]o nounset"
	}

	if {$exitOnFail != 1 || $generateDefault} {
	    if [set version@bash(index)] {
		print "shopt -[pick $exitOnFail u s] execfail"
	    } {
		print "[pick $exitOnFail "unset no_exit_on_failed_exec" "export no_exit_on_failed_exec=on"]"
	    }
	}

	if {$errExit || $generateDefault} {
	    print "set [pick $errExit - +]o errexit"
	}

	if {($shiftErr || $generateDefault) && [set version@bash(index)]} {
	    print "shopt -[pick $shiftErr s u] shift_verbose"
	}
    }
}
