comparison Python/pythonrun.c @ 5108:a9a6d416b945 legacy-trunk

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.
author Guido van Rossum <guido@python.org>
date Fri, 14 Feb 1997 19:45:36 +0000
parents 4fa19659591e
children f5d707ce4223
comparison
equal deleted inserted replaced
5107:f9b46b503751 5108:a9a6d416b945
77 static void initsigs PROTO((void)); 77 static void initsigs PROTO((void));
78 78
79 int debugging; /* Needed by parser.c */ 79 int debugging; /* Needed by parser.c */
80 int verbose; /* Needed by import.c */ 80 int verbose; /* Needed by import.c */
81 int suppress_print; /* Needed by ceval.c */ 81 int suppress_print; /* Needed by ceval.c */
82 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
82 83
83 /* Initialize all */ 84 /* Initialize all */
84 85
85 void 86 void
86 initall() 87 initall()
131 FILE *fp; 132 FILE *fp;
132 char *filename; 133 char *filename;
133 { 134 {
134 if (filename == NULL) 135 if (filename == NULL)
135 filename = "???"; 136 filename = "???";
136 if (isatty((int)fileno(fp))) 137 if (Py_FdIsInteractive(fp, filename))
137 return run_tty_loop(fp, filename); 138 return run_tty_loop(fp, filename);
138 else 139 else
139 return run_script(fp, filename); 140 return run_script(fp, filename);
140 } 141 }
141 142
751 { 752 {
752 return fd == fileno(stdin); 753 return fd == fileno(stdin);
753 } 754 }
754 755
755 #endif 756 #endif
757
758 /*
759 * The file descriptor fd is considered ``interactive'' if either
760 * a) isatty(fd) is TRUE, or
761 * b) the -i flag was given, and the filename associated with
762 * the descriptor is NULL or "<stdin>" or "???".
763 */
764 int
765 Py_FdIsInteractive(fp, filename)
766 FILE *fp;
767 char *filename;
768 {
769 if (isatty((int)fileno(fp)))
770 return 1;
771 if (!Py_InteractiveFlag)
772 return 0;
773 return (filename == NULL) ||
774 (strcmp(filename, "<stdin>") == 0) ||
775 (strcmp(filename, "???") == 0);
776 }