#
# <20220312.1445.09>
#
# This code installs the tkconrc file if needed.
# It also provides a hook for tkconrc to load or
# call functions located in other *.tcl file in this
# "dir" (i.e. where our pkgIndex file is.

package provide tkconrc 22.03.12
#
# First, the tkconrc file:
#
namespace eval tkcon {
  proc tkconrc {} {
    set us [info script]
    set loc [file dir $us]
    if {[file exists $loc/.tkconrc]} {
      # it exists. Where should it be?
      set envHome "HOME"
      set rcfile  "tkcon.cfg"
      
      switch $::tcl_platform(platform) {
	mcaintosh  {set envHome PREF_FOLDER}
	unix       {set rcfile  .tkconrc}
      }
      if {[info exists ::env($envHome)]} {
	set home $::env($envHome)
	if {[file pathtype $home] == "volumerelative"} {
	  # Convert 'C:' to 'C:/' if necessary, innocuous otherwise
	  append home /
	}

	if {![file exists [set drc [file join $home $rcfile]]]} {
	  # Don't have one yet, fix that...
	  # Log "$loc to $drc"
	  if {[namespace exists ::freewrap]} {
	    set sFile [::zvfs::list *$loc/.tkconrc]
	  } else {
	    set sFile $loc/.tkconrc
	    file copy $sFile $drc
	  }
	}
      }
    }
    return $loc
  }
}
# Log "call ::tkcon::tkconrc"
set loc [::tkcon::tkconrc]
if {$loc ni $::auto_path} {
  lappend ::auto_path $loc
}
# Log "require tkcon"
package require tkcon
