1/* <module> SWI-Prolog compat for startup
    2% ===================================================================
    3    File:         'logicmoo_swilib.'
    4    Purpose:       To load the logicmoo libraries as needed
    5    Contact:       $Author: dmiles $@users.sourceforge.net ;
    6    Version:       'logicmoo_swilib.' 1.0.0
    7    Revision:      $Revision: 1.7 $
    8    Revised At:    $Date: 2002/07/11 21:57:28 $
    9    Author:        Douglas R. Miles
   10    Maintainers:   TeamSPoon
   11    E-mail:        logicmoo@gmail.com
   12    WWW:           http://www.prologmoo.com
   13    SCM:           https://github.com/TeamSPoon/PrologMUD/tree/master/pack/logicmoo_base
   14    Copyleft:      1999-2015, LogicMOO Prolog Extensions
   15    License:       Lesser GNU Public License
   16% ===================================================================
   17*/
   18
   19:- module(logicmoo_swilib,[logicmoo_goal/0,logicmoo_run_goal/0,logicmoo_toplevel/0,add_history_ideas/0,start_x_ide/0]).   20
   21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   22% DEFAULT PROLOG FLAGS
   23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   24 % :- set_prolog_flag(subclause_expansion,default).
   25 % :- set_prolog_flag(subclause_expansion,false).
   26 % :- set_prolog_flag(dialect_pfc,default).
   27:- set_prolog_flag(double_quotes,string).   28:- set_prolog_flag(autoload_logicmoo,false).   29
   30:- if( \+ current_module(prolog_stack)).   31:- use_module(library(prolog_stack)).   32 prolog_stack:stack_guard(none).
   33:- endif.   34
   35
   36:- if(current_prolog_flag(xpce,true) ).   37
   38:- if(current_prolog_flag(xpce,false)).   39:- set_prolog_flag(xpce,true).   40:- use_module(library(gui_tracer)).   41:- use_module(library(swi_ide)).   42:- use_module(library(pce)).   43:- set_prolog_flag(xpce,false).   44:- else.   45:- use_module(library(gui_tracer)).   46:- use_module(library(swi_ide)).   47:- use_module(library(pce)).   48:- endif.   49
   50:- endif.   51
   52:- if( (current_prolog_flag(xpce,false); current_prolog_flag(logicmoo_headless, true); ( \+ getenv('DISPLAY',_)) ; ((app_argv(List),  (member('--nopce',List) ; member('--nogui',List)) )))).   53:- set_prolog_flag(logicmoo_headless,true).   54:- set_prolog_flag(xpce,false).   55:- unsetenv('DISPLAY').   56:- endif.   57
   58/*
   59:- set_prolog_flag(access_level,system).
   60:- set_prolog_flag(compile_meta_arguments,false). % default is false
   61*/
   62
   63:- user:use_module(library(base32)).   64/*
   65% :- user:use_module(library(http/http_dispatch)).
   66:- use_module(library(http/thread_httpd)).
   67:- use_module(thread_httpd:library(http/http_dispatch)).
   68:- use_module(library(http/http_path)).
   69:- use_module(library(http/http_server_files)).
   70:- use_module(library(http/http_parameters)).
   71%:- use_module(library(http/html_head)).
   72%:- use_module(swi(library/http/html_write)).
   73:- use_module(library(threadutil)).
   74:- user:use_module(library(shell)).
   75:- use_module(library(console_input)).
   76:- if(current_predicate(system:mode/1)).
   77:- user:use_module(library(quintus),except([mode/1])). 
   78:- else.
   79:- user:use_module(library(quintus)). 
   80:- endif.
   81:- user:use_module(library(dialect/ifprolog),except([op(_,_,_)])).
   82:- abolish(system:time/1).
   83:- use_module(library(dialect/hprolog)).
   84:- abolish(hprolog:time/1).
   85:- system:use_module(library(statistics),[time/1]).
   86:- user:use_module(library(statistics)).
   87:- baseKB:use_module(library(statistics),[time/1]).
   88%:- autoload([verbose(false)]).
   89*/
   90
   91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   92% MISC UTILS
   93%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   94:- user:use_module(library(logicmoo_common)).   95
   96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   97% DEFAULT DEBUG PROLOG FLAGS
   98%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   99setup_for_debug :- 
  100   set_prolog_flag(report_error,true),
  101   set_prolog_flag(debugger_show_context,true),
  102   set_prolog_flag(debug_on_error,true),
  103   % set_prolog_flag(debugger_write_options,[quoted(true), portray(true), max_depth(1000), attributes(portray)]),
  104   set_prolog_flag(generate_debug_info,true).
  105
  106%:- before_boot(setup_for_debug).
  107
  108
  109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110% DEFAULT HISTORY
  111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  112
  113%add_history_ideas:- \+ app_argv('--history'),!.
  114add_history_ideas:- app_argv('--no-history'),!.
  115%add_history_ideas:- !.
  116add_history_ideas:- has_ran_once(add_history_ideas),!.
  117add_history_ideas:- 
  118       asserta(lmcache:added_history_ideas_once),
  119       % use_module(library(editline)),
  120        use_module(library(prolog_history)),
  121
  122        add_history(start_telnet),
  123        add_history(help(match_regex/2)),
  124        add_history(list_undefined),
  125        add_history(listing(lmconf:at_restore_goal/2)),
  126	add_history(ensure_loaded(run_mud_game)),
  127	add_history(statistics),        
  128        add_history(qsave_lm(lm_repl)),        
  129        add_history(make),        
  130        add_history(mmake),
  131        add_history(login_and_run),        
  132        forall(lmconf:at_restore_goal(_,G),add_history(G)),
  133        add_history(loadSumo),
  134        add_history(loadTinyKB),
  135        add_history(threads),
  136        add_history(run_pending_inits),
  137        add_history(use_module(library(sexpr_reader))),
  138        add_history(input_to_forms("( #\\a #\\u0009 . #\\bell )",'$VAR'('O'),'$VAR'('Vs'))),
  139        add_history(tstl),
  140        add_history(qconsult_kb7166),
  141        add_history(ensure_loaded(library(logicmoo_user))),
  142        add_history(ensure_loaded(library(logicmoo_clif))),
  143        add_history(ensure_loaded(library(logicmoo_sumo))),
  144        add_history(ensure_loaded(library(logicmoo_webbot))),
  145        add_history(ensure_loaded(library(logicmoo_repl))),
  146        add_history(user:load_library_system(library(logicmoo_planner))),
  147        add_history([user:init_mud_server]),
  148        add_history([user:run_mud_server]),
  149        add_history(consult(library(prologmud_sample_games/run_mud_server))),
  150        !.
  151
  152:- before_boot(add_history_ideas).  153
  154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  155% DEFAULT GOALS
  156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  157logicmoo_goal:-  dmsg("logicmoo_goal"),logicmoo_toplevel.
  158
  159logicmoo_run_goal:- has_ran_once(logicmoo_run_goal),!.
  160logicmoo_run_goal:- 
  161 %module(baseKB),
  162 dmsg("logicmoo_run_goal"),
  163 nb_setval('$oo_stack',[]),
  164 run_pending_inits.
  165
  166logicmoo_toplevel:- has_ran_once(logicmoo_toplevel),!.
  167logicmoo_toplevel:- dmsg("logicmoo_toplevel"),
  168 %module(baseKB),
  169 add_history_ideas,
  170 dmsg("  [logicmoo_repl]."),
  171 dmsg("  [user:init_mud_server]."),
  172 dmsg("  [user:run_mud_server]."),!,
  173 dmsg("?- make:make_no_trace."), 
  174 % make:make_no_trace,
  175 listing(lmconf:at_restore_goal/2),
  176 logicmoo_run_goal,
  177 dmsg("Press Ctrl-D to Start"),
  178 prolog.
  179
  180
  181
  182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  183% (X)WINDOWS (DE)BUGGERY
  184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185start_x_ide:- !.
  186start_x_ide:- current_prolog_flag(logicmoo_headless,true),!.
  187start_x_ide:- 
  188  quietly((prolog_ide(thread_monitor),prolog_ide(debug_monitor),
  189   % prolog_ide(open_debug_status),
  190   guitracer,
  191   use_module(library(pce_prolog_xref)),
  192   noguitracer)).
  193
  194:- after_boot(dmsg(start_x_ide)).  195
  196:- fixup_exports.