allow better control over using SWI I/O

This commit is contained in:
Vitor Santos Costa 2010-05-06 11:36:47 +01:00
parent 261b5163c7
commit 9301b67724

View File

@ -20,6 +20,7 @@
'$set_predicate_attribute'/3, '$set_predicate_attribute'/3,
load_foreign_library/1, load_foreign_library/1,
load_foreign_library/2, load_foreign_library/2,
use_foreign_library/1,
time_file/2, time_file/2,
flag/3, flag/3,
current_flag/1 current_flag/1
@ -115,108 +116,106 @@ goal_expansion(exists_directory(A), system:swi_exists_directory(A)).
:- dynamic swi_io/0. :- dynamic swi_io/0.
:- if(swi_io). goal_expansion(open(A,B,C,D),system:swi_open(A,B,C,D)) :- swi_io.
goal_expansion(open(A,B,C,D),system:swi_open(A,B,C,D)). goal_expansion(open(A,B,C), system:swi_open(A,B,C)) :- swi_io.
goal_expansion(open(A,B,C), system:swi_open(A,B,C)). goal_expansion(close(A), system:swi_close(A)) :- swi_io.
goal_expansion(close(A), system:swi_close(A)). goal_expansion(close(A,B), system:swi_close(A,B)) :- swi_io.
goal_expansion(close(A,B), system:swi_close(A,B)). goal_expansion(set_input(A), system:swi_set_input(A)) :- swi_io.
goal_expansion(set_input(A), system:swi_set_input(A)). goal_expansion(set_output(A), system:swi_set_output(A)) :- swi_io.
goal_expansion(set_output(A), system:swi_set_output(A)). goal_expansion(current_input(A), system:swi_current_input(A)) :- swi_io.
goal_expansion(current_input(A), system:swi_current_input(A)). goal_expansion(current_output(A), system:swi_current_output(A)) :- swi_io.
goal_expansion(current_output(A), system:swi_current_output(A)). goal_expansion(get_code(A,B),system:swi_get_code(A,B)) :- swi_io.
goal_expansion(get_code(A,B),system:swi_get_code(A,B)). goal_expansion(get_code(A), system:swi_get_code(A)) :- swi_io.
goal_expansion(get_code(A), system:swi_get_code(A)). goal_expansion(get_char(A,B),system:swi_get_char(A,B)) :- swi_io.
goal_expansion(get_char(A,B),system:swi_get_char(A,B)). goal_expansion(get_char(A), system:swi_get_char(A)) :- swi_io.
goal_expansion(get_char(A), system:swi_get_char(A)). goal_expansion(get_byte(A,B),system:swi_get_byte(A,B)) :- swi_io.
goal_expansion(get_byte(A,B),system:swi_get_byte(A,B)). goal_expansion(get_byte(A), system:swi_get_byte(A)) :- swi_io.
goal_expansion(get_byte(A), system:swi_get_byte(A)). goal_expansion(peek_code(A,B),system:swi_peek_code(A,B)) :- swi_io.
goal_expansion(peek_code(A,B),system:swi_peek_code(A,B)). goal_expansion(peek_code(A), system:swi_peek_code(A)) :- swi_io.
goal_expansion(peek_code(A), system:swi_peek_code(A)). goal_expansion(peek_char(A,B),system:swi_peek_char(A,B)) :- swi_io.
goal_expansion(peek_char(A,B),system:swi_peek_char(A,B)). goal_expansion(peek_char(A), system:swi_peek_char(A)) :- swi_io.
goal_expansion(peek_char(A), system:swi_peek_char(A)). goal_expansion(peek_byte(A,B),system:swi_peek_byte(A,B)) :- swi_io.
goal_expansion(peek_byte(A,B),system:swi_peek_byte(A,B)). goal_expansion(peek_byte(A), system:swi_peek_byte(A)) :- swi_io.
goal_expansion(peek_byte(A), system:swi_peek_byte(A)). goal_expansion(put_byte(A,B),system:swi_put_byte(A,B)) :- swi_io.
goal_expansion(put_byte(A,B),system:swi_put_byte(A,B)). goal_expansion(put_byte(A), system:swi_put_byte(A)) :- swi_io.
goal_expansion(put_byte(A), system:swi_put_byte(A)). goal_expansion(put_code(A,B),system:swi_put_code(A,B)) :- swi_io.
goal_expansion(put_code(A,B),system:swi_put_code(A,B)). goal_expansion(put_code(A), system:swi_put_code(A)) :- swi_io.
goal_expansion(put_code(A), system:swi_put_code(A)). goal_expansion(put_char(A,B),system:swi_put_char(A,B)) :- swi_io.
goal_expansion(put_char(A,B),system:swi_put_char(A,B)). goal_expansion(put_char(A), system:swi_put_char(A)) :- swi_io.
goal_expansion(put_char(A), system:swi_put_char(A)).
goal_expansion(flush_output, system:swi_flush_output). goal_expansion(flush_output, system:swi_flush_output).
goal_expansion(flush_output(A), system:swi_flush_output(A)). goal_expansion(flush_output(A), system:swi_flush_output(A)) :- swi_io.
goal_expansion(at_end_of_stream(A), system:swi_at_end_of_stream(A)). goal_expansion(at_end_of_stream(A), system:swi_at_end_of_stream(A)) :- swi_io.
goal_expansion(at_end_of_stream, system:swi_at_end_of_stream). goal_expansion(at_end_of_stream, system:swi_at_end_of_stream).
goal_expansion(stream_property(A,B),system:swi_stream_property(A,B)). goal_expansion(stream_property(A,B),system:swi_stream_property(A,B)) :- swi_io.
goal_expansion(set_stream_position(A,B),system:swi_set_stream_position(A,B)). goal_expansion(set_stream_position(A,B),system:swi_set_stream_position(A,B)) :- swi_io.
/* edinburgh IO */ /* edinburgh IO */
goal_expansion(see(A), system:swi_see(A)). goal_expansion(see(A), system:swi_see(A)) :- swi_io.
goal_expansion(seen, system:swi_seen). goal_expansion(seen, system:swi_seen).
goal_expansion(seeing(A), system:swi_seeing(A)). goal_expansion(seeing(A), system:swi_seeing(A)) :- swi_io.
goal_expansion(tell(A), system:swi_tell(A)). goal_expansion(tell(A), system:swi_tell(A)) :- swi_io.
goal_expansion(append(A), system:swi_append(A)). goal_expansion(append(A), system:swi_append(A)) :- swi_io.
goal_expansion(told, system:swi_told). goal_expansion(told, system:swi_told).
goal_expansion(telling(A), system:swi_telling(A)). goal_expansion(telling(A), system:swi_telling(A)) :- swi_io.
goal_expansion(put(A,B),system:swi_put(A,B)). goal_expansion(put(A,B),system:swi_put(A,B)) :- swi_io.
goal_expansion(put(A), system:swi_put(A)). goal_expansion(put(A), system:swi_put(A)) :- swi_io.
goal_expansion(skip(A), system:swi_skip(A)). goal_expansion(skip(A), system:swi_skip(A)) :- swi_io.
goal_expansion(skip(A,B),system:swi_skip(A,B)). goal_expansion(skip(A,B),system:swi_skip(A,B)) :- swi_io.
goal_expansion(get(A), system:swi_get(A)). goal_expansion(get(A), system:swi_get(A)) :- swi_io.
goal_expansion(get(A,B),system:swi_get(A,B)). goal_expansion(get(A,B),system:swi_get(A,B)) :- swi_io.
goal_expansion(get0(A,B),system:swi_get0(A,B)). goal_expansion(get0(A,B),system:swi_get0(A,B)) :- swi_io.
goal_expansion(get0(A), system:swi_get0(A)). goal_expansion(get0(A), system:swi_get0(A)) :- swi_io.
goal_expansion(ttyflush, system:swi_ttyflush). goal_expansion(ttyflush, system:swi_ttyflush).
goal_expansion(prompt(A,B),system:swi_prompt(A,B)). goal_expansion(prompt(A,B),system:swi_prompt(A,B)) :- swi_io.
goal_expansion(tab(A,B),system:swi_tab(A,B)). goal_expansion(tab(A,B),system:swi_tab(A,B)) :- swi_io.
goal_expansion(tab(A), system:swi_tab(A)). goal_expansion(tab(A), system:swi_tab(A)) :- swi_io.
/* Quintus IO */ /* Quintus IO */
goal_expansion(byte_count(A,B),system:swi_byte_count(A,B)). goal_expansion(byte_count(A,B),system:swi_byte_count(A,B)) :- swi_io.
goal_expansion(character_count(A,B),system:swi_character_count(A,B)). goal_expansion(character_count(A,B),system:swi_character_count(A,B)) :- swi_io.
goal_expansion(line_count(A,B),system:swi_line_count(A,B)). goal_expansion(line_count(A,B),system:swi_line_count(A,B)) :- swi_io.
goal_expansion(line_position(A,B),system:swi_line_position(A,B)). goal_expansion(line_position(A,B),system:swi_line_position(A,B)) :- swi_io.
goal_expansion(open_null_stream(A), system:swi_open_null_stream(A)). goal_expansion(open_null_stream(A), system:swi_open_null_stream(A)) :- swi_io.
/* SWI specific */ /* SWI specific */
goal_expansion(is_stream(A), system:swi_is_stream(A)). goal_expansion(is_stream(A), system:swi_is_stream(A)) :- swi_io.
goal_expansion(set_stream(A,B),system:swi_set_stream(A,B)). goal_expansion(set_stream(A,B),system:swi_set_stream(A,B)) :- swi_io.
goal_expansion(with_output_to(A,B),system:swi_with_output_to(A,B)). goal_expansion(with_output_to(A,B),system:swi_with_output_to(A,B)) :- swi_io.
goal_expansion(set_prolog_IO(A,B,C), system:swi_set_prolog_IO(A,B,C)). goal_expansion(set_prolog_IO(A,B,C), system:swi_set_prolog_IO(A,B,C)) :- swi_io.
goal_expansion(protocol(A), system:swi_protocol(A)). goal_expansion(protocol(A), system:swi_protocol(A)) :- swi_io.
goal_expansion(protocola(A), system:swi_protocola(A)). goal_expansion(protocola(A), system:swi_protocola(A)) :- swi_io.
goal_expansion(noprotocol, noprotocol). goal_expansion(noprotocol, noprotocol).
goal_expansion(protocolling(A), system:swi_protocolling(A)). goal_expansion(protocolling(A), system:swi_protocolling(A)) :- swi_io.
goal_expansion(prompt1(A), system:swi_prompt1(A)). goal_expansion(prompt1(A), system:swi_prompt1(A)) :- swi_io.
goal_expansion(seek(A,B,C,D),system:swi_seek(A,B,C,D)). goal_expansion(seek(A,B,C,D),system:swi_seek(A,B,C,D)) :- swi_io.
goal_expansion(wait_for_input(A,B,C), system:swi_wait_for_input(A,B,C)). goal_expansion(wait_for_input(A,B,C), system:swi_wait_for_input(A,B,C)) :- swi_io.
goal_expansion(get_single_char(A), system:swi_get_single_char(A)). goal_expansion(get_single_char(A), system:swi_get_single_char(A)) :- swi_io.
goal_expansion(read_pending_input(A,B,C), system:swi_read_pending_input(A,B,C)). goal_expansion(read_pending_input(A,B,C), system:swi_read_pending_input(A,B,C)) :- swi_io.
goal_expansion(source_location(A,B),system:swi_source_location(A,B)). goal_expansion(source_location(A,B),system:swi_source_location(A,B)) :- swi_io.
goal_expansion(copy_stream_data(A,B,C), system:swi_copy_stream_data(A,B,C)). goal_expansion(copy_stream_data(A,B,C), system:swi_copy_stream_data(A,B,C)) :- swi_io.
goal_expansion(copy_stream_data(A,B),system:swi_copy_stream_data(A,B)). goal_expansion(copy_stream_data(A,B),system:swi_copy_stream_data(A,B)) :- swi_io.
/* SWI internal */ /* SWI internal */
goal_expansion('$push_input_context', system:'swi_$push_input_context'). goal_expansion('$push_input_context', system:'swi_$push_input_context').
goal_expansion('$pop_input_context', system:'swi_$pop_input_context'). goal_expansion('$pop_input_context', system:'swi_$pop_input_context').
goal_expansion('$size_stream'(A,B),system:'swi_$size_stream'(A,B)). goal_expansion('$size_stream'(A,B),system:'swi_$size_stream'(A,B)) :- swi_io.
goal_expansion(working_directory(A,B),system:swi_working_directory(A,B)). goal_expansion(working_directory(A,B),system:swi_working_directory(A,B)) :- swi_io.
goal_expansion(access_file(A,B),system:swi_access_file(A,B)). goal_expansion(access_file(A,B),system:swi_access_file(A,B)) :- swi_io.
goal_expansion(size_file(A,B),system:swi_size_file(A,B)). goal_expansion(size_file(A,B),system:swi_size_file(A,B)) :- swi_io.
goal_expansion(read_link(A,B,C), system:swi_read_link(A,B,C)). goal_expansion(read_link(A,B,C), system:swi_read_link(A,B,C)) :- swi_io.
goal_expansion(tmp_file(A,B),system:swi_tmp_file(A,B)). goal_expansion(tmp_file(A,B),system:swi_tmp_file(A,B)) :- swi_io.
goal_expansion(tmp_file_stream(A,B,C), system:swi_tmp_file_stream(A,B,C)). goal_expansion(tmp_file_stream(A,B,C), system:swi_tmp_file_stream(A,B,C)) :- swi_io.
goal_expansion(delete_file(A), delete_file(A)). goal_expansion(delete_file(A), delete_file(A)) :- swi_io.
goal_expansion(delete_directory(A), delete_directory(A)). goal_expansion(delete_directory(A), delete_directory(A)) :- swi_io.
goal_expansion(make_directory(A), make_directory(A)). goal_expansion(make_directory(A), make_directory(A)) :- swi_io.
goal_expansion(same_file(A,B),system:swi_same_file(A,B)). goal_expansion(same_file(A,B),system:swi_same_file(A,B)) :- swi_io.
goal_expansion(rename_file(A,B),system:swi_rename_file(A,B)). goal_expansion(rename_file(A,B),system:swi_rename_file(A,B)) :- swi_io.
goal_expansion(is_absolute_file_name(A), is_absolute_file_name(A)). goal_expansion(is_absolute_file_name(A), is_absolute_file_name(A)) :- swi_io.
goal_expansion(file_base_name(A,B),system:swi_file_base_name(A,B)). goal_expansion(file_base_name(A,B),system:swi_file_base_name(A,B)) :- swi_io.
goal_expansion(file_directory_name(A,B),system:swi_file_directory_name(A,B)). goal_expansion(file_directory_name(A,B),system:swi_file_directory_name(A,B)) :- swi_io.
goal_expansion(prolog_to_os_filename(A,B),system:swi_prolog_to_os_filename(A,B)). goal_expansion(prolog_to_os_filename(A,B),system:swi_prolog_to_os_filename(A,B)) :- swi_io.
goal_expansion('$mark_executable'(A), system:'swi_is_absolute_file_name'(A)). goal_expansion('$mark_executable'(A), system:'swi_is_absolute_file_name'(A)) :- swi_io.
goal_expansion('$absolute_file_name'(A,B),system:'swi_$absolute_file_name'(A,B)). goal_expansion('$absolute_file_name'(A,B),system:'swi_$absolute_file_name'(A,B)) :- swi_io.
:- endif.
% make sure we also use % make sure we also use
@ -254,6 +253,13 @@ load_foreign_library(P,Command) :-
load_foreign_library(P) :- load_foreign_library(P) :-
prolog:load_foreign_library(P,install). prolog:load_foreign_library(P,install).
:- dynamic loaded/1.
use_foreign_library(A) :-
loaded(foreign_library(A)), !.
use_foreign_library(A) :-
load_foreign_library(A),
assert(loaded(foreign_library(A))).
term_to_atom(Term,Atom) :- term_to_atom(Term,Atom) :-
nonvar(Atom), !, nonvar(Atom), !,
atom_codes(Atom,S), atom_codes(Atom,S),