View source with formatted comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org/packages/xpce/
    6    Copyright (c)  1996-2012, University of Amsterdam
    7                              VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(pce_compatibility_layer,
   37          [ auto_call/1,
   38            callable_predicate/1,
   39            modified_since_last_loaded/1,
   40            pce_error/1,
   41            pce_warn/1,
   42            pce_info/1
   43          ]).   44
   45/** <module> XPCE Compatibility layer
   46
   47This layer defines some predicates to   enhance portability with SICStus
   48and Quintus Prolog. These systems are  no   longer  supported, but it is
   49probably wise to keep this layer for `just-in-case'.
   50*/
   51
   52:- meta_predicate
   53    auto_call(0),
   54    callable_predicate(:).   55
   56%!  auto_call(:Goal)
   57%
   58%   Autoload Goal and call it. If autoloading   is enabled we can simply
   59%   call  the  target.  Otherwise   we    autoload   the  predicate  and
   60%   subsequently call it.
   61%
   62%   This predicate should be used to open new IDE tools, for example the
   63%   manual opening the editor, etc.
   64
   65auto_call(G) :-
   66    current_prolog_flag(autoload, true),
   67    !,
   68    call(G).
   69auto_call(G) :-
   70    '$pi_head'(PI, G),
   71    current_prolog_flag(autoload, Old),
   72    setup_call_cleanup(
   73        asserta(user:thread_message_hook(autoload(disabled(_Count)),_,_), Ref),
   74        setup_call_cleanup(
   75            set_prolog_flag(autoload, true),
   76            '$autoload'(PI),
   77            set_prolog_flag(autoload, Old)),
   78        erase(Ref)),
   79    call(G).
   80
   81
   82                 /*******************************
   83                 *      DIALOG EDITOR SUPPORT   *
   84                 *******************************/
   85
   86%!  callable_predicate(:Head) is semidet.
   87%
   88%   Succeeds if Head can be called without raising an exception for
   89%   an undefined predicate
   90
   91callable_predicate(M:Head) :-
   92    callable(Head),
   93    functor(Head, Name, Arity),
   94    current_predicate(M:Name/Arity).
   95
   96%!  modified_since_last_loaded(Path) is semidet.
   97%
   98%   True is file has been modified since the last time it was loaded.
   99
  100modified_since_last_loaded(File) :-
  101    '$time_source_file'(File, LoadTime, user),
  102    !,
  103    time_file(File, Modified),
  104    Modified > LoadTime.
  105modified_since_last_loaded(InFile) :-
  106    '$time_source_file'(File, LoadTime, user),
  107    same_file(InFile, File),
  108    !,
  109    time_file(File, Modified),
  110    Modified > LoadTime.
  111
  112
  113                 /*******************************
  114                 *           MESSAGES           *
  115                 *******************************/
  116
  117%!  pce_error(+Term) is det.
  118%!  pce_warn(+Term) is det.
  119%!  pce_info(+Term) is det.
  120%
  121%   Portability layer wrappers around print_message/2.
  122
  123pce_error(Term) :-
  124    (   current_prolog_flag(xref, true)
  125    ->  true
  126    ;   print_message(error, Term)
  127    ).
  128
  129pce_warn(Term) :-
  130    (   current_prolog_flag(xref, true)
  131    ->  true
  132    ;   print_message(warning, Term)
  133    ).
  134
  135pce_info(Term) :-
  136    print_message(informational, Term)