don't core dump if Yap tries to reconsult redirect standard input.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@490 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-05-24 04:45:05 +00:00
parent 1ae6ae839d
commit ba40e074ea
3 changed files with 81 additions and 38 deletions

View File

@ -456,26 +456,37 @@ InitStdStream (int sno, SMALLUNSGN flags, YP_File file, Atom name)
s->stream_getc = MemGetc;
} else {
/* check if our console is promptable: may be tty or pipe */
if (s->status & (Promptable_Stream_f)) {
/* the putc routine only has to check it is putting out a newline */
s->stream_putc = ConsolePutc;
/* if a tty have a special routine to call readline */
if (s->status & (Promptable_Stream_f)) {
/* the putc routine only has to check it is putting out a newline */
s->stream_putc = ConsolePutc;
/* if a tty have a special routine to call readline */
#if HAVE_LIBREADLINE
if (s->status & Tty_Stream_f) {
if (Stream[0].status & Tty_Stream_f &&
s->u.file.name == Stream[0].u.file.name)
s->stream_putc = ReadlinePutc;
s->stream_getc = ReadlineGetc;
} else
if (s->status & Tty_Stream_f) {
if (Stream[0].status & Tty_Stream_f &&
s->u.file.name == Stream[0].u.file.name)
s->stream_putc = ReadlinePutc;
s->stream_getc = ReadlineGetc;
} else
#endif
{
/* else just PlGet plus checking for prompt */
s->stream_getc = ConsoleGetc;
}
{
/* else just PlGet plus checking for prompt */
s->stream_getc = ConsoleGetc;
}
} else {
/* we are reading from a file, no need to check for prompts */
s->stream_putc = FilePutc;
s->stream_getc = PlGetc;
}
switch(sno) {
case 0:
s->u.file.name=LookupAtom("user_input");
break;
case 1:
s->u.file.name=LookupAtom("user_output");
break;
default:
s->u.file.name=LookupAtom("user_error");
break;
}
s->u.file.user_name = MkAtomTerm (s->u.file.name);
}
@ -4846,6 +4857,60 @@ p_stream(void)
return(FALSE);
}
static Int
p_same_file(void) {
char *f1 = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
char *f2 = RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE;
if (strcmp(f1,f2) == 0)
return(TRUE);
#if HAVE_LSTAT
{
struct stat buf1, buf2;
if (strcmp(f1,"user_input") == 0) {
if (fstat(fileno(Stream[0].u.file.file), &buf1) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (strcmp(f1,"user_output") == 0) {
if (fstat(fileno(Stream[1].u.file.file), &buf1) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (strcmp(f1,"user_error") == 0) {
if (fstat(fileno(Stream[2].u.file.file), &buf1) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (stat(f1, &buf1) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
if (strcmp(f2,"user_input") == 0) {
if (fstat(fileno(Stream[0].u.file.file), &buf2) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (strcmp(f2,"user_output") == 0) {
if (fstat(fileno(Stream[1].u.file.file), &buf2) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (strcmp(f2,"user_error") == 0) {
if (fstat(fileno(Stream[2].u.file.file), &buf2) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
} else if (stat(f2, &buf2) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
return(buf1.st_ino == buf2.st_ino &&
buf1.st_dev == buf2.st_dev);
}
#endif
return(FALSE);
}
void
InitBackIO (void)
{
@ -4921,6 +4986,7 @@ InitIOPreds(void)
#if HAVE_SELECT
InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
#endif
InitCPred ("$same_file", 2, p_same_file, SafePredFlag|SyncPredFlag);
#if USE_SOCKET
InitSockets ();

View File

@ -2052,27 +2052,6 @@ p_host_type(void) {
return(unify(out,ARG1));
}
static Int
p_same_file(void) {
char *f1 = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
char *f2 = RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE;
#if HAVE_LSTAT
struct stat buf1, buf2;
if (stat(f1, &buf1) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
if (stat(f2, &buf2) == -1) {
/* file does not exist, but was opened? Return -1 */
return(FALSE);
}
return(buf1.st_ino == buf2.st_ino &&
buf1.st_dev == buf2.st_dev);
#else
return(strcmp(f1,f2) == 0);
#endif
}
/*
* This is responsable for the initialization of all machine dependant
* predicates
@ -2122,7 +2101,6 @@ InitSysPreds(void)
InitCPred ("$file_age", 2, p_file_age, SafePredFlag|SyncPredFlag);
InitCPred ("$set_fpu_exceptions", 0, p_set_fpu_exceptions, SafePredFlag|SyncPredFlag);
InitCPred ("$host_type", 1, p_host_type, SafePredFlag|SyncPredFlag);
InitCPred ("$same_file", 2, p_same_file, SafePredFlag|SyncPredFlag);
}

View File

@ -113,10 +113,9 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
vsc_count++;
/* if (vsc_count < 618000) return; */
/* if (vsc_count == 656) {
if (vsc_count == 131) {
printf("Here I go\n");
}
*/
/* if (vsc_count > 500000) exit(0); */
/* if (gc_calls < 1) return;*/
#if defined(__GNUC__)