enable obtaining current stream_position from SWI.y
This commit is contained in:
parent
cb7c2e0ca8
commit
168a6366f8
@ -4765,6 +4765,9 @@ StreamPosition(int sno)
|
|||||||
Term sargs[5];
|
Term sargs[5];
|
||||||
Int cpos;
|
Int cpos;
|
||||||
cpos = Stream[sno].charcount;
|
cpos = Stream[sno].charcount;
|
||||||
|
if (Stream[sno].status & SWI_Stream_f) {
|
||||||
|
return Yap_get_stream_position(Stream[sno].u.swi_stream.swi_ptr);
|
||||||
|
}
|
||||||
if (Stream[sno].stream_getc == PlUnGetc) {
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
cpos--;
|
cpos--;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ typedef int (*SWI_GetWideFunction)(void *);
|
|||||||
typedef int (*SWI_CloseFunction)(void *);
|
typedef int (*SWI_CloseFunction)(void *);
|
||||||
typedef int (*SWI_FlushFunction)(void *);
|
typedef int (*SWI_FlushFunction)(void *);
|
||||||
typedef int (*SWI_PLGetStreamFunction)(void *);
|
typedef int (*SWI_PLGetStreamFunction)(void *);
|
||||||
|
typedef int (*SWI_PLGetStreamPositionFunction)(void *);
|
||||||
|
|
||||||
#include "../include/dswiatoms.h"
|
#include "../include/dswiatoms.h"
|
||||||
|
|
||||||
|
@ -462,6 +462,7 @@ void STD_PROTO(Yap_InitMYDDAS_TopLevelPreds,(void));
|
|||||||
void STD_PROTO(Yap_swi_install,(void));
|
void STD_PROTO(Yap_swi_install,(void));
|
||||||
void STD_PROTO(Yap_InitSWIHash,(void));
|
void STD_PROTO(Yap_InitSWIHash,(void));
|
||||||
int STD_PROTO(Yap_get_stream_handle,(Term, int, int, void *));
|
int STD_PROTO(Yap_get_stream_handle,(Term, int, int, void *));
|
||||||
|
Term STD_PROTO(Yap_get_stream_position,(void *));
|
||||||
|
|
||||||
/* ypsocks.c */
|
/* ypsocks.c */
|
||||||
void STD_PROTO(Yap_InitSockets,(void));
|
void STD_PROTO(Yap_InitSockets,(void));
|
||||||
|
@ -188,6 +188,7 @@
|
|||||||
#define SWIClose Yap_global->swi_close
|
#define SWIClose Yap_global->swi_close
|
||||||
#define SWIFlush Yap_global->swi_flush
|
#define SWIFlush Yap_global->swi_flush
|
||||||
#define SWIGetStream Yap_global->swi_get_stream_f
|
#define SWIGetStream Yap_global->swi_get_stream_f
|
||||||
|
#define SWIGetStreamPosition Yap_global->swi_get_stream_position_f
|
||||||
|
|
||||||
#define Yap_AllowLocalExpansion Yap_global->allow_local_expansion
|
#define Yap_AllowLocalExpansion Yap_global->allow_local_expansion
|
||||||
#define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion
|
#define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion
|
||||||
|
@ -190,6 +190,7 @@ typedef struct worker_shared {
|
|||||||
SWI_CloseFunction swi_close;
|
SWI_CloseFunction swi_close;
|
||||||
SWI_FlushFunction swi_flush;
|
SWI_FlushFunction swi_flush;
|
||||||
SWI_PLGetStreamFunction swi_get_stream_f;
|
SWI_PLGetStreamFunction swi_get_stream_f;
|
||||||
|
SWI_PLGetStreamPositionFunction swi_get_stream_position_f;
|
||||||
|
|
||||||
int allow_local_expansion;
|
int allow_local_expansion;
|
||||||
int allow_global_expansion;
|
int allow_global_expansion;
|
||||||
|
@ -188,6 +188,7 @@ static void InitGlobal(void) {
|
|||||||
Yap_global->swi_close = NULL;
|
Yap_global->swi_close = NULL;
|
||||||
Yap_global->swi_flush = NULL;
|
Yap_global->swi_flush = NULL;
|
||||||
Yap_global->swi_get_stream_f = NULL;
|
Yap_global->swi_get_stream_f = NULL;
|
||||||
|
Yap_global->swi_get_stream_position_f = NULL;
|
||||||
|
|
||||||
Yap_global->allow_local_expansion = TRUE;
|
Yap_global->allow_local_expansion = TRUE;
|
||||||
Yap_global->allow_global_expansion = TRUE;
|
Yap_global->allow_global_expansion = TRUE;
|
||||||
|
@ -199,6 +199,7 @@ static void RestoreGlobal(void) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_LIBREADLINE
|
#if HAVE_LIBREADLINE
|
||||||
|
|
||||||
|
|
||||||
|
@ -699,6 +699,7 @@ typedef struct SWI_IO {
|
|||||||
void *flush_s;
|
void *flush_s;
|
||||||
void *close_s;
|
void *close_s;
|
||||||
void *get_stream_handle;
|
void *get_stream_handle;
|
||||||
|
void *get_stream_position;
|
||||||
} swi_io_struct;
|
} swi_io_struct;
|
||||||
|
|
||||||
/* SWI stream info */
|
/* SWI stream info */
|
||||||
|
@ -3096,6 +3096,7 @@ PL_YAP_InitSWIIO(struct SWI_IO *swio)
|
|||||||
SWIFlush = swio->flush_s;
|
SWIFlush = swio->flush_s;
|
||||||
SWIClose = swio->close_s;
|
SWIClose = swio->close_s;
|
||||||
SWIGetStream = swio->get_stream_handle;
|
SWIGetStream = swio->get_stream_handle;
|
||||||
|
SWIGetStreamPosition = swio->get_stream_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*GetStreamF)(term_t, int, int, IOSTREAM **s);
|
typedef int (*GetStreamF)(term_t, int, int, IOSTREAM **s);
|
||||||
@ -3115,6 +3116,23 @@ Yap_get_stream_handle(Term t0, int read_mode, int write_mode, void *s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*GetStreamPosF)(IOSTREAM *s, term_t);
|
||||||
|
|
||||||
|
Term
|
||||||
|
Yap_get_stream_position(void *s){
|
||||||
|
term_t t;
|
||||||
|
Term t0;
|
||||||
|
GetStreamPosF f = (GetStreamPosF)SWIGetStreamPosition;
|
||||||
|
|
||||||
|
t = (term_t)Yap_NewSlots(1);
|
||||||
|
if (!(*f)(s, t))
|
||||||
|
return 0L;
|
||||||
|
t0 = Yap_GetFromSlot((Int)t);
|
||||||
|
Yap_RecoverSlots(1);
|
||||||
|
return t0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
X_API void (*PL_signal(int sig, void (*func)(int)))(int)
|
X_API void (*PL_signal(int sig, void (*func)(int)))(int)
|
||||||
{
|
{
|
||||||
// return Yap_signal2(sig,func);
|
// return Yap_signal2(sig,func);
|
||||||
|
@ -211,6 +211,7 @@ SWI_PutWideFunction swi_wputc SWIWidePutc =NULL
|
|||||||
SWI_CloseFunction swi_close SWIClose =NULL
|
SWI_CloseFunction swi_close SWIClose =NULL
|
||||||
SWI_FlushFunction swi_flush SWIFlush =NULL
|
SWI_FlushFunction swi_flush SWIFlush =NULL
|
||||||
SWI_PLGetStreamFunction swi_get_stream_f SWIGetStream =NULL
|
SWI_PLGetStreamFunction swi_get_stream_f SWIGetStream =NULL
|
||||||
|
SWI_PLGetStreamPositionFunction swi_get_stream_position_f SWIGetStreamPosition =NULL
|
||||||
|
|
||||||
// stack overflow expansion/gc control
|
// stack overflow expansion/gc control
|
||||||
int allow_local_expansion Yap_AllowLocalExpansion =TRUE
|
int allow_local_expansion Yap_AllowLocalExpansion =TRUE
|
||||||
|
@ -4350,6 +4350,12 @@ get_stream_handle_no_errors(term_t t, int read, int write, IOSTREAM **s)
|
|||||||
return get_stream_handle(t, s, SH_ALIAS);
|
return get_stream_handle(t, s, SH_ALIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_stream_position(IOSTREAM *s, term_t t)
|
||||||
|
{ GET_LD
|
||||||
|
return stream_position_prop(s, t);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_yap_extras(void)
|
init_yap_extras(void)
|
||||||
{
|
{
|
||||||
@ -4363,6 +4369,7 @@ init_yap_extras(void)
|
|||||||
swiio.flush_s = Sflush;
|
swiio.flush_s = Sflush;
|
||||||
swiio.close_s = closeStream;
|
swiio.close_s = closeStream;
|
||||||
swiio.get_stream_handle = get_stream_handle_no_errors;
|
swiio.get_stream_handle = get_stream_handle_no_errors;
|
||||||
|
swiio.get_stream_position = get_stream_position;
|
||||||
PL_YAP_InitSWIIO(&swiio);
|
PL_YAP_InitSWIIO(&swiio);
|
||||||
initCharTypes();
|
initCharTypes();
|
||||||
initFiles();
|
initFiles();
|
||||||
|
Reference in New Issue
Block a user