### 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 path {} {
    # System<->Bash interface / Paths

    Desc "This configuration page will help you to setup command-, CD- and manualpaths."

    ShortDesc "Paths"

    ### Command path ###

    Header head1 -text "Command path"\
	    -background gray\
	    -help "Setup of command path--where to search for commands/programs (executables)."

    Dir-Browser comPathEntry -text "Path"
    ExtEntry comPath -text ""\
	    -entries frame_comPathEntry\
	    -help "This is the path, where a command/program can be found. Remember to"\
	    "write the complete name of each element in the path, including the prefix slash (/)."\
	    -export 0

    Command readComPath -setvalue {$widget configure -text "Load path from system"}\
	    -invoke {
	if {[info exists env(PATH)]} {
	    foreach elm [split $env(PATH) ":"] {
		AddTuple comPath
		set comPathEntry $elm
		set com_comPathEntry $elm
	    }
        }
    }
	    
    ### CD path ###

    Header head2 -text "\"Change Directory\" path"\
	    -background gray\
	    -help "Setup of where \"cd\" is to search for subdirs."

    Dir-Browser cdPathEntry -text "Path"
    ExtEntry cdPath -text ""\
	-entries frame_cdPathEntry\
	-help "This is the path, where a specific subdir can be found. Remember to"\
	"write the complete name of each element in the path, including the prefix slash (/)."\
	-export 0

    ### Manual path ###

    Header head3 -text "Manual path"\
	    -background gray\
	    -help "Setup of where \"man\" is to search for manual pages."

    Dir-Browser manPathEntry -text "Path"
    ExtEntry manPath -text ""\
	-entries frame_manPathEntry\
	-help "This is the path, where manual pages can be found. Remember to"\
	"write the complete name of each element in the path, including the prefix slash (/)."\
	-export 0

    Command readManPath -setvalue {$widget configure -text "Load path from system"}\
	    -invoke {
	if {[info exists env(MANPATH)]} {
	    foreach elm [split $env(MANPATH) ":"] {
		AddTuple manPath
		set manPathEntry $elm
		set com_manPathEntry $elm
	    }
        }
    }

    ### Security precautions ###

    Header head4 -text "Security precautions"\
	    -background gray

    Label label1 -text "When setting up your command/program path,\nplease bear in mind, that putting your personal 'bin'\n(or any other of your directories, for that sake)\ndirectory in front of the path, will cause a security\nbreach. Therefore, append new directories at\nthe end of the path."

    Save {
	### Command path ###
	set temp ""
	forevery comPath {
	    if {$comPathEntry != ""} {
		append temp "$comPathEntry:\\\n"
	    }
	}
	set temp [string trim $temp ":\\\n"]
	if {$temp != ""} {
	    print "PATH=\\\n$temp"
	    print "export PATH"
	}

	### CD path ###
	set temp ""
	forevery cdPath {
	    if {$cdPathEntry != ""} {
		append temp "$cdPathEntry:\\\n"
	    }
	}
	set temp [string trim $temp ":\\\n"]
	if {$temp != ""} {
	    print "CDPATH=\\\n$temp"
	    print "export CDPATH"
	}

	### Manual path ###
	set temp ""
	forevery manPath {
	    if {$manPathEntry != ""} {
		append temp "$manPathEntry:\\\n"
	    }
	}
	set temp [string trim $temp ":\\\n"]
	if {$temp != ""} {
	    print "MANPATH=\\\n$temp"
	    print "export MANPATH"
	}
    }
}


