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

set RcsVersion "[lindex [split {$Revision: 1.12 $} { $}] 2 ]"

wm withdraw .

###
### Options
###

set shell "/usr/bin/sh"
set hdocu "hdocu"

if { $tcl_platform(platform) == "unix" } {
    font create gui -family helvetica -size 9 -weight bold
    option add *font gui
}

font create txt -family courier -size 9

option add *foreground           Black
option add *background           #ccc
option add *highlightBackground  #ccc
option add *highlightForeground  Black
option add *Text.background      #eee
option add *Entry.background     #eee
option add *Text.font            txt
option add *Entry.font           txt

set fontFamily {helvetica times courier}
set fontFamilyIdx 2

set fontSize {6 8 10 12 18}
set fontSizeIdx 1

# disable some default bindings as they are needed for our accelerators
foreach key {a A b c d e h i k l L m n o O p q r s S u U v w x z} {
    bind Text  <Control-$key> ""
    bind Entry <Control-$key> ""
}

###
### Helper Functions for GUI
###

proc updateFont {name1 name2 op} {
    global allTop fontSize fontSizeIdx fontFamilyIdx fontFamily
    font configure txt -size [lindex $fontSize $fontSizeIdx] \
        -family [lindex $fontFamily $fontFamilyIdx]
    foreach top [array names allTop] {
        resizeCanvas $top
    }
}

trace variable fontSizeIdx   w updateFont
trace variable fontFamilyIdx w updateFont

set nonce 0

proc newToplevel { {menu ""} } {
    global nonce allTop

    incr nonce
    set top ".top$nonce"
    set allTop($top) 1

    if { $menu != "" } {
        toplevel $top -menu $top.$menu
    } else {
        toplevel $top
    }

    wm protocol $top WM_DELETE_WINDOW "myClose $top"
    return $top
}

proc delToplevel {top} {
    global allTop

    destroy $top
    unset allTop($top)
    if { [array size allTop] == 0} {
        exit
    }
}

proc resize {widget top step} {
    set height [$widget cget -height]
    if { $step > 0 || $height > 4 } {
        $widget configure -height [expr $height + $step]
        resizeCanvas $top
    }
}

proc resizeCanvas {top} {
    # compute size of canvas (only height is important:-)
    update
    $top.c config -scrollregion "0 0 0 [winfo height $top.c.f]"
}

proc addEntry {frame top name label {helpStr ""} {comlabel ""} {command ""} } {
    if { [string length $command] == 0 } {
        grid [label $frame.$name-l -text $label -anchor ne -justify right] \
             [entry $frame.$name-m -width 0] \
             -sticky nsew
    } else {
        grid [label $frame.$name-l -text $label -anchor ne -justify right] \
             [entry $frame.$name-m -width 0] \
             [frame $frame.$name-r -bd 0] \
             -sticky nsew
        pack [button $frame.$name-r.b -text $comlabel -command $command] \
             -anchor nw -padx 2
    }
    bind $frame.$name-m <FocusIn>  "scrollVisible $top.c $frame %W; set help($top) {$helpStr}"
    bind $frame.$name-m <FocusOut> "set help($top) {}"

    bind $frame.$name-m <Control-KeyPress> "#"
    bind $frame.$name-m <KeyPress>      "if {%N < 65000} {setModified $top 1}"
    bind $frame.$name-m <Button-2>      "setModified $top 1"
    bind $frame.$name-m <Any-Delete>    "setModified $top 1"
    bind $frame.$name-m <Any-BackSpace> "setModified $top 1"
    bind $frame.$name-m <<Cut>>         "setModified $top 1"
    bind $frame.$name-m <<Paste>>       "setModified $top 1"
}

