#!/home/heller/Deepwoods/HomeLibrarian/bin/LibrWish -f
# Program: TkLibrarian
# Tcl version: 7.3 (Tcl/Tk/XF)
# Tk version: 3.6
# XF version: $__lastrelease$
#

global tklibrpath
#set tklibrpath [join [list TKLIBRPATH {/}] {}]
set tklibrpath {/home/heller/Deepwoods/HomeLibrarian/TkLibrarian/}

# module inclusion
global env
global xfLoadPath
if {[info exists env(XF_LOAD_PATH)]} {
  if {[string first $env(XF_LOAD_PATH) /usr/local/lib/] == -1} {
    set xfLoadPath $env(XF_LOAD_PATH):$tklibrpath:/usr/local/lib/
  } {
    set xfLoadPath $tklibrpath:/usr/local/lib/
  }
} {
  set xfLoadPath $tklibrpath:/usr/local/lib/
}

global argc
global argv
global tk_version
global xfLoadInfo
global xfLoadPath
set xfLoadInfo 0
set tmpArgv ""
for {set counter 0} {$counter < $argc} {incr counter 1} {
  case [string tolower [lindex $argv $counter]] in {
    {-xfloadpath} {
      incr counter 1
      set xfLoadPath "[lindex $argv $counter]:$xfLoadPath"
    }
    {-xfstartup} {
      incr counter 1
      source [lindex $argv $counter]
    }
    {-xfbindfile} {
      incr counter 1
      set env(XF_BIND_FILE) "[lindex $argv $counter]"
    }
    {-xfcolorfile} {
      incr counter 1
      set env(XF_COLOR_FILE) "[lindex $argv $counter]"
    }
    {-xfcursorfile} {
      incr counter 1
      set env(XF_CURSOR_FILE) "[lindex $argv $counter]"
    }
    {-xffontfile} {
      incr counter 1
      set env(XF_FONT_FILE) "[lindex $argv $counter]"
    }
    {-xfmodelmono} {
      if {$tk_version >= 3.0} {
        tk colormodel . monochrome
      }
    }
    {-xfmodelcolor} {
      if {$tk_version >= 3.0} {
        tk colormodel . color
      }
    }
    {-xfloading} {
      set xfLoadInfo 1
    }
    {-xfnoloading} {
      set xfLoadInfo 0
    }
    {default} {
      lappend tmpArgv [lindex $argv $counter]
    }
  }
}
set argv $tmpArgv
set argc [llength $tmpArgv]
unset counter
unset tmpArgv


# procedure to show window .
proc ShowWindow. {args} {# xf ignore me 7

  # Window manager configurations
  global tk_version
  wm sizefrom . ""
  wm maxsize . 1000 768
  wm minsize . 10 10
  wm title . {Librarian (no library database loaded)}


  # build widget .frame0
  frame .frame0 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .frame0.menubutton1
  menubutton .frame0.menubutton1 \
    -menu {.frame0.menubutton1.m}\
    -text {File}\
    -underline {0}

  # build widget .frame0.menubutton1.m
  menu .frame0.menubutton1.m -tearoff 0
  .frame0.menubutton1.m add command\
    -command {LoadLibrary}\
    -label {Load}\
    -underline {0}
  .frame0.menubutton1.m add command\
    -command {Exit}\
    -label {Exit}\
    -underline {1}

  # build widget .frame0.menubutton2
  menubutton .frame0.menubutton2 \
    -menu {.frame0.menubutton2.m}\
    -text {Help}\
    -underline {0}

  # build widget .frame0.menubutton2.m
  menu .frame0.menubutton2.m  -tearoff 0
  .frame0.menubutton2.m add command\
    -command {HelpProc}\
    -label {Help}\
    -underline {0}
  .frame0.menubutton2.m add command\
    -command {VersionProc}\
    -label {On Version...}\
    -underline {3}
  .frame0.menubutton2.m add command\
    -command {CopyingProc}\
    -label {Copying}
  .frame0.menubutton2.m add command\
    -command {WarrantyProc}\
    -label {Warranty}

  # pack widget .frame0
  pack append .frame0 \
    .frame0.menubutton1 {left frame center} \
    .frame0.menubutton2 {right frame center} 

  # build widget .main
  frame .main \
    -borderwidth {2}

  # build widget .main.frame1
  frame .main.frame1 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .main.frame1.quit
  button .main.frame1.quit \
    -command {Exit}\
    -text {Quit}

  # pack widget .main.frame1
  pack append .main.frame1 \
    .main.frame1.quit {top frame center fillx} 

  # build widget .main.frame12
  frame .main.frame12 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .main.frame12.entry9
  entry .main.frame12.entry9 \
    -relief {sunken}
  # bindings
  bind .main.frame12.entry9 <Key-Return> {ListTitles [%W get]}

  # build widget .main.frame12.label8
  label .main.frame12.label8 \
    -text {Search Titles: }

  # pack widget .main.frame12
  pack append .main.frame12 \
    .main.frame12.label8 {left frame center} \
    .main.frame12.entry9 {left frame center expand fillx} 

  # build widget .main.frame13
  frame .main.frame13 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .main.frame13.entry9
  entry .main.frame13.entry9 \
    -relief {sunken}
  # bindings
  bind .main.frame13.entry9 <Key-Return> {ListAuthors [%W get]}

  # build widget .main.frame13.label8
  label .main.frame13.label8 \
    -text {Search Authors: }

  # pack widget .main.frame13
  pack append .main.frame13 \
    .main.frame13.label8 {left frame center} \
    .main.frame13.entry9 {left frame center expand fillx} 

  # build widget .main.frame14
  frame .main.frame14 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .main.frame14.entry9
  entry .main.frame14.entry9 \
    -relief {sunken}
  # bindings
  bind .main.frame14.entry9 <Key-Return> {ListSubjects [%W get]}

  # build widget .main.frame14.label8
  label .main.frame14.label8 \
    -text {Search Subjets: }

  # pack widget .main.frame14
  pack append .main.frame14 \
    .main.frame14.label8 {left frame center} \
    .main.frame14.entry9 {left frame center expand fillx} 

  # build widget .main.frame2
  frame .main.frame2 \
    -borderwidth {2}\
    -relief {raised}

  # build widget .main.frame2.entry9
  entry .main.frame2.entry9 \
    -relief {sunken}
  # bindings
  bind .main.frame2.entry9 <Key-Return> {ListCards [%W get]}

  # build widget .main.frame2.label8
  label .main.frame2.label8 \
    -text {Search Cards: }

  # pack widget .main.frame2
  pack append .main.frame2 \
    .main.frame2.label8 {left frame center} \
    .main.frame2.entry9 {left frame center expand fillx} 

  # pack widget .main
  pack append .main \
    .main.frame1 {top frame center fill} \
    .main.frame2 {top frame center fill} \
    .main.frame12 {top frame center fill} \
    .main.frame13 {top frame center fill} \
    .main.frame14 {top frame center fill} 

  # pack widget .
  pack append . \
    .frame0 {top frame center fillx} \
    .main {top frame center fill} 

  if {"[info procs XFEdit]" != ""} {
    XFEditSetShowWindows
    XFMiscBindWidgetTree .xfEdit
  }

  global tk_version
  if {$tk_version >= 3.0} {
    tk_menuBar .frame0 .frame0.menubutton1 .frame0.menubutton2
  } {
    tk_menus . .frame0.menubutton1 .frame0.menubutton2
  }

  .main.frame12.entry9 insert end {}
  .main.frame13.entry9 insert end {}
  .main.frame14.entry9 insert end {}
  .main.frame2.entry9 insert end {}


}


# User defined procedures


