Kaydet (Commit) 7433b12a authored tarafından Guido van Rossum's avatar Guido van Rossum

Added new global flag variable Py_InteractiveFlag and new function

Py_FdIsInteractive().  The flag is supposed to be set by the -i
command line option.  The function is supposed to be called instead of
isatty().  This is used for Lee Busby's wish #1, to have an option
that pretends stdin is interactive even when it really isn't.
üst 115eb64f
...@@ -79,6 +79,7 @@ static void initsigs PROTO((void)); ...@@ -79,6 +79,7 @@ static void initsigs PROTO((void));
int debugging; /* Needed by parser.c */ int debugging; /* Needed by parser.c */
int verbose; /* Needed by import.c */ int verbose; /* Needed by import.c */
int suppress_print; /* Needed by ceval.c */ int suppress_print; /* Needed by ceval.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
/* Initialize all */ /* Initialize all */
...@@ -133,7 +134,7 @@ run(fp, filename) ...@@ -133,7 +134,7 @@ run(fp, filename)
{ {
if (filename == NULL) if (filename == NULL)
filename = "???"; filename = "???";
if (isatty((int)fileno(fp))) if (Py_FdIsInteractive(fp, filename))
return run_tty_loop(fp, filename); return run_tty_loop(fp, filename);
else else
return run_script(fp, filename); return run_script(fp, filename);
...@@ -753,3 +754,23 @@ isatty(fd) ...@@ -753,3 +754,23 @@ isatty(fd)
} }
#endif #endif
/*
* The file descriptor fd is considered ``interactive'' if either
* a) isatty(fd) is TRUE, or
* b) the -i flag was given, and the filename associated with
* the descriptor is NULL or "<stdin>" or "???".
*/
int
Py_FdIsInteractive(fp, filename)
FILE *fp;
char *filename;
{
if (isatty((int)fileno(fp)))
return 1;
if (!Py_InteractiveFlag)
return 0;
return (filename == NULL) ||
(strcmp(filename, "<stdin>") == 0) ||
(strcmp(filename, "???") == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment