#!/usr/local/bin/wish
# convert templates to auto_load able templates
set TMPLT_ROOT ./templates

catch "exec mkdir $TMPLT_ROOT"
catch "exec mkdir $TMPLT_ROOT/autoProcedures"

# read file
set curDir [pwd]
cd $TMPLT_ROOT/Procedures
set fileList ""
foreach fileName [exec ls] {
  if {[string match *.t $fileName]} {
    lappend fileList $fileName
  }
}
foreach fileName $fileList {
  puts stdout "converting: $fileName"
  set inFd [open $fileName r]
  set fileContents [read $inFd]
  close $inFd
  set outFd [open ../autoProcedures/$fileName w]
  regsub -all "# xf ignore me 0" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 1" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 2" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 3" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 4" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 5" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 6" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 7" $fileContents "# xf ignore me 9" fileContents
  regsub -all "# xf ignore me 8" $fileContents "# xf ignore me 9" fileContents
  puts $outFd $fileContents
  close $outFd
}
auto_mkindex ../autoProcedures *.t

exit
