diff --git a/C/flags.c b/C/flags.c index e7c22d3af..1c6650a3a 100644 --- a/C/flags.c +++ b/C/flags.c @@ -47,9 +47,13 @@ static Term sys_pid(Term inp); static bool mkprompt(Term inp); static Term synerr(Term inp); static Term indexer(Term inp); +static Term stream(Term inp); static bool getenc(Term inp); static bool typein(Term inp); static bool dqf(Term t2); +static bool set_error_stream( Term inp ); +static bool set_input_stream( Term inp ); +static bool set_output_stream( Term inp ); static void newFlag(Term fl, Term val); static Int current_prolog_flag(USES_REGS1); @@ -168,6 +172,41 @@ static Term isaccess(Term inp) { return TermZERO; } +static Term stream(Term inp) { + if ( IsVarTerm(inp) ) + return inp; + return Yap_CheckStream( inp, Input_Stream_f | Output_Stream_f | + Append_Stream_f | Socket_Stream_f, "yap_flag/3" ) >= 0; + +} + +static bool +set_error_stream( Term inp ) { + LOCAL_c_error_stream = Yap_CheckStream( inp, Output_Stream_f | + Append_Stream_f | Socket_Stream_f, "yap_flag/3" ); + if( IsVarTerm(inp) ) + return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_error_stream ) ); + return true; +} + +static bool +set_input_stream( Term inp ) { + LOCAL_c_input_stream = Yap_CheckStream( inp, Input_Stream_f | Socket_Stream_f, "yap_flag/3" ); + if( IsVarTerm(inp) ) + return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_input_stream ) ); + return true; +} + +static bool +set_output_stream( Term inp ) { + LOCAL_c_output_stream = Yap_CheckStream( inp, Output_Stream_f | + Append_Stream_f | Socket_Stream_f, "yap_flag/3" ); + if( IsVarTerm(inp) ) + return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_output_stream ) ); + return true; +} + + static Term isground(Term inp) { return Yap_IsGroundTerm(inp) ? inp : TermZERO; } @@ -1473,7 +1512,7 @@ static void newFlag(Term fl, Term val) { GLOBAL_flagCount++; f.name = (char *)RepAtom(AtomOfTerm(fl))->StrOfAE; f.writable = true; - f.helper = 0; + f.helper = NULL; f.def = ok; initFlag(&f, i, true); if (IsAtomOrIntTerm(val)) { diff --git a/H/YapLFlagInfo.h b/H/YapLFlagInfo.h index 9260b2385..4fa1e16ee 100644 --- a/H/YapLFlagInfo.h +++ b/H/YapLFlagInfo.h @@ -83,7 +83,7 @@ which must be an atom. If unbound, unify the argument with the current working module. */ -YAP_FLAG( USER_ERROR_FLAG, "user_error", true, isatom, "user_error" , NULL ), /**< `user_error1` + YAP_FLAG( USER_ERROR_FLAG, "user_error", true, stream, "user_error" , set_error_stream ), /**< `user_error1` If the second argument is bound to a stream, set user_error to this stream. If the second argument is unbound, unify the argument with @@ -114,5 +114,5 @@ prompts from the system were redirected to the stream automatically redirects the user_error alias to the original `stderr`. */ -YAP_FLAG( USER_INPUT_FLAG, "user_input", true, isatom, "user_input" , NULL ), - YAP_FLAG( USER_OUTPUT_FLAG, "user_output", true, isatom, "user_output" , NULL ), +YAP_FLAG( USER_INPUT_FLAG, "user_input", true, stream, "user_input" , set_input_stream ), + YAP_FLAG( USER_OUTPUT_FLAG, "user_output", true, stream, "user_output" , set_output_stream ),