proc addText {frame top name label {helpStr ""} {comlabel ""} {command ""} } {
    global help do_drag pan_step

    grid [label $frame.$name-l -text $label -anchor ne -justify right] \
         [frame $frame.$name-m ] \
         [frame $frame.$name-r -bd 0] \
         -sticky nsew
    pack [scrollbar $frame.$name-m.y -command "$frame.$name-m.t yview" \
        -orient vertical -highlightthickness 0 -takefocus 0] -side right -fill both
    pack [text $frame.$name-m.t -width 0 -height 6 -yscrollcommand "$frame.$name-m.y set"] \
        -side right -fill both -expand true
    if { $command != "" } {
        pack [button $frame.$name-r.b -text $comlabel -command $command] \
             -anchor nw -padx 2 -side top
    }

    grid [frame $frame.$name-pan -cursor sb_v_double_arrow -height 3] \
        -sticky nsew -col 1

    set do_drag 0
    bind $frame.$name-pan <ButtonPress> {set do_drag 1}
    bind $frame.$name-pan <ButtonRelease> {set do_drag 0}
    bind $frame.$name-pan <Motion> "
      if \$do_drag {
        if {%y > \$pan_step} {
	  resize $frame.$name-m.t $top 1
	} elseif {%y < -\$pan_step} {
	  resize $frame.$name-m.t $top -1
	}
      }"

    bind $frame.$name-m <FocusIn>  "scrollVisible $top.c $frame %W; set help($top) {$helpStr}"
    bind $frame.$name-m <FocusOut> "set help($top) {} "

    bind $frame.$name-m.t <Control-KeyPress> "#"
    bind $frame.$name-m.t <KeyPress>      "if {%N < 65000} {setModified $top 1}"
    bind $frame.$name-m.t <Button-2>      "setModified $top 1"
    bind $frame.$name-m.t <Any-Delete>    "setModified $top 1"
    bind $frame.$name-m.t <Any-BackSpace> "setModified $top 1"
    bind $frame.$name-m.t <<Cut>>         "setModified $top 1"
    bind $frame.$name-m.t <<Paste>>       "setModified $top 1"
}

# --- canvas
# === frame
# *** widget
# 
# ----------------------------------
#   ^              ^                ^
#   | myPosition   | scrolledHeight |
#   |              v  (neg. Value)  |
# ==|==============                 |
#   v              ^                |
# ***** ^          |                |
#       | myHeight | visibleHeight  |
# ***** v          |                | virtualHeight
#                  v                | (the whole canvas)
# =================                 |
#                                   |
#                                   v
# ----------------------------------
#

proc scrollVisible {canvas frame widget} {
    set visibleHeight  [winfo height $canvas]
    set virtualHeight  [winfo height $frame]
    set scrolledHeight [winfo y      $frame]
    set myPosition     [winfo y      $widget]
    set myHeight       [winfo height $widget]
    if {$myPosition < - $scrolledHeight } {
        $canvas yview moveto [expr $myPosition.0 / $virtualHeight.0 ]
    } elseif { $myPosition + $myHeight > $visibleHeight - $scrolledHeight } {
        if { $myHeight < $visibleHeight } {
            $canvas yview moveto [expr ($myPosition.0 + $myHeight - $visibleHeight) / $virtualHeight.0 ]
        } else {
            $canvas yview moveto [expr $myPosition.0 / $virtualHeight.0 ]
        }
    }
}

proc addMenu {menu label underline accel top command} {
    set call "$menu add command -label {$label} -command {$command}"
    if { [string length $underline] > 0 } {
        set call "$call -underline {$underline}"
    }
    if { [string length $accel] > 0 } {
        set call "$call -accelerator {Ctrl+$accel}"
        bind $top <Control-$accel> $command
    }
    eval $call
}

proc setModified {top {mod -1}} {
    global modified filename oldTitle
    set title "XHdocu"

    if { $mod >= 0 } {
        set modified($top) $mod
    }

    if { $filename($top) != "" } {
        set title "$title $filename($top)"
    }

    if { $modified($top) } {
        set title "$title (modified)"
    }
    
    if { $title != $oldTitle($top) } {
        set oldTitle($top) $title
        wm title $top $title
    }
}

###
### Build main widget
###

