#!/usr/local/tcl/bin/wish -f
#
# TK interface to the MH Mail utility
# Brent Welch <welch@parc.xerox.com>
# Original version by <Ed Oskiewicz (eo@ansa.co.uk)>
#
# Copyright (c) 1993 Xerox Corporation.
# Use and copying of this software and preparation of derivative works based
# upon this software are permitted. Any distribution of this software or
# derivative works must comply with all applicable United States export
# control laws. This software is made available AS IS, and Xerox Corporation
# makes no warranty about the software, its performance or its conformity to
# any specification.

# The following lines are patched by exmh.install
#CONFIGURATION
set wish /usr/local/tcl/bin/wish
set exmh(version) {version 1.6 4/21/95}
set exmh(maintainer) Brent.Welch@eng.sun.com
set mh_path /usr/bin/mh
set exmh(slocal) /usr/lib/mh/slocal
set mime(dir) /usr/local/bin
set mailcap_default /etc/mailcap
set exmh(expect) /usr/local/bin/expect
set faces(dir) /usr/local/faces/faces
set faces(set) {parc logos news facesaver}
set faces(defaultDomain) uwa.edu.au
set pgp(path) /usr/local/bin
set glimpse(path) /usr/local/bin
set sound(cmd) {/usr/demo/SOUND/play -v 38}
set exmh(library) /usr/local/lib/exmh-1.6
set install(dir,bin) /usr/local/bin
set install(dir,man) /usr/local/man/manl
set install(dir,lib) /usr/local/lib/exmh-1.6

#END CONFIGURATION

if {$tk_version < 3.3} {
    puts stderr "Warning: EXMH requires Tk 3.3 through Tk 4.0."
    exit 1
}
# Do this so popups related to user initialization
# appear all alone.
wm withdraw .

proc auto_path_update { path } {
    # Add library directories to the auto_path,
    # ensuring that later paths have precedence
    # and that function override works
    global auto_path tk_version
    if [file exists $path/tclIndex] {
	if {[info tclversion] != 7.0} {
	    set auto_path "$path $auto_path"
	} else {
	    lappend auto_path $path
	}
	catch {auto_reset} ;# Needed for function override
    }
}

auto_path_update $exmh(library)

if ![file exists $exmh(library)/tclIndex] {
    if [file exists ./lib/tclIndex] {
	puts stderr "Warning, using local script library, ./lib"
	set exmh(library) ./lib
    }
}

# Make sure MH is on the path
set hit 0
foreach dir [split $env(PATH) :] {
    if {[string compare $dir $mh_path] == 0} {
	set hit 1
	break
    }
}
if {! $hit} {
    set env(PATH) $mh_path:$env(PATH)
}
# Use an alternate MH context file to avoid conflicts with command line use.
set env(MHCONTEXT) .exmhcontext

# For session managers
wm command . "$argv0 $argv"

# modified by k.furukawa, jul.1994.  for kanji
# this piece of code enables japanese kanji display if you use
# tk-jp extension and JIS code.  if you use EUC for MH processing 
# codes, you may replace JIS with EUC and you may need more works.

if {[info commands kanji] == "kanji"} {
    kanji internalCode JIS
    option add *Text.Font a14
}

# Ensure the user is in a writable directory for @ links
if {[string match /* $exmh(library)] &&
    ![string match */* $argv0]} {
    # Don't go anywhere when testing
    cd
}

# The rest of the application is defined by routines in the exmh library
# The after 1 trick is to ensure we get the built-in error handler.

after 1 {Exmh}
