fixes to?\012handle interrupts ^C in Windows.
Improvements to configure scripts for WIN32 configurations. --with-readline= option for configure git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@96 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
14
C/absmi.c
14
C/absmi.c
@@ -1978,9 +1978,11 @@ absmi(int inp)
|
||||
*/
|
||||
/* make sure we are here because of an awoken goal */
|
||||
if (CFREG == Unsigned(LCL0) && !(PrologMode & AbortMode)) {
|
||||
Term WGs = ReadTimedVar(WokenGoals);
|
||||
Term my_goal = AbsAppl(H);
|
||||
Term WGs;
|
||||
Term my_goal;
|
||||
|
||||
WGs = ReadTimedVar(WokenGoals);
|
||||
my_goal = AbsAppl(H);
|
||||
if (WGs != TermNil) {
|
||||
#if SHADOW_S
|
||||
/* save S for ModuleName() */
|
||||
@@ -2049,6 +2051,13 @@ absmi(int inp)
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
if (PrologMode & AbortMode) {
|
||||
PrologMode &= ~AbortMode;
|
||||
CFREG = CalculateStackGap();
|
||||
/* same instruction */
|
||||
if (ProcessSIGINT() < 0) Abort("");
|
||||
JMPNext();
|
||||
}
|
||||
#if SHADOW_S
|
||||
S = SREG;
|
||||
#endif
|
||||
@@ -2100,7 +2109,6 @@ absmi(int inp)
|
||||
H += 2;
|
||||
CFREG = CalculateStackGap();
|
||||
SREG = (CELL *) (Unsigned(CreepCode) - sizeof(SMALLUNSGN));
|
||||
|
||||
#ifdef COROUTINING
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -86,6 +86,7 @@ p_inf(E_ARGS)
|
||||
#define NAN (0.0/0.0)
|
||||
#endif
|
||||
|
||||
|
||||
static E_FUNC
|
||||
p_nan(E_ARGS)
|
||||
{
|
||||
|
||||
@@ -3818,12 +3818,14 @@ p_enqueue(void)
|
||||
} else
|
||||
father_key = (db_queue *)DBRefOfTerm(Father);
|
||||
x = StoreTermInDB(Deref(ARG2), 2);
|
||||
x->Parent = NULL;
|
||||
WRITE_LOCK(father_key->QRWLock);
|
||||
if (father_key->LastInQueue != NIL)
|
||||
if (father_key->LastInQueue != NULL)
|
||||
father_key->LastInQueue->Parent = (DBProp)x;
|
||||
father_key->LastInQueue = x;
|
||||
if (father_key->FirstInQueue == NIL)
|
||||
if (father_key->FirstInQueue == NULL) {
|
||||
father_key->FirstInQueue = x;
|
||||
}
|
||||
WRITE_UNLOCK(father_key->QRWLock);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -3873,7 +3875,7 @@ p_dequeue(void)
|
||||
} else
|
||||
father_key = (db_queue *)DBRefOfTerm(Father);
|
||||
WRITE_LOCK(father_key->QRWLock);
|
||||
if ((cur_instance = father_key->FirstInQueue) == NIL) {
|
||||
if ((cur_instance = father_key->FirstInQueue) == NULL) {
|
||||
/* an empty queue automatically goes away */
|
||||
if (father_key == DBQueues)
|
||||
DBQueues = father_key->next;
|
||||
|
||||
22
C/errors.c
22
C/errors.c
@@ -249,22 +249,20 @@ Abort (char *format,...)
|
||||
#ifdef DEBUGX
|
||||
DumpActiveGoals();
|
||||
#endif /* DEBUG */
|
||||
if (PrologMode & BootMode)
|
||||
{
|
||||
exit_yap (1, NIL);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreepFlag = CalculateStackGap();
|
||||
if (PrologMode & BootMode) {
|
||||
exit_yap (1, NIL);
|
||||
} else {
|
||||
PutValue(AtomThrow, MkAtomTerm(AtomFalse));
|
||||
CreepFlag = CalculateStackGap();
|
||||
#if PUSH_REGS
|
||||
restore_absmi_regs(&standard_regs);
|
||||
restore_absmi_regs(&standard_regs);
|
||||
#endif
|
||||
#if defined(__GNUC__) && defined(hppa)
|
||||
/* siglongjmp resets the TR hardware register */
|
||||
save_TR();
|
||||
/* siglongjmp resets the TR hardware register */
|
||||
save_TR();
|
||||
#endif
|
||||
siglongjmp (RestartEnv, 1);
|
||||
}
|
||||
siglongjmp (RestartEnv, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
8
C/init.c
8
C/init.c
@@ -747,6 +747,12 @@ InitCodes(void)
|
||||
#endif /* YAPOR */
|
||||
#endif /* TABLING */
|
||||
heap_regs->failcode = opcode(_op_fail);
|
||||
heap_regs->failcode_1 = opcode(_op_fail);
|
||||
heap_regs->failcode_2 = opcode(_op_fail);
|
||||
heap_regs->failcode_3 = opcode(_op_fail);
|
||||
heap_regs->failcode_4 = opcode(_op_fail);
|
||||
heap_regs->failcode_5 = opcode(_op_fail);
|
||||
heap_regs->failcode_6 = opcode(_op_fail);
|
||||
|
||||
heap_regs->trustfailcode = opcode(_trust_fail);
|
||||
|
||||
@@ -941,6 +947,8 @@ InitCodes(void)
|
||||
heap_regs->functor_change_module = MkFunctor (LookupAtom("$change_module"), 1);
|
||||
heap_regs->functor_current_module = MkFunctor (LookupAtom("$current_module"), 1);
|
||||
heap_regs->functor_mod_switch = MkFunctor (LookupAtom("$mod_switch"), 2);
|
||||
heap_regs->functor_u_minus = MkFunctor (heap_regs->atom_minus, 1);
|
||||
heap_regs->functor_u_plus = MkFunctor (heap_regs->atom_plus, 1);
|
||||
heap_regs->functor_v_bar = MkFunctor(LookupAtom("|"), 2);
|
||||
heap_regs->functor_var = MkFunctor(AtomVar, 1);
|
||||
#ifdef EUROTRA
|
||||
|
||||
73
C/iopreds.c
73
C/iopreds.c
@@ -51,6 +51,9 @@ static char SccsId[] = "%W% %G%";
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#if HAVE_FCNTL_H
|
||||
/* for O_BINARY and O_TEXT in WIN32 */
|
||||
#include <fcntl.h>
|
||||
@@ -77,6 +80,18 @@ static char SccsId[] = "%W% %G%";
|
||||
/* if we botched in a LongIO operation */
|
||||
jmp_buf IOBotch;
|
||||
|
||||
int in_getc = FALSE;
|
||||
|
||||
int sigint_pending = FALSE;
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
jmp_buf readline_jmpbuf;
|
||||
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
FILE *rl_instream, *rl_outstream;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
@@ -319,8 +334,8 @@ unix_upd_stream_info (StreamDesc * s)
|
||||
#endif /* USE_SOCKET */
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
{
|
||||
struct stat buf;
|
||||
if (fstat(fileno(s->u.file.file), &buf) == -1) {
|
||||
struct _stat buf;
|
||||
if (_fstat(YP_fileno(s->u.file.file), &buf) == -1) {
|
||||
return;
|
||||
}
|
||||
if (buf.st_mode & S_IFCHR) {
|
||||
@@ -768,6 +783,10 @@ static void
|
||||
InitReadline(void) {
|
||||
ReadlineBuf = (char *)AllocAtomSpace(READLINE_OUT_BUF_MAX+1);
|
||||
ReadlinePos = ReadlineBuf;
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
rl_instream = stdin;
|
||||
rl_outstream = stdout;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -813,6 +832,10 @@ ReadlineGetc(int sno)
|
||||
register int ch;
|
||||
|
||||
if (ttyptr == NIL) {
|
||||
if (setjmp(readline_jmpbuf) < 0) {
|
||||
Abort("");
|
||||
}
|
||||
in_getc = TRUE;
|
||||
/* Do it the gnu way */
|
||||
YP_fflush (YP_stdout);
|
||||
/* Only sends a newline if we are at the start of a line */
|
||||
@@ -845,10 +868,8 @@ ReadlineGetc(int sno)
|
||||
}
|
||||
newline=FALSE;
|
||||
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
|
||||
in_getc = FALSE;
|
||||
/* window of vulnerability closed */
|
||||
if (PrologMode & AbortMode) {
|
||||
Abort ((char *) NULL);
|
||||
}
|
||||
if (_line == NULL || _line == (char *) EOF)
|
||||
return(console_post_process_read_char(EOF, s, sno));
|
||||
if (_line[0] != '\0' && _line[1] != '\0')
|
||||
@@ -1156,18 +1177,15 @@ ISOGetc (int sno)
|
||||
return(ch);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int in_getc = FALSE;
|
||||
#endif
|
||||
|
||||
/* send a prompt, and use the system for internal buffering. Speed is
|
||||
not of the essence here !!! */
|
||||
static int
|
||||
ConsoleGetc(int sno)
|
||||
{
|
||||
register StreamDesc *s = &Stream[sno];
|
||||
register int ch;
|
||||
char ch;
|
||||
|
||||
restart:
|
||||
if (newline) {
|
||||
char *cptr = Prompt, ch;
|
||||
|
||||
@@ -1178,20 +1196,28 @@ ConsoleGetc(int sno)
|
||||
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
|
||||
newline = FALSE;
|
||||
}
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
next_getc:
|
||||
in_getc = TRUE;
|
||||
#if HAVE_SIGINTERRUPT
|
||||
siginterrupt(SIGINT, TRUE);
|
||||
#endif
|
||||
ch = YP_getc (s->u.file.file);
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
if (!in_getc) {
|
||||
ProcessSIGINT();
|
||||
if (PrologMode & AbortMode) {
|
||||
Abort((char *)NULL);
|
||||
} else
|
||||
goto next_getc;
|
||||
}
|
||||
ch = YP_fgetc(s->u.file.file);
|
||||
#if HAVE_SIGINTERRUPT
|
||||
siginterrupt(SIGINT, FALSE);
|
||||
#endif
|
||||
in_getc = FALSE;
|
||||
if (PrologMode & AbortMode) {
|
||||
PrologMode &= ~AbortMode;
|
||||
CreepFlag = CalculateStackGap();
|
||||
if (ProcessSIGINT() < 0) Abort("");
|
||||
newline = TRUE;
|
||||
goto restart;
|
||||
} else if (ch == -1 && errno == EINTR) {
|
||||
errno = 0;
|
||||
PrologMode &= ~AbortMode;
|
||||
if (ProcessSIGINT() < 0) Abort("");
|
||||
newline = TRUE;
|
||||
goto restart;
|
||||
}
|
||||
return(console_post_process_read_char(ch, s, sno));
|
||||
}
|
||||
|
||||
@@ -1393,8 +1419,13 @@ static int
|
||||
binary_file(char *file_name)
|
||||
{
|
||||
#if HAVE_STAT
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
struct _stat ss;
|
||||
if (_stat(file_name, &ss) != 0) {
|
||||
#else
|
||||
struct stat ss;
|
||||
if (stat(file_name, &ss) != 0) {
|
||||
#endif
|
||||
/* ignore errors while checking a file */
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
8
C/save.c
8
C/save.c
@@ -873,6 +873,12 @@ restore_codes(void)
|
||||
#endif /* YAPOR */
|
||||
#endif /* TABLING */
|
||||
heap_regs->failcode = opcode(_op_fail);
|
||||
heap_regs->failcode_1 = opcode(_op_fail);
|
||||
heap_regs->failcode_2 = opcode(_op_fail);
|
||||
heap_regs->failcode_3 = opcode(_op_fail);
|
||||
heap_regs->failcode_4 = opcode(_op_fail);
|
||||
heap_regs->failcode_5 = opcode(_op_fail);
|
||||
heap_regs->failcode_6 = opcode(_op_fail);
|
||||
heap_regs->trustfailcode = opcode(_trust_fail);
|
||||
heap_regs->yescode = opcode(_Ystop);
|
||||
#ifdef YAPOR
|
||||
@@ -1089,6 +1095,8 @@ restore_codes(void)
|
||||
heap_regs->functor_change_module = FuncAdjust(heap_regs->functor_change_module);
|
||||
heap_regs->functor_current_module = FuncAdjust(heap_regs->functor_current_module);
|
||||
heap_regs->functor_mod_switch = FuncAdjust(heap_regs->functor_mod_switch);
|
||||
heap_regs->functor_u_minus = FuncAdjust(heap_regs->functor_u_minus);
|
||||
heap_regs->functor_u_plus = FuncAdjust(heap_regs->functor_u_plus);
|
||||
heap_regs->functor_v_bar = FuncAdjust(heap_regs->functor_v_bar);
|
||||
heap_regs->functor_var = FuncAdjust(heap_regs->functor_var);
|
||||
#ifdef EUROTRA
|
||||
|
||||
32
C/scanner.c
32
C/scanner.c
@@ -51,14 +51,6 @@ static char SccsId[] = "@(#)scanner.c 1.2";
|
||||
C <= (SU)) || (C >= 'a' && C <= (SL)))
|
||||
#define my_isupper(C) ( C >= 'A' && C <= 'Z' )
|
||||
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (1.0/0.0)
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
#define NAN (0.0/0.0)
|
||||
#endif
|
||||
|
||||
STATIC_PROTO(void my_ungetch, (void));
|
||||
STATIC_PROTO(int my_getch, (void));
|
||||
STATIC_PROTO(Term float_send, (char *));
|
||||
@@ -224,7 +216,7 @@ float_send(char *s)
|
||||
|
||||
/* we have an overflow at s */
|
||||
static Term
|
||||
read_int_overflow(const char *s, Int base)
|
||||
read_int_overflow(const char *s, Int base, Int val)
|
||||
{
|
||||
#ifdef USE_GMP
|
||||
/* try to scan it as a bignum */
|
||||
@@ -234,7 +226,7 @@ read_int_overflow(const char *s, Int base)
|
||||
return(MkBigIntTerm(new));
|
||||
#else
|
||||
/* try to scan it as a float */
|
||||
return(float_send((char *)s));
|
||||
return(MkIntegerTerm(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -434,7 +426,7 @@ get_num(void)
|
||||
my_ungetch();
|
||||
*--sp = '\0';
|
||||
if (has_overflow)
|
||||
return(read_int_overflow(s,base));
|
||||
return(read_int_overflow(s,base,val));
|
||||
return (MkIntegerTerm(val));
|
||||
}
|
||||
do
|
||||
@@ -465,12 +457,12 @@ get_num(void)
|
||||
*sp = '\0';
|
||||
/* skip base */
|
||||
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
return(read_int_overflow(s+2,16));
|
||||
return(read_int_overflow(s+2,16,val));
|
||||
if (s[1] == '\'')
|
||||
return(read_int_overflow(s+2,base));
|
||||
return(read_int_overflow(s+2,base,val));
|
||||
if (s[2] == '\'')
|
||||
return(read_int_overflow(s+3,base));
|
||||
return(read_int_overflow(s,base));
|
||||
return(read_int_overflow(s+3,base,val));
|
||||
return(read_int_overflow(s,base,val));
|
||||
} else
|
||||
return (MkIntegerTerm(val));
|
||||
}
|
||||
@@ -1172,7 +1164,7 @@ fast_tokenizer(void)
|
||||
*/
|
||||
#endif
|
||||
if (has_overflow)
|
||||
t->TokInfo = read_int_overflow(TokImage,base);
|
||||
t->TokInfo = read_int_overflow(TokImage,base,val);
|
||||
else
|
||||
t->TokInfo = MkIntegerTerm(val);
|
||||
t->TokPos = TokenPos;
|
||||
@@ -1274,13 +1266,13 @@ fast_tokenizer(void)
|
||||
*sp = '\0';
|
||||
/* skip base */
|
||||
if (TokImage[0] == '0' && (TokImage[1] == 'x' || TokImage[1] == 'X'))
|
||||
TokenInfo = read_int_overflow(TokImage+2,16);
|
||||
TokenInfo = read_int_overflow(TokImage+2,16,val);
|
||||
else if (TokImage[1] == '\'')
|
||||
TokenInfo = read_int_overflow(TokImage+2,base);
|
||||
TokenInfo = read_int_overflow(TokImage+2,base,val);
|
||||
else if (TokImage[2] == '\'')
|
||||
TokenInfo = read_int_overflow(TokImage+3,base);
|
||||
TokenInfo = read_int_overflow(TokImage+3,base,val);
|
||||
else
|
||||
TokenInfo = read_int_overflow(TokImage,base);
|
||||
TokenInfo = read_int_overflow(TokImage,base,val);
|
||||
} else
|
||||
TokenInfo = (CELL) MkIntegerTerm(val);
|
||||
}
|
||||
|
||||
11
C/stdpreds.c
11
C/stdpreds.c
@@ -304,14 +304,6 @@ get_char_from_string(int sno)
|
||||
}
|
||||
|
||||
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (1.0/0.0)
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
#define NAN (0.0/0.0)
|
||||
#endif
|
||||
|
||||
static Term
|
||||
get_num(char *t)
|
||||
{
|
||||
@@ -1249,7 +1241,7 @@ p_abort(void)
|
||||
/* make sure we won't go creeping around */
|
||||
CreepFlag = CalculateStackGap();
|
||||
yap_flags[SPY_CREEP_FLAG] = 0;
|
||||
Error(PURE_ABORT,TermNil,"");
|
||||
Abort("");
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
@@ -2085,6 +2077,7 @@ p_has_yap_or(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
p_has_tabling(void)
|
||||
{
|
||||
|
||||
331
C/sysbits.c
331
C/sysbits.c
@@ -652,7 +652,7 @@ void walltime_interval(Int *now,Int *interval)
|
||||
#include <time.h>
|
||||
|
||||
/* since the point YAP was started */
|
||||
static struct timeb StartOfWTimes;
|
||||
static struct _timeb StartOfWTimes;
|
||||
|
||||
/* since last call to walltime */
|
||||
#define LastWtime (*(struct timeb *)LastWtimePtr)
|
||||
@@ -661,7 +661,7 @@ static struct timeb StartOfWTimes;
|
||||
static void
|
||||
InitWTime (void)
|
||||
{
|
||||
ftime(&StartOfWTimes);
|
||||
_ftime(&StartOfWTimes);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -675,9 +675,9 @@ InitLastWtime(void) {
|
||||
Int
|
||||
walltime (void)
|
||||
{
|
||||
struct timeb tp;
|
||||
struct _timeb tp;
|
||||
|
||||
ftime(&tp);
|
||||
_ftime(&tp);
|
||||
if (StartOfWTimes.millitm > tp.millitm)
|
||||
return((tp.time - StartOfWTimes.time - 1) * 1000 +
|
||||
(StartOfWTimes.millitm - tp.millitm));
|
||||
@@ -688,9 +688,9 @@ walltime (void)
|
||||
|
||||
void walltime_interval(Int *now,Int *interval)
|
||||
{
|
||||
struct timeb tp;
|
||||
struct _timeb tp;
|
||||
|
||||
ftime(&tp);
|
||||
_ftime(&tp);
|
||||
*now = (tp.time - StartOfWTimes.time) * 1000 +
|
||||
(tp.millitm - StartOfWTimes.millitm);
|
||||
*interval = (tp.time - LastWtime.time) * 1000 +
|
||||
@@ -1068,151 +1068,157 @@ void (*handler)(int);
|
||||
static char *_line = NULL;
|
||||
#endif
|
||||
|
||||
void
|
||||
static int
|
||||
InteractSIGINT(char ch) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
/* abort computation */
|
||||
/* we can't do a direct abort, so ask the system to do
|
||||
it for us */
|
||||
p_creep();
|
||||
PutValue(AtomThrow, MkAtomTerm(AtomTrue));
|
||||
return(-1);
|
||||
case 'c':
|
||||
/* continue */
|
||||
return(1);
|
||||
case 'e':
|
||||
/* exit */
|
||||
exit_yap(0, "");
|
||||
return(-1);
|
||||
case 't':
|
||||
/* start tracing */
|
||||
PutValue (LookupAtom ("debug"), MkIntTerm (1));
|
||||
PutValue (LookupAtom ("spy_sl"), MkIntTerm (0));
|
||||
PutValue (LookupAtom ("spy_creep"), MkIntTerm (1));
|
||||
p_creep ();
|
||||
return(1);
|
||||
#ifdef LOW_LEVEL_TRACER
|
||||
case 'T':
|
||||
toggle_low_level_trace();
|
||||
return(1);
|
||||
#endif
|
||||
case 'd':
|
||||
/* enter debug mode */
|
||||
PutValue (LookupAtom ("debug"), MkIntTerm (1));
|
||||
return(1);
|
||||
case 's':
|
||||
/* show some statistics */
|
||||
#if SHORT_INTS==0
|
||||
YP_fprintf(YP_stderr, "aux. stack: %d ", Unsigned (AuxTop) -
|
||||
Unsigned (LCL0 + 1));
|
||||
if (Unsigned (AuxSp) <= Unsigned (LCL0))
|
||||
YP_fprintf(YP_stderr, "( 0 bytes used)\n");
|
||||
else
|
||||
YP_fprintf(YP_stderr, "( %d bytes used)\n",
|
||||
Unsigned (AuxSp) - Unsigned (LCL0 + 1));
|
||||
YP_fprintf(YP_stderr, "heap space: %d ", Unsigned (AuxTop) -
|
||||
Unsigned (HeapBase));
|
||||
YP_fprintf(YP_stderr, "( %d bytes used for heap",
|
||||
Unsigned (HeapUsed));
|
||||
YP_fprintf(YP_stderr, " and %d bytes used for trail)\n",
|
||||
Unsigned (TR) - Unsigned (TrailBase));
|
||||
YP_fprintf(YP_stderr, "stack space: %d ", Unsigned (LCL0) -
|
||||
Unsigned (H0));
|
||||
YP_fprintf(YP_stderr, "( %d bytes used for local",
|
||||
Unsigned (LCL0) - Unsigned (ASP));
|
||||
YP_fprintf(YP_stderr, " and %d bytes used for global)\n",
|
||||
Unsigned (H) - Unsigned (H0));
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "aux. stack: %ld ", Unsigned (AuxTop) -
|
||||
Unsigned (LCL0 + 1));
|
||||
if (Unsigned (AuxSp) <= Unsigned (LCL0))
|
||||
YP_fprintf(YP_stderr, "( 0 bytes used)\n");
|
||||
else
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used)\n",
|
||||
Unsigned (AuxSp) - Unsigned (LCL0 + 1));
|
||||
YP_fprintf(YP_stderr, "heap space: %ld ", Unsigned (AuxTop) -
|
||||
Unsigned (HeapBase));
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used for heap",
|
||||
Unsigned (HeapUsed));
|
||||
YP_fprintf(YP_stderr, " and %ld bytes used for trail)\n",
|
||||
Unsigned (TR) - Unsigned (TrailBase));
|
||||
YP_fprintf(YP_stderr, "stack space: %ld ", Unsigned (LCL0) -
|
||||
Unsigned (H0));
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used for local",
|
||||
Unsigned (LCL0) - Unsigned (ASP));
|
||||
YP_fprintf(YP_stderr, " and %ld bytes used for global)\n",
|
||||
Unsigned (H) - Unsigned (H0));
|
||||
#endif
|
||||
#if SHORT_INTS
|
||||
YP_fprintf(YP_stderr, "Runtime: %lds.\n", runtime ());
|
||||
YP_fprintf(YP_stderr, "Cputime: %lds.\n", cputime ());
|
||||
YP_fprintf(YP_stderr, "Walltime: %lds.\n", walltime ());
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "Runtime: %ds.\n", runtime ());
|
||||
YP_fprintf(YP_stderr, "Cputime: %ds.\n", cputime ());
|
||||
YP_fprintf(YP_stderr, "Walltime: %ds.\n", walltime ());
|
||||
#endif
|
||||
return(1);
|
||||
case EOF:
|
||||
return(0);
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
/* show an helpful message */
|
||||
YP_fprintf(YP_stderr, "Please press one of:\n");
|
||||
YP_fprintf(YP_stderr, " a for abort\n c for continue\n d for debug\n");
|
||||
YP_fprintf(YP_stderr, " e for exit\n t for trace\n s for statistics\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
This function talks to the user about a signal. We assume we are in
|
||||
the context of the main Prolog thread (trivial in Unix, but hard in WIN32)
|
||||
*/
|
||||
int
|
||||
ProcessSIGINT(void)
|
||||
{
|
||||
int ch, out;
|
||||
|
||||
while (TRUE) {
|
||||
int ch;
|
||||
#ifdef MPW
|
||||
int ch0;
|
||||
#if HAVE_ISATTY
|
||||
if (!isatty(0)) {
|
||||
InteractSIGINT('e');
|
||||
}
|
||||
#if !HAVE_LIBREADLINE
|
||||
if (in_getc) {
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
do {
|
||||
#if HAVE_LIBREADLINE
|
||||
if (_line != (char *) NULL && _line != (char *) EOF)
|
||||
free (_line);
|
||||
_line = readline ("Action (h for help): ");
|
||||
if (_line == (char *)NULL || _line == (char *)EOF)
|
||||
if (_line == (char *)NULL || _line == (char *)EOF) {
|
||||
ch = EOF;
|
||||
continue;
|
||||
}
|
||||
ch = _line[0];
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "\nAction (h for help): ");
|
||||
ch = YP_getchar ( );
|
||||
while ((YP_getchar()) != '\n');
|
||||
/* ask for a new line */
|
||||
fprintf(stderr, "Action (h for help): ");
|
||||
ch = getc(stdin);
|
||||
/* first process up to end of line */
|
||||
while ((fgetc(stdin)) != '\n');
|
||||
#endif
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
/* abort computation, but take care in case we are within readline
|
||||
code */
|
||||
if (!(PrologMode & CritMode))
|
||||
{
|
||||
#if HAVE_SIGPROCMASK
|
||||
sigset_t sig_set;
|
||||
sigemptyset(&sig_set);
|
||||
sigaddset(&sig_set, SIGINT);
|
||||
sigprocmask(SIG_UNBLOCK, &sig_set, NULL);
|
||||
#elif HAVE_SIGGETMASK
|
||||
sigsetmask (siggetmask () ^ (1 << (SIGINT - 1)));
|
||||
#endif
|
||||
#ifdef VAX
|
||||
VaxFixFrame (CritMode);
|
||||
#endif
|
||||
/* we cannot abort until we finish readline :-( */
|
||||
if (!(PrologMode & CritMode)) {
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
/* we can't do a direct abort, so ask the system to do it for us */
|
||||
p_creep();
|
||||
PutValue(AtomThrow, MkAtomTerm(AtomTrue));
|
||||
#else
|
||||
Abort ((char *) NULL);
|
||||
#endif
|
||||
#if HAVE_LIBREADLINE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PrologMode |= AbortMode;
|
||||
return;
|
||||
case 'c':
|
||||
/* continue */
|
||||
return;
|
||||
case 'e':
|
||||
/* exit */
|
||||
exit_yap(0, "");
|
||||
case 't':
|
||||
/* start tracing */
|
||||
PutValue (LookupAtom ("debug"), MkIntTerm (1));
|
||||
PutValue (LookupAtom ("spy_sl"), MkIntTerm (0));
|
||||
PutValue (LookupAtom ("spy_creep"), MkIntTerm (1));
|
||||
p_creep ();
|
||||
return;
|
||||
#ifdef LOW_LEVEL_TRACER
|
||||
case 'T':
|
||||
toggle_low_level_trace();
|
||||
return;
|
||||
#endif
|
||||
case 'd':
|
||||
/* enter debug mode */
|
||||
PutValue (LookupAtom ("debug"), MkIntTerm (1));
|
||||
return;
|
||||
case 's':
|
||||
/* show some statistics */
|
||||
#if SHORT_INTS==0
|
||||
YP_fprintf(YP_stderr, "aux. stack: %d ", Unsigned (AuxTop) -
|
||||
Unsigned (LCL0 + 1));
|
||||
if (Unsigned (AuxSp) <= Unsigned (LCL0))
|
||||
YP_fprintf(YP_stderr, "( 0 bytes used)\n");
|
||||
else
|
||||
YP_fprintf(YP_stderr, "( %d bytes used)\n",
|
||||
Unsigned (AuxSp) - Unsigned (LCL0 + 1));
|
||||
YP_fprintf(YP_stderr, "heap space: %d ", Unsigned (AuxTop) -
|
||||
Unsigned (HeapBase));
|
||||
YP_fprintf(YP_stderr, "( %d bytes used for heap",
|
||||
Unsigned (HeapUsed));
|
||||
YP_fprintf(YP_stderr, " and %d bytes used for trail)\n",
|
||||
Unsigned (TR) - Unsigned (TrailBase));
|
||||
YP_fprintf(YP_stderr, "stack space: %d ", Unsigned (LCL0) -
|
||||
Unsigned (H0));
|
||||
YP_fprintf(YP_stderr, "( %d bytes used for local",
|
||||
Unsigned (LCL0) - Unsigned (ASP));
|
||||
YP_fprintf(YP_stderr, " and %d bytes used for global)\n",
|
||||
Unsigned (H) - Unsigned (H0));
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "aux. stack: %ld ", Unsigned (AuxTop) -
|
||||
Unsigned (LCL0 + 1));
|
||||
if (Unsigned (AuxSp) <= Unsigned (LCL0))
|
||||
YP_fprintf(YP_stderr, "( 0 bytes used)\n");
|
||||
else
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used)\n",
|
||||
Unsigned (AuxSp) - Unsigned (LCL0 + 1));
|
||||
YP_fprintf(YP_stderr, "heap space: %ld ", Unsigned (AuxTop) -
|
||||
Unsigned (HeapBase));
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used for heap",
|
||||
Unsigned (HeapUsed));
|
||||
YP_fprintf(YP_stderr, " and %ld bytes used for trail)\n",
|
||||
Unsigned (TR) - Unsigned (TrailBase));
|
||||
YP_fprintf(YP_stderr, "stack space: %ld ", Unsigned (LCL0) -
|
||||
Unsigned (H0));
|
||||
YP_fprintf(YP_stderr, "( %ld bytes used for local",
|
||||
Unsigned (LCL0) - Unsigned (ASP));
|
||||
YP_fprintf(YP_stderr, " and %ld bytes used for global)\n",
|
||||
Unsigned (H) - Unsigned (H0));
|
||||
#endif
|
||||
#if SHORT_INTS
|
||||
YP_fprintf(YP_stderr, "Runtime: %lds.\n", runtime ());
|
||||
YP_fprintf(YP_stderr, "Cputime: %lds.\n", cputime ());
|
||||
YP_fprintf(YP_stderr, "Walltime: %lds.\n", walltime ());
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "Runtime: %ds.\n", runtime ());
|
||||
YP_fprintf(YP_stderr, "Cputime: %ds.\n", cputime ());
|
||||
YP_fprintf(YP_stderr, "Walltime: %ds.\n", walltime ());
|
||||
#endif
|
||||
break;
|
||||
case EOF:
|
||||
/* ignore end of file */
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
/* show an helpful message */
|
||||
YP_fprintf(YP_stderr, "Please press one of:\n");
|
||||
YP_fprintf(YP_stderr, " a for abort\n c for continue\n d for debug\n");
|
||||
YP_fprintf(YP_stderr, " e for exit\n t for trace\n s for statistics\n");
|
||||
break;
|
||||
}
|
||||
} while (!(out = InteractSIGINT(ch)));
|
||||
if (out < 0)
|
||||
sigint_pending = out;
|
||||
#if HAVE_LIBREADLINE
|
||||
if (in_getc) {
|
||||
longjmp(readline_jmpbuf, (out < 0 ? -1 : 1));
|
||||
}
|
||||
#endif
|
||||
return(out);
|
||||
}
|
||||
|
||||
/* This function is called from the signal handler to process signals.
|
||||
We assume we are within the context of the signal handler, whatever
|
||||
that might be
|
||||
*/
|
||||
static RETSIGTYPE
|
||||
#if defined(__svr4__)
|
||||
HandleSIGINT (int sig, siginfo_t *x, ucontext_t *y)
|
||||
@@ -1220,21 +1226,14 @@ HandleSIGINT (int sig, siginfo_t *x, ucontext_t *y)
|
||||
HandleSIGINT (int sig)
|
||||
#endif
|
||||
{
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
extern int in_getc;
|
||||
|
||||
if (in_getc) {
|
||||
/* YP_ungetc(YP_stdin,'\n');
|
||||
PrologMode |= InterruptMode; */
|
||||
in_getc = FALSE;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
my_signal(SIGINT, HandleSIGINT);
|
||||
#if (_MSC_VER || defined(__MINGW32__))
|
||||
printf("hello\n");
|
||||
return;
|
||||
#endif
|
||||
#ifdef HAVE_SETBUF
|
||||
/* make sure we are not waiting for the end of line */
|
||||
YP_setbuf (stdin, NULL);
|
||||
#endif
|
||||
my_signal(SIGINT, HandleSIGINT);
|
||||
#endif
|
||||
if (snoozing)
|
||||
{
|
||||
@@ -1266,6 +1265,7 @@ HandleALRM(int s)
|
||||
* 6 possibilities : abort, continue, trace, debug, help, exit
|
||||
*/
|
||||
|
||||
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
||||
static RETSIGTYPE
|
||||
#if defined(__svr4__)
|
||||
ReceiveSignal (int s, siginfo_t *x, ucontext_t *y)
|
||||
@@ -1292,20 +1292,21 @@ ReceiveSignal (int s)
|
||||
exit (FALSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
static BOOL WINAPI MSCHandleSignal(DWORD dwCtrlType) {
|
||||
#if (_MSC_VER || defined(__MINGW32__))
|
||||
static BOOL WINAPI
|
||||
MSCHandleSignal(DWORD dwCtrlType) {
|
||||
switch(dwCtrlType) {
|
||||
case CTRL_C_EVENT:
|
||||
HandleSIGINT(SIGINT);
|
||||
break;
|
||||
case CTRL_BREAK_EVENT:
|
||||
HandleSIGINT(SIGINT);
|
||||
break;
|
||||
p_creep();
|
||||
PutValue(AtomThrow, MkAtomTerm(AtomTrue));
|
||||
PrologMode |= AbortMode;
|
||||
return(TRUE);
|
||||
default:
|
||||
exit_yap(1, "[ SYSTEM ERROR: Received Termination Event ]\n");
|
||||
return(FALSE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1313,32 +1314,28 @@ static BOOL WINAPI MSCHandleSignal(DWORD dwCtrlType) {
|
||||
static void
|
||||
InitSignals (void)
|
||||
{
|
||||
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
||||
my_signal (SIGQUIT, ReceiveSignal);
|
||||
my_signal (SIGKILL, ReceiveSignal);
|
||||
my_signal(SIGALRM, HandleALRM);
|
||||
#endif
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
signal (SIGINT, SIG_IGN);
|
||||
SetConsoleCtrlHandler(MSCHandleSignal,TRUE);
|
||||
#else
|
||||
my_signal (SIGINT, HandleSIGINT);
|
||||
#endif
|
||||
#ifndef MPW
|
||||
my_signal (SIGFPE, HandleMatherr);
|
||||
#if !defined(LIGHT) && !defined(_WIN32)
|
||||
my_signal (SIGQUIT, ReceiveSignal);
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(LIGHT) && !defined(_WIN32)
|
||||
my_signal (SIGKILL, ReceiveSignal);
|
||||
#endif
|
||||
#if HAVE_SIGSEGV
|
||||
my_signal_info (SIGSEGV, HandleSIGSEGV);
|
||||
#endif
|
||||
#if !defined(LIGHT) && !defined(_WIN32)
|
||||
my_signal(SIGALRM, HandleALRM);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef ACOW
|
||||
signal(SIGCHLD, SIG_IGN); /* avoid ghosts */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_SIGNAL */
|
||||
|
||||
|
||||
|
||||
@@ -210,7 +210,6 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
send_tracer_message("RETRY: ", s, arity, mname, args);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
20
C/ypsocks.c
20
C/ypsocks.c
@@ -78,7 +78,7 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#endif /* HAVE_WINSOCK_H */
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
@@ -177,7 +177,7 @@
|
||||
#define MAXHOSTNAMELEN 256
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
#define socket_errno WSAGetLastError()
|
||||
#define invalid_socket_fd(fd) (fd) == INVALID_SOCKET
|
||||
#else
|
||||
@@ -468,7 +468,7 @@ CloseSocket(int fd, socket_info status, socket_domain domain)
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
if (closesocket(fd) != 0) {
|
||||
#else
|
||||
if (close(fd) < 0) {
|
||||
@@ -905,7 +905,7 @@ p_socket_select(void)
|
||||
fd_set readfds, writefds, exceptfds;
|
||||
struct timeval timeout, *ptime;
|
||||
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
u_int fdmax=0;
|
||||
#else
|
||||
int fdmax=0;
|
||||
@@ -943,7 +943,7 @@ p_socket_select(void)
|
||||
/* fetch the input streams */
|
||||
ti = t1;
|
||||
while (ti != TermNil) {
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
u_int fd;
|
||||
#else
|
||||
int fd;
|
||||
@@ -1038,8 +1038,8 @@ p_current_hostname(void) {
|
||||
int faq = (strrchr(sin,'.') != NULL);
|
||||
|
||||
if (faq)
|
||||
#if _MSC_VER
|
||||
return(stricmp(name,sin) == 0);
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
return(_stricmp(name,sin) == 0);
|
||||
#else
|
||||
return(strcasecmp(name,sin) == 0);
|
||||
#endif
|
||||
@@ -1052,8 +1052,8 @@ p_current_hostname(void) {
|
||||
}
|
||||
if (name[isize] != '.') return(FALSE);
|
||||
name[isize] = '\0';
|
||||
#if _MSC_VER
|
||||
return(stricmp(name,sin) == 0);
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
return(_stricmp(name,sin) == 0);
|
||||
#else
|
||||
return(strcasecmp(name,sin) == 0);
|
||||
#endif
|
||||
@@ -1129,7 +1129,7 @@ InitSockets(void)
|
||||
InitCPred("$socket_select", 4, p_socket_select, SafePredFlag|SyncPredFlag);
|
||||
InitCPred("current_hostname", 1, p_current_hostname, SafePredFlag);
|
||||
InitCPred("hostname_address", 2, p_hostname_address, SafePredFlag);
|
||||
#if _MSC_VER
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
{
|
||||
WSADATA info;
|
||||
if (WSAStartup(MAKEWORD(2,1), &info) != 0)
|
||||
|
||||
Reference in New Issue
Block a user