1% BEGIN LICENSE BLOCK
2% Version: CMPL 1.1
3%
4% The contents of this file are subject to the Cisco-style Mozilla Public
5% License Version 1.1 (the "License"); you may not use this file except
6% in compliance with the License.  You may obtain a copy of the License
7% at www.eclipse-clp.org/license.
8% 
9% Software distributed under the License is distributed on an "AS IS"
10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11% the License for the specific language governing rights and limitations
12% under the License. 
13% 
14% The Original Code is  The ECLiPSe Constraint Logic Programming System. 
15% The Initial Developer of the Original Code is  Cisco Systems, Inc. 
16% Portions created by the Initial Developer are
17% Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18% 
19% Contributor(s): 
20% 
21% END LICENSE BLOCK
22
23:- local variable(pid).
24
25:- [mapcolour].
26
27exec_mapdisplay(Pid, Port, Sock) :-
28        get_flag(hostarch, ARCH),
29        TclFile = "mapdebugdemo.tcl",
30        (exists(TclFile) -> 
31            true
32        ;
33            printf(error, "Cannot find %w, which is needed to run"
34                           " this program.%nCheck that you are in the"
35                           " right directory to run this program.\n", [TclFile]),
36            (current_stream(Sock) -> close(Sock) ; true),
37            abort
38        ),
39        ((ARCH == "i386_nt"; ARCH == "x86_64_nt") ->
40             get_flag(installation_directory, ECDIR),
41             concat_string([ECDIR, "/tcltk/",ARCH, "/bin/"], WISHPATH),
42	     read_directory(WISHPATH, "wish*", _, [WISH|_]), 
43	     concat_string([WISHPATH, WISH], WISHEXEC),
44             exec([WISHEXEC, TclFile, "--", "-p", Port], [], Pid)
45        ;
46             exec([wish, TclFile, "--", "-p", Port], [], Pid)
47        ),
48        setval(pid, Pid).
49
50
51
52disconnect_handler :-
53        get_flag(hostarch, ARCH),
54        ((ARCH == "i386_nt" ; ARCH == "x86_64_nt") -> 
55             true ; getval(pid, Pid), wait(Pid, _)
56        ).
57
58post_attach(S) :-
59        set_event_handler(S, disconnect_handler/0).
60
61
62colour :-
63        remote_connect_setup(localhost/Port, Peer, Sock),
64        exec_mapdisplay(_Pid, Port, Sock),
65        (remote_connect_accept(Peer, Sock, 10, post_attach(Peer), "", _) ->
66            block(colouring1(prolog, input_order, indomain, 4, _), _,  true)
67        ;
68            writeln("Unable to connect to program to display the map."),
69            (current_stream(Sock) -> close(Sock) ; true),
70            abort
71        ).
72
73
74colourdelay :-
75        colouring1(delay, input_order, indomain, 4, _).
76
77