IOSTREAM -> FILE

This commit is contained in:
Vítor Santos Costa 2015-06-19 00:32:38 +01:00
parent 144eb6ab47
commit 42b79d7ee7
1 changed files with 35 additions and 32 deletions

View File

@ -652,19 +652,19 @@ RestoreAtomList(Atom atm USES_REGS)
} }
static size_t static size_t
read_bytes(IOSTREAM *stream, void *ptr, size_t sz) read_bytes(FILE *stream, void *ptr, size_t sz)
{ {
return Sfread(ptr, sz, 1, stream); return fread(ptr, sz, 1, stream);
} }
static unsigned char static unsigned char
read_byte(IOSTREAM *stream) read_byte(FILE *stream)
{ {
return Sgetc(stream); return getc(stream);
} }
static BITS16 static BITS16
read_bits16(IOSTREAM *stream) read_bits16(FILE *stream)
{ {
BITS16 v; BITS16 v;
read_bytes(stream, &v, sizeof(BITS16)); read_bytes(stream, &v, sizeof(BITS16));
@ -672,7 +672,7 @@ read_bits16(IOSTREAM *stream)
} }
static UInt static UInt
read_UInt(IOSTREAM *stream) read_UInt(FILE *stream)
{ {
UInt v; UInt v;
read_bytes(stream, &v, sizeof(UInt)); read_bytes(stream, &v, sizeof(UInt));
@ -680,7 +680,7 @@ read_UInt(IOSTREAM *stream)
} }
static Int static Int
read_Int(IOSTREAM *stream) read_Int(FILE *stream)
{ {
Int v; Int v;
read_bytes(stream, &v, sizeof(Int)); read_bytes(stream, &v, sizeof(Int));
@ -688,14 +688,14 @@ read_Int(IOSTREAM *stream)
} }
static qlf_tag_t static qlf_tag_t
read_tag(IOSTREAM *stream) read_tag(FILE *stream)
{ {
int ch = read_byte(stream); int ch = read_byte(stream);
return ch; return ch;
} }
static UInt static UInt
read_predFlags(IOSTREAM *stream) read_predFlags(FILE *stream)
{ {
pred_flags_t v; pred_flags_t v;
read_bytes(stream, &v, sizeof(pred_flags_t)); read_bytes(stream, &v, sizeof(pred_flags_t));
@ -703,7 +703,7 @@ read_predFlags(IOSTREAM *stream)
} }
static bool static bool
checkChars(IOSTREAM *stream, char s[]) checkChars(FILE *stream, char s[])
{ {
int ch, c; int ch, c;
char *p = s; char *p = s;
@ -717,7 +717,7 @@ checkChars(IOSTREAM *stream, char s[])
} }
static Atom static Atom
get_header(IOSTREAM *stream) get_header(FILE *stream)
{ {
char s[256], *p = s, ch; char s[256], *p = s, ch;
Atom at; Atom at;
@ -738,7 +738,7 @@ get_header(IOSTREAM *stream)
static Int static Int
p_get_header( USES_REGS1 ) p_get_header( USES_REGS1 )
{ {
IOSTREAM *stream; FILE *stream;
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Atom at; Atom at;
@ -746,7 +746,7 @@ p_get_header( USES_REGS1 )
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3"); Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
return FALSE; return FALSE;
} }
if (!(stream = Yap_GetInputStream(AtomOfTerm(t1))) ) { if (!(stream = Yap_GetInputStream(t1, "header scanning in qload")) ) {
return FALSE; return FALSE;
} }
if ((at = get_header( stream )) == NIL) if ((at = get_header( stream )) == NIL)
@ -755,7 +755,7 @@ p_get_header( USES_REGS1 )
} }
static void static void
ReadHash(IOSTREAM *stream) ReadHash(FILE *stream)
{ {
CACHE_REGS CACHE_REGS
UInt i; UInt i;
@ -901,7 +901,7 @@ ReadHash(IOSTREAM *stream)
} }
static void static void
read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, pred_flags_t flags) { read_clauses(FILE *stream, PredEntry *pp, UInt nclauses, pred_flags_t flags) {
CACHE_REGS CACHE_REGS
if (flags & LogUpdatePredFlag) { if (flags & LogUpdatePredFlag) {
/* first, clean up whatever was there */ /* first, clean up whatever was there */
@ -1005,7 +1005,7 @@ read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, pred_flags_t flags)
} }
static void static void
read_pred(IOSTREAM *stream, Term mod) { read_pred(FILE *stream, Term mod) {
pred_flags_t flags, fl1; pred_flags_t flags, fl1;
UInt nclauses; UInt nclauses;
PredEntry *ap; PredEntry *ap;
@ -1045,6 +1045,9 @@ read_pred(IOSTREAM *stream, Term mod) {
} }
if (nclauses) if (nclauses)
read_clauses(stream, ap, nclauses, flags); read_clauses(stream, ap, nclauses, flags);
#if DEBUG
//Yap_PrintPredName( ap );
#endif
if (flags & HiddenPredFlag) { if (flags & HiddenPredFlag) {
Yap_HidePred(ap); Yap_HidePred(ap);
@ -1052,7 +1055,7 @@ read_pred(IOSTREAM *stream, Term mod) {
} }
static void static void
read_ops(IOSTREAM *stream) { read_ops(FILE *stream) {
Int x; Int x;
while ((x = read_tag(stream)) != QLY_END_OPS) { while ((x = read_tag(stream)) != QLY_END_OPS) {
Atom at = (Atom)read_UInt(stream); Atom at = (Atom)read_UInt(stream);
@ -1072,7 +1075,7 @@ read_ops(IOSTREAM *stream) {
static void static void
read_module(IOSTREAM *stream) { read_module(FILE *stream) {
qlf_tag_t x; qlf_tag_t x;
InitHash(); InitHash();
@ -1094,7 +1097,7 @@ read_module(IOSTREAM *stream) {
static Int static Int
p_read_module_preds( USES_REGS1 ) p_read_module_preds( USES_REGS1 )
{ {
IOSTREAM *stream; FILE *stream;
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
@ -1105,7 +1108,7 @@ p_read_module_preds( USES_REGS1 )
Yap_Error(TYPE_ERROR_ATOM,t1,"read_qly/3"); Yap_Error(TYPE_ERROR_ATOM,t1,"read_qly/3");
return(FALSE); return(FALSE);
} }
if (!(stream = Yap_GetInputStream(AtomOfTerm(t1))) ) { if (!(stream = Yap_GetInputStream(t1, "scanning preducate modules")) ) {
return FALSE; return FALSE;
} }
read_module(stream); read_module(stream);
@ -1122,26 +1125,26 @@ ReInitProlog(void)
static Int static Int
p_read_program( USES_REGS1 ) qload_program( USES_REGS1 )
{ {
IOSTREAM *stream; FILE *stream;
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3"); Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
return FALSE; return FALSE;
} }
if ((stream = Yap_GetInputStream(AtomOfTerm(t1))) ) { if ((stream = Yap_GetInputStream(t1, "from read_program")) ) {
return FALSE; return FALSE;
} }
YAP_Reset( YAP_RESET_FROM_RESTORE ); Yap_Reset( YAP_RESET_FROM_RESTORE );
if (get_header( stream ) == NIL) if (get_header( stream ) == NIL)
return FALSE; return FALSE;
read_module(stream); read_module(stream);
Sclose( stream ); fclose( stream );
/* back to the top level we go */ /* back to the top level we go */
ReInitProlog(); ReInitProlog();
return TRUE; return true;
} }
int int
@ -1149,14 +1152,14 @@ Yap_Restore(char *s, char *lib_dir)
{ {
CACHE_REGS CACHE_REGS
IOSTREAM *stream = Yap_OpenRestore(s, lib_dir); FILE *stream = Yap_OpenRestore(s, lib_dir);
if (!stream) if (!stream)
return -1; return -1;
GLOBAL_RestoreFile = s; GLOBAL_RestoreFile = s;
if (get_header( stream ) == NIL) if (get_header( stream ) == NIL)
return FALSE; return FALSE;
read_module(stream); read_module(stream);
Sclose( stream ); fclose( stream );
GLOBAL_RestoreFile = NULL; GLOBAL_RestoreFile = NULL;
CurrentModule = USER_MODULE; CurrentModule = USER_MODULE;
return DO_ONLY_CODE; return DO_ONLY_CODE;
@ -1165,10 +1168,10 @@ Yap_Restore(char *s, char *lib_dir)
void Yap_InitQLYR(void) void Yap_InitQLYR(void)
{ {
Yap_InitCPred("$qload_module_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag); Yap_InitCPred("$qload_module_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag|HiddenPredFlag);
Yap_InitCPred("$qload_file_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag); Yap_InitCPred("$qload_file_preds", 1, p_read_module_preds, SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$qload_program", 1, p_read_program, SyncPredFlag|UserCPredFlag); Yap_InitCPred("$qload_program", 1, qload_program, SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$q_header", 2, p_get_header, SyncPredFlag|UserCPredFlag); Yap_InitCPred("$q_header", 2, p_get_header, SyncPredFlag|HiddenPredFlag);
if (FALSE) { if (FALSE) {
restore_codes(); restore_codes();
} }