Mercurial > cpython-lru_cache-weakref
annotate Python/pythonmain.c @ 1877:32d005faf5fc legacy-trunk
Mods for HP-UX dynamic loading.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 12 Sep 1994 10:39:56 +0000 |
| parents | b724599401ff |
| children | 35947f60528e |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1014
diff
changeset
|
3 Amsterdam, 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); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
74 /* Ignore malloc errors this early... */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
75 strcpy(command, optarg); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
76 strcat(command, "\n"); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
77 break; |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
78 } |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
79 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
80 switch (c) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
81 |
|
618
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
82 case 'd': |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
83 debugging++; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
84 break; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
85 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
86 case 'i': |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
87 inspect++; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
88 break; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
89 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
90 case 's': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
91 suppress_print++; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
92 break; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
93 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
94 case 'u': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
95 unbuffered++; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
96 break; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
97 |
|
728
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
98 case 'v': |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
99 verbose++; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
100 break; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
101 |
|
560
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
102 /* This space reserved for other options */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
103 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
104 default: |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
105 fprintf(stderr, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
106 "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
|
107 argv[0]); |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
108 fprintf(stderr, "\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
109 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
110 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
|
111 -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
|
112 -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
|
113 -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
|
114 -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
|
115 -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
|
116 -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
|
117 "); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
118 /* ANSI does not allow strings > 512 chars |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
119 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
|
120 fprintf(stderr, "\ |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
121 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
|
122 - : 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
|
123 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
|
124 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
125 Other environment variables:\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 "); |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
130 exit(2); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
131 /*NOTREACHED*/ |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
132 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
133 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
134 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
135 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
136 if (unbuffered) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
137 #ifndef MPW |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
138 setbuf(stdout, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
139 setbuf(stderr, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
140 #else |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
141 /* On MPW (3.2) unbuffered seems to hang */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
142 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
143 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
144 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
145 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
146 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
147 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
|
148 filename = argv[optind]; |
|
1848
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 if (verbose || |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
151 command == NULL && filename == NULL && isatty((int)fileno(fp))) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
152 fprintf(stderr, "Python %s\n%s\n", |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
153 getversion(), getcopyright()); |
| 86 | 154 |
| 6 | 155 if (filename != NULL) { |
| 156 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
|
157 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
|
158 argv[0], filename); |
| 6 | 159 exit(2); |
| 160 } | |
| 161 } | |
| 162 | |
|
891
a8ca720fd921
Removed confusing, incorrect comment.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
163 initall(); |
| 86 | 164 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
165 if (command != NULL) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
166 /* 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
|
167 optind--; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
168 argv[optind] = "-c"; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
169 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
891
diff
changeset
|
170 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
171 setpythonargv(argc-optind, argv+optind); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
172 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
173 if (command) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
174 sts = run_command(command) != 0; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
175 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
176 else { |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
177 if (filename == NULL && isatty((int)fileno(fp))) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
178 char *startup = getenv("PYTHONSTARTUP"); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
179 #ifdef macintosh |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
180 if (startup == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
181 startup = "PythonStartup"; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
182 #endif |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
183 if (startup != NULL && startup[0] != '\0') { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
184 FILE *fp = fopen(startup, "r"); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
185 if (fp != NULL) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
186 (void) run_script(fp, startup); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
187 err_clear(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
188 fclose(fp); |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
189 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
190 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
191 } |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
192 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
|
193 if (filename != NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
194 fclose(fp); |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
195 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
196 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
197 if (inspect && isatty((int)fileno(stdin)) && |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
198 (filename != NULL || command != NULL)) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
199 sts = run(stdin, "<stdin>") != 0; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
200 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
201 goaway(sts); |
| 86 | 202 /*NOTREACHED*/ |
| 203 } |
