### 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 fileDir {} {
    # System<->Bash interface / File and directory handling

    Desc "This configuration page will help you to setup how Bash is to create files and"\
    "directories, handle links, etc."

    ShortDesc "File/directory handling"

    ### File/directory creation ###

    Header head1 -text "File/directory creation"\
	    -background gray\
	    -help "Setup on how files and directories are created."

    CheckBox noclobber -text "Allow redirected output overwriting existing files"\
	    -default 1\
	    -help "When redirecting output (with >, >& and <>), you can make sure existing files"\
	    "will not be overwritten. That is, you can still use >! to force an overwriting."

    Line line1

    ###

    Label userLabel -text "User"\
	    -help "File/dir permissions for user (creator)."\
	    -height 2

    Label groupLabel -text "Group"\
	    -help "File/dir permission for persons in the same \"group\" as you."\
	    -height 2

    Label otherLabel -text "Other"\
	    -help "File/dir permission for other persons (i.e. persons not in the same group"\
	    "as you)."\
	    -height 2

    array set readList {User 1 Group 1 Other 1}
    array set writeList {User 1 Group 0 Other 0}
    array set executeList {User 1 Group 1 Other 1}

    foreach elm {User Group Other} {
	CheckBox read$elm -text "Read file\nRead dir"\
		-help "When checked, persons (user, group or others) are allowed to read"\
		"your files/directories."\
		-default $readList($elm)

	CheckBox write$elm -text "Write file\nWrite in dir"\
		-help "When checked, persons (user, group or others) are allowed to"\
		"(over)write files or for directories, allowed to create files."\
		-default $writeList($elm)

	CheckBox execute$elm -text "\ncd to dir"\
		-help "When checked, persons (user, group or others) are allowd to \"change"\
		"dir\" to your directory. This option has no influence on files--you cannot"\
		"create files with execute permission."\
		-default $executeList($elm)
    }

    Frame label -text ""\
	    -entries {userLabel groupLabel otherLabel}\
	    -orient top
    Frame read -text ""\
	    -entries {readUser readGroup readOther}\
	    -orient top
    Frame write -text ""\
	    -entries {writeUser writeGroup writeOther}\
	    -orient top
    Frame execute -text ""\
	    -entries {executeUser executeGroup executeOther}\
	    -orient top

    Frame umask -text ""\
	    -entries {label read write execute}


    ### Directory options ###

    Header head2 -text "Directory options"\
	    -background gray\
	    -help "Setup of how to handle directory links and variables."

    Radio links -text "How is Bash to follow directory links?"\
	    -entryhelp {"logically" "Follow the link, but use link name as directory name."\
	    "physically"\
	    "Follow the link, but change the current working directory to the physical path."}\
	    -help "This option influence on how Bash will set current working directory. If set"\
	    "to physical, \"cd\"-ing a symbolic directory link and then returning via \"cd ..\""\
	    "might not return you to where you started--which you are insured if you choose"\
	    "following links logically."\
	    -packFrame:fill x

    Line line2

    CheckBox cdvars -text "\"cd\" allow variables as argument"\
	    -help "\"cd\" will usually try to find the subdir specified (if set, by searching"\
	    "through the CDPATH). If failing this, return unsuccessfully. But if this option"\
	    "is checked another task is included before failing--\"cd\" will check to see"\
	    "if a variable is specified with a similar name as the argument, and that variable"\
	    "contains a valid directory path.\nUsing normal variable expansion (prefix \$)"\
	    "will give the same result, even if the option is not checked. The main difference"\
	    "is \"cd\" is able to expand and check the variable contains for a valid directory"\
	    "structure, before executing--and that without prefix a \$ to the variable."

    CheckBox cdspell -text "\"cd\" guess directory name if misspelled"\
	    -help "If set, minor errors in the spelling of a directory component in a cd command"\
	    "will be corrected. The errors checked for are transposed characters, a missing"\
	    "character, and one character too many. If a correction is found, the corrected"\
	    "file name is printed, and the command proceeds. This option is enabled by default,"\
	    "but is only used by interactive shells. (This option is available in Bash version"\
	    "2.0 only)"\
	    -default 1

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

    Save {
	### File/directory creation ###
	if {$noclobber == 0 || $generateDefault} {
	    print "set [pick $noclobber + -]o noclobber"
	}

	foreach elm {User Group Other} {
	    set $elm [expr (![set read$elm])*4 + (![set write$elm])*2 + ![set execute$elm]]
	}
	set permission "$User$Group$Other"
	if {$permission != "022" || $generateDefault} {
	    print "umask $permission"
	}

	### Directory options ###
	if {$links(index) || $generateDefault} {
	    print "set [pick $links(index) - +]o physical"
	}

	if {$cdvars || $generateDefault} {
	    if [set version@bash(index)] {
		print "shopt -[pick $cdvars s u] cdable_vars"
	    } {
		print "[pick $cdvars "export cdable_vars=on" "unset cdable_vars"]"
	    }
	}

	if {($cdspell != 1 || $generateDefault) && [set version@bash(index)]} {
	    print "shopt -[pick $cdspell s u] cdspell"
	}
    }
}