# Procedure: AlertBox
proc AlertBox { {alertBoxMessage "Alert message"} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBox
# Description: show alert box
# Arguments: {alertBoxMessage} - the text to display
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBoxFile - to open and read a file automatically
#          AlertBoxFd - to read from an already opened filedescriptor
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxFd
proc AlertBoxFd { {alertBoxInFile ""} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBoxFd
# Description: show alert box containing a filedescriptor
# Arguments: {alertBoxInFile} - a filedescriptor to read. The descriptor
#                               is closed after reading
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBox - to display a passed string
#          AlertBoxFile - to open and read a file automatically
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # check file existance
  if {"$alertBoxInFile" == ""} {
    puts stderr "No filedescriptor specified"
    return
  }

  set alertBoxMessage [read $alertBoxInFile]
  close $alertBoxInFile

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxFile
proc AlertBoxFile { {alertBoxFile ""} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBoxFile
# Description: show alert box containing a file
# Arguments: {alertBoxFile} - filename to read
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBox - to display a passed string
#          AlertBoxFd - to read from an already opened filedescriptor
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # check file existance
  if {"$alertBoxFile" == ""} {
    puts stderr "No filename specified"
    return
  }

  if {[catch "open $alertBoxFile r" alertBoxInFile]} {
    puts stderr "$alertBoxInFile"
    return
  }

  set alertBoxMessage [read $alertBoxInFile]
  close $alertBoxInFile

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxInternal
proc AlertBoxInternal { alertBoxMessage alertBoxCommand alertBoxGeometry alertBoxTitle args} {
# xf ignore me 6
  global alertBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  if {"$alertBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$alertBox(activeBackground)\" "
  }
  if {"$alertBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$alertBox(activeForeground)\" "
  }
  if {"$alertBox(background)" != ""} {
    append tmpButtonOpt "-background \"$alertBox(background)\" "
    append tmpFrameOpt "-background \"$alertBox(background)\" "
    append tmpMessageOpt "-background \"$alertBox(background)\" "
  }
  if {"$alertBox(font)" != ""} {
    append tmpButtonOpt "-font \"$alertBox(font)\" "
    append tmpMessageOpt "-font \"$alertBox(font)\" "
  }
  if {"$alertBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$alertBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$alertBox(foreground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $alertBox(toplevelName)}
  } {
    catch {destroy $alertBox(toplevelName)}
  }
  toplevel $alertBox(toplevelName)  -borderwidth 0
  catch "$alertBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $alertBox(toplevelName) $alertBoxGeometry"]} {
    wm geometry $alertBox(toplevelName) 350x150
  }
  wm title $alertBox(toplevelName) $alertBoxTitle
  wm maxsize $alertBox(toplevelName) 1000 1000
  wm minsize $alertBox(toplevelName) 100 100
  # end build of toplevel

  message $alertBox(toplevelName).message1  -anchor "$alertBox(anchor)"  -justify "$alertBox(justify)"  -relief raised  -text "$alertBoxMessage"
  catch "$alertBox(toplevelName).message1 config $tmpMessageOpt"

  set xfTmpWidth  [string range $alertBoxGeometry 0 [expr [string first x $alertBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch "$alertBox(toplevelName).message1 configure  -width [expr $xfTmpWidth-10]"
  } {
    $alertBox(toplevelName).message1 configure  -aspect 1500
  }

  frame $alertBox(toplevelName).frame1  -borderwidth 0  -relief raised
  catch "$alertBox(toplevelName).frame1 config $tmpFrameOpt"

  set alertBoxCounter 0
  set buttonNum [llength $args]
  if {$buttonNum > 0} {
    while {$alertBoxCounter < $buttonNum} {
      button $alertBox(toplevelName).frame1.button$alertBoxCounter  -text "[lindex $args $alertBoxCounter]"  -command "
          global alertBox
          set alertBox(button) $alertBoxCounter
          if {\"\[info commands XFDestroy\]\" != \"\"} {
            catch {XFDestroy $alertBox(toplevelName)}
          } {
            catch {destroy $alertBox(toplevelName)}
          }"
      catch "$alertBox(toplevelName).frame1.button$alertBoxCounter config $tmpButtonOpt"

      pack append $alertBox(toplevelName).frame1  $alertBox(toplevelName).frame1.button$alertBoxCounter {left fillx expand}

      incr alertBoxCounter
    }
  } {
    button $alertBox(toplevelName).frame1.button0  -text "OK"  -command "
        global alertBox
        set alertBox(button) 0
        if {\"\[info commands XFDestroy\]\" != \"\"} {
          catch {XFDestroy $alertBox(toplevelName)}
        } {
          catch {destroy $alertBox(toplevelName)}
        }
        $alertBoxCommand"
    catch "$alertBox(toplevelName).frame1.button0 config $tmpButtonOpt"

    pack append $alertBox(toplevelName).frame1  $alertBox(toplevelName).frame1.button0 {left fillx expand}
  }

  # packing
  pack append $alertBox(toplevelName)  $alertBox(toplevelName).frame1 {bottom fill}  $alertBox(toplevelName).message1 {top fill expand}

  if {$alertBox(after) != 0} {
    after [expr $alertBox(after)*1000]  "catch \"$alertBox(toplevelName).frame1.button0 invoke\""
  }
}


# Procedure: CopyingProc
proc CopyingProc {} {
  global CopyingMessage
  if {$CopyingMessage != ""} {
    AlertBoxFile $CopyingMessage "" {500x300}
  }
}


# Procedure: DismisCard
proc DismisCard { handle} {
  catch "$handle delete"
  if {"[info commands XFDestroy]" != ""} {
    catch "XFDestroy .top$handle"
  } else {
    catch "destroy .top$handle"
  }
}


# Procedure: DismisList
proc DismisList { handle } {
  if {"[info commands XFDestroy]" != ""} {
    catch "XFDestroy .$handle"
  } else {
    catch "destroy .$handle"
  }
}


# Procedure: DispAAuth
proc DispAAuth { handle selection} {
  global CurrentLibrary
  set authorid "$selection"
  set ids [$CurrentLibrary readauthorlist "$authorid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    DispACard {} $ids
  } else {
    set title "List of all ids for author $authorid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" DispACard $lines
  }
}


# Procedure: DispACard
proc DispACard { handle selection} {
  global CurrentLibrary
  set cardid [lindex $selection 0]
  set card [$CurrentLibrary readid "$cardid"]
  DispCard $card "$cardid"
}


# Procedure: DispASubj
proc DispASubj { handle selection} {
  global CurrentLibrary
  set subjid "$selection"
  set ids [$CurrentLibrary readsubjectlist "$subjid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    DispACard {} $ids
  } else {
    set title "List of all ids for subject $subjid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" DispACard $lines
  }
}


# Procedure: DispATitle
proc DispATitle { handle selection} {
  global CurrentLibrary
  set titleid "$selection"
  set ids [$CurrentLibrary readtitlelist "$titleid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    DispACard {} $ids
  } else {
    set title "List of all ids for title $titleid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" DispACard $lines
  }
}


# Procedure: DispCard
proc DispCard { handle key} {

  # build widget .top$handle
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .top$handle"
  } {
    catch "destroy .top$handle"
  }
  toplevel .top$handle  -relief {raised}

  # Window manager configurations
  global tk_version
  wm sizefrom .top$handle ""
  wm maxsize .top$handle 1000 768
  wm minsize .top$handle 10 10
  wm title .top$handle "[$handle title]"


  # build widget .top$handle.buttons
  frame .top$handle.buttons  -borderwidth {2}

  # build widget .top$handle.buttons.dismis
  button .top$handle.buttons.dismis  -text {Dismis}  -command "DismisCard $handle"

  # build widget .top$handle.buttons.help
  button .top$handle.buttons.help  -text {Help}  -command {HelpDispCard}

  # pack widget .top$handle.buttons
  pack append .top$handle.buttons  .top$handle.buttons.dismis {left frame center expand fillx}  .top$handle.buttons.help {left frame center expand fillx} 

  # build widget .top$handle.main
  frame .top$handle.main  -borderwidth {2}

  # build widget .top$handle.main.ay
  frame .top$handle.main.ay 

  # build widget .top$handle.main.ay.author
  entry .top$handle.main.ay.author  -relief {sunken}
  # bindings
  bind .top$handle.main.ay.author <Any-Key> {break}

  # build widget .top$handle.main.ay.label15
  label .top$handle.main.ay.label15  -text {,}

  # build widget .top$handle.main.ay.year
  entry .top$handle.main.ay.year  -relief {sunken}
  # bindings
  bind .top$handle.main.ay.year <Any-Key> {break}

  # pack widget .top$handle.main.ay
  pack append .top$handle.main.ay  .top$handle.main.ay.author {left frame center expand fillx}  .top$handle.main.ay.label15 {left frame center}  .top$handle.main.ay.year {left frame center fillx} 

  # build widget .top$handle.main.id
  entry .top$handle.main.id  -relief {sunken}
  # bindings
  bind .top$handle.main.id <Any-Key> {break}

  # build widget .top$handle.main.label12
  label .top$handle.main.label12  -text {}

  # build widget .top$handle.main.m2
  frame .top$handle.main.m2 

  # build widget .top$handle.main.m2.label18
  label .top$handle.main.m2.label18  -text {     }

  # build widget .top$handle.main.m2.m3
  frame .top$handle.main.m2.m3  -borderwidth {2}

  # build widget .top$handle.main.m2.m3.descr
  frame .top$handle.main.m2.m3.descr  -relief {raised}

  # build widget .top$handle.main.m2.m3.descr.scrollbar1
  scrollbar .top$handle.main.m2.m3.descr.scrollbar1  -command ".top$handle.main.m2.m3.descr.description yview" -relief {raised}

  # build widget .top$handle.main.m2.m3.descr.description
  text .top$handle.main.m2.m3.descr.description  -borderwidth {2} -relief {sunken} -wrap {none} -yscrollcommand ".top$handle.main.m2.m3.descr.scrollbar1 set"
  # bindings
  bind .top$handle.main.m2.m3.descr.description <Any-Key> {break} 


  # pack widget .top$handle.main.m2.m3.descr
  pack append .top$handle.main.m2.m3.descr  .top$handle.main.m2.m3.descr.scrollbar1 {right frame center filly}  .top$handle.main.m2.m3.descr.description {top frame center expand fill} 

  # build widget .top$handle.main.m2.m3.pubframe
  frame .top$handle.main.m2.m3.pubframe 

  # build widget .top$handle.main.m2.m3.pubframe.city
  entry .top$handle.main.m2.m3.pubframe.city  -relief {sunken}
  # bindings
  bind .top$handle.main.m2.m3.pubframe.city <Any-Key> {break}

  # build widget .top$handle.main.m2.m3.pubframe.label23
  label .top$handle.main.m2.m3.pubframe.label23  -text {Published by }

  # build widget .top$handle.main.m2.m3.pubframe.publisher
  entry .top$handle.main.m2.m3.pubframe.publisher  -relief {sunken}
  # bindings
  bind .top$handle.main.m2.m3.pubframe.publisher <Any-Key> {break}

  # pack widget .top$handle.main.m2.m3.pubframe
  pack append .top$handle.main.m2.m3.pubframe  .top$handle.main.m2.m3.pubframe.label23 {left frame center}  .top$handle.main.m2.m3.pubframe.publisher {left frame center expand fillx}  .top$handle.main.m2.m3.pubframe.city {left frame center} 

  # build widget .top$handle.main.m2.m3.title
  entry .top$handle.main.m2.m3.title  -relief {sunken}
  # bindings
  bind .top$handle.main.m2.m3.title <Any-Key> {break}

  # build widget .top$handle.main.m2.m3.type
  entry .top$handle.main.m2.m3.type  -relief {sunken}
  # bindings
  bind .top$handle.main.m2.m3.type <Any-Key> {break}

  # build widget .top$handle.main.m2.m3.volframe
  frame .top$handle.main.m2.m3.volframe 

  # build widget .top$handle.main.m2.m3.volframe.label27
  label .top$handle.main.m2.m3.volframe.label27  -text {Volume: }

  # build widget .top$handle.main.m2.m3.volframe.volume
  entry .top$handle.main.m2.m3.volframe.volume  -relief {sunken}
  # bindings
  bind .top$handle.main.m2.m3.volframe.volume <Any-Key> {break}

  # pack widget .top$handle.main.m2.m3.volframe
  pack append .top$handle.main.m2.m3.volframe  .top$handle.main.m2.m3.volframe.label27 {left frame center}  .top$handle.main.m2.m3.volframe.volume {left frame center expand fillx} 

  # pack widget .top$handle.main.m2.m3
  pack append .top$handle.main.m2.m3  .top$handle.main.m2.m3.title {top frame center fillx}  .top$handle.main.m2.m3.type {top frame center fillx}  .top$handle.main.m2.m3.pubframe {top frame center fillx}  .top$handle.main.m2.m3.volframe {top frame center fillx}  .top$handle.main.m2.m3.descr {top frame center fill} 

  # pack widget .top$handle.main.m2
  pack append .top$handle.main.m2  .top$handle.main.m2.label18 {left frame center fill}  .top$handle.main.m2.m3 {left frame center expand fill} 

  # pack widget .top$handle.main
  pack append .top$handle.main  .top$handle.main.id {top frame center fillx}  .top$handle.main.label12 {top frame center fillx}  .top$handle.main.ay {top frame center fillx}  .top$handle.main.m2 {top frame center fillx} 

  # pack widget .top$handle
  pack append .top$handle  .top$handle.main {top frame center fill}  .top$handle.buttons {top frame center fill} 

  .top$handle.main.ay.author insert end "[$handle author]"
  .top$handle.main.ay.year insert end "[$handle year]"
  .top$handle.main.id insert end "$key"
  .top$handle.main.m2.m3.descr.description insert end "[$handle description]"
  .top$handle.main.m2.m3.pubframe.city insert end "[$handle city]"
  .top$handle.main.m2.m3.pubframe.publisher insert end "[$handle publisher]"
  .top$handle.main.m2.m3.title insert end "[$handle title]"
  .top$handle.main.m2.m3.type insert end "[$handle cardtype]"
  .top$handle.main.m2.m3.volframe.volume insert end "[$handle vol]"
}


# Procedure: Exit
proc Exit {} {
  if {![YesNoBox "Really Exit?"]} {
    return
  }
  global CurrentLibrary
  if {$CurrentLibrary != {}} {
    $CurrentLibrary delete
  }
  exit
}



proc FSBox {{fsBoxMessage "Select file:"} {fsBoxFileName ""} {fsBoxActionOk ""} {fsBoxActionCancel ""}} {# xf ignore me 5
##########
# Procedure: FSBox
# Description: show file selector box
# Arguments: fsBoxMessage - the text to display
#            fsBoxFileName - a file name that should be selected
#            fsBoxActionOk - the action that should be performed on ok
#            fsBoxActionCancel - the action that should be performed on cancel
# Returns: the filename that was selected, or nothing
# Sideeffects: none
##########
# 
# global fsBox(activeBackground) - active background color
# global fsBox(activeForeground) - active foreground color
# global fsBox(background) - background color
# global fsBox(font) - text font
# global fsBox(foreground) - foreground color
# global fsBox(extensions) - scan directory for extensions
# global fsBox(scrollActiveForeground) - scrollbar active background color
# global fsBox(scrollBackground) - scrollbar background color
# global fsBox(scrollForeground) - scrollbar foreground color
# global fsBox(scrollSide) - side where scrollbar is located

  global fsBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScaleOpt ""
  set tmpScrollOpt ""
  if {"$fsBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "
  }
  if {"$fsBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "
  }
  if {"$fsBox(background)" != ""} {
    append tmpButtonOpt "-background \"$fsBox(background)\" "
    append tmpFrameOpt "-background \"$fsBox(background)\" "
    append tmpMessageOpt "-background \"$fsBox(background)\" "
  }
  if {"$fsBox(font)" != ""} {
    append tmpButtonOpt "-font \"$fsBox(font)\" "
    append tmpMessageOpt "-font \"$fsBox(font)\" "
  }
  if {"$fsBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$fsBox(foreground)\" "
  }
  if {"$fsBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$fsBox(scrollActiveForeground)\" "
  }
  if {"$fsBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$fsBox(scrollBackground)\" "
  }
  if {"$fsBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$fsBox(scrollForeground)\" "
  }

  if {[file exists [file tail $fsBoxFileName]] &&
      [IsAFile [file tail $fsBoxFileName]]} {
    set fsBox(name) [file tail $fsBoxFileName]
  } {
    set fsBox(name) ""
  }
  if {[file exists $fsBoxFileName] && [IsADir $fsBoxFileName]} {
    set fsBox(path) $fsBoxFileName
  } {
    if {"[file rootname $fsBoxFileName]" != "."} {
      set fsBox(path) [file rootname $fsBoxFileName]
    }
  }
  if {$fsBox(showPixmap)} {
    set fsBox(path) [string trimleft $fsBox(path) @]
  }
  if {"$fsBox(path)" != "" && [file exists $fsBox(path)] &&
      [IsADir $fsBox(path)]} {
    set fsBox(internalPath) $fsBox(path)
  } {
    if {"$fsBox(internalPath)" == "" ||
        ![file exists $fsBox(internalPath)]} {
      set fsBox(internalPath) [pwd]
    }
  }
  # build widget structure

  # build widget .fsbox
  catch "destroy .fsbox"

  toplevel .fsbox
  catch ".fsBox config $tmpFrameOpt"
  # Window manager configurations
  global tk_version
  wm sizefrom .fsbox program
  wm maxsize .fsbox 1000 1000
  wm minsize .fsbox 100 100
  wm title .fsbox {File Select Box}


  # build widget .fsbox.filter
  entry .fsbox.filter -relief {sunken}
  catch ".fsbox.filter config $tmpMessageOpt"

  # build widget .fsbox.selection
  entry .fsbox.selection -relief {sunken}
  catch ".fsbox.selection config $tmpMessageOpt"

  # build widget .fsbox.frame3
  frame .fsbox.frame3 -relief {raised}
  catch ".fsbox.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7
  frame .fsbox.frame3.frame7 -borderwidth {2}
  catch ".fsbox.frame3.frame7 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0
  frame .fsbox.frame3.frame7.frame0 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1
  frame .fsbox.frame3.frame7.frame0.frame1 
  catch ".fsbox.frame3.frame7.frame0.frame1 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame3
  frame .fsbox.frame3.frame7.frame0.frame1.frame3 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8
  listbox .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 \
    -width 20 -height 10 \
    -relief {sunken}\
    -selectmode single\
    -xscrollcommand {.fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 set}\
    -yscrollcommand {.fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 set}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame1.frame3
  pack append .fsbox.frame3.frame7.frame0.frame1.frame3 \
    .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 {left frame center expand fill} 

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame4
  frame .fsbox.frame3.frame7.frame0.frame1.frame4 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame4 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9
  scrollbar .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 \
    -command {.fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 yview}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame1.frame4
  pack append .fsbox.frame3.frame7.frame0.frame1.frame4 \
    .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

  # pack widget .fsbox.frame3.frame7.frame0.frame1
  pack append .fsbox.frame3.frame7.frame0.frame1 \
    .fsbox.frame3.frame7.frame0.frame1.frame3 {left frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame1.frame4 {right frame center filly} 

  # build widget .fsbox.frame3.frame7.frame0.frame2
  frame .fsbox.frame3.frame7.frame0.frame2 -borderwidth {1}
  catch ".fsbox.frame3.frame7.frame0.frame2 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame5
  frame .fsbox.frame3.frame7.frame0.frame2.frame5  -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame5 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10
  scrollbar .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 \
    -command {.fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 xview}\
    -orient {horizontal}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame2.frame5
  pack append .fsbox.frame3.frame7.frame0.frame2.frame5 \
    .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame6
  frame .fsbox.frame3.frame7.frame0.frame2.frame6 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame6 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame6.frame11
  frame .fsbox.frame3.frame7.frame0.frame2.frame6.frame11 \
    -borderwidth {2}\
    -height {13}\
    -width {16}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame2.frame6
  pack append .fsbox.frame3.frame7.frame0.frame2.frame6 \
    .fsbox.frame3.frame7.frame0.frame2.frame6.frame11 {top frame center expand fill} 

  # pack widget .fsbox.frame3.frame7.frame0.frame2
  pack append .fsbox.frame3.frame7.frame0.frame2 \
    .fsbox.frame3.frame7.frame0.frame2.frame5 {left frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame2.frame6 {right frame center filly} 

  # pack widget .fsbox.frame3.frame7.frame0
  pack append .fsbox.frame3.frame7.frame0 \
    .fsbox.frame3.frame7.frame0.frame1 {top frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame2 {bottom frame center fillx} 

  # build widget .fsbox.frame3.frame7.label9
  label .fsbox.frame3.frame7.label9 \
    -text {Directories:}
  catch ".fsbox.frame3.frame7.label9 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame7
  pack append .fsbox.frame3.frame7 \
    .fsbox.frame3.frame7.label9 {top frame w} \
    .fsbox.frame3.frame7.frame0 {top frame center expand fill} 

  # build widget .fsbox.frame3.frame8
  frame .fsbox.frame3.frame8 -borderwidth {2}
  catch ".fsbox.frame3.frame8 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0
  frame .fsbox.frame3.frame8.frame0 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1
  frame .fsbox.frame3.frame8.frame0.frame1 
  catch ".fsbox.frame3.frame8.frame0.frame1 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame3
  frame .fsbox.frame3.frame8.frame0.frame1.frame3 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8
  listbox .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 \
    -width 20 -height 10 \
    -relief {sunken}\
    -selectmode single \
    -xscrollcommand {.fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 set}\
    -yscrollcommand {.fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 set}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame1.frame3
  pack append .fsbox.frame3.frame8.frame0.frame1.frame3 \
    .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 {left frame center expand fill} 

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame4
  frame .fsbox.frame3.frame8.frame0.frame1.frame4 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame4 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9
  scrollbar .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 \
    -command {.fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 yview}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame1.frame4
  pack append .fsbox.frame3.frame8.frame0.frame1.frame4 \
    .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

  # pack widget .fsbox.frame3.frame8.frame0.frame1
  pack append .fsbox.frame3.frame8.frame0.frame1 \
    .fsbox.frame3.frame8.frame0.frame1.frame3 {left frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame1.frame4 {right frame center filly} 

  # build widget .fsbox.frame3.frame8.frame0.frame2
  frame .fsbox.frame3.frame8.frame0.frame2 -borderwidth {1}
  catch ".fsbox.frame3.frame8.frame0.frame2 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame5
  frame .fsbox.frame3.frame8.frame0.frame2.frame5 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame5 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10
  scrollbar .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 \
    -command {.fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 xview}\
    -orient {horizontal}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame2.frame5
  pack append .fsbox.frame3.frame8.frame0.frame2.frame5 \
    .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame6
  frame .fsbox.frame3.frame8.frame0.frame2.frame6 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame6 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame6.frame11
  frame .fsbox.frame3.frame8.frame0.frame2.frame6.frame11 \
    -borderwidth {2}\
    -height {13}\
    -width {16}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame2.frame6
  pack append .fsbox.frame3.frame8.frame0.frame2.frame6 \
    .fsbox.frame3.frame8.frame0.frame2.frame6.frame11 {top frame center expand fill} 

  # pack widget .fsbox.frame3.frame8.frame0.frame2
  pack append .fsbox.frame3.frame8.frame0.frame2 \
    .fsbox.frame3.frame8.frame0.frame2.frame5 {left frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame2.frame6 {right frame center filly} 

  # pack widget .fsbox.frame3.frame8.frame0
  pack append .fsbox.frame3.frame8.frame0 \
    .fsbox.frame3.frame8.frame0.frame1 {top frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame2 {bottom frame center fillx} 

  # build widget .fsbox.frame3.frame8.label10
  label .fsbox.frame3.frame8.label10 -text {Files:}
  catch ".fsbox.frame3.frame8.label10 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame8
  pack append .fsbox.frame3.frame8 \
    .fsbox.frame3.frame8.label10 {top frame w} \
    .fsbox.frame3.frame8.frame0 {top frame center expand fill} 

  if {$fsBox(showPixmap)} {
    # build widget .fsbox.frame3.frame9
    frame .fsbox.frame3.frame9 -borderwidth {2}
    catch ".fsbox.frame3.frame9 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0
    frame .fsbox.frame3.frame9.frame0 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1
    frame .fsbox.frame3.frame9.frame0.frame1 
    catch ".fsbox.frame3.frame9.frame0.frame1 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame3
    frame .fsbox.frame3.frame9.frame0.frame1.frame3 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame3 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame3.canvas
    canvas .fsbox.frame3.frame9.frame0.frame1.frame3.canvas \
      -confine {true} \
      -width {100} \
      -relief {sunken}\
      -borderwidth 2 \
      -scrollregion {0c 0c 20c 20c} \
      -xscrollcommand {.fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 set}\
      -yscrollcommand {.fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 set}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame3.canvas config $tmpFrameOpt"
    .fsbox.frame3.frame9.frame0.frame1.frame3.canvas addtag currentBitmap withtag [.fsbox.frame3.frame9.frame0.frame1.frame3.canvas create bitmap 5 5 -anchor nw]

    # pack widget .fsbox.frame3.frame9.frame0.frame1.frame3
    pack append .fsbox.frame3.frame9.frame0.frame1.frame3 \
      .fsbox.frame3.frame9.frame0.frame1.frame3.canvas {left frame center expand fill} 

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame4
    frame .fsbox.frame3.frame9.frame0.frame1.frame4 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame4 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9
    scrollbar .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 \
      -command {.fsbox.frame3.frame9.frame0.frame1.frame3.canvas yview}\
      -relief {sunken}\
      -width {13}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame1.frame4
    pack append .fsbox.frame3.frame9.frame0.frame1.frame4 \
      .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

    # pack widget .fsbox.frame3.frame9.frame0.frame1
    pack append .fsbox.frame3.frame9.frame0.frame1 \
      .fsbox.frame3.frame9.frame0.frame1.frame3 {left frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame1.frame4 {right frame center filly} 

    # build widget .fsbox.frame3.frame9.frame0.frame2
    frame .fsbox.frame3.frame9.frame0.frame2 -borderwidth {1}
    catch ".fsbox.frame3.frame9.frame0.frame2 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame5
    frame .fsbox.frame3.frame9.frame0.frame2.frame5 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame5 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10
    scrollbar .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 \
      -command {.fsbox.frame3.frame9.frame0.frame1.frame3.canvas xview}\
      -orient {horizontal}\
      -relief {sunken}\
      -width {13}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame2.frame5
    pack append .fsbox.frame3.frame9.frame0.frame2.frame5 \
      .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame6
    frame .fsbox.frame3.frame9.frame0.frame2.frame6 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame6 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame6.frame11
    frame .fsbox.frame3.frame9.frame0.frame2.frame6.frame11 \
      -borderwidth {2}\
      -height {13}\
      -width {16}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame2.frame6
    pack append .fsbox.frame3.frame9.frame0.frame2.frame6 \
      .fsbox.frame3.frame9.frame0.frame2.frame6.frame11 {top frame center expand fill} 

    # pack widget .fsbox.frame3.frame9.frame0.frame2
    pack append .fsbox.frame3.frame9.frame0.frame2 \
      .fsbox.frame3.frame9.frame0.frame2.frame5 {left frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame2.frame6 {right frame center filly} 

    # pack widget .fsbox.frame3.frame9.frame0
    pack append .fsbox.frame3.frame9.frame0 \
      .fsbox.frame3.frame9.frame0.frame1 {top frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame2 {bottom frame center fillx} 

    # build widget .fsbox.frame3.frame9.label10
    label .fsbox.frame3.frame9.label10 -text {Pixmap:}
    catch ".fsbox.frame3.frame9.label10 config $tmpMessageOpt"

    # pack widget .fsbox.frame3.frame9
    pack append .fsbox.frame3.frame9 \
      .fsbox.frame3.frame9.label10 {top frame w} \
      .fsbox.frame3.frame9.frame0 {top frame center expand fill} 

    # pack widget .fsbox.frame3
    pack append .fsbox.frame3 \
      .fsbox.frame3.frame7 {left frame center expand fill} \
      .fsbox.frame3.frame8 {left frame center expand fill} \
      .fsbox.frame3.frame9 {right frame center expand fill} 
  } else {
    # pack widget .fsbox.frame3
    pack append .fsbox.frame3 \
      .fsbox.frame3.frame7 {left frame center expand fill} \
      .fsbox.frame3.frame8 {right frame center expand fill} 
  }

  # build widget .fsbox.buttons
  frame .fsbox.buttons -relief {raised}
  catch ".fsbox.buttons config $tmpFrameOpt"

  # build widget .fsbox.buttons.filter
  button .fsbox.buttons.filter -text {Filter} -command {FSBoxFilter .fsbox}
  catch ".fsbox.buttons.filter config $tmpButtonOpt"

  # build widget .fsbox.buttons.ok
  button .fsbox.buttons.ok -text {OK} -command {FSBoxOk .fsbox}
  catch ".fsbox.buttons.ok config $tmpButtonOpt"

  # build widget .fsbox.buttons.cancel
  button .fsbox.buttons.cancel -text {Cancel} -command {FSBoxCancel .fsbox}
  catch ".fsbox.buttons.cancel config $tmpButtonOpt"

  # build widget .fsbox.buttons.help
  button .fsbox.buttons.help -text {Help} -command {FSBoxHelp .fsbox}
  catch ".fsbox.buttons.help config $tmpButtonOpt"

  # pack widget .fsbox.buttons
  pack append .fsbox.buttons \
    .fsbox.buttons.filter {left frame center expand} \
    .fsbox.buttons.ok {left frame center expand} \
    .fsbox.buttons.cancel {left frame center expand} \
    .fsbox.buttons.help {right frame center expand} 

  # build widget .fsbox.label1
  label .fsbox.label1 -text {Filter:}
  catch ".fsbox.label1 config $tmpMessageOpt"

  # build widget .fsbox.label4
  label .fsbox.label4 -text {Selection:}
  catch ".fsbox.label4 config $tmpMessageOpt"

  # pack widget .fsbox
  pack append .fsbox \
    .fsbox.label1 {top frame w} \
    .fsbox.filter {top frame center expand fillx} \
    .fsbox.frame3 {top frame center expand fill} \
    .fsbox.label4 {top frame w expand} \
    .fsbox.selection {top frame center expand fillx} \
    .fsbox.buttons {top frame center expand fill} 

  .fsbox.filter insert end "$fsBox(internalPath)/$fsBox(pattern)"

  FSBoxFilter .fsbox
  bindtags .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 {Listbox .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8}
  bind .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 <ButtonRelease-1> {FSBoxSingle1Directories .fsbox %W}
  bindtags .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 {Listbox .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8}
  bind .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 <ButtonRelease-1> {FSBoxSingle1Files .fsbox %W}

  bind .fsbox.filter <Return> {FSBoxFilter .fsbox}
  bind .fsbox.selection <Return> {.fsbox.buttons.ok invoke}

# end of widget tree

  update idletask
  grab .fsbox
  tkwait window .fsbox
  if {"[string trim $fsBox(path)]" != "" ||
      "[string trim $fsBox(name)]" != ""} {
    if {"[string trimleft [string trim $fsBox(name)] /]" == ""} {
      return [string trimright [string trim $fsBox(path)] /]
    } {
      return [string trimright [string trim $fsBox(path)] /]/[string trimleft [string trim $fsBox(name)] /]
    }
  }


}

proc FSBoxFilter {toplevel} {
  global fsBox
  set filter "[$toplevel.filter get]"
  set fsBox(internalPath) [file dirname $filter]
  set fsBox(pattern) [file tail $filter]
  set files "[lsort [glob -nocomplain -- $filter]]"
  $toplevel.frame3.frame7.frame0.frame1.frame3.listbox8 delete 0 end
  $toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 delete 0 end
  foreach f "$files" {
    set tail "[file tail $f]"
    set isdir "[file isdir $f]"
    if {$isdir} {
      if {$fsBox(typeMask) != "Regular"} {
	$toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 insert end "$tail"
      }
    } else {
      if {$fsBox(typeMask) != "Directory"} {
	$toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 insert end "$tail"
      }
    }
  }
  set dirs "$fsBox(internalPath)/.. [lsort [glob -nocomplain -- $fsBox(internalPath)/*]]"
  foreach d "$dirs" {
    set tail "[file tail $d]"
    set isdir "[file isdir $d]"
    if {$isdir} {
      $toplevel.frame3.frame7.frame0.frame1.frame3.listbox8 insert end "$tail/"
    }
  }
  $toplevel.selection delete 0 end
  $toplevel.selection insert end "$fsBox(internalPath)/$fsBox(name)"
}

proc FSBoxSingle1Directories {toplevel listbox} {
  global fsBox
  set selection "[string trimright [$listbox get active] {/}]"
  if {[string compare {..} "$selection"] == 0} {
    set temp "[file dirname $fsBox(internalPath)]/$fsBox(pattern)"
    $toplevel.filter delete 0 end
    $toplevel.filter insert end "$temp"
  } else {
    set temp "$fsBox(internalPath)/$selection/$fsBox(pattern)"
    $toplevel.filter delete 0 end
    $toplevel.filter insert end "$temp"
  }
}

proc FSBoxSingle1Files {toplevel listbox} {
  global fsBox
  set selection "[$listbox get active]"
  set temp "$fsBox(internalPath)/$selection"
  $toplevel.selection delete 0 end
  $toplevel.selection insert end "$temp"
  if {$fsBox(showPixmap) && ![file isdir $temp]} {
    catch "$toplevel.frame3.frame9.frame0.frame1.frame3.canvas itemconfigure currentBitmap -bitmap \"@$temp\""
  }
}

proc FSBoxOk {toplevel} {
  global fsBox
  set result "[$toplevel.selection get]"
  set fsBox(path) "[file dirname $result]"
  set fsBox(name) "[file tail $result]"
  catch "destroy $toplevel"
}

proc FSBoxCancel {toplevel} {
  global fsBox
  set fsBox(name) ""
  catch "destroy $toplevel"
}

proc FSBoxHelp {toplevel} {
  global fsBox
}


# Procedure: FindFileFromPath
proc FindFileFromPath { basename} {
  global xfLoadPath
  set loadpathlist [split $xfLoadPath ":"]
  foreach i $loadpathlist {
    set testfile [join [list $i $basename] ""]
    if {[file exists $testfile]} {
      return $testfile
    }
  }
  return {}
}


# Procedure: HelpDispCard
proc HelpDispCard {} {
  global CardDispHelpFile
  if {$CardDispHelpFile != ""} {
    TextBoxFile $CardDispHelpFile "" 550x300 "Help for Card display popup"
  }
}


# Procedure: HelpProc
proc HelpProc {} {
  global HelpFile
  if {$HelpFile != ""} {
    TextBoxFile $HelpFile "" 550x300 "Help for TkLibrarian"
  }
}


# Procedure: IsADir
proc IsADir { pathName} {
# xf ignore me 5
##########
# Procedure: IsADir
# Description: check if name is a directory (including symbolic links)
# Arguments: pathName - the path to check
# Returns: 1 if its a directory, otherwise 0
# Sideeffects: none
##########

  if {[file isdirectory $pathName]} {
    return 1
  } {
    catch "file type $pathName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $pathName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isdirectory $linkName]
    }
  }
  return 0
}


# Procedure: IsAFile
proc IsAFile { fileName} {
# xf ignore me 5
##########
# Procedure: IsAFile
# Description: check if filename is a file (including symbolic links)
# Arguments: fileName - the filename to check
# Returns: 1 if its a file, otherwise 0
# Sideeffects: none
##########

  if {[file isfile $fileName]} {
    return 1
  } {
    catch "file type $fileName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $fileName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isfile $linkName]
    }
  }
  return 0
}


# Procedure: IsASymlink
proc IsASymlink { fileName} {
# xf ignore me 5
##########
# Procedure: IsASymlink
# Description: check if filename is a symbolic link
# Arguments: fileName - the path/filename to check
# Returns: none
# Sideeffects: none
##########

  catch "file type $fileName" fileType
  if {"$fileType" == "link"} {
    return 1
  }
  return 0
}


# Procedure: ListAuthors
proc ListAuthors { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchauthors $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for author prefix $key"
  } elseif {[llength $ids] == 1} {
    DispAAuth {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all authors"
    } else {
      set title "List of authors with prefix $key"
    }
    ListItems [NewListHandle xAuthors] "$title" DispAAuth $ids
  }
}


# Procedure: ListCards
proc ListCards { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchids $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for id prefix $key"
  } elseif {[llength $ids] == 1} {
    DispACard {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all ids"
    } else {
      set title "List of ids with prefix $key"
    }
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" DispACard $lines
  }
}


# Procedure: ListItems
proc ListItems { handle title selectfunction items} {

  # build widget .$handle
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .$handle"
  } {
    catch "destroy .$handle"
  }
  toplevel .$handle  -relief {raised}

  # Window manager configurations
  global tk_version
  wm sizefrom .$handle ""
  wm maxsize .$handle 1000 768
  wm minsize .$handle 10 10
  wm title .$handle "$title"


  # build widget .$handle.buttons
  frame .$handle.buttons  -borderwidth {2}

  # build widget .$handle.buttons.dismis
  button .$handle.buttons.dismis  -text {Dismis}  -command "DismisList $handle"

  # build widget .$handle.buttons.help
  button .$handle.buttons.help  -text {Help} -command {ListItemsHelp}

  # build widget .$handle.buttons.select
  button .$handle.buttons.select  -text {Select} -command "ListItemsSelect $handle \"$selectfunction\""

  # pack widget .$handle.buttons
  pack append .$handle.buttons  .$handle.buttons.select {left frame center expand fillx}  .$handle.buttons.dismis {left frame center expand fillx}  .$handle.buttons.help {right frame center expand fillx} 

  # build widget .$handle.listframe
  frame .$handle.listframe 

  # build widget .$handle.listframe.scrollbar2
  scrollbar .$handle.listframe.scrollbar2  -command ".$handle.listframe.list yview" -relief {raised}

  # build widget .$handle.listframe.scrollbar3
  scrollbar .$handle.listframe.scrollbar3  -command ".$handle.listframe.list xview" -orient {horizontal} -relief {raised}

  # build widget .$handle.listframe.list
  listbox .$handle.listframe.list -width 72 -height 19 -relief {raised} -xscrollcommand ".$handle.listframe.scrollbar3 set" -yscrollcommand ".$handle.listframe.scrollbar2 set"

  # pack widget .$handle.listframe
  pack append .$handle.listframe  .$handle.listframe.scrollbar2 {right frame center filly}  .$handle.listframe.list {top frame center expand fill}  .$handle.listframe.scrollbar3 {bottom frame center fillx} 

  # pack widget .$handle
  pack append .$handle  .$handle.listframe {top frame center fill}  .$handle.buttons {top frame center fill} 

  foreach i $items {
    .$handle.listframe.list insert end "$i"
  }
}


# Procedure: ListItemsHelp
proc ListItemsHelp {} {
  global ListItemsHelpFile
  if {$ListItemsHelpFile != ""} {
    TextBoxFile $ListItemsHelpFile "" 550x300 "Help for list display popup"
  }
}


# Procedure: ListItemsSelect
proc ListItemsSelect { handle function} {
  if {[selection own] == ".$handle.listframe.list"} {
    catch [list $function $handle "[selection get]"]
  }
}


# Procedure: ListSubjects
proc ListSubjects { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchsubjects $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for subject prefix $key"
  } elseif {[llength $ids] == 1} {
    DispASubj {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all subjects"
    } else {
      set title "List of subjects with prefix $key"
    }
    ListItems [NewListHandle xSubjects] "$title" DispASubj $ids
  }
}


# Procedure: ListTitles
proc ListTitles { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchtitles $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for title prefix $key"
  } elseif {[llength $ids] == 1} {
    DispATitle {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all titles"
    } else {
      set title "List of titles with prefix $key"
    }
    ListItems [NewListHandle xTitles] "$title" DispATitle $ids 
  }
}


# Procedure: LoadLibrary
proc LoadLibrary {} {
  global CurrentLibrary
  if {$CurrentLibrary != {}} {
    if {![YesNoBox "A library is already loaded, load another?"]} {
      return
    }
    $CurrentLibrary delete
    set CurrentLibrary {}
    wm title . {Librarian (no library database loaded)}
  }
  global fsBox
  set fsBox(pattern) {*.libr}
  set lfile [FSBox "Select Library"]
  if {$lfile == {}} {
    return
  }
  set CurrentLibrary [TkvBTree $lfile ReadOnly]
  if {[$CurrentLibrary openstat] == {failure}} {
    AlertBox "Error opening $lfile"
    $CurrentLibrary delete
    set CurrentLibrary {}
    return
  }
  wm title . "Librarian $lfile"
}


# Procedure: NewListHandle
proc NewListHandle { prefix} {
  for {set i 0} {[winfo exists .$prefix$i]} {incr i} {
  }
  return "$prefix$i"
}


# Procedure: TextBox
proc TextBox { {textBoxMessage "Text message"} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBox
# Description: show text box
# Arguments: {textBoxMessage} - the text to display
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, or nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBoxFile - to open and read a file automatically
#          TextBoxFd - to read from an already opened filedescriptor
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxFd
proc TextBoxFd { {textBoxInFile ""} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBoxFd
# Description: show text box containing a filedescriptor
# Arguments: {textBoxInFile} - a filedescriptor to read. The descriptor
#                              is closed after reading
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBox - to display a passed string
#          TextBoxFile - to open and read a file automatically
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # check file existance
  if {"$textBoxInFile" == ""} {
    puts stderr "No filedescriptor specified"
    return
  }

  set textBoxMessage [read $textBoxInFile]
  close $textBoxInFile

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxFile
proc TextBoxFile { {textBoxFile ""} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBoxFile
# Description: show text box containing a file
# Arguments: {textBoxFile} - filename to read
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBox - to display a passed string
#          TextBoxFd - to read from an already opened filedescriptor
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # check file existance
  if {"$textBoxFile" == ""} {
    puts stderr "No filename specified"
    return
  }

  if {[catch "open $textBoxFile r" textBoxInFile]} {
    puts stderr "$textBoxInFile"
    return
  }

  set textBoxMessage [read $textBoxInFile]
  close $textBoxInFile

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxInternal
proc TextBoxInternal { textBoxMessage textBoxCommand textBoxGeometry textBoxTitle args} {
# xf ignore me 6
  global textBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScrollOpt ""
  if {"$textBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$textBox(activeBackground)\" "
  }
  if {"$textBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$textBox(activeForeground)\" "
  }
  if {"$textBox(background)" != ""} {
    append tmpButtonOpt "-background \"$textBox(background)\" "
    append tmpFrameOpt "-background \"$textBox(background)\" "
    append tmpMessageOpt "-background \"$textBox(background)\" "
  }
  if {"$textBox(font)" != ""} {
    append tmpButtonOpt "-font \"$textBox(font)\" "
    append tmpMessageOpt "-font \"$textBox(font)\" "
  }
  if {"$textBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$textBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$textBox(foreground)\" "
  }
  if {"$textBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$textBox(scrollActiveForeground)\" "
  }
  if {"$textBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$textBox(scrollBackground)\" "
  }
  if {"$textBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$textBox(scrollForeground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $textBox(toplevelName)}
  } {
    catch {destroy $textBox(toplevelName)}
  }
  toplevel $textBox(toplevelName)  -borderwidth 0
  catch "$textBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $textBox(toplevelName) $textBoxGeometry"]} {
    wm geometry $textBox(toplevelName) 350x150
  }
  wm title $textBox(toplevelName) $textBoxTitle
  wm maxsize $textBox(toplevelName) 1000 1000
  wm minsize $textBox(toplevelName) 100 100
  # end build of toplevel

  frame $textBox(toplevelName).frame0  -borderwidth 0  -relief raised
  catch "$textBox(toplevelName).frame0 config $tmpFrameOpt"

  text $textBox(toplevelName).frame0.text1  -relief raised  -wrap none  -borderwidth 2  -yscrollcommand "$textBox(toplevelName).frame0.vscroll set"
  catch "$textBox(toplevelName).frame0.text1 config $tmpMessageOpt"

  scrollbar $textBox(toplevelName).frame0.vscroll  -relief raised  -command "$textBox(toplevelName).frame0.text1 yview"
  catch "$textBox(toplevelName).frame0.vscroll config $tmpScrollOpt"

  frame $textBox(toplevelName).frame1  -borderwidth 0  -relief raised
  catch "$textBox(toplevelName).frame1 config $tmpFrameOpt"

  set textBoxCounter 0
  set buttonNum [llength $args]

  if {$buttonNum > 0} {
    while {$textBoxCounter < $buttonNum} {
      button $textBox(toplevelName).frame1.button$textBoxCounter  -text "[lindex $args $textBoxCounter]"  -command "
          global textBox
          set textBox(button) $textBoxCounter
          set textBox(contents) \[$textBox(toplevelName).frame0.text1 get 1.0 end\]
          if {\"\[info commands XFDestroy\]\" != \"\"} {
            catch {XFDestroy $textBox(toplevelName)}
          } {
            catch {destroy $textBox(toplevelName)}
          }"
      catch "$textBox(toplevelName).frame1.button$textBoxCounter config $tmpButtonOpt"

      pack append $textBox(toplevelName).frame1  $textBox(toplevelName).frame1.button$textBoxCounter {left fillx expand}

      incr textBoxCounter
    }
  } {
    button $textBox(toplevelName).frame1.button0  -text "OK"  -command "
        global textBox
        set textBox(button) 0
        set textBox(contents) \[$textBox(toplevelName).frame0.text1 get 1.0 end\]
        if {\"\[info commands XFDestroy\]\" != \"\"} {
          catch {XFDestroy $textBox(toplevelName)}
        } {
          catch {destroy $textBox(toplevelName)}
        }
        $textBoxCommand"
    catch "$textBox(toplevelName).frame1.button0 config $tmpButtonOpt"

    pack append $textBox(toplevelName).frame1  $textBox(toplevelName).frame1.button0 {left fillx expand}
  }

  $textBox(toplevelName).frame0.text1 insert end "$textBoxMessage"

  $textBox(toplevelName).frame0.text1 config  -state $textBox(state)

  # packing
  pack append $textBox(toplevelName).frame0  $textBox(toplevelName).frame0.vscroll "$textBox(scrollSide) filly"  $textBox(toplevelName).frame0.text1 {left fill expand}
  pack append $textBox(toplevelName)  $textBox(toplevelName).frame1 {bottom fill}  $textBox(toplevelName).frame0 {top fill expand}
}


# Procedure: VersionProc
proc VersionProc {} {
  AlertBox {TkLibrarian Version 1.0} "" {180x50}
}


# Procedure: WarrantyProc
proc WarrantyProc {} {
  global WarrantyMessage
  if {$WarrantyMessage != ""} {
    AlertBoxFile $WarrantyMessage "" {600x350}
  }
}


# Procedure: YesNoBox
proc YesNoBox { {yesNoBoxMessage "Yes/no message"} {yesNoBoxGeometry "350x150"}} {
# xf ignore me 5
##########
# Procedure: YesNoBox
# Description: show yesno box
# Arguments: {yesNoBoxMessage} - the text to display
#            {yesNoBoxGeometry} - the geometry for the window
# Returns: none
# Sideeffects: none
##########
#
# global yesNoBox(activeBackground) - active background color
# global yesNoBox(activeForeground) - active foreground color
# global yesNoBox(anchor) - anchor for message box
# global yesNoBox(background) - background color
# global yesNoBox(font) - message font
# global yesNoBox(foreground) - foreground color
# global yesNoBox(justify) - justify for message box
# global yesNoBox(afterNo) - destroy yes-no box after n seconds.
#                            The no button is activated
# global yesNoBox(afterYes) - destroy yes-no box after n seconds.
#                             The yes button is activated

  global yesNoBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  if {"$yesNoBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$yesNoBox(activeBackground)\" "
  }
  if {"$yesNoBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$yesNoBox(activeForeground)\" "
  }
  if {"$yesNoBox(background)" != ""} {
    append tmpButtonOpt "-background \"$yesNoBox(background)\" "
    append tmpFrameOpt "-background \"$yesNoBox(background)\" "
    append tmpMessageOpt "-background \"$yesNoBox(background)\" "
  }
  if {"$yesNoBox(font)" != ""} {
    append tmpButtonOpt "-font \"$yesNoBox(font)\" "
    append tmpMessageOpt "-font \"$yesNoBox(font)\" "
  }
  if {"$yesNoBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$yesNoBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$yesNoBox(foreground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy .yesNoBox}
  } {
    catch {destroy .yesNoBox}
  }
  toplevel .yesNoBox  -borderwidth 0
  catch ".yesNoBox config $tmpFrameOpt"
  if {[catch "wm geometry .yesNoBox $yesNoBoxGeometry"]} {
    wm geometry .yesNoBox 350x150
  }
  wm title .yesNoBox {Alert box}
  wm maxsize .yesNoBox 1000 1000
  wm minsize .yesNoBox 100 100
  # end build of toplevel

  message .yesNoBox.message1  -anchor "$yesNoBox(anchor)"  -justify "$yesNoBox(justify)"  -relief raised  -text "$yesNoBoxMessage"
  catch ".yesNoBox.message1 config $tmpMessageOpt"

  set xfTmpWidth  [string range $yesNoBoxGeometry 0 [expr [string first x $yesNoBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch ".yesNoBox.message1 configure  -width [expr $xfTmpWidth-10]"
  } {
    .yesNoBox.message1 configure  -aspect 1500
  }

  frame .yesNoBox.frame1  -borderwidth 0  -relief raised
  catch ".yesNoBox.frame1 config $tmpFrameOpt"

  button .yesNoBox.frame1.button0  -text "Yes"  -command "
      global yesNoBox
      set yesNoBox(button) 1
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .yesNoBox}
      } {
        catch {destroy .yesNoBox}
      }"
  catch ".yesNoBox.frame1.button0 config $tmpButtonOpt"

  button .yesNoBox.frame1.button1  -text "No"  -command "
      global yesNoBox
      set yesNoBox(button) 0
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .yesNoBox}
      } {
        catch {destroy .yesNoBox}
      }"
  catch ".yesNoBox.frame1.button1 config $tmpButtonOpt"

  pack append .yesNoBox.frame1  .yesNoBox.frame1.button0 {left fillx expand}  .yesNoBox.frame1.button1 {left fillx expand}

  # packing
  pack append .yesNoBox  .yesNoBox.frame1 {bottom fill}  .yesNoBox.message1 {top fill expand}

  if {$yesNoBox(afterYes) != 0} {
    after [expr $yesNoBox(afterYes)*1000]  "catch \".yesNoBox.frame1.button0 invoke\""
  }
  if {$yesNoBox(afterNo) != 0} {
    after [expr $yesNoBox(afterNo)*1000]  "catch \".yesNoBox.frame1.button1 invoke\""
  }

  # wait for the box to be destroyed
  update idletask
  grab .yesNoBox
  tkwait window .yesNoBox

  return $yesNoBox(button)
}


# Procedure: auto_load_ouster_index
proc auto_load_ouster_index { fn} {
    global auto_index
    set dir [file dirname $fn]

    if [catch {set f [open $dir/tclIndex]}] {
        return
    }
    set error [catch {
        set id [gets $f]
        if {$id == "# Tcl autoload index file, version 2.0"} {
            eval [read $f]
        } elseif {$id == "# Tcl autoload index file: each line identifies a Tcl"} {
            while {[gets $f line] >= 0} {
                if {([string index $line 0] == "#")
                        || ([llength $line] != 2)} {
                    continue
                }
                set name [lindex $line 0]
                if {![info exists auto_index($name)]} {
                    set auto_index($name) "source $dir/[lindex $line 1]"
                }
            }
        } else {
            error "$dir/tclIndex isn't a proper Tcl index file"
        }
    } msg]
    if {$f != ""} {
        close $f
    }
    if $error {
        global errorInfo errorCode
        error $msg $errorInfo $errorCode
    }
}


# Procedure: tclx_unknown2
proc tclx_unknown2 { cmd} {
    global tcl_interactive auto_noexec

    set name [lindex $cmd 0]

    if ![info exists auto_noexec] {
        if [auto_execok $name] {
            if {!$tcl_interactive || ([info level] > 2) ||
                [info script] != ""} {
                error "Auto execution of Unix commands only supported as interactive commands.\nUse \"exec\" to execute \"$name\""
            }
            uplevel 2 system [list $cmd]
            return
        }
    }

    if {!$tcl_interactive || ([info level] > 2) || [info script] != ""} {
        error "invalid command name \"$name\""
    }


    if {([info level] == 2) && ([info script] == "")} {
        if {$name == "!!"} {
            return [uplevel 2 {history redo}]
        }
        if [regexp {^!(.+)$} $name dummy event] {
            return [uplevel 2 [list history redo $event]]
        }
        if [regexp {^\^([^^]*)\^([^^]*)\^?$} $name dummy old new] {
            return [uplevel 2 [list history substitute $old $new]]
        }
        set cmds [info commands $name*]
        if {[llength $cmds] == 1} {
            return [uplevel 2 [lreplace $cmd 0 0 $cmds]]
        }
        if {[llength $cmds] != 0} {
            if {$name == ""} {
                return -code error "empty command name \"\""
            } else {
                return -code error  "ambiguous command name \"$name\": [lsort $cmds]"
            }
        }
    }
    error "invalid command name \"$name\""
}


# Internal procedures


# Procedure: Alias
proc Alias { args} {
# xf ignore me 7
##########
# Procedure: Alias
# Description: establish an alias for a procedure
# Arguments: args - no argument means that a list of all aliases
#                   is returned. Otherwise the first parameter is
#                   the alias name, and the second parameter is
#                   the procedure that is aliased.
# Returns: nothing, the command that is bound to the alias or a
#          list of all aliases - command pairs. 
# Sideeffects: internalAliasList is updated, and the alias
#              proc is inserted
##########
  global internalAliasList

  if {[llength $args] == 0} {
    return $internalAliasList
  } {
    if {[llength $args] == 1} {
      set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
      if {$xfTmpIndex != -1} {
        return [lindex [lindex $internalAliasList $xfTmpIndex] 1]
      }
    } {
      if {[llength $args] == 2} {
        eval "proc [lindex $args 0] {args} {#xf ignore me 4
return \[eval \"[lindex $args 1] \$args\"\]}"
        set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
        if {$xfTmpIndex != -1} {
          set internalAliasList [lreplace $internalAliasList $xfTmpIndex $xfTmpIndex "[lindex $args 0] [lindex $args 1]"]
        } {
          lappend internalAliasList "[lindex $args 0] [lindex $args 1]"
        }
      } {
        error "Alias: wrong number or args: $args"
      }
    }
  }
}


# Procedure: GetSelection
if {"[info procs GetSelection]" == ""} {
proc GetSelection {} {
# xf ignore me 7
##########
# Procedure: GetSelection
# Description: get current selection
# Arguments: none
# Returns: none
# Sideeffects: none
##########

  # the save way
  set xfSelection ""
  catch "selection get" xfSelection
  if {"$xfSelection" == "selection doesn't exist or form \"STRING\" not defined"} {
    return ""
  } {
    return $xfSelection
  }
}
}


# Procedure: MenuPopupAdd
if {"[info procs MenuPopupAdd]" == ""} {
proc MenuPopupAdd { xfW xfButton xfMenu {xfModifier ""} {xfCanvasTag ""}} {
# xf ignore me 7
# the popup menu handling is from (I already gave up with popup handling :-):
#
# Copyright 1991,1992 by James Noble.
# Everyone is granted permission to copy, modify and redistribute.
# This notice must be preserved on all copies or derivates.
#
##########
# Procedure: MenuPopupAdd
# Description: attach a popup menu to widget
# Arguments: xfW - the widget
#            xfButton - the button we use
#            xfMenu - the menu to attach
#            {xfModifier} - a optional modifier
#            {xfCanvasTag} - a canvas tagOrId
# Returns: none
# Sideeffects: none
##########

  if {"$xfModifier" != ""} {
    set xfPressModifier "$xfModifier-"
    set xfMoveModifier "$xfModifier-"
    set xfReleaseModifier "Any-"
  } {
    set xfPressModifier ""
    set xfMoveModifier ""
    set xfReleaseModifier ""
  }

  if {"$xfCanvasTag" == ""} {
    if {[catch "bind $xfW \"<${xfPressModifier}ButtonPress-$xfButton>\"  \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "bind $xfW \"<${xfMoveModifier}B$xfButton-Motion>\"  \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "bind $xfW \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"  \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  } {
    if {[catch "$xfW bind $xfCanvasTag \"<${xfPressModifier}ButtonPress-$xfButton>\"  \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "$xfW bind $xfCanvasTag \"<${xfMoveModifier}B$xfButton-Motion>\"  \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "$xfW bind $xfCanvasTag \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"  \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  }
}
}


# Procedure: MenuPopupHandle
if {"[info procs MenuPopupHandle]" == ""} {
proc MenuPopupHandle { xfMenu xfW xfX xfY} {
# xf ignore me 7
##########
# Procedure: MenuPopupHandle
# Description: handle the popup menus
# Arguments: xfMenu - the menu to attach
#            xfW - the widget
#            xfX - the root x coordinate
#            xfY - the root x coordinate
# Returns: none
# Sideeffects: none
##########

  if {"[info commands $xfMenu]" != "" && [winfo ismapped $xfMenu]} {
    set xfPopMinX [winfo rootx $xfMenu]
    set xfPopMaxX [expr $xfPopMinX+[winfo width $xfMenu]]
    if {($xfX >= $xfPopMinX) &&  ($xfX <= $xfPopMaxX)} {
      $xfMenu activate @[expr $xfY-[winfo rooty $xfMenu]]
    } {
      $xfMenu activate none
    }
  }
}
}


# Procedure: NoFunction
if {"[info procs NoFunction]" == ""} {
proc NoFunction { args} {
# xf ignore me 7
##########
# Procedure: NoFunction
# Description: do nothing (especially with scales and scrollbars)
# Arguments: args - a number of ignored parameters
# Returns: none
# Sideeffects: none
##########
}
}


# Procedure: SN
if {"[info procs SN]" == ""} {
proc SN { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SN
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  SymbolicName $xfName
}
}


# Procedure: SymbolicName
if {"[info procs SymbolicName]" == ""} {
proc SymbolicName { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SymbolicName
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  global symbolicName

  if {"$xfName" != ""} {
    set xfArrayName ""
    append xfArrayName symbolicName ( $xfName )
    if {![catch "set \"$xfArrayName\"" xfValue]} {
      return $xfValue
    } {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "Unknown symbolic name:\n$xfName"
      } {
        puts stderr "XF error: unknown symbolic name:\n$xfName"
      }
    }
  }
  return ""
}
}


# Procedure: Unalias
proc Unalias { aliasName} {
# xf ignore me 7
##########
# Procedure: Unalias
# Description: remove an alias for a procedure
# Arguments: aliasName - the alias name to remove
# Returns: none
# Sideeffects: internalAliasList is updated, and the alias
#              proc is removed
##########
  global internalAliasList

  set xfIndex [lsearch $internalAliasList "$aliasName *"]
  if {$xfIndex != -1} {
    rename $aliasName ""
    set internalAliasList [lreplace $internalAliasList $xfIndex $xfIndex]
  }
}



# application parsing procedure
proc XFLocalParseAppDefs {xfAppDefFile} {
  global xfAppDefaults

  # basically from: Michael Moore
  if {[file exists $xfAppDefFile] &&
      [file readable $xfAppDefFile] &&
      "[file type $xfAppDefFile]" == "link"} {
    catch "file type $xfAppDefFile" xfType
    while {"$xfType" == "link"} {
      if {[catch "file readlink $xfAppDefFile" xfAppDefFile]} {
        return
      }
      catch "file type $xfAppDefFile" xfType
    }
  }
  if {!("$xfAppDefFile" != "" &&
        [file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        "[file type $xfAppDefFile]" == "file")} {
    return
  }
  if {![catch "open $xfAppDefFile r" xfResult]} {
    set xfAppFileContents [read $xfResult]
    close $xfResult
    foreach line [split $xfAppFileContents "\n"] {
      # backup indicates how far to backup.  It applies to the
      # situation where a resource name ends in . and when it
      # ends in *.  In the second case you want to keep the *
      # in the widget name for pattern matching, but you want
      # to get rid of the . if it is the end of the name. 
      set backup -2  
      set line [string trim $line]
      if {[string index $line 0] == "#" || "$line" == ""} {
        # skip comments and empty lines
        continue
      }
      set list [split $line ":"]
      set resource [string trim [lindex $list 0]]
      set i [string last "." $resource]
      set j [string last "*" $resource]
      if {$j > $i} { 
        set i $j
        set backup -1
      }
      incr i
      set name [string range $resource $i end]
      incr i $backup
      set widname [string range $resource 0 $i]
      set value [string trim [lindex $list 1]]
      if {"$widname" != "" && "$widname" != "*"} {
        # insert the widget and resourcename to the application
        # defaults list.
        set xfAppDefaults($widname:[string tolower $name]) $value
      }
    }
  }
}

# application loading procedure
proc XFLocalLoadAppDefs {xfClasses {xfPriority "startupFile"} {xfAppDefFile ""}} {
  global env

  if {"$xfAppDefFile" == ""} {
    set xfFileList ""
    if {[info exists env(XUSERFILESEARCHPATH)]} {
      append xfFileList [split $env(XUSERFILESEARCHPATH) :]
    }
    if {[info exists env(XAPPLRESDIR)]} {
      append xfFileList [split $env(XAPPLRESDIR) :]
    }
    if {[info exists env(XFILESEARCHPATH)]} {
      append xfFileList [split $env(XFILESEARCHPATH) :]
    }
    append xfFileList " /usr/lib/X11/app-defaults"
    append xfFileList " /usr/X11/lib/X11/app-defaults"

    foreach xfCounter1 $xfClasses {
      foreach xfCounter2 $xfFileList {
        set xfPathName $xfCounter2
        if {[regsub -all "%N" "$xfPathName" "$xfCounter1" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%T" "$xfPathName" "app-defaults" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%S" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%C" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[file exists $xfPathName] &&
            [file readable $xfPathName] &&
            ("[file type $xfPathName]" == "file" ||
             "[file type $xfPathName]" == "link")} {
          catch "option readfile $xfPathName $xfPriority"
          if {"[info commands XFParseAppDefs]" != ""} {
            XFParseAppDefs $xfPathName
          } {
            if {"[info commands XFLocalParseAppDefs]" != ""} {
              XFLocalParseAppDefs $xfPathName
            }
          }
        } {
          if {[file exists $xfCounter2/$xfCounter1] &&
              [file readable $xfCounter2/$xfCounter1] &&
              ("[file type $xfCounter2/$xfCounter1]" == "file" ||
               "[file type $xfCounter2/$xfCounter1]" == "link")} {
            catch "option readfile $xfCounter2/$xfCounter1 $xfPriority"
            if {"[info commands XFParseAppDefs]" != ""} {
              XFParseAppDefs $xfCounter2/$xfCounter1
            } {
              if {"[info commands XFLocalParseAppDefs]" != ""} {
                XFLocalParseAppDefs $xfCounter2/$xfCounter1
              }
            }
          }
        }
      }
    }
  } {
    # load a specific application defaults file
    if {[file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        ("[file type $xfAppDefFile]" == "file" ||
         "[file type $xfAppDefFile]" == "link")} {
      catch "option readfile $xfAppDefFile $xfPriority"
      if {"[info commands XFParseAppDefs]" != ""} {
        XFParseAppDefs $xfAppDefFile
      } {
        if {"[info commands XFLocalParseAppDefs]" != ""} {
          XFLocalParseAppDefs $xfAppDefFile
        }
      }
    }
  }
}

# application setting procedure
proc XFLocalSetAppDefs {{xfWidgetPath "."}} {
  global xfAppDefaults

  if {![info exists xfAppDefaults]} {
    return
  }
  foreach xfCounter [array names xfAppDefaults] {
    if {[string match "${xfWidgetPath}*" $xfCounter]} {
      set widname [string range $xfCounter 0 [expr [string first : $xfCounter]-1]]
      set name [string range $xfCounter [expr [string first : $xfCounter]+1] end]
      # Now lets see how many tcl commands match the name
      # pattern specified.
      set widlist [info command $widname]
      if {"$widlist" != ""} {
        foreach widget $widlist {
          # make sure this command is a widget.
          if {![catch "winfo id $widget"]} {
            catch "$widget configure -[string tolower $name] $xfAppDefaults($xfCounter)" 
          }
        }
      }
    }
  }
}



# end source
proc EndSrc {} {
  global CopyingMessage
  set CopyingMessage [FindFileFromPath tklibr.copying.message]
  global WarrantyMessage
  set WarrantyMessage [FindFileFromPath Warranty.message]
  global HelpFile
  set HelpFile [FindFileFromPath TkLibrarian.help]
  global CardDispHelpFile
  set CardDispHelpFile [FindFileFromPath CardDisp.help]
  global ListItemsHelpFile
  set ListItemsHelpFile [FindFileFromPath ListItems.help]
  global argc
  global argv
  if {$argc == 1} {
    global CurrentLibrary
    set CurrentLibrary [TkvBTree [lindex $argv 0] ReadOnly]
    if {[$CurrentLibrary openstat] == {failure}} {
      AlertBox "Error opening [lindex $argv 0]"
      $CurrentLibrary delete
      set CurrentLibrary {}
    } else {
      wm title . "Librarian [lindex $argv 0]"
    }
  }
}

# prepare auto loading
global auto_path
global tk_library
global xfLoadPath
set auto_path "[split $xfLoadPath :] $tk_library [info library]"

# initialize global variables
proc InitGlobals {} {
  global {CardDispHelpFile}
  set {CardDispHelpFile} {}
  global {CopyingMessage}
  set {CopyingMessage} {}
  global {CurrentLibrary}
  set {CurrentLibrary} {}
  global {DispCardHelpFile}
  set {DispCardHelpFile} {}
  global {HelpFile}
  set {HelpFile} {}
  global {ListItemsHelpFile}
  set {ListItemsHelpFile} {}
  global {WarrantyMessage}
  set {WarrantyMessage} {}
  global {alertBox}
  set {alertBox(activeBackground)} {}
  set {alertBox(activeForeground)} {}
  set {alertBox(after)} {0}
  set {alertBox(anchor)} {nw}
  set {alertBox(background)} {}
  set {alertBox(button)} {0}
  set {alertBox(font)} {}
  set {alertBox(foreground)} {}
  set {alertBox(justify)} {left}
  set {alertBox(toplevelName)} {.alertBox}
  global fsBox
  set fsBox(activeBackground) ""
  set fsBox(activeForeground) ""
  set fsBox(background) ""
  set fsBox(font) ""
  set fsBox(foreground) ""
  set fsBox(scrollActiveForeground) ""
  set fsBox(scrollBackground) ""
  set fsBox(scrollForeground) ""
  set fsBox(scrollSide) left
  set fsBox(showPixmap) 0
  set fsBox(name) ""
  set fsBox(path) [pwd]
  set fsBox(pattern) *
  set fsBox(typeMask) Regular
  set fsBox(button) 0
  set fsBox(extensions) 0
  set fsBox(internalPath) [pwd]
  global {textBox}
  set {textBox(activeBackground)} {}
  set {textBox(activeForeground)} {}
  set {textBox(background)} {}
  set {textBox(button)} {0}
  set {textBox(contents)} {}
  set {textBox(font)} {}
  set {textBox(foreground)} {}
  set {textBox(scrollActiveForeground)} {}
  set {textBox(scrollBackground)} {}
  set {textBox(scrollForeground)} {}
  set {textBox(scrollSide)} {left}
  set {textBox(state)} {disabled}
  set {textBox(toplevelName)} {.textBox}
  global {tklibrpath}
  set {tklibrpath} {/usr/home/heller/libr_cpp/TkLibrarian/}
  global {yesNoBox}
  set {yesNoBox(activeBackground)} {}
  set {yesNoBox(activeForeground)} {}
  set {yesNoBox(afterNo)} {0}
  set {yesNoBox(afterYes)} {0}
  set {yesNoBox(anchor)} {n}
  set {yesNoBox(background)} {}
  set {yesNoBox(button)} {1}
  set {yesNoBox(font)} {*times-bold-r-normal*24*}
  set {yesNoBox(foreground)} {}
  set {yesNoBox(justify)} {center}

  # please don't modify the following
  # variables. They are needed by xf.
  global {autoLoadList}
  set {autoLoadList(TkLibrarian)} {0}
  set {autoLoadList(main.tcl)} {0}
  global {internalAliasList}
  set {internalAliasList} {}
  global {moduleList}
  set {moduleList(TkLibrarian)} {}
  global {preloadList}
  set {preloadList(xfInternal)} {}
  global {symbolicName}
  set {symbolicName(root)} {.}
  global {xfWmSetPosition}
  set {xfWmSetPosition} {}
  global {xfWmSetSize}
  set {xfWmSetSize} {}
  global {xfAppDefToplevels}
  set {xfAppDefToplevels} {}
}

# initialize global variables
InitGlobals

# display/remove toplevel windows.
ShowWindow.

# load default bindings.
if {[info exists env(XF_BIND_FILE)] &&
    "[info procs XFShowHelp]" == ""} {
  source $env(XF_BIND_FILE)
}

# parse and apply application defaults.
XFLocalLoadAppDefs TkLibrarian
XFLocalSetAppDefs

# end source
EndSrc

# eof
#

