%      Production system KORE/IE (version 12.48)
%
%          (C)1992 Institute for New Generation Computer Technology
%                          (Read COPYRIGHT for detailed information)
%
%      1992.7 Check and refine every programs 
%                             for IFS (ICOT Free Software) release.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% File Load %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
#load --- predicate for loading production rules file
	UASGE: load Load_Name.
	pruduction_rules_file_name ::= 'rule.'Load_Name
*/

%%%%% LOAD
(load [H|T]) :-
	!,
	(load H),
	!,
	(load T).
(load []) :-
	!.
(load File_Name) :- 
	!,
	(atomic(File_Name),
	 name(File_Name,FN),
	 !,
	 (append(FN,".rule",NFILE_NAME),
	  name(FILE_NAME,NFILE_NAME),
	  true;
%	  exists(FILE_NAME);
	  append(FN,".fact",NFILE_NAME),
	  name(FILE_NAME,NFILE_NAME),
	  true;
%	  exists(FILE_NAME);
	  FILE_NAME=File_Name,
	  true;
%	  exists(FILE_NAME);
	  write('*** ERROR ***'),
	  nl,
	  write(File_Name),
	  write(' cannot load ...'),
	  nl,
	  !,
	  fail);
	 var(File_Name),
	 seeing(File_Name),
	 File_Name = FILE_NAME),
	(retract(rule_base_name(File_Name));
	 !),
	asserta(rule_base_name(File_Name)),
	write('[load '),display(FILE_NAME),display(']'),ttynl,
	statistics(runtime,[Time_0,_]),
	statistics(heap,[Heap_0,_]),
	see(FILE_NAME),
	loading,
	seen,
	(retract(cs(File_Name,_));
	 true),
	asserta(cs(File_Name,[])),
	(retract(strategy_rec(File_Name,_,_));
	 true),
	asserta(strategy_rec(File_Name,lex,lex)),
	(retract(watch_mode(File_Name,_));
	 true),
	asserta(watch_mode(File_Name,1)),
	statistics(runtime,[Time_1,_]),
	statistics(heap,[Heap_1,_]),
	Time is Time_1 - Time_0,
	Heap is Heap_1 - Heap_0,
	write(File_Name),display(' loaded '),
	write(Heap),display(' bytes used '),
	write(Time),display(' msec...'),
	ttynl,
	!.

%%%%% LOAD_F
load_f([H|T]) :-
	!,
	load_f(H),
	!,
	load_f(H).
load_f(File) :-
	atomic(File),
	name(File,NFile),
	(append(NFile,".pl",NFILE),
	 name(FILE,NFILE),
	 exists(FILE);
	 append(NFile,".f",NFILE),
	 name(FILE,NFILE),
	 exists(FILE);
	 append(NFile,".fact",NFILE),
	 name(FILE,NFILE),
	 exists(FILE);
	 FILE=File,
	 exists(FILE);
	 write('*** ERROR ***'),
	 nl,
	 write(File),
	 write(' cannot load ...'),
	 nl,
	 !,
	 fail),
	reconsult(FILE),
	!.

%%%%% loading
loading :-
	no_style_check(all),  %% 1.8.1
	repeat,
	read(X),
	load_ex(X),
	!.
loading.

%%%%% load_ex
load_ex(end_of_file) :-
	style_check(all),   %% 1.8.1
	!.
load_ex(X) :-
	call(X),
	!,
	fail.
load_ex(X) :-
	write('Can not load ...'),
	write(X),
	nl,
	!,
	fail.
