encoding is done by SWI code, don't mess around.

This commit is contained in:
Vitor Santos Costa 2011-09-02 21:03:41 +01:00
parent 8a9868a120
commit 5a91af843f
4 changed files with 5 additions and 106 deletions

View File

@ -1079,35 +1079,6 @@ p_float_format( USES_REGS1 )
return TRUE;
}
extern IOENC Yap_DefaultEncoding(void);
extern void Yap_SetDefaultEncoding(IOENC);
extern int PL_get_stream_handle(Int, IOSTREAM **);
static Int
p_get_default_encoding( USES_REGS1 )
{
Term out = MkIntegerTerm(Yap_DefaultEncoding());
return Yap_unify(ARG1, out);
}
static Int
p_encoding ( USES_REGS1 )
{ /* '$encoding'(Stream,N) */
IOSTREAM *st;
Term t = Deref(ARG2);
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &st)) {
Yap_RecoverSlots(1 PASS_REGS);
return FALSE;
}
Yap_RecoverSlots(1 PASS_REGS);
if (IsVarTerm(t)) {
return Yap_unify(ARG2, MkIntegerTerm(st->encoding));
}
st->encoding = IntegerOfTerm(Deref(ARG2));
return TRUE;
}
void
Yap_InitBackIO (void)
{
@ -1132,8 +1103,6 @@ Yap_InitIOPreds(void)
Yap_InitCPred ("$all_char_conversions", 1, p_all_char_conversions, SyncPredFlag|HiddenPredFlag);
Yap_InitCPred ("$force_char_conversion", 0, p_force_char_conversion, SyncPredFlag|HiddenPredFlag);
Yap_InitCPred ("$disable_char_conversion", 0, p_disable_char_conversion, SyncPredFlag|HiddenPredFlag);
Yap_InitCPred ("$get_default_encoding", 1, p_get_default_encoding, SafePredFlag|TestPredFlag);
Yap_InitCPred ("$encoding", 2, p_encoding, SafePredFlag|SyncPredFlag|UserCPredFlag),
#if HAVE_SELECT
// Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
#endif

View File

@ -76,7 +76,6 @@ typedef struct stream_desc
int (* stream_wgetc_for_read)(int);
int (* stream_wgetc)(int);
int (* stream_wputc)(int,wchar_t);
encoding_t encoding;
mbstate_t mbstate;
}
StreamDesc;

View File

