#!/usr/local/bin/wish4.0

wm withdraw .

## begin boiler_header

global VERSION
set VERSION {3.6/2.0+}

if {[info exists env(JSTOOLS_LIB)]} {
  set jstools_library $env(JSTOOLS_LIB)
} else {
  set jstools_library /usr/local/lib/jstools
}

# add the jstools library to the library search path:

set auto_path [concat [list $jstools_library] $auto_path]

# check for ~/.tk and prepend it to the auto_path if it exists.
# that way the user can override and customise the jstools libraries.

if {[file isdirectory ~/.tk]} then {
  set auto_path [concat [list [glob ~/.tk]] $auto_path]
}

## end boiler_header

j:jstools_init

foreach file [lsort [glob *.jdoc]] {
  set t [jedit:top_to_text [jedit:jedit -file $file]]
  update
  regsub -- {\.jdoc$} $file .html html
  if {1 || [j:confirm -priority 100 -text "Convert $file to $html?"]} {
    j:fileio:write $html [j:tc:html:convert_text $t]
  }
  destroy [winfo toplevel $t]
  set jed_icons 0
}

j:alert -text "All done!"
exit 0
