####################################################
# by wiebe @ QuakeNet
#
#
####################################################

# what directory to load scripts from
set loadall(dir) "scripts/test/"

# what file pattern to load
set loadall(file) "*.tcl"



####################################################
# loadall
####################################################
if {![info exists loadall(dir)]} { set loadall(dir) "scripts/" }
if {![string match "*/" $loadall(dir)]} { append loadall(dir) "/" }
if {![info exists loadall(file)]} { set loadall(file) "*.tcl" }
if {![file exists $loadall(dir)]} {
  putlog "LOADALL: $loadall(dir) does not exist"
} elseif {![file isdirectory $loadall(dir)]} {
  putlog "LOADALL: $loadall(dir) is not a directory"
} elseif {![file readable $loadall(dir)]} {
  putlog "LOADALL: $loadall(dir) is not readable"
} elseif {[catch {glob "$loadall(dir)$loadall(file)"} loadallz]} {
  putlog "LOADALL: no files to load from $loadall(dir) matching $loadall(file)"
} else {
  set loadallc 0; set loadallt 0; set loadallx 0; set loadalle ""
  foreach loadalls [lsort $loadallz] {
    if {![file exists $loadalls]} { continue }
    if {![file isfile $loadalls]} { continue }
    if {![file readable $loadalls]} { continue }
    if {[string equal $loadalls [info script]]} { continue }
    if {[catch {source $loadalls} loadalle]} {
      putlog "LOADALL: error loading $loadalls \"$loadalle\""
    } else {
      incr loadallc 1; set loadallf [open $loadalls r]
      set loadalld [llength [split [read $loadallf] \n]];incr loadallx $loadalld;close $loadallf
      putlog "LOADALL: loaded $loadalls (lines $loadalld)"
    }
    incr loadallt 1
  }
  putlog "LOADALL: loaded $loadallc / $loadallt scripts from $loadall(dir) (lines $loadallx)"
  unset loadallc loadalld loadalle loadallf loadalls loadallt loadallx loadallz
}

