1#! /bin/sh
2# \
3	exec wish $0 ${1+"$@"}
4
5# BEGIN LICENSE BLOCK
6# Version: CMPL 1.1
7#
8# The contents of this file are subject to the Cisco-style Mozilla Public
9# License Version 1.1 (the "License"); you may not use this file except
10# in compliance with the License.  You may obtain a copy of the License
11# at www.eclipse-clp.org/license.
12#
13# Software distributed under the License is distributed on an "AS IS"
14# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
15# the License for the specific language governing rights and limitations
16# under the License.
17#
18# The Original Code is  The ECLiPSe Constraint Logic Programming System.
19# The Initial Developer of the Original Code is  Cisco Systems, Inc.
20# Portions created by the Initial Developer are
21# Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
22#
23# Contributor(s):
24#
25# END LICENSE BLOCK
26#----------------------------------------------------------------------
27# Preamble: Find and load the eclipse package
28#----------------------------------------------------------------------
29
30switch $tcl_platform(platform) {
31    unix {
32	if {![info exists env(ECLIPSEDIR)]} {
33	    puts "Cannot run Eclipse: ECLIPSEDIR environment variable is undefined."
34	    exit -1
35	}
36	set tkecl(ECLIPSEDIR) $env(ECLIPSEDIR)
37    }
38    windows {
39	package require registry
40	set tkecl(ECLIPSEDIR) [registry get \
41	    HKEY_LOCAL_MACHINE\\SOFTWARE\\IC-Parc\\Eclipse\\6.2 ECLIPSEDIR]
42    }
43    default {
44	error "$tcl_platform(platform) not supported"
45	exit -1
46    }
47}
48
49lappend auto_path [file join $tkecl(ECLIPSEDIR) lib_tcl]
50
51package require eclipse
52package require eclipse_tools
53
54
55#----------------------------------------------------------------------
56# Make a standard menu bar and a 'File' and 'Tools' menu
57#----------------------------------------------------------------------
58
59wm title . "A small ECLiPSe/Tcl/Tk Application"
60
61. config -menu .mbar
62
63menu .mbar
64.mbar add cascade -label File -menu .mbar.file
65.mbar add cascade -label Tools -menu .mbar.tools
66
67menu .mbar.file
68.mbar.file add command -label Run -command run_eclipse
69.mbar.file add command -label Exit -command exit
70
71
72#----------------------------------------------------------------------
73# The sample Eclipse-goal and a button to run it
74#----------------------------------------------------------------------
75
76proc run_eclipse {} {
77
78    # Goals can be posted either in ECLiPSe syntax:
79    ec_post_goal {writeln("hello world"),flush(output)}
80
81    # .. or ceated from Tcl data using EXDR conversion:
82    ec_post_goal {, {writeln "hello again"} {flush output}} ((S)(()))
83
84    ec_resume
85}
86
87
88button .run -text Run -command run_eclipse
89pack .run -side top -expand true -fill x
90
91
92#----------------------------------------------------------------------
93# Initialise the embedded ECLiPSe (plus the optional toolkit)
94#----------------------------------------------------------------------
95
96#ec_set_option io 0;	# uncomment this to debug bootstrapping problems
97
98ec_init
99ec_tools_init .mbar.tools
100# allow ECLiPSe engine to shutdown when exiting
101bind .run <Destroy> {ec_cleanup}
102
103
104#----------------------------------------------------------------------
105# Add an output window and connect it to the eclipse 'output' stream
106#----------------------------------------------------------------------
107
108text .tout
109pack .tout
110
111ec_queue_connect output r {ec_stream_to_window {} .tout}
112
113