proc addWidget {} {
    global filename oldTitle hdocu fontSize fontSizeIdx fontFamily fontFamilyIdx RcsVersion pan_step
    set top [newToplevel m]
    set filename($top) ""
    set oldTitle($top) ""
    setModified $top 0
    wm withdraw $top

    # Menu bar

    menu $top.m -type menubar
    menu $top.m.file
    $top.m add cascade -menu $top.m.file -label "File" -underline 0
    addMenu $top.m.file "New"        0 n $top "addWidget"
    addMenu $top.m.file "Open..."    0 e $top "fileOpen $top"
    $top.m.file add separator
    addMenu $top.m.file "Save"       0 s $top "fileSave $top"
    addMenu $top.m.file "Save as..." 5 S $top "fileSaveAs $top"
    $top.m.file add separator
    addMenu $top.m.file "Close"      0 w $top "myClose $top"
    addMenu $top.m.file "Exit"       0 q $top "myExit  $top"
    menu $top.m.edit
    $top.m add cascade -menu $top.m.edit -label "Edit" -underline 0
    addMenu $top.m.edit "Cut"   0 x $top "" ;#"event generate \[ focus -lastfor $top \] <<Cut>>"
    addMenu $top.m.edit "Copy"  1 c $top "" ;#"event generate \[ focus -lastfor $top \] <<Copy>>"
    addMenu $top.m.edit "Paste" 0 v $top "" ;#"event generate \[ focus -lastfor $top \] <<Paste>>"
    menu $top.m.insert
    $top.m add cascade -menu $top.m.insert -label "Insert" -underline 0
    addMenu $top.m.insert "" "" a $top "insertString {&auml;} $top"
    addMenu $top.m.insert "" "" o $top "insertString {&ouml;} $top"
    addMenu $top.m.insert "" "" u $top "insertString {&uuml;} $top"
    addMenu $top.m.insert "" "" A $top "insertString {&Auml;} $top"
    addMenu $top.m.insert "" "" O $top "insertString {&Ouml;} $top"
    addMenu $top.m.insert "" "" U $top "insertString {&Uuml;} $top"
    addMenu $top.m.insert "" "" z $top "insertString {&szlig;} $top"
    $top.m.insert add separator
    addMenu $top.m.insert "Bold"      0 b $top "insertString {<B></B>} $top 4"
    addMenu $top.m.insert "Italics"   0 i $top "insertString {<I></I>} $top 4"
    $top.m.insert add separator
    addMenu $top.m.insert "Linebreak" 0 r $top "insertString {<BR>\n} $top"
    addMenu $top.m.insert "Preformatted" 0 p $top "insertString {<PRE></PRE>} $top 6"
    $top.m.insert add separator
    addMenu $top.m.insert "List"      0 L $top "insertString {<UL>\n  <LI>\n</UL>} $top 6"
    addMenu $top.m.insert "List Item" 0 l $top "insertString {\n  <LI>} $top"
    menu $top.m.exec
    $top.m add cascade -menu $top.m.exec -label "Execute" -underline 1
    addMenu $top.m.exec "Hdocu"    0 d $top "runCommand $top {$hdocu} Hdocu"
    addMenu $top.m.exec "Manpages" 0 m $top "runCommand $top {$hdocu -nomake -man} Hdocu"
    addMenu $top.m.exec "Check"    0 k $top "runCommand $top {$hdocu -check} Hdocu"
    menu $top.m.font
    $top.m add cascade -menu $top.m.font -label "Font" -underline 0
    menu $top.m.font.family -tearoff false
    $top.m.font add cascade -menu $top.m.font.family -label "Family" -underline 0
    for {set i 0} {$i < [llength $$fontFamily]} {incr i} {
        $top.m.font.family add radio -label [lindex $fontFamily $i] -value $i -variable fontFamilyIdx
    }
    menu $top.m.font.size -tearoff false
    $top.m.font add cascade -menu $top.m.font.size -label "Size" -underline 0
    for {set i 0} {$i < [llength $fontSize]} {incr i} {
        $top.m.font.size add radio -label [lindex $fontSize $i] -value $i -variable fontSizeIdx
    }
    menu $top.m.help
    $top.m add cascade -menu $top.m.help -label "Help" -underline 0
    addMenu $top.m.help "About" 0 h $top \
        "tk_messageBox -type ok -default ok -icon info -parent $top -title About \
	 -message {Xhdocu $RcsVersion\nedit INFO.LDV files\n(c) FJL} "

    # status line

    pack [label $top.label -textvariable help($top) -anchor w -relief sunken] \
        -fill both -side bottom

    # Scrolled Canvas

    pack [scrollbar $top.scrolly -command "$top.c yview" \
        -orient vertical -highlightthickness 0 -takefocus 0] \
        -side right -fill both
    pack [canvas $top.c -bd 0 -highlightthickness 0 \
        -yscrollcommand "$top.scrolly set" ] \
        -side right -fill both -expand true

    # Widget within Canvas

    set frame [frame $top.c.f -bd 4 -highlightthickness 0]
    $top.c create window 0 0 -anchor nw -window $frame
    grid columnconfigure $frame 1 -weight 1

    addEntry $frame $top name "Name:" \
        "Enter the name of this package"
    addEntry $frame $top vers "Version:" \
        "Version number of this package"
    grid [frame $frame.f -bd 1 -height 2 -container 0 -relief sunken] \
         -columnspan 3 -pady 8 -sticky nsew
    addEntry $frame $top date "Date:" \
        "Date of installation of this package" \
        "Today" "setDate $frame.date-m"
    addEntry $frame $top owner "Owner:" \
        "Login-Name(s) of owner(s), separated by whitespace" \
        "Me" "setUser $frame.owner-m"

    addText $frame $top key  "Keywords:" \
        "Some keywords describing this package, one per line"
    addText $frame $top src  "Source:" \
        "Where did you recieve this package from? (Text or HTML)"
    addText $frame $top use  "Usage:" \
        "Insert some local documentation (Text or HTML)" \
        "..." "includeFile $frame.use-m.t $top"
    addText $frame $top more "More\nDocumentation:" \
        "Where can the user find more documentation? (Text or HTML)" \
        "..." "includeFile $frame.more-m.t $top"
    addText $frame $top inst "Installation:" \
        "Infos about the local installation of this package" \
        "..." "includeFile $frame.inst-m.t $top"
    addText $frame $top bin  "Binaries:" \
        "All installed binaries from this package. Full path name, one per line, comment after whitepsace" \
        "..." "includePath $frame.bin-m.t $top bin"
    addText $frame $top lib  "Libraries:" \
        "All installed libraries from this package. Full path name, one per line, comment after whitepsace" \
        "..." "includePath $frame.lib-m.t $top lib"
    addText $frame $top inc "Header:" \
        "All installed header files from this package. Full path name, one per line, comment after whitepsace" \
        "..." "includePath $frame.inc-m.t $top inc"
    addText $frame $top man  "Manpages:" \
        "All installed manpages from this package. No path, with suffix, one per line" \
        "..." "includePath $frame.man-m.t $top man"

    # make first two lines as high as third line
    update
    grid rowconfigure $frame "0 1" -minsize [ lindex [ grid bbox $frame 0 3 ] 3 ]

    # calculate stepping of panner movement: text widget is 6 lines high
    set pan_step [expr [winfo height $frame.use-m.t] / 6]

    # compute size of canvas (only height is important:-)
    resizeCanvas $top

    # finished...
    wm geometry $top "600x400"
    wm deiconify $top
    focus $frame.name-m

    # resizing by hand
    bind $top.c <Configure> "\
        $frame.f configure -width \[ \
            expr \[winfo width $top\] - [$top.scrolly cget -width] - 12 \]
        $frame configure -width \[ \
            expr \[winfo width $top\] - [$top.scrolly cget -width] - 4 \]"
    return $top
}

