popen support
This commit is contained in:
parent
2c1d6910de
commit
af848f28aa
@ -2119,7 +2119,7 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool consulted = (mode == YAP_CONSULT_MODE);
|
bool consulted = (mode == YAP_CONSULT_MODE);
|
||||||
sno = Yap_OpenStream(fl, "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding);
|
sno = Yap_OpenStream(MkStringTerm(fl), "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding);
|
||||||
if (sno < 0 ||
|
if (sno < 0 ||
|
||||||
!Yap_ChDir(dirname((char *)fl))) {
|
!Yap_ChDir(dirname((char *)fl))) {
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
|
6
H/ATOMS
6
H/ATOMS
@ -290,15 +290,15 @@ A OutOfStackError N "out_of_stack_error"
|
|||||||
A OutOfTrailError N "out_of_trail_error"
|
A OutOfTrailError N "out_of_trail_error"
|
||||||
A Output N "output"
|
A Output N "output"
|
||||||
A Parameter N "parameter"
|
A Parameter N "parameter"
|
||||||
A PrologCommonsDir N "prolog_commons_directory"
|
|
||||||
A Past N "past"
|
A Past N "past"
|
||||||
A PastEndOfStream N "past_end_of_stream"
|
A PastEndOfStream N "past_end_of_stream"
|
||||||
A PermissionError N "permission_error"
|
A PermissionError N "permission_error"
|
||||||
A Pi N "pi"
|
A Pi N "pi"
|
||||||
A Pipe N "pipe"
|
A Pipe N "pipe"
|
||||||
A Priority N "priority"
|
A Priority N "priority"
|
||||||
A Plus N "+"
|
A Plus N "+"
|
||||||
A Pointer N "pointer"
|
A Pointer N "pointer"
|
||||||
|
A Popen N "popen"
|
||||||
A Portray F "portray"
|
A Portray F "portray"
|
||||||
A PredicateIndicator N "predicate_indicator"
|
A PredicateIndicator N "predicate_indicator"
|
||||||
A Primitive N "primitive"
|
A Primitive N "primitive"
|
||||||
@ -307,6 +307,7 @@ A PrivateProcedure N "private_procedure"
|
|||||||
A Procedure N "procedure"
|
A Procedure N "procedure"
|
||||||
A Profile F "$profile"
|
A Profile F "$profile"
|
||||||
A Prolog N "prolog"
|
A Prolog N "prolog"
|
||||||
|
A PrologCommonsDir N "prolog_commons_directory"
|
||||||
A ProtectStack F "$protect_stack"
|
A ProtectStack F "$protect_stack"
|
||||||
A Qly N "qly"
|
A Qly N "qly"
|
||||||
A Query N "?-"
|
A Query N "?-"
|
||||||
@ -558,6 +559,7 @@ F Or Semic 2
|
|||||||
F Output Output 1
|
F Output Output 1
|
||||||
F PermissionError PermissionError 3
|
F PermissionError PermissionError 3
|
||||||
F Plus Plus 2
|
F Plus Plus 2
|
||||||
|
F Popen Popen 1
|
||||||
F Portray Portray 1
|
F Portray Portray 1
|
||||||
F PrintMessage PrintMessage 2
|
F PrintMessage PrintMessage 2
|
||||||
F Procedure Procedure 5
|
F Procedure Procedure 5
|
||||||
|
@ -285,7 +285,6 @@
|
|||||||
AtomOutOfTrailError = Yap_LookupAtom("out_of_trail_error"); TermOutOfTrailError = MkAtomTerm(AtomOutOfTrailError);
|
AtomOutOfTrailError = Yap_LookupAtom("out_of_trail_error"); TermOutOfTrailError = MkAtomTerm(AtomOutOfTrailError);
|
||||||
AtomOutput = Yap_LookupAtom("output"); TermOutput = MkAtomTerm(AtomOutput);
|
AtomOutput = Yap_LookupAtom("output"); TermOutput = MkAtomTerm(AtomOutput);
|
||||||
AtomParameter = Yap_LookupAtom("parameter"); TermParameter = MkAtomTerm(AtomParameter);
|
AtomParameter = Yap_LookupAtom("parameter"); TermParameter = MkAtomTerm(AtomParameter);
|
||||||
AtomPrologCommonsDir = Yap_LookupAtom("prolog_commons_directory"); TermPrologCommonsDir = MkAtomTerm(AtomPrologCommonsDir);
|
|
||||||
AtomPast = Yap_LookupAtom("past"); TermPast = MkAtomTerm(AtomPast);
|
AtomPast = Yap_LookupAtom("past"); TermPast = MkAtomTerm(AtomPast);
|
||||||
AtomPastEndOfStream = Yap_LookupAtom("past_end_of_stream"); TermPastEndOfStream = MkAtomTerm(AtomPastEndOfStream);
|
AtomPastEndOfStream = Yap_LookupAtom("past_end_of_stream"); TermPastEndOfStream = MkAtomTerm(AtomPastEndOfStream);
|
||||||
AtomPermissionError = Yap_LookupAtom("permission_error"); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
AtomPermissionError = Yap_LookupAtom("permission_error"); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
||||||
@ -294,6 +293,7 @@
|
|||||||
AtomPriority = Yap_LookupAtom("priority"); TermPriority = MkAtomTerm(AtomPriority);
|
AtomPriority = Yap_LookupAtom("priority"); TermPriority = MkAtomTerm(AtomPriority);
|
||||||
AtomPlus = Yap_LookupAtom("+"); TermPlus = MkAtomTerm(AtomPlus);
|
AtomPlus = Yap_LookupAtom("+"); TermPlus = MkAtomTerm(AtomPlus);
|
||||||
AtomPointer = Yap_LookupAtom("pointer"); TermPointer = MkAtomTerm(AtomPointer);
|
AtomPointer = Yap_LookupAtom("pointer"); TermPointer = MkAtomTerm(AtomPointer);
|
||||||
|
AtomPopen = Yap_LookupAtom("popen"); TermPopen = MkAtomTerm(AtomPopen);
|
||||||
AtomPortray = Yap_FullLookupAtom("portray"); TermPortray = MkAtomTerm(AtomPortray);
|
AtomPortray = Yap_FullLookupAtom("portray"); TermPortray = MkAtomTerm(AtomPortray);
|
||||||
AtomPredicateIndicator = Yap_LookupAtom("predicate_indicator"); TermPredicateIndicator = MkAtomTerm(AtomPredicateIndicator);
|
AtomPredicateIndicator = Yap_LookupAtom("predicate_indicator"); TermPredicateIndicator = MkAtomTerm(AtomPredicateIndicator);
|
||||||
AtomPrimitive = Yap_LookupAtom("primitive"); TermPrimitive = MkAtomTerm(AtomPrimitive);
|
AtomPrimitive = Yap_LookupAtom("primitive"); TermPrimitive = MkAtomTerm(AtomPrimitive);
|
||||||
@ -302,6 +302,7 @@
|
|||||||
AtomProcedure = Yap_LookupAtom("procedure"); TermProcedure = MkAtomTerm(AtomProcedure);
|
AtomProcedure = Yap_LookupAtom("procedure"); TermProcedure = MkAtomTerm(AtomProcedure);
|
||||||
AtomProfile = Yap_FullLookupAtom("$profile"); TermProfile = MkAtomTerm(AtomProfile);
|
AtomProfile = Yap_FullLookupAtom("$profile"); TermProfile = MkAtomTerm(AtomProfile);
|
||||||
AtomProlog = Yap_LookupAtom("prolog"); TermProlog = MkAtomTerm(AtomProlog);
|
AtomProlog = Yap_LookupAtom("prolog"); TermProlog = MkAtomTerm(AtomProlog);
|
||||||
|
AtomPrologCommonsDir = Yap_LookupAtom("prolog_commons_directory"); TermPrologCommonsDir = MkAtomTerm(AtomPrologCommonsDir);
|
||||||
AtomProtectStack = Yap_FullLookupAtom("$protect_stack"); TermProtectStack = MkAtomTerm(AtomProtectStack);
|
AtomProtectStack = Yap_FullLookupAtom("$protect_stack"); TermProtectStack = MkAtomTerm(AtomProtectStack);
|
||||||
AtomQly = Yap_LookupAtom("qly"); TermQly = MkAtomTerm(AtomQly);
|
AtomQly = Yap_LookupAtom("qly"); TermQly = MkAtomTerm(AtomQly);
|
||||||
AtomQuery = Yap_LookupAtom("?-"); TermQuery = MkAtomTerm(AtomQuery);
|
AtomQuery = Yap_LookupAtom("?-"); TermQuery = MkAtomTerm(AtomQuery);
|
||||||
@ -553,6 +554,7 @@
|
|||||||
FunctorOutput = Yap_MkFunctor(AtomOutput,1);
|
FunctorOutput = Yap_MkFunctor(AtomOutput,1);
|
||||||
FunctorPermissionError = Yap_MkFunctor(AtomPermissionError,3);
|
FunctorPermissionError = Yap_MkFunctor(AtomPermissionError,3);
|
||||||
FunctorPlus = Yap_MkFunctor(AtomPlus,2);
|
FunctorPlus = Yap_MkFunctor(AtomPlus,2);
|
||||||
|
FunctorPopen = Yap_MkFunctor(AtomPopen,1);
|
||||||
FunctorPortray = Yap_MkFunctor(AtomPortray,1);
|
FunctorPortray = Yap_MkFunctor(AtomPortray,1);
|
||||||
FunctorPrintMessage = Yap_MkFunctor(AtomPrintMessage,2);
|
FunctorPrintMessage = Yap_MkFunctor(AtomPrintMessage,2);
|
||||||
FunctorProcedure = Yap_MkFunctor(AtomProcedure,5);
|
FunctorProcedure = Yap_MkFunctor(AtomProcedure,5);
|
||||||
|
@ -285,7 +285,6 @@
|
|||||||
AtomOutOfTrailError = AtomAdjust(AtomOutOfTrailError); TermOutOfTrailError = MkAtomTerm(AtomOutOfTrailError);
|
AtomOutOfTrailError = AtomAdjust(AtomOutOfTrailError); TermOutOfTrailError = MkAtomTerm(AtomOutOfTrailError);
|
||||||
AtomOutput = AtomAdjust(AtomOutput); TermOutput = MkAtomTerm(AtomOutput);
|
AtomOutput = AtomAdjust(AtomOutput); TermOutput = MkAtomTerm(AtomOutput);
|
||||||
AtomParameter = AtomAdjust(AtomParameter); TermParameter = MkAtomTerm(AtomParameter);
|
AtomParameter = AtomAdjust(AtomParameter); TermParameter = MkAtomTerm(AtomParameter);
|
||||||
AtomPrologCommonsDir = AtomAdjust(AtomPrologCommonsDir); TermPrologCommonsDir = MkAtomTerm(AtomPrologCommonsDir);
|
|
||||||
AtomPast = AtomAdjust(AtomPast); TermPast = MkAtomTerm(AtomPast);
|
AtomPast = AtomAdjust(AtomPast); TermPast = MkAtomTerm(AtomPast);
|
||||||
AtomPastEndOfStream = AtomAdjust(AtomPastEndOfStream); TermPastEndOfStream = MkAtomTerm(AtomPastEndOfStream);
|
AtomPastEndOfStream = AtomAdjust(AtomPastEndOfStream); TermPastEndOfStream = MkAtomTerm(AtomPastEndOfStream);
|
||||||
AtomPermissionError = AtomAdjust(AtomPermissionError); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
AtomPermissionError = AtomAdjust(AtomPermissionError); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
||||||
@ -294,6 +293,7 @@
|
|||||||
AtomPriority = AtomAdjust(AtomPriority); TermPriority = MkAtomTerm(AtomPriority);
|
AtomPriority = AtomAdjust(AtomPriority); TermPriority = MkAtomTerm(AtomPriority);
|
||||||
AtomPlus = AtomAdjust(AtomPlus); TermPlus = MkAtomTerm(AtomPlus);
|
AtomPlus = AtomAdjust(AtomPlus); TermPlus = MkAtomTerm(AtomPlus);
|
||||||
AtomPointer = AtomAdjust(AtomPointer); TermPointer = MkAtomTerm(AtomPointer);
|
AtomPointer = AtomAdjust(AtomPointer); TermPointer = MkAtomTerm(AtomPointer);
|
||||||
|
AtomPopen = AtomAdjust(AtomPopen); TermPopen = MkAtomTerm(AtomPopen);
|
||||||
AtomPortray = AtomAdjust(AtomPortray); TermPortray = MkAtomTerm(AtomPortray);
|
AtomPortray = AtomAdjust(AtomPortray); TermPortray = MkAtomTerm(AtomPortray);
|
||||||
AtomPredicateIndicator = AtomAdjust(AtomPredicateIndicator); TermPredicateIndicator = MkAtomTerm(AtomPredicateIndicator);
|
AtomPredicateIndicator = AtomAdjust(AtomPredicateIndicator); TermPredicateIndicator = MkAtomTerm(AtomPredicateIndicator);
|
||||||
AtomPrimitive = AtomAdjust(AtomPrimitive); TermPrimitive = MkAtomTerm(AtomPrimitive);
|
AtomPrimitive = AtomAdjust(AtomPrimitive); TermPrimitive = MkAtomTerm(AtomPrimitive);
|
||||||
@ -302,6 +302,7 @@
|
|||||||
AtomProcedure = AtomAdjust(AtomProcedure); TermProcedure = MkAtomTerm(AtomProcedure);
|
AtomProcedure = AtomAdjust(AtomProcedure); TermProcedure = MkAtomTerm(AtomProcedure);
|
||||||
AtomProfile = AtomAdjust(AtomProfile); TermProfile = MkAtomTerm(AtomProfile);
|
AtomProfile = AtomAdjust(AtomProfile); TermProfile = MkAtomTerm(AtomProfile);
|
||||||
AtomProlog = AtomAdjust(AtomProlog); TermProlog = MkAtomTerm(AtomProlog);
|
AtomProlog = AtomAdjust(AtomProlog); TermProlog = MkAtomTerm(AtomProlog);
|
||||||
|
AtomPrologCommonsDir = AtomAdjust(AtomPrologCommonsDir); TermPrologCommonsDir = MkAtomTerm(AtomPrologCommonsDir);
|
||||||
AtomProtectStack = AtomAdjust(AtomProtectStack); TermProtectStack = MkAtomTerm(AtomProtectStack);
|
AtomProtectStack = AtomAdjust(AtomProtectStack); TermProtectStack = MkAtomTerm(AtomProtectStack);
|
||||||
AtomQly = AtomAdjust(AtomQly); TermQly = MkAtomTerm(AtomQly);
|
AtomQly = AtomAdjust(AtomQly); TermQly = MkAtomTerm(AtomQly);
|
||||||
AtomQuery = AtomAdjust(AtomQuery); TermQuery = MkAtomTerm(AtomQuery);
|
AtomQuery = AtomAdjust(AtomQuery); TermQuery = MkAtomTerm(AtomQuery);
|
||||||
@ -553,6 +554,7 @@
|
|||||||
FunctorOutput = FuncAdjust(FunctorOutput);
|
FunctorOutput = FuncAdjust(FunctorOutput);
|
||||||
FunctorPermissionError = FuncAdjust(FunctorPermissionError);
|
FunctorPermissionError = FuncAdjust(FunctorPermissionError);
|
||||||
FunctorPlus = FuncAdjust(FunctorPlus);
|
FunctorPlus = FuncAdjust(FunctorPlus);
|
||||||
|
FunctorPopen = FuncAdjust(FunctorPopen);
|
||||||
FunctorPortray = FuncAdjust(FunctorPortray);
|
FunctorPortray = FuncAdjust(FunctorPortray);
|
||||||
FunctorPrintMessage = FuncAdjust(FunctorPrintMessage);
|
FunctorPrintMessage = FuncAdjust(FunctorPrintMessage);
|
||||||
FunctorProcedure = FuncAdjust(FunctorProcedure);
|
FunctorProcedure = FuncAdjust(FunctorProcedure);
|
||||||
|
@ -285,7 +285,6 @@ X_API EXTERNAL Atom AtomOutOfStackError; X_API EXTERNAL Term TermOutOfStackError
|
|||||||
X_API EXTERNAL Atom AtomOutOfTrailError; X_API EXTERNAL Term TermOutOfTrailError;
|
X_API EXTERNAL Atom AtomOutOfTrailError; X_API EXTERNAL Term TermOutOfTrailError;
|
||||||
X_API EXTERNAL Atom AtomOutput; X_API EXTERNAL Term TermOutput;
|
X_API EXTERNAL Atom AtomOutput; X_API EXTERNAL Term TermOutput;
|
||||||
X_API EXTERNAL Atom AtomParameter; X_API EXTERNAL Term TermParameter;
|
X_API EXTERNAL Atom AtomParameter; X_API EXTERNAL Term TermParameter;
|
||||||
X_API EXTERNAL Atom AtomPrologCommonsDir; X_API EXTERNAL Term TermPrologCommonsDir;
|
|
||||||
X_API EXTERNAL Atom AtomPast; X_API EXTERNAL Term TermPast;
|
X_API EXTERNAL Atom AtomPast; X_API EXTERNAL Term TermPast;
|
||||||
X_API EXTERNAL Atom AtomPastEndOfStream; X_API EXTERNAL Term TermPastEndOfStream;
|
X_API EXTERNAL Atom AtomPastEndOfStream; X_API EXTERNAL Term TermPastEndOfStream;
|
||||||
X_API EXTERNAL Atom AtomPermissionError; X_API EXTERNAL Term TermPermissionError;
|
X_API EXTERNAL Atom AtomPermissionError; X_API EXTERNAL Term TermPermissionError;
|
||||||
@ -294,6 +293,7 @@ X_API EXTERNAL Atom AtomPipe; X_API EXTERNAL Term TermPipe;
|
|||||||
X_API EXTERNAL Atom AtomPriority; X_API EXTERNAL Term TermPriority;
|
X_API EXTERNAL Atom AtomPriority; X_API EXTERNAL Term TermPriority;
|
||||||
X_API EXTERNAL Atom AtomPlus; X_API EXTERNAL Term TermPlus;
|
X_API EXTERNAL Atom AtomPlus; X_API EXTERNAL Term TermPlus;
|
||||||
X_API EXTERNAL Atom AtomPointer; X_API EXTERNAL Term TermPointer;
|
X_API EXTERNAL Atom AtomPointer; X_API EXTERNAL Term TermPointer;
|
||||||
|
X_API EXTERNAL Atom AtomPopen; X_API EXTERNAL Term TermPopen;
|
||||||
X_API EXTERNAL Atom AtomPortray; X_API EXTERNAL Term TermPortray;
|
X_API EXTERNAL Atom AtomPortray; X_API EXTERNAL Term TermPortray;
|
||||||
X_API EXTERNAL Atom AtomPredicateIndicator; X_API EXTERNAL Term TermPredicateIndicator;
|
X_API EXTERNAL Atom AtomPredicateIndicator; X_API EXTERNAL Term TermPredicateIndicator;
|
||||||
X_API EXTERNAL Atom AtomPrimitive; X_API EXTERNAL Term TermPrimitive;
|
X_API EXTERNAL Atom AtomPrimitive; X_API EXTERNAL Term TermPrimitive;
|
||||||
@ -302,6 +302,7 @@ X_API EXTERNAL Atom AtomPrivateProcedure; X_API EXTERNAL Term TermPrivateProcedu
|
|||||||
X_API EXTERNAL Atom AtomProcedure; X_API EXTERNAL Term TermProcedure;
|
X_API EXTERNAL Atom AtomProcedure; X_API EXTERNAL Term TermProcedure;
|
||||||
X_API EXTERNAL Atom AtomProfile; X_API EXTERNAL Term TermProfile;
|
X_API EXTERNAL Atom AtomProfile; X_API EXTERNAL Term TermProfile;
|
||||||
X_API EXTERNAL Atom AtomProlog; X_API EXTERNAL Term TermProlog;
|
X_API EXTERNAL Atom AtomProlog; X_API EXTERNAL Term TermProlog;
|
||||||
|
X_API EXTERNAL Atom AtomPrologCommonsDir; X_API EXTERNAL Term TermPrologCommonsDir;
|
||||||
X_API EXTERNAL Atom AtomProtectStack; X_API EXTERNAL Term TermProtectStack;
|
X_API EXTERNAL Atom AtomProtectStack; X_API EXTERNAL Term TermProtectStack;
|
||||||
X_API EXTERNAL Atom AtomQly; X_API EXTERNAL Term TermQly;
|
X_API EXTERNAL Atom AtomQly; X_API EXTERNAL Term TermQly;
|
||||||
X_API EXTERNAL Atom AtomQuery; X_API EXTERNAL Term TermQuery;
|
X_API EXTERNAL Atom AtomQuery; X_API EXTERNAL Term TermQuery;
|
||||||
@ -662,6 +663,8 @@ X_API EXTERNAL Functor FunctorPermissionError;
|
|||||||
|
|
||||||
X_API EXTERNAL Functor FunctorPlus;
|
X_API EXTERNAL Functor FunctorPlus;
|
||||||
|
|
||||||
|
X_API EXTERNAL Functor FunctorPopen;
|
||||||
|
|
||||||
X_API EXTERNAL Functor FunctorPortray;
|
X_API EXTERNAL Functor FunctorPortray;
|
||||||
|
|
||||||
X_API EXTERNAL Functor FunctorPrintMessage;
|
X_API EXTERNAL Functor FunctorPrintMessage;
|
||||||
|
@ -64,21 +64,6 @@ available by loading the
|
|||||||
:- use_module(library(readutil),
|
:- use_module(library(readutil),
|
||||||
[read_line_to_codes/2]).
|
[read_line_to_codes/2]).
|
||||||
|
|
||||||
re_open(S, Mode, S) :-
|
|
||||||
is_stream(S),
|
|
||||||
!,
|
|
||||||
current_stream(_, Mode, S).
|
|
||||||
re_open(F, Mode, S) :-
|
|
||||||
open(F, Mode, S).
|
|
||||||
|
|
||||||
re_open(S, Mode, S, Props) :-
|
|
||||||
is_stream(S),
|
|
||||||
!,
|
|
||||||
current_stream(_, Mode, S),
|
|
||||||
maplist( set_stream(S), Props).
|
|
||||||
re_open(F, Mode, S, Props) :-
|
|
||||||
open(F, Mode, S, Props).
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@pred search_for(+ _Char_,+ _Line_)
|
@pred search_for(+ _Char_,+ _Line_)
|
||||||
Search for a character _Char_ in the list of codes _Line_.
|
Search for a character _Char_ in the list of codes _Line_.
|
||||||
@ -469,8 +454,8 @@ process(StreamInp, Command) :-
|
|||||||
the output stream is accessible through `filter_output`.
|
the output stream is accessible through `filter_output`.
|
||||||
*/
|
*/
|
||||||
file_filter(Inp, Out, Command) :-
|
file_filter(Inp, Out, Command) :-
|
||||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||||
re_open(Out, write, StreamOut),
|
open(Out, write, StreamOut),
|
||||||
filter(StreamInp, StreamOut, Command),
|
filter(StreamInp, StreamOut, Command),
|
||||||
close(StreamInp),
|
close(StreamInp),
|
||||||
close(StreamOut).
|
close(StreamOut).
|
||||||
@ -482,8 +467,8 @@ Same as file_filter/3, but before starting the filter execute
|
|||||||
_Arguments_.
|
_Arguments_.
|
||||||
*/
|
*/
|
||||||
file_filter_with_initialization(Inp, Out, Command, FormatString, Parameters) :-
|
file_filter_with_initialization(Inp, Out, Command, FormatString, Parameters) :-
|
||||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||||
re_open(Out, write, StreamOut, [alias(filter_output)]),
|
open(Out, write, StreamOut, [alias(filter_output)]),
|
||||||
format(StreamOut, FormatString, Parameters),
|
format(StreamOut, FormatString, Parameters),
|
||||||
filter(StreamInp, StreamOut, Command),
|
filter(StreamInp, StreamOut, Command),
|
||||||
close(StreamInp),
|
close(StreamInp),
|
||||||
@ -498,8 +483,8 @@ _StartGoal_, and call _ENdGoal_ as an epilog.
|
|||||||
The input stream are always accessible through `filter_output` and `filter_input`.
|
The input stream are always accessible through `filter_output` and `filter_input`.
|
||||||
*/
|
*/
|
||||||
file_filter_with_start_end(Inp, Out, Command, StartGoal, EndGoal) :-
|
file_filter_with_start_end(Inp, Out, Command, StartGoal, EndGoal) :-
|
||||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||||
re_open(Out, write, StreamOut, [alias(filter_output)]),
|
open(Out, write, StreamOut, [alias(filter_output)]),
|
||||||
call( StartGoal, StreamInp, StreamOut ),
|
call( StartGoal, StreamInp, StreamOut ),
|
||||||
filter(StreamInp, StreamOut, Command),
|
filter(StreamInp, StreamOut, Command),
|
||||||
call( EndGoal, StreamInp, StreamOut ),
|
call( EndGoal, StreamInp, StreamOut ),
|
||||||
@ -525,7 +510,7 @@ file_filter_with_start_end(Inp, Out, Command, StartGoal, EndGoal) :-
|
|||||||
file_select(Inp, Command) :-
|
file_select(Inp, Command) :-
|
||||||
( retract(alias(F)) -> true ; F = '' ),
|
( retract(alias(F)) -> true ; F = '' ),
|
||||||
atom_concat(filter_input, F, Alias),
|
atom_concat(filter_input, F, Alias),
|
||||||
re_open(Inp, read, StreamInp, [Alias]),
|
open(Inp, read, StreamInp, [Alias]),
|
||||||
atom_concat('_', F, NF),
|
atom_concat('_', F, NF),
|
||||||
assert( alias(NF) ),
|
assert( alias(NF) ),
|
||||||
repeat,
|
repeat,
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
* *
|
* *
|
||||||
* YAP Prolog *
|
* YAP Prolog *
|
||||||
* *
|
* *
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
* *
|
* *
|
||||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
@ -74,44 +74,7 @@ are available through the `use_module(library(system))` command.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
@pred datime(datime(- _Year_, - _Month_, - _DayOfTheMonth_, - _Hour_, - _Minute_, - _Second_)
|
|
||||||
|
|
||||||
The datime/1 procedure returns the current date and time, with
|
|
||||||
information on _Year_, _Month_, _DayOfTheMonth_,
|
|
||||||
_Hour_, _Minute_, and _Second_. The _Hour_ is returned
|
|
||||||
on local time. This function uses the WIN32
|
|
||||||
`GetLocalTime` function or the Unix `localtime` function.
|
|
||||||
|
|
||||||
~~~~~
|
|
||||||
?- datime(X).
|
|
||||||
|
|
||||||
X = datime(2001,5,28,15,29,46) ?
|
|
||||||
~~~~~
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** @pred environ(+ _E_,- _S_)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Given an environment variable _E_ this predicate unifies the second argument _S_ with its value.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/** @pred system(+ _S_)
|
|
||||||
|
|
||||||
|
|
||||||
Passes command _S_ to the Bourne shell (on UNIX environments) or the
|
|
||||||
current command interpreter in WIN32 environments.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/** @pred working_directory(- _CurDir_,? _NextDir_)
|
/** @pred working_directory(- _CurDir_,? _NextDir_)
|
||||||
|
|
||||||
|
|
||||||
@ -176,27 +139,6 @@ X = 'C:\\cygwin\\home\\administrator' ?
|
|||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/** @pred exec(+ _Command_, _StandardStreams_,- _PID_)
|
|
||||||
|
|
||||||
|
|
||||||
Execute command _Command_ with its standard streams connected to
|
|
||||||
the list [_InputStream_, _OutputStream_, _ErrorStream_]. The
|
|
||||||
process that executes the command is returned as _PID_. The
|
|
||||||
command is executed by the default shell `bin/sh -c` in Unix.
|
|
||||||
|
|
||||||
The following example demonstrates the use of exec/3 to send a
|
|
||||||
command and process its output:
|
|
||||||
|
|
||||||
~~~~~
|
|
||||||
exec(ls,[std,pipe(S),null],P),repeat, get0(S,C), (C = -1, close(S) ! ; put(C)).
|
|
||||||
~~~~~
|
|
||||||
|
|
||||||
The streams may be one of standard stream, `std`, null stream,
|
|
||||||
`null`, or `pipe(S)`, where _S_ is a pipe stream. Note
|
|
||||||
that it is up to the user to close the pipe.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/** @pred file_exists(+ _File_)
|
/** @pred file_exists(+ _File_)
|
||||||
|
|
||||||
@ -289,37 +231,7 @@ process. An interface to the <tt>getpid</tt> function.
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/** @pred popen(+ _Command_, + _TYPE_, - _Stream_)
|
|
||||||
|
|
||||||
|
|
||||||
Interface to the <tt>popen</tt> function. It opens a process by creating a
|
|
||||||
pipe, forking and invoking _Command_ on the current shell. Since a
|
|
||||||
pipe is by definition unidirectional the _Type_ argument may be
|
|
||||||
`read` or `write`, not both. The stream should be closed
|
|
||||||
using close/1, there is no need for a special `pclose`
|
|
||||||
command.
|
|
||||||
|
|
||||||
The following example demonstrates the use of popen/3 to process
|
|
||||||
the output of a command, as exec/3 would do:
|
|
||||||
|
|
||||||
~~~~~{.prolog}
|
|
||||||
?- popen(ls,read,X),repeat, get0(X,C), (C = -1, ! ; put(C)).
|
|
||||||
|
|
||||||
X = 'C:\\cygwin\\home\\administrator' ?
|
|
||||||
~~~~~
|
|
||||||
|
|
||||||
The WIN32 implementation of popen/3 relies on exec/3.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/** @pred rename_file(+ _OldFile_,+ _NewFile_)
|
|
||||||
|
|
||||||
|
|
||||||
Create file _OldFile_ to _NewFile_. This predicate uses the
|
|
||||||
`C` built-in function `rename`.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/** @pred read_link(+ SymbolicLink, -Link, -NewPath)
|
/** @pred read_link(+ SymbolicLink, -Link, -NewPath)
|
||||||
|
|
||||||
|
|
||||||
@ -423,6 +335,24 @@ also `absolute_file_name/2` and chdir/1.
|
|||||||
|
|
||||||
% time builtins
|
% time builtins
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
@pred datime(datime(- _Year_, - _Month_, - _DayOfTheMonth_, - _Hour_, - _Minute_, - _Second_)
|
||||||
|
|
||||||
|
The datime/1 procedure returns the current date and time, with
|
||||||
|
information on _Year_, _Month_, _DayOfTheMonth_,
|
||||||
|
_Hour_, _Minute_, and _Second_. The _Hour_ is returned
|
||||||
|
on local time. This function uses the WIN32
|
||||||
|
`GetLocalTime` function or the Unix `localtime` function.
|
||||||
|
|
||||||
|
~~~~~
|
||||||
|
?- datime(X).
|
||||||
|
|
||||||
|
X = datime(2001,5,28,15,29,46) ?
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
datime(X) :-
|
datime(X) :-
|
||||||
datime(X, Error),
|
datime(X, Error),
|
||||||
handle_system_internal(Error, off, datime(X)).
|
handle_system_internal(Error, off, datime(X)).
|
||||||
@ -567,10 +497,14 @@ file_property(File, Type, Size, Date, Permissions, LinkName) :-
|
|||||||
handle_system_internal(Error, off, file_property(File)).
|
handle_system_internal(Error, off, file_property(File)).
|
||||||
|
|
||||||
|
|
||||||
%
|
/** @pred environ(+E, -S)
|
||||||
% environment manipulation.
|
|
||||||
%
|
|
||||||
|
|
||||||
|
Given an environment variable _E_ this predicate unifies the second
|
||||||
|
argument _S_ with its value. _E_ may be bound to an atom, or just be
|
||||||
|
unbound. In the latter case environ/2 will enumerate over all
|
||||||
|
environment variables.
|
||||||
|
|
||||||
|
*/
|
||||||
environ(Na,Val) :- var(Na), !,
|
environ(Na,Val) :- var(Na), !,
|
||||||
environ_enum(0,I),
|
environ_enum(0,I),
|
||||||
( p_environ(I,S) -> environ_split(S,SNa,SVal) ; !, fail ),
|
( p_environ(I,S) -> environ_split(S,SNa,SVal) ; !, fail ),
|
||||||
@ -597,9 +531,33 @@ environ_split([61|SVal], [], SVal) :- !.
|
|||||||
environ_split([C|S],[C|SNa],SVal) :-
|
environ_split([C|S],[C|SNa],SVal) :-
|
||||||
environ_split(S,SNa,SVal).
|
environ_split(S,SNa,SVal).
|
||||||
|
|
||||||
%
|
/** @pred exec(+ _Command_, _StandardStreams_,- _PID_)
|
||||||
% process execution
|
*
|
||||||
%
|
*
|
||||||
|
*
|
||||||
|
* Execute command _Command_ with its standard streams connected to the
|
||||||
|
* list [_InputStream_, _OutputStream_, _ErrorStream_]. A numeric
|
||||||
|
* identifier to the process that executes the command is returned as
|
||||||
|
* _PID_. The command is executed by the default shell `bin/sh -c` in
|
||||||
|
* Unix.
|
||||||
|
*
|
||||||
|
* The following example demonstrates the use of exec/3 to send a
|
||||||
|
* command and process its output:
|
||||||
|
*
|
||||||
|
* ~~~~~
|
||||||
|
go :-
|
||||||
|
exec(ls,[std,pipe(S),null],P),
|
||||||
|
repeat,
|
||||||
|
get0(S,C),
|
||||||
|
(C = -1, close(S) ! ; put(C)).
|
||||||
|
~~~~~
|
||||||
|
*
|
||||||
|
* The streams may be one of standard stream, `std`, null stream,
|
||||||
|
* `null`, or `pipe(S)`, where _S_ is a pipe stream. Note
|
||||||
|
* that it is up to the user to close the pipe.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
exec(Command, [StdIn, StdOut, StdErr], PID) :-
|
exec(Command, [StdIn, StdOut, StdErr], PID) :-
|
||||||
G = exec(Command, [StdIn, StdOut, StdErr], PID),
|
G = exec(Command, [StdIn, StdOut, StdErr], PID),
|
||||||
check_command_with_default_shell(Command, TrueCommand, G),
|
check_command_with_default_shell(Command, TrueCommand, G),
|
||||||
@ -652,8 +610,32 @@ close_temp_streams([S|Ss]) :-
|
|||||||
close(S),
|
close(S),
|
||||||
close_temp_streams(Ss).
|
close_temp_streams(Ss).
|
||||||
|
|
||||||
popen(Command, Mode, Stream) :-
|
/** @pred popen(+ _Command_, + _TYPE_, - _Stream_)
|
||||||
open(pipe(Command), Mode, Stream).
|
|
||||||
|
* Provides the functionaluty of the Unix <tt>popen</tt> function. It
|
||||||
|
* opens a process by creating a pipe, forking and invoking _Command_ on
|
||||||
|
* the child process. Since a pipe is by definition unidirectional the
|
||||||
|
* _Type_ argument may be `read` or `write`, not both. The stream should
|
||||||
|
* be closed using close/1, there is no need for a special `pclose`
|
||||||
|
* command.
|
||||||
|
*
|
||||||
|
* The following example demonstrates the use of popen/3 to process the
|
||||||
|
* output of a command, note that popen/3 works as a simplified interface
|
||||||
|
* to the exec/3 command:
|
||||||
|
*
|
||||||
|
~~~~~{.prolog}
|
||||||
|
?- popen(ls,read,X),repeat, get0(X,C), (C = -1, ! ; put(C)).
|
||||||
|
|
||||||
|
X = 'C:\\cygwin\\home\\administrator' ?
|
||||||
|
~~~~~
|
||||||
|
*
|
||||||
|
* The implementation of popen/3 relies on exec/3.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
popen(Command, read, Stream) :-
|
||||||
|
exec(Command, [std,pipe(Stream),std], Stream).
|
||||||
|
popen(Command, write, Stream) :-
|
||||||
|
exec(Command, [pipe(Stream),std,std], Stream).
|
||||||
|
|
||||||
check_command_with_default_shell(Com, ComF, G) :-
|
check_command_with_default_shell(Com, ComF, G) :-
|
||||||
check_command(Com, G),
|
check_command(Com, G),
|
||||||
@ -811,5 +793,23 @@ read_link(P,D,F) :-
|
|||||||
read_link(P, D),
|
read_link(P, D),
|
||||||
absolute_file_name(D, [], F).
|
absolute_file_name(D, [], F).
|
||||||
|
|
||||||
|
/** @pred rename_file(+ _OldFile_,+ _NewFile_)
|
||||||
|
|
||||||
|
|
||||||
|
Create file _OldFile_ to _NewFile_. This predicate uses the
|
||||||
|
`C` built-in function `rename`.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
rename_file(F0, F) :-
|
||||||
|
rename_file(F0, F, Error),
|
||||||
|
handle_system_internal(Error, off, rename_file(F0, F))).
|
||||||
|
|
||||||
|
/** @pred system(+ _S_)
|
||||||
|
|
||||||
|
Passes command _S_ to the Bourne shell (on UNIX environments) or the
|
||||||
|
current command interpreter in WIN32 environments.
|
||||||
|
*/
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@ -729,7 +729,15 @@ static YAP_Bool execute_command(void) {
|
|||||||
#endif /* UNIX code */
|
#endif /* UNIX code */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* execute a command as a detached process */
|
/** @pred system(+ _S_)
|
||||||
|
|
||||||
|
Passes command _S_ to the Bourne shell (on UNIX environments) or the
|
||||||
|
current command interpreter in WIN32 environments.
|
||||||
|
|
||||||
|
Note that it executes them command as a detached process. It requires
|
||||||
|
`system` to be implemented by the system library.
|
||||||
|
|
||||||
|
*/
|
||||||
static YAP_Bool do_system(void) {
|
static YAP_Bool do_system(void) {
|
||||||
char *command = (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1));
|
char *command = (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1));
|
||||||
#if HAVE_SYSTEM
|
#if HAVE_SYSTEM
|
||||||
|
1280
os/iopreds.c
1280
os/iopreds.c
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,7 @@ extern int Yap_PlGetWchar(void);
|
|||||||
extern int Yap_PlFGetchar(void);
|
extern int Yap_PlFGetchar(void);
|
||||||
extern int Yap_GetCharForSIGINT(void);
|
extern int Yap_GetCharForSIGINT(void);
|
||||||
extern Int Yap_StreamToFileNo(Term);
|
extern Int Yap_StreamToFileNo(Term);
|
||||||
extern int Yap_OpenStream(const char *fname, const char* io_mode, Term user_name, encoding_t enc);
|
extern int Yap_OpenStream(Term tin, const char* io_mode, Term user_name, encoding_t enc);
|
||||||
extern int Yap_FileStream(FILE*, char *, Term, int, VFS_t *);
|
extern int Yap_FileStream(FILE*, char *, Term, int, VFS_t *);
|
||||||
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags);
|
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags);
|
||||||
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
||||||
|
Reference in New Issue
Block a user