fix writing streams by write.c

This commit is contained in:
Vítor Santos Costa 2012-02-27 08:53:18 +00:00
parent 5d65c49292
commit 665d426e13
5 changed files with 38 additions and 15 deletions

View File

@ -336,6 +336,23 @@ wrputref(CODEADDR ref, int Quote_illegal, struct write_globs *wglb)
lastw = alphanum; lastw = alphanum;
} }
/* writes a blob (default) */
static void
wrputblob(CODEADDR ref, int Quote_illegal, struct write_globs *wglb)
{
char s[256];
wrf stream = wglb->stream;
putAtom(AtomSWIStream, Quote_illegal, wglb);
#if defined(__linux__) || defined(__APPLE__)
sprintf(s, "(%p)", ref);
#else
sprintf(s, "(0x%p)", ref);
#endif
wrputs(s, stream);
lastw = alphanum;
}
static int static int
legalAtom(unsigned char *s) /* Is this a legal atom ? */ legalAtom(unsigned char *s) /* Is this a legal atom ? */
{ {
@ -455,25 +472,16 @@ write_quoted(int ch, int quote, wrf stream)
static void static void
putAtom(Atom atom, int Quote_illegal, struct write_globs *wglb) putAtom(Atom atom, int Quote_illegal, struct write_globs *wglb)
{ {
unsigned char *s = (unsigned char *)RepAtom(atom)->StrOfAE; unsigned char *s;
wtype atom_or_symbol = AtomIsSymbols(s); wtype atom_or_symbol;
wrf stream = wglb->stream; wrf stream = wglb->stream;
/* #define CRYPT_FOR_STEVE 1*/
#ifdef CRYPT_FOR_STEVE
if (Yap_GetValue(AtomCryptAtoms) != TermNil && Yap_GetAProp(atom, OpProperty) == NIL) {
char s[16];
sprintf(s,"x%x", (CELL)s);
wrputs(s, stream);
return;
}
#endif
if (IsBlob(atom)) { if (IsBlob(atom)) {
wrputref((CODEADDR)RepAtom(atom),1,stream); wrputblob((CODEADDR)RepAtom(atom),wglb->Quote_illegal,wglb);
return; return;
} }
if (IsWideAtom(atom)) { if (IsWideAtom(atom)) {
wchar_t *ws = (wchar_t *)s; wchar_t *ws = RepAtom(atom)->WStrOfAE;
if (Quote_illegal) { if (Quote_illegal) {
wrputc('\'', stream); wrputc('\'', stream);
@ -487,6 +495,17 @@ putAtom(Atom atom, int Quote_illegal, struct write_globs *wglb)
} }
return; return;
} }
s = (unsigned char *)RepAtom(atom)->StrOfAE;
/* #define CRYPT_FOR_STEVE 1*/
#ifdef CRYPT_FOR_STEVE
if (Yap_GetValue(AtomCryptAtoms) != TermNil && Yap_GetAProp(atom, OpProperty) == NIL) {
char s[16];
sprintf(s,"x%x", (CELL)s);
wrputs(s, stream);
return;
}
#endif
atom_or_symbol = AtomIsSymbols(s);
if (lastw == atom_or_symbol && atom_or_symbol != separator /* solo */) if (lastw == atom_or_symbol && atom_or_symbol != separator /* solo */)
wrputc(' ', stream); wrputc(' ', stream);
lastw = atom_or_symbol; lastw = atom_or_symbol;
@ -669,7 +688,6 @@ restore_from_write(struct rewind_term *rwt, struct write_globs *wglb)
if (rwt->u.s.ptr) { if (rwt->u.s.ptr) {
CELL *ptr; CELL *ptr;
if (wglb->Keep_terms) { if (wglb->Keep_terms) {
ptr = (CELL *)Yap_GetPtrFromSlot(rwt->u.s.ptr PASS_REGS);
t = Yap_GetPtrFromSlot(rwt->u.s.old PASS_REGS); t = Yap_GetPtrFromSlot(rwt->u.s.old PASS_REGS);
Yap_RecoverSlots(2 PASS_REGS); Yap_RecoverSlots(2 PASS_REGS);
} else { } else {
@ -853,7 +871,7 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, str
write_var(RepAppl(t)+1, wglb, &nrwt); write_var(RepAppl(t)+1, wglb, &nrwt);
return; return;
case (CELL)FunctorDBRef: case (CELL)FunctorDBRef:
wrputref(RefOfTerm(t), wglb->Quote_illegal, wglb->stream); wrputref(RefOfTerm(t), wglb->Quote_illegal, wglb);
return; return;
case (CELL)FunctorLongInt: case (CELL)FunctorLongInt:
wrputn(LongIntOfTerm(t),wglb); wrputn(LongIntOfTerm(t),wglb);

View File

@ -272,6 +272,7 @@
AtomStaticClause = Yap_FullLookupAtom("$static_clause"); AtomStaticClause = Yap_FullLookupAtom("$static_clause");
AtomStaticProcedure = Yap_LookupAtom("static_procedure"); AtomStaticProcedure = Yap_LookupAtom("static_procedure");
AtomStream = Yap_FullLookupAtom("$stream"); AtomStream = Yap_FullLookupAtom("$stream");
AtomSWIStream = Yap_FullLookupAtom("<stream>");
AtomVStream = Yap_LookupAtom("stream"); AtomVStream = Yap_LookupAtom("stream");
AtomStreams = Yap_LookupAtom("streams"); AtomStreams = Yap_LookupAtom("streams");
AtomStreamOrAlias = Yap_LookupAtom("stream_or_alias"); AtomStreamOrAlias = Yap_LookupAtom("stream_or_alias");

View File

@ -272,6 +272,7 @@
AtomStaticClause = AtomAdjust(AtomStaticClause); AtomStaticClause = AtomAdjust(AtomStaticClause);
AtomStaticProcedure = AtomAdjust(AtomStaticProcedure); AtomStaticProcedure = AtomAdjust(AtomStaticProcedure);
AtomStream = AtomAdjust(AtomStream); AtomStream = AtomAdjust(AtomStream);
AtomSWIStream = AtomAdjust(AtomSWIStream);
AtomVStream = AtomAdjust(AtomVStream); AtomVStream = AtomAdjust(AtomVStream);
AtomStreams = AtomAdjust(AtomStreams); AtomStreams = AtomAdjust(AtomStreams);
AtomStreamOrAlias = AtomAdjust(AtomStreamOrAlias); AtomStreamOrAlias = AtomAdjust(AtomStreamOrAlias);

View File

@ -542,6 +542,8 @@
#define AtomStaticProcedure Yap_heap_regs->AtomStaticProcedure_ #define AtomStaticProcedure Yap_heap_regs->AtomStaticProcedure_
Atom AtomStream_; Atom AtomStream_;
#define AtomStream Yap_heap_regs->AtomStream_ #define AtomStream Yap_heap_regs->AtomStream_
Atom AtomSWIStream_;
#define AtomSWIStream Yap_heap_regs->AtomSWIStream_
Atom AtomVStream_; Atom AtomVStream_;
#define AtomVStream Yap_heap_regs->AtomVStream_ #define AtomVStream Yap_heap_regs->AtomVStream_
Atom AtomStreams_; Atom AtomStreams_;

View File

@ -277,6 +277,7 @@ A StartupSavedState F "$startup_saved_state"
A StaticClause F "$static_clause" A StaticClause F "$static_clause"
A StaticProcedure N "static_procedure" A StaticProcedure N "static_procedure"
A Stream F "$stream" A Stream F "$stream"
A SWIStream F "<stream>"
A VStream N "stream" A VStream N "stream"
A Streams N "streams" A Streams N "streams"
A StreamOrAlias N "stream_or_alias" A StreamOrAlias N "stream_or_alias"