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 */
{
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);
}
#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);
+}