###
### Menu Functions
###

proc insertString {string top {relpos 0} } {
    set widget [focus -lastfor $top]
    # find out if widget is an entry or a text widget
    # only text widget has an yscrollcommand
    if [catch {
    	$widget cget -yscrollcommand
    } ] {
    	set isText 0
    } else {
    	set isText 1
    }

    # get selection (if needed)
    set selection ""
    if { $relpos > 0 } {
	if $isText {
	    catch {
		set selection [$widget get sel.first sel.last]
		$widget delete sel.first sel.last
	    }
	} else {
	    if [$widget selection present] {
		set selection [string range [$widget get] [$widget index sel.first] [expr [$widget index sel.last] -1]]
		$widget delete sel.first sel.last
	    }
	}
    }

    # insert string
    if { ! [catch {
        $widget insert insert $string
    } ] } {
        setModified $top 1
    }
    # set cursor and paste selection
    if $isText {
    	$widget mark set insert "insert - $relpos c"
        $widget insert insert $selection
    } else {
    	$widget icursor [expr [$widget index insert] - $relpos]
        $widget insert insert $selection
    }
}

proc setDate {widget} {
    $widget delete 0 end
    $widget insert end [clock format [clock seconds] -format "%d.%m.%Y"]
    focus $widget
    setModified [winfo toplevel $widget] 1
}

proc setUser {widget} {
    global tcl_platform

    $widget delete 0 end
    if { $tcl_platform(platform) == "unix" } {
        $widget insert end [exec whoami]
    } else {
        $widget insert end "n/a"
    }
    focus $widget
    setModified [winfo toplevel $widget] 1
}

proc myExit {top} {
    if {[tk_messageBox -type okcancel -default cancel -icon question -parent $top -title Exit \
	-message "Do you really want to exit?"] == "ok" } {
        exit
    }
}

