summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-06-24 11:10:19 (GMT)
committerGuido van Rossum <guido@python.org>1993-06-24 11:10:19 (GMT)
commit9e90a672b44e2acfd5c6dabfb9435bb4bb46c845 (patch)
treef3904d6dfed9d57f98f9e90c93241cb23cb802ad /Python
parent5ef74b8f8edbebe22d0b86c85f08b0c618d808f7 (diff)
downloadcpython-9e90a672b44e2acfd5c6dabfb9435bb4bb46c845.zip
cpython-9e90a672b44e2acfd5c6dabfb9435bb4bb46c845.tar.gz
cpython-9e90a672b44e2acfd5c6dabfb9435bb4bb46c845.tar.bz2
* pythonmain.c: -k option, usage message, more environment flags.
(the latter also in frozenmain.c) * ceval.c: global 'killprint' flag raises exception when printing an expression statement's value (useful for finding stray output) * timemodule.c: add asctime() and ctime(). Change julian date to 1-based origin (as intended and documented). * Removed unused DO_TIMES stuff from timemodule.c. Added 'epoch' and 'day0' globals (year where time.time() == 0 and day of the week the epoch started).
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c8
-rw-r--r--Python/frozenmain.c21
-rw-r--r--Python/pythonmain.c36
3 files changed, 57 insertions, 8 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 1c12d9c..8ed4663 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -49,6 +49,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define CHECKEXC 1 /* Double-check exception checking */
#endif
+/* Global option, may be set by main() */
+int killprint;
+
/* Forward declarations */
@@ -639,6 +642,11 @@ eval_code(co, globals, locals, owner, arg)
softspace(x, 1);
err = writeobject(v, x, 0);
flushline();
+ if (killprint) {
+ err_setstr(RuntimeError,
+ "printing expression statement");
+ x = 0;
+ }
}
DECREF(v);
break;
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index 90d1623..8bc136a 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -30,28 +30,43 @@ extern char *getenv();
extern int debugging;
extern int verbose;
+extern int killprint;
main(argc, argv)
int argc;
char **argv;
{
char *p;
+ int n, inspect, sts;
int n;
+
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
debugging = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
verbose = 1;
- initargs(&argc, &argv); /* Defined in config*.c */
+ if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
+ inspect = 1;
+ if ((p = getenv("PYTHONKILLPRINT")) && *p != '\0')
+ killprint = 1;
+
+ initargs(&argc, &argv);
initall();
setpythonargv(argc, argv);
+
n = init_frozen("__main__");
if (n == 0)
fatal("__main__ not frozen");
if (n < 0) {
print_error();
- goaway(1);
+ sts = 1;
}
else
- goaway(0);
+ sts = 0;
+
+ if (inspect && isatty((int)fileno(stdin)) &&
+ (filename != NULL || command != NULL))
+ sts = run(stdin, "<stdin>") != 0;
+
+ goaway(sts);
/*NOTREACHED*/
}
diff --git a/Python/pythonmain.c b/Python/pythonmain.c
index 760e5da..ac1d86a 100644
--- a/Python/pythonmain.c
+++ b/Python/pythonmain.c
@@ -26,8 +26,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
-extern int debugging; /* Needed by parser.c */
-extern int verbose; /* Needed by import.c */
+extern int debugging; /* Defined in parser.c */
+extern int verbose; /* Defined in import.c */
+extern int killprint; /* Defined in ceval.c */
/* Interface to getopt(): */
extern int optind;
@@ -52,10 +53,14 @@ main(argc, argv)
debugging = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
verbose = 1;
+ if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
+ inspect = 1;
+ if ((p = getenv("PYTHONKILLPRINT")) && *p != '\0')
+ killprint = 1;
- initargs(&argc, &argv); /* Defined in config*.c */
+ initargs(&argc, &argv);
- while ((c = getopt(argc, argv, "c:div")) != EOF) {
+ while ((c = getopt(argc, argv, "c:dikv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
@@ -77,6 +82,10 @@ main(argc, argv)
inspect++;
break;
+ case 'k':
+ killprint++;
+ break;
+
case 'v':
verbose++;
break;
@@ -85,8 +94,25 @@ main(argc, argv)
default:
fprintf(stderr,
- "usage: %s [-c cmd | file | -] [arg] ...\n",
+"usage: %s [-d] [-i] [-k] [-v] [-c cmd | file | -] [arg] ...\n",
argv[0]);
+ fprintf(stderr, "\
+\n\
+Options and arguments (and corresponding environment variables):\n\
+-d : debug output from parser (also PYTHONDEBUG=x)\n\
+-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
+-k : kill printing expression statement (also PYTHONKILLPRINT=x)\n\
+-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
+-c cmd : program passed in as string (terminates option list)\n\
+file : program read from script file\n\
+- : program read from stdin (default; interactive mode if a tty)\n\
+arg ...: arguments passed to program in sys.argv[1:]\n\
+\n\
+Other environment variables:\n\
+PYTHONSTARTUP: file executed on interactive startup (no default)\n\
+PYTHONPATH : colon-separated list of directories prefixed to the\n\
+ default module search path. The result is sys.path.\n\
+");
exit(2);
/*NOTREACHED*/