add Yap_ReadBuffer
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1064 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
19bfe301db
commit
0aa358a2b7
@ -1,17 +1,18 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog %W% %G% *
|
||||
* YAP Prolog *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* Copyright L.Damas, V.Santos Costa and Universidade do Porto 1985-- *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: c_interface.c *
|
||||
* Last rev: 19/2/88 *
|
||||
* mods: *
|
||||
* comments: c_interface primitives definition *
|
||||
* *
|
||||
* Last rev: $Date: 2004-05-14 16:33:44 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $ *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#define Bool int
|
||||
@ -77,7 +78,6 @@ X_API void *STD_PROTO(YAP_ExtraSpace,(void));
|
||||
X_API Int STD_PROTO(YAP_cut_fail,(void));
|
||||
X_API Int STD_PROTO(YAP_cut_succeed,(void));
|
||||
X_API Int STD_PROTO(YAP_Unify,(Term,Term));
|
||||
X_API Int STD_PROTO(YAP_Unify,(Term,Term));
|
||||
X_API int STD_PROTO(YAP_Reset,(void));
|
||||
X_API Int STD_PROTO(YAP_Init,(YAP_init_args *));
|
||||
X_API Int STD_PROTO(YAP_FastInit,(char *));
|
||||
@ -85,6 +85,7 @@ X_API Int STD_PROTO(YAP_CallProlog,(Term));
|
||||
X_API void *STD_PROTO(YAP_AllocSpaceFromYap,(unsigned int));
|
||||
X_API void STD_PROTO(YAP_FreeSpaceFromYap,(void *));
|
||||
X_API int STD_PROTO(YAP_StringToBuffer, (Term, char *, unsigned int));
|
||||
X_API Term STD_PROTO(YAP_ReadBuffer, (char *,Term *));
|
||||
X_API Term STD_PROTO(YAP_BufferToString, (char *));
|
||||
X_API Term STD_PROTO(YAP_BufferToAtomList, (char *));
|
||||
X_API void STD_PROTO(YAP_Error,(char *));
|
||||
@ -227,7 +228,7 @@ YAP_MkFloatTerm(double n)
|
||||
t = MkFloatTerm(n);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API flt
|
||||
@ -242,7 +243,7 @@ YAP_MkAtomTerm(Atom n)
|
||||
Term t;
|
||||
|
||||
t = MkAtomTerm(n);
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Atom
|
||||
@ -285,7 +286,7 @@ YAP_MkVarTerm(void)
|
||||
t = MkVarTerm();
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
@ -297,7 +298,7 @@ YAP_MkPairTerm(Term t1, Term t2)
|
||||
t = MkPairTerm(t1, t2);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
@ -309,7 +310,7 @@ YAP_MkNewPairTerm()
|
||||
t = Yap_MkNewPairTerm();
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
@ -333,7 +334,7 @@ YAP_MkApplTerm(Functor f,unsigned long int arity, Term args[])
|
||||
t = Yap_MkApplTerm(f, arity, args);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
@ -345,7 +346,7 @@ YAP_MkNewApplTerm(Functor f,unsigned long int arity)
|
||||
t = Yap_MkNewApplTerm(f, arity);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Functor
|
||||
@ -658,7 +659,20 @@ YAP_BufferToString(char *s)
|
||||
t = Yap_StringToList(s);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* copy a string to a buffer */
|
||||
X_API Term
|
||||
YAP_ReadBuffer(char *s, Term *tp)
|
||||
{
|
||||
Term t;
|
||||
BACKUP_H();
|
||||
|
||||
t = Yap_StringToTerm(s,tp);
|
||||
|
||||
RECOVER_H();
|
||||
return t;
|
||||
}
|
||||
|
||||
/* copy a string to a buffer */
|
||||
@ -671,7 +685,7 @@ YAP_BufferToAtomList(char *s)
|
||||
t = Yap_StringToListOfAtoms(s);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
@ -819,7 +833,7 @@ YAP_Read(int (*mygetc)(void))
|
||||
TR = old_TR;
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API void
|
||||
|
90
C/iopreds.c
90
C/iopreds.c
@ -1981,11 +1981,40 @@ p_open_pipe_stream (void)
|
||||
return (Yap_unify (ARG1, t1) && Yap_unify (ARG2, t2));
|
||||
}
|
||||
|
||||
static int
|
||||
open_buf_read_stream(char *nbuf, Int nchars)
|
||||
{
|
||||
int sno;
|
||||
StreamDesc *st;
|
||||
|
||||
|
||||
for (sno = 0; sno < MaxStreams; ++sno)
|
||||
if (Stream[sno].status & Free_Stream_f)
|
||||
break;
|
||||
if (sno == MaxStreams)
|
||||
return (PlIOError (SYSTEM_ERROR,TermNil, "new stream not available for open_mem_read_stream/1"));
|
||||
st = &Stream[sno];
|
||||
/* currently these streams are not seekable */
|
||||
st->status = Input_Stream_f | InMemory_Stream_f;
|
||||
st->linepos = 0;
|
||||
st->charcount = 0;
|
||||
st->linecount = 1;
|
||||
st->stream_putc = MemPutc;
|
||||
st->stream_getc = MemGetc;
|
||||
if (CharConversionTable != NULL)
|
||||
st->stream_getc_for_read = ISOGetc;
|
||||
else
|
||||
st->stream_getc_for_read = MemGetc;
|
||||
st->u.mem_string.pos = 0;
|
||||
st->u.mem_string.buf = nbuf;
|
||||
st->u.mem_string.max_size = nchars;
|
||||
return sno;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_open_mem_read_stream (void) /* $open_mem_read_stream(+List,-Stream) */
|
||||
{
|
||||
Term t, ti;
|
||||
StreamDesc *st;
|
||||
int sno;
|
||||
Int sl = 0, nchars = 0;
|
||||
char *nbuf;
|
||||
@ -2024,26 +2053,7 @@ p_open_mem_read_stream (void) /* $open_mem_read_stream(+List,-Stream) */
|
||||
ti = TailOfTerm(ti);
|
||||
}
|
||||
nbuf[nchars] = '\0';
|
||||
for (sno = 0; sno < MaxStreams; ++sno)
|
||||
if (Stream[sno].status & Free_Stream_f)
|
||||
break;
|
||||
if (sno == MaxStreams)
|
||||
return (PlIOError (SYSTEM_ERROR,TermNil, "new stream not available for open_mem_read_stream/1"));
|
||||
st = &Stream[sno];
|
||||
/* currently these streams are not seekable */
|
||||
st->status = Input_Stream_f | InMemory_Stream_f;
|
||||
st->linepos = 0;
|
||||
st->charcount = 0;
|
||||
st->linecount = 1;
|
||||
st->stream_putc = MemPutc;
|
||||
st->stream_getc = MemGetc;
|
||||
if (CharConversionTable != NULL)
|
||||
st->stream_getc_for_read = ISOGetc;
|
||||
else
|
||||
st->stream_getc_for_read = MemGetc;
|
||||
st->u.mem_string.pos = 0;
|
||||
st->u.mem_string.buf = nbuf;
|
||||
st->u.mem_string.max_size = nchars;
|
||||
sno = open_buf_read_stream(nbuf, nchars);
|
||||
t = MkStream (sno);
|
||||
return (Yap_unify (ARG2, t));
|
||||
}
|
||||
@ -4624,6 +4634,44 @@ p_same_file(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Term
|
||||
Yap_StringToTerm(char *s,Term *tp)
|
||||
{
|
||||
int sno = open_buf_read_stream(s, strlen(s)+1);
|
||||
Term t;
|
||||
TokEntry *tokstart;
|
||||
|
||||
if (sno < 0)
|
||||
return FALSE;
|
||||
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(sno);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
if (tokstart == NIL && tokstart->Tok == Ord (eot_tok)) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(Yap_LookupAtom("end of file found before end of term"));
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
return FALSE;
|
||||
} else if (Yap_ErrorMessage) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
return FALSE;
|
||||
}
|
||||
t = Yap_Parse();
|
||||
if (Yap_ErrorMessage) {
|
||||
if (tp) {
|
||||
*tp = syntax_error(tokstart);
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
return FALSE;
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitBackIO (void)
|
||||
{
|
||||
|
@ -4,15 +4,19 @@
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: stdpreds.c *
|
||||
* comments: General-purpose C implemented system predicates *
|
||||
* *
|
||||
* Last rev: $Date: 2004-05-13 20:54:58 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2004-05-14 16:33:45 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.66 2004/05/13 20:54:58 vsc
|
||||
* debugger fixes
|
||||
* make sure we always go back to current module, even during initizlization.
|
||||
*
|
||||
* Revision 1.65 2004/04/27 15:14:36 vsc
|
||||
* fix halt/0 and halt/1
|
||||
* *
|
||||
|
@ -274,6 +274,7 @@ int STD_PROTO(Yap_PlFGetchar,(void));
|
||||
int STD_PROTO(Yap_GetCharForSIGINT,(void));
|
||||
int STD_PROTO(Yap_StreamToFileNo,(Term));
|
||||
Term STD_PROTO(Yap_OpenStream,(FILE *,char *,Term,int));
|
||||
Term STD_PROTO(Yap_StringToTerm,(char *,Term *));
|
||||
|
||||
extern int
|
||||
Yap_c_input_stream,
|
||||
|
@ -105,13 +105,11 @@ static FILE *bootfile;
|
||||
static int eof_found = FALSE;
|
||||
static int yap_lineno = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
myputc (int ch)
|
||||
{
|
||||
putc(ch,stderr);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
mygetc (void)
|
||||
@ -532,6 +530,11 @@ exec_top_level(int BootMode, YAP_init_args *iap)
|
||||
*/
|
||||
livegoal = YAP_FullLookupAtom("$live");
|
||||
atomfalse = YAP_MkAtomTerm (YAP_FullLookupAtom("$false"));
|
||||
{
|
||||
YAP_Term t = YAP_ReadBuffer("a(1)",NULL);
|
||||
if (t)
|
||||
YAP_Write(t,myputc,0);
|
||||
}
|
||||
while (YAP_GetValue (livegoal) != atomfalse) {
|
||||
YAP_Reset();
|
||||
do_top_goal (YAP_MkAtomTerm (livegoal));
|
||||
|
19
docs/yap.tex
19
docs/yap.tex
@ -5627,11 +5627,11 @@ signal name or one that is not supported on this platform. No checks
|
||||
are made on the handler provided by the user.
|
||||
|
||||
@table @code
|
||||
@item SIGHUP (Hangup)
|
||||
sig_hup in YAP; Reconsult the initialization files
|
||||
@item sig_up (Hangup)
|
||||
SIGHUP in Unix/Linux; Reconsult the initialization files
|
||||
~/.yaprc, ~/.prologrc and ~/prolog.ini.
|
||||
@item SIGUSR1 and SIGUSR2 (User signals)
|
||||
sig_usr1 and sig_usr2 in YAP; Print a message and halt.
|
||||
@item sig_usr1 and sig_usr2 (User signals)
|
||||
SIGUSR1 and SIGUSR2 in Unix/Linux; Print a message and halt.
|
||||
@end table
|
||||
|
||||
A special case is made, where if @var{Callable} is bound to
|
||||
@ -13585,6 +13585,17 @@ character atoms
|
||||
@noindent
|
||||
The user-provided string must include a terminating null character.
|
||||
|
||||
@findex YAP_ReadBuffer (C-Interface function)
|
||||
The C-interface function calls the parser on a sequence of characters
|
||||
stored at @var{buf} and returns the resulting term.
|
||||
@example
|
||||
YAP_Term YAP_ReadBuffer(char *@var{buf},YAP_Term *@var{error})
|
||||
@end example
|
||||
@noindent
|
||||
The user-provided string must include a terminating null
|
||||
character. Syntax errors will cause returning @code{FALSE} and binding
|
||||
@var{error} to a Prolog term.
|
||||
|
||||
@node Memory Allocation, Controlling Streams, Manipulating Strings, C-Interface
|
||||
@section Memory Allocation
|
||||
|
||||
|
@ -250,6 +250,9 @@ extern X_API int PROTO(YAP_StringToBuffer,(YAP_Term,char *,unsigned int));
|
||||
/* int BufferToString(char *) */
|
||||
extern X_API YAP_Term PROTO(YAP_BufferToString,(char *));
|
||||
|
||||
/* YAP_Term BufferToTerm(char *) */
|
||||
extern X_API YAP_Term PROTO(YAP_ReadBuffer,(char *,YAP_Term *));
|
||||
|
||||
/* int BufferToAtomList(char *) */
|
||||
extern X_API YAP_Term PROTO(YAP_BufferToAtomList,(char *));
|
||||
|
||||
|
37
misc/yap.def
37
misc/yap.def
@ -1,13 +1,9 @@
|
||||
EXPORTS
|
||||
YAP_A
|
||||
YAP_Init
|
||||
YAP_RunGoal
|
||||
YAP_RestartGoal
|
||||
YAP_Reset
|
||||
YAP_Deref
|
||||
YAP_MkVarTerm
|
||||
YAP_IsVarTerm
|
||||
YAP_IsNonVarTerm
|
||||
YAP_MkVarTerm
|
||||
YAP_IsIntTerm
|
||||
YAP_IsFloatTerm
|
||||
YAP_IsDbRefTerm
|
||||
@ -18,8 +14,8 @@ YAP_MkIntTerm
|
||||
YAP_IntOfTerm
|
||||
YAP_MkFloatTerm
|
||||
YAP_FloatOfTerm
|
||||
YAP_MkAtomTerm
|
||||
YAP_AtomOfTerm
|
||||
YAP_MkAtomTerm
|
||||
YAP_LookupAtom
|
||||
YAP_FullLookupAtom
|
||||
YAP_AtomName
|
||||
@ -35,36 +31,36 @@ YAP_MkFunctor
|
||||
YAP_NameOfFunctor
|
||||
YAP_ArityOfFunctor
|
||||
YAP_ExtraSpace
|
||||
YAP_Unify
|
||||
YAP_UserCPredicate
|
||||
YAP_UserCPredicateWithArgs
|
||||
YAP_UserBackCPredicate
|
||||
YAP_CallProlog
|
||||
YAP_cut_fail
|
||||
YAP_cut_succeed
|
||||
YAP_Unify
|
||||
YAP_Reset
|
||||
YAP_Init
|
||||
YAP_FastInit
|
||||
YAP_CallProlog
|
||||
YAP_AllocSpaceFromYap
|
||||
YAP_FreeSpaceFromYap
|
||||
YAP_StringToBuffer
|
||||
YAP_ReadBuffer
|
||||
YAP_BufferToString
|
||||
YAP_BufferToAtomList
|
||||
YAP_Error
|
||||
YAP_RunGoal
|
||||
YAP_RestartGoal
|
||||
YAP_GoalHasException
|
||||
YAP_ContinueGoal
|
||||
YAP_PruneGoal
|
||||
YAP_GoalHasException
|
||||
YAP_InitConsult
|
||||
YAP_EndConsult
|
||||
YAP_Read
|
||||
YAP_Write
|
||||
YAP_CompileClause
|
||||
YAP_Init
|
||||
YAP_FastInit
|
||||
YAP_PutValue
|
||||
YAP_GetValue
|
||||
YAP_Reset
|
||||
YAP_Exit
|
||||
YAP_InitSocks
|
||||
YAP_SetOutputMessage
|
||||
YAP_Write
|
||||
YAP_InitConsult
|
||||
YAP_EndConsult
|
||||
YAP_StreamToFileNo
|
||||
YAP_CloseAllOpenStreams
|
||||
YAP_OpenStream
|
||||
@ -75,11 +71,12 @@ YAP_AddressFromSlot
|
||||
YAP_PutInSlot
|
||||
YAP_RecoverSlots
|
||||
YAP_Throw
|
||||
YAP_LookupModule
|
||||
YAP_ModuleName
|
||||
YAP_Halt
|
||||
YAP_TopOfLocalStack
|
||||
YAP_Predicate
|
||||
YAP_CurrentModule
|
||||
YAP_PredicateInfo
|
||||
|
||||
YAP_UserCPredicate
|
||||
YAP_UserBackCPredicate
|
||||
YAP_UserCPredicateWithArgs
|
||||
YAP_CurrentModule
|
||||
|
Reference in New Issue
Block a user