Mercurial > cpython-lru_cache-weakref
annotate Python/pythonmain.c @ 2810:fc2190ec1bea legacy-trunk
added sys.platform
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 07 Jul 1995 22:45:02 +0000 |
| parents | b8937e74fdf5 |
| children | 85140b354890 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1910
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1910
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Python interpreter main program */ |
| 26 | |
|
206
3cc54972ab52
Move allobjects.h to front (needed by THINK C precompiled headers)
Guido van Rossum <guido@python.org>
parents:
179
diff
changeset
|
27 #include "allobjects.h" |
|
156
43cabac5023d
Include patchlevel.h (to ensure it is distributed with the rest).
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
28 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
29 extern int debugging; /* Needed in parser.c, declared in pythonrun.c */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
30 extern int verbose; /* Needed in import.c, declared in pythonrun.c */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
31 extern int suppress_print; /* Needed in ceval.c, declared in pythonrun.c */ |
| 6 | 32 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
33 /* Interface to getopt(): */ |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
34 extern int optind; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
35 extern char *optarg; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1318
diff
changeset
|
36 extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */ |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
37 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
38 extern char *getenv(); |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
39 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
40 extern char *getversion(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
41 extern char *getcopyright(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
42 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
43 int |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
44 realmain(argc, argv) |
| 6 | 45 int argc; |
| 46 char **argv; | |
| 47 { | |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
48 int c; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
49 int sts; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
50 char *command = NULL; |
| 6 | 51 char *filename = NULL; |
| 52 FILE *fp = stdin; | |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
53 char *p; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
54 int inspect = 0; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
55 int unbuffered = 0; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
56 |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
57 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
58 debugging = 1; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
59 if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0') |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
60 suppress_print = 1; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
61 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
62 verbose = 1; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
63 if ((p = getenv("PYTHONINSPECT")) && *p != '\0') |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
64 inspect = 1; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
65 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
66 unbuffered = 1; |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
67 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
68 while ((c = getopt(argc, argv, "c:disuv")) != EOF) { |
|
560
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
69 if (c == 'c') { |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
70 /* -c is the last option; following arguments |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
71 that look like options are left for the |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
72 the command to interpret. */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
73 command = malloc(strlen(optarg) + 2); |
|
1910
35947f60528e
* Python/pythonmain.c: fatal error if can't alloc mem for -c
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
74 if (command == NULL) |
|
35947f60528e
* Python/pythonmain.c: fatal error if can't alloc mem for -c
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
75 fatal("not enough memory to copy -c argument"); |
|
560
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
76 strcpy(command, optarg); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
77 strcat(command, "\n"); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
78 break; |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
79 } |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
80 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
81 switch (c) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
82 |
|
618
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
83 case 'd': |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
84 debugging++; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
85 break; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
86 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
87 case 'i': |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
88 inspect++; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
89 break; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
90 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
91 case 's': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
92 suppress_print++; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
93 break; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
94 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
95 case 'u': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
96 unbuffered++; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
97 break; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
98 |
|
728
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
99 case 'v': |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
100 verbose++; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
101 break; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
102 |
|
560
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
103 /* This space reserved for other options */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
104 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
105 default: |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
106 fprintf(stderr, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
107 "usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n", |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
108 argv[0]); |
| 2793 | 109 #if !(defined(__CFM68K__) && defined(__MWERKS__)) |
| 110 /* Mwerks cfm68k linker doesn't like these... */ | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
111 fprintf(stderr, "\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
112 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
113 Options and arguments (and corresponding environment variables):\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
114 -d : debug output from parser (also PYTHONDEBUG=x)\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
115 -i : inspect interactively after running script (also PYTHONINSPECT=x)\n\ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
116 -s : suppress the printing of top level expressions (also PYTHONSUPPRESS=x)\n\ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
117 -u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\ |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
118 -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
119 -c cmd : program passed in as string (terminates option list)\n\ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
120 "); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
121 /* ANSI does not allow strings > 512 chars |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
122 and MPW doesn't like it either -- so split it! */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
123 fprintf(stderr, "\ |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
124 file : program read from script file\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
125 - : program read from stdin (default; interactive mode if a tty)\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
126 arg ...: arguments passed to program in sys.argv[1:]\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
127 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
128 Other environment variables:\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
129 PYTHONSTARTUP: file executed on interactive startup (no default)\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
130 PYTHONPATH : colon-separated list of directories prefixed to the\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
131 default module search path. The result is sys.path.\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
132 "); |
| 2793 | 133 #endif /* !cfm68k || !mwerks */ |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
134 exit(2); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
135 /*NOTREACHED*/ |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
136 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
137 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
138 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
139 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
140 if (unbuffered) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
141 #ifndef MPW |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
142 setbuf(stdout, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
143 setbuf(stderr, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
144 #else |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
145 /* On MPW (3.2) unbuffered seems to hang */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
146 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
147 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
148 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
149 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
150 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
151 if (command == NULL && optind < argc && strcmp(argv[optind], "-") != 0) |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
152 filename = argv[optind]; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
153 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
154 if (verbose || |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
155 command == NULL && filename == NULL && isatty((int)fileno(fp))) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
156 fprintf(stderr, "Python %s\n%s\n", |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
157 getversion(), getcopyright()); |
| 86 | 158 |
| 6 | 159 if (filename != NULL) { |
| 160 if ((fp = fopen(filename, "r")) == NULL) { | |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
161 fprintf(stderr, "%s: can't open file '%s'\n", |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
162 argv[0], filename); |
| 6 | 163 exit(2); |
| 164 } | |
| 165 } | |
| 166 | |
|
891
a8ca720fd921
Removed confusing, incorrect comment.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
167 initall(); |
| 86 | 168 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
169 if (command != NULL) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
170 /* Backup optind and force sys.argv[0] = '-c' */ |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
171 optind--; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
172 argv[optind] = "-c"; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
173 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
891
diff
changeset
|
174 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
175 setpythonargv(argc-optind, argv+optind); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
176 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
177 if (command) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
178 sts = run_command(command) != 0; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
179 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
180 else { |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
181 if (filename == NULL && isatty((int)fileno(fp))) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
182 char *startup = getenv("PYTHONSTARTUP"); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
183 #ifdef macintosh |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
184 if (startup == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
185 startup = "PythonStartup"; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
186 #endif |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
187 if (startup != NULL && startup[0] != '\0') { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
188 FILE *fp = fopen(startup, "r"); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
189 if (fp != NULL) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
190 (void) run_script(fp, startup); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
191 err_clear(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
192 fclose(fp); |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
193 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
194 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
195 } |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
196 sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
197 if (filename != NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
198 fclose(fp); |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
199 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
200 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
201 if (inspect && isatty((int)fileno(stdin)) && |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
202 (filename != NULL || command != NULL)) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
203 sts = run(stdin, "<stdin>") != 0; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
204 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
205 goaway(sts); |
| 86 | 206 /*NOTREACHED*/ |
| 207 } |