@ -221,28 +221,6 @@ typedef struct AliasDescS {
/************ SWI compatible support for different encodings ************/
#ifndef _PL_STREAM_H
typedef enum {
ENC_OCTET = 0,
ENC_ISO_LATIN1 = 1,
ENC_ISO_ASCII = 2,
ENC_ISO_ANSI = 4,
ENC_ISO_UTF8 = 8,
ENC_UNICODE_BE = 16,
ENC_UNICODE_LE = 32,
ENC_ISO_UTF32_BE = 64,
ENC_ISO_UTF32_LE = 128
} encoding_t;
#else
#define ENC_ISO_LATIN1 ENC_ISO_LATIN_1
#define ENC_ISO_UTF32_BE ENC_UNKNOWN //bogus
#define ENC_ISO_UTF32_LE ENC_WCHAR // bogus
#define ENC_ISO_UTF8 ENC_UTF8
#define ENC_ISO_ASCII ENC_ASCII
#define ENC_ISO_ANSI ENC_ANSI
typedef IOENC encoding_t;
#endif
#define MAX_ISO_LATIN1 255
/****************** character definition table **************************/

View File

@ -90,15 +90,8 @@ load_files(Files,Opts) :-
( atom(Files) -> true ; '$do_error'(type_error(atom,Files),Call) ),
/* call make */
'$do_error'(domain_error(unimplemented_option,derived_from),Call).
'$process_lf_opt'(encoding(Encoding),_,_,_,_,_,_,_,_,EncCode,_,_,_,Call) :-
( var(Encoding) ->
'$do_error'(instantiation_error,Call)
;
'$valid_encoding'(Encoding, EncCode) ->
true
;
'$do_error'(domain_error(io_mode,encoding(Encoding)),Call)
).
'$process_lf_opt'(encoding(Encoding),_,_,_,_,_,_,_,_,Encoding,_,_,_,Call) :-
atom(Encoding).
'$process_lf_opt'(expand(true),_,_,true,_,_,_,_,_,_,_,_,_,Call) :-
'$do_error'(domain_error(unimplemented_option,expand),Call).
'$process_lf_opt'(expand(false),_,_,false,_,_,_,_,_,_,_,_,_,_).
@ -152,14 +145,13 @@ load_files(Files,Opts) :-
'$do_lf'(Mod, user_input, InfLevel, CompilationMode,Imports,SkipUnixComments,CompMode,Reconsult,UseModule).
'$lf'(user_input, Mod, _,InfLevel,_,_,CompilationMode,Imports,_,_,SkipUnixComments,CompMode,Reconsult,UseModule) :- !,
'$do_lf'(Mod, user_input, InfLevel, CompilationMode,Imports,SkipUnixComments,CompMode,Reconsult,UseModule).
'$lf'(X, Mod, Call, InfLevel,_,Changed,CompilationMode,Imports,_,Enc,SkipUnixComments,CompMode,Reconsult,UseModule) :-
'$lf'(X, Mod, Call, InfLevel,_,Changed,CompilationMode,Imports,_,Encoding,SkipUnixComments,CompMode,Reconsult,UseModule) :-
'$full_filename'(X, Y, Call),
(
var(Encoding)
->
Opts = []
;
'$valid_encoding'(Encoding, Enc),
Opts = [encoding(Encoding)]
),
open(Y, read, Stream, Opts), !,
@ -624,48 +616,9 @@ remove_from_path(New) :- '$check_path'(New,Path),
fail.
'$record_loaded'(_, _, _).
%
% encoding stuff: what I believe SWI does.
%
% 8-bit binaries
'$valid_encoding'(octet, 0).
% 7-bit ASCII as America originally intended
'$valid_encoding'(ascii, 2).
% Ye europeaners made it 8 bits
'$valid_encoding'(iso_latin_1, 3).
% UTF-8: default 8 bits but 80 extends to 16bits
'$valid_encoding'(utf8, 5).
% UNICODE: 16 bits throughout, the way it was supposed to be!
'$valid_encoding'(unicode_be, 6).
'$valid_encoding'(unicode_le, 7).
% whatever the system tell us to do.
'$valid_encoding'(text, 8).
'$default_encoding'(DefCode) :- nonvar(DefCode), !,
'$encoding'('$stream'(0),DefCode),
'$encoding'('$stream'(1),DefCode),
'$encoding'('$stream'(2),DefCode),
set_value('$default_encoding',DefCode).
'$default_encoding'(DefCode) :-
get_value('$default_encoding',DefCode0),
( DefCode0 == [] ->
'$get_default_encoding'(DefCode)
;
DefCode = DefCode0
).
'$set_encoding'(V) :- var(V), !,
'$do_error'(instantiation_error, encoding(V)).
'$set_encoding'(EncAtom) :-
'$valid_encoding'(EncAtom, Enc), !,
'$set_encoding'(Encoding) :-
'$current_loop_stream'(Stream),
'$encoding'(Stream, Enc).
'$set_encoding'(EncAtom) :-
atom(EncAtom), !,
'$do_error'(domain_error(encoding,EncAtom),encoding(EncAtom)).
'$set_encoding'(EncAtom) :-
'$do_error'(type_error(atom,V),encoding(EncAtom)).
( Encoding == default -> true ; set_stream(Stream, encoding(Encoding)) ).
absolute_file_name(V,Out) :- var(V), !,
'$do_error'(instantiation_error, absolute_file_name(V, Out)).