static Term readFromBuffer(const char *s, Term opts) { Term rval; int sno; encoding_t enc = ENC_ISO_UTF8; sno = Yap_open_buf_read_stream( (char *)s, strlen_utf8((unsigned char *)s), &enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s, 16)), TermNone); rval = Yap_read_term(sno, opts, 3); Yap_CloseStream(sno); return rval; }
static Int read_stream_to_terms(USES_REGS1) { int sno = Yap_CheckStream(ARG1, Input_Stream_f, "read_line_to_codes/2"); Term t, hd; yhandle_t tails, news; if (sno < 0) return FALSE; t = AbsPair(HR); RESET_VARIABLE(HR); Yap_InitSlot((CELL)(HR)); tails = Yap_InitSlot((CELL)(HR)); news = Yap_InitSlot((CELL)(HR)); HR++; while (!(GLOBAL_Stream[sno].status & Eof_Stream_f)) { RESET_VARIABLE(HR); RESET_VARIABLE(HR + 1); hd = (CELL)HR; Yap_PutInSlot(news, (CELL)(HR + 1)); HR += 2; while ((hd = Yap_read_term(sno, TermNil, 2)) == 0L) ; // just ignore failure CELL *pt = VarOfTerm(Yap_GetFromSlot(tails)); if (Deref(hd) == TermEOfCode) { *pt = Deref(ARG3); break; } else { CELL *newpt = (CELL *)Yap_GetFromSlot(news); *pt = AbsPair(newpt - 1); Yap_PutInSlot(tails, (CELL)newpt); } } UNLOCK(GLOBAL_Stream[sno].streamlock); return Yap_unify(t, ARG2); }