summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-02-14 19:45:36 (GMT)
committerGuido van Rossum <guido@python.org>1997-02-14 19:45:36 (GMT)
commit7433b12a5ca8c1c6a6685160edb09efbf61c4544 (patch)
treea9640e590c02eea085dcaaeb155b30242bfa2754 /Python
parent115eb64ff69fdeb48a7cb7e62981284b2de49ef5 (diff)
downloadcpython-7433b12a5ca8c1c6a6685160edb09efbf61c4544.zip
cpython-7433b12a5ca8c1c6a6685160edb09efbf61c4544.tar.gz
cpython-7433b12a5ca8c1c6a6685160edb09efbf61c4544.tar.bz2
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 7cdcf46..6fbe4ec 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -79,6 +79,7 @@ static void initsigs PROTO((void));
int debugging; /* Needed by parser.c */
int verbose; /* Needed by import.c */
int suppress_print; /* Needed by ceval.c */
+int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
/* Initialize all */
@@ -133,7 +134,7 @@ run(fp, filename)
{
if (filename == NULL)
filename = "???";
- if (isatty((int)fileno(fp)))
+ if (Py_FdIsInteractive(fp, filename))
return run_tty_loop(fp, filename);
else
return run_script(fp, filename);
@@ -753,3 +754,23 @@ isatty(fd)
}
#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);
+}