proc myClose {top} {
    global modified allTop

    if {$modified($top)} {
        set answer [tk_messageBox -type yesnocancel -default cancel -icon warning -parent $top -title "Unsaved Changes" \
	    -message "Save changes before closing window?"]

        case $answer {
            yes    { if {! [fileSave $top] } return }
            cancel return
        }
    } elseif { [array size allTop] == 1} {
        myExit $top
    } elseif {[tk_messageBox -type okcancel -default cancel -icon question -parent $top -title Close \
	 -message "Do you really want to close this window?"] == "cancel" } {
        return
    }
    delToplevel $top
}

proc runCommand {top command {title "Hdocu"}} {
    global tcl_platform shell

    if { $tcl_platform(platform) == "unix" } {
        exec $shell "xterm -bg '#eee' -fg '#000' -sb -sl 250 -name '$title' -title '$title' \
              -e $shell '$command; echo; echo Press \[return\] to continue; read x'" &
    } else {
        tk_messageBox -type ok -default ok -icon warning -parent $top -title "Not here..." \
	 -message "Sorry, only available on UNIX"
    }
}

proc includeFile {widget top} {
    set filetypes {
        {{All files}  {*}               }
        {{Text files} {{.txt} {.TXT}}   }
        {{Readme}     {README}          }
    }

    set filename [tk_getOpenFile -parent $top -title "Include file..." -filetypes $filetypes]
    if { $filename != "" } {
        if { [file readable $filename] } {
            set datei [open $filename]
            $widget insert insert [read $datei]
            focus $widget
            close $datei
            setModified $top 1
        }
    }
}

proc includePath {widget top {type "bin"}} {
    switch -exact -- $type {
        bin {
            set filetypes {
                {{All files} {*} }
            }
        } lib {
            set filetypes {
                {{Libraries} { {.a} {.so} {.sl} }  }
                {{All files} {*}                   }
            }
        } inc {
            set filetypes {
                {{Header}    {.h} }
                {{All files} {*}  }
            }
        } man {
            set filetypes {
                {{Man-Pages} {*.?} }
                {{All files} {*}   }
            }
        }
    }

    set filename [tk_getOpenFile -parent $top -title "Include file..." -filetypes $filetypes]
    if { $filename != "" } {
        if { $type == "man" } {
            $widget insert insert "[file tail $filename]\n"
            focus $widget
            setModified $top 1
        } else {
            if { ($type == "bin") && (![file executable $filename]) } {
                tk_messageBox -type ok -default ok -icon warning -parent $top -title Warning \
	         -message "File \"$filename\" is not executable!"
            } else {
                $widget insert insert "$filename\n"
                focus $widget
                setModified $top 1
            }
        }
    }
}

proc fileOpen {top {name ""} } {
    global modified filename

    if {$modified($top)} {
        set answer [tk_messageBox -type yesnocancel -default cancel -icon warning -parent $top -title "Unsaved Changes" \
	    -message "Save changes before opening new file?"]

        case $answer {
            yes    { if {! [fileSave $top] } return }
            cancel return
        }
    }
    set filetypes {
        {{INFO.LDV files} {INFO.LDV} }
        {{All files}      {*}        }
    }

    if {$name == ""} {
        set name [tk_getOpenFile -parent $top -title "Open file..." -filetypes $filetypes]
    }
    if { $name == "" } {
        return 0
    }
    set filename($top) $name
    set section "NONE"
    set result($section) ""
    if [ catch { set datei [open $filename($top) r] } errorMsg ] {
        tk_messageBox -type ok -default ok -icon error -parent $top -title Error -message $errorMsg
        return 0
    }
    # clear/create array elements (both new and old style)
    foreach key {NAME VERSION DATE OWNER KEY SOURCE \
                 USAGE DOCU INSTALL BIN LIB INC MAN \
		 PAKETNAME KEYWORDS LOKALE_DOKU DOKU \
		 BINARIES INCLUDE BETREUER DATUM \
		 DISTRIBUTION INSTALLATIONSHINWEISE } {
        set result($key) ""
    }

    while { ! [eof $datei] } {
        set line [gets $datei]
        # Comment?
        if { ! [regexp {(^[ \t]*$)|(^#.*$)} $line] } {
            # new section?
            if { [regexp {^_([^ \t]+)} $line {} section] } {
                set result($section) ""
            } else {
                if {$result($section) != "" } {
                    set result($section) "$result($section)\n$line"
                } else {
                    set result($section) "$line"
                }
            }
        }
    }
    close $datei
    convertOldStyle result

    set frame $top.c.f
    $frame.name-m   delete 0 end
    $frame.name-m   insert end [join [split $result(NAME) "\n"] "" ]
    $frame.vers-m   delete 0 end
    $frame.vers-m   insert end [join [split $result(VERSION) "\n"] "" ]
    $frame.date-m   delete 0 end
    $frame.date-m   insert end [join [split $result(DATE) "\n"] "" ]
    $frame.owner-m  delete 0 end
    $frame.owner-m  insert end [join [split $result(OWNER) "\n"] " " ]
    $frame.key-m.t  delete 1.0 end
    $frame.key-m.t  insert end $result(KEY)
    $frame.src-m.t  delete 1.0 end
    $frame.src-m.t  insert end $result(SOURCE)
    $frame.use-m.t  delete 1.0 end
    $frame.use-m.t  insert end $result(USAGE)
    $frame.more-m.t delete 1.0 end
    $frame.more-m.t insert end $result(DOCU)
    $frame.inst-m.t delete 1.0 end
    $frame.inst-m.t insert end $result(INSTALL)
    $frame.bin-m.t  delete 1.0 end
    $frame.bin-m.t  insert end $result(BIN)
    $frame.lib-m.t  delete 1.0 end
    $frame.lib-m.t  insert end $result(LIB)
    $frame.inc-m.t  delete 1.0 end
    $frame.inc-m.t  insert end $result(INC)
    $frame.man-m.t  delete 1.0 end
    $frame.man-m.t  insert end $result(MAN)

    setModified $top 0
    return 1
}

proc convertOldStyle { arrayName } {
    upvar $arrayName result
    # You shouldn't mix old and new style in one file,
    #     but you can use both styles in different files.
    #     So we have to guess wich one is used:
    if { $result(PAKETNAME) != "" || $result(LOKALE_DOKU) != "" } {
	set result(NAME)    "$result(PAKETNAME)"
	# VERSION
	set result(KEY)     "$result(KEYWORDS)"
	set result(USAGE)   "$result(LOKALE_DOKU)"
	set result(DOCU)    "$result(DOKU)"
	set result(BIN)     "$result(BINARIES)"
	# LIB
	set result(INC)     "$result(INCLUDE)"
	# MAN
	set result(OWNER)   "$result(BETREUER)"
	set result(DATE)    "$result(DATUM)"
	set result(SOURCE)  "$result(DISTRIBUTION)"
	set result(INSTALL) "$result(INSTALLATIONSHINWEISE)"
    }
}

proc fileSave {top} {
    global filename

    if { $filename($top) == "" } {
        return [fileSaveAs $top]
    } else {
        if [ catch { set datei [open $filename($top) w] } errorMsg ] {
            tk_messageBox -type ok -default ok -icon error -parent $top -title Error -message $errorMsg
            return 0
        }
        set frame $top.c.f
        puts $datei \
"# This file was generated automatically by XHdocu

#
_NAME
[$frame.name-m get]

#
_VERSION
[$frame.vers-m get]

#
_DATE
[$frame.date-m get]

#
_OWNER
[join [split [$frame.owner-m get] { }] \n]

#
_KEY
[$frame.key-m.t get 1.0 end-1c]

#
_SOURCE
[$frame.src-m.t get 1.0 end-1c]

#
_USAGE
[$frame.use-m.t get 1.0 end-1c]

#
_DOCU
[$frame.more-m.t get 1.0 end-1c]

#
_INSTALL
[$frame.inst-m.t get 1.0 end-1c]

#
_BIN
[$frame.bin-m.t get 1.0 end-1c]

#
_LIB
[$frame.lib-m.t get 1.0 end-1c]

#
_INC
[$frame.inc-m.t get 1.0 end-1c]

#
_MAN
[$frame.man-m.t get 1.0 end-1c]"

        close $datei
        setModified $top 0
    }
    return 1
}

proc fileSaveAs {top} {
    global filename

    set filetypes {
        {{INFO.LDV files} {INFO.LDV} }
        {{All files}      {*}        }
    }
    set name [tk_getSaveFile -parent $top -title "Save file..." \
        -filetypes $filetypes -initialfile "INFO.LDV"]

    if { $name == "" } {
        return 0
    } else {
        set filename($top) $name
        setModified $top
        return [fileSave $top]
    }
}


###
### Go
###

if { $argc > 0 } {
    if { [ lsearch -exact $argv "-version" ] >= 0 } {
        puts "XHdocu version $RcsVersion"
        exit
    }
    foreach arg $argv {
        set top [addWidget]
	fileOpen $top $arg
    }
} else {
    addWidget
}
