Mercurial > cpython-lru_cache-weakref
annotate Python/pythonmain.c @ 8358:da4bdceeaad7 legacy-trunk
Another veeeeeery old patch...
Date: Thu, 14 Sep 1995 12:18:20 -0400
From: Alan Morse <alan@dvcorp.com>
To: python-list@cwi.nl
Subject: getargs bug in 1.2 and 1.3 BETA
We have found a bug in the part of the getargs code that we added
and submitted, and which was incorporated into 1.1.
The parsing of "O?" format specifiers is not handled correctly;
there is no "else" for the "if" and therefore it can never fail.
What's worse, the advancing of the varargs pointer is not
handled properly, so from then on it is out of sync, wreaking
all sorts of havoc. (If it had failed properly, then the out-of-sync
varargs would not have been an issue.)
Below is the context diff for the change.
Note that I have made a few stylistic changes beyond adding the
else case, namely:
1) Making the "O" case follow the convention established by the other
format specifiers of getting all their vararg arguments before
performing the test, rather than getting some before and some after
the test passes.
2) Making the logic of the tests parallel, so the "if" part indicates
that the format is accepted and the "else" part indicates that the
format has failed. They were inconsistent with each other and with the
the other format specifiers.
-Alan Morse (amorse@dvcorp.com)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 15 May 1998 22:04:07 +0000 |
| parents | 85140b354890 |
| children |
| 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 |
|
2876
85140b354890
Allow mac user to set "command line flags" by option-starting python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2793
diff
changeset
|
68 #ifdef macintosh |
|
85140b354890
Allow mac user to set "command line flags" by option-starting python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2793
diff
changeset
|
69 PyMac_InteractiveOptions(&inspect, &verbose, &suppress_print, &unbuffered, &debugging); |
|
85140b354890
Allow mac user to set "command line flags" by option-starting python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2793
diff
changeset
|
70 #endif |
|
85140b354890
Allow mac user to set "command line flags" by option-starting python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2793
diff
changeset
|
71 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
72 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
|
73 if (c == 'c') { |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
74 /* -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
|
75 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
|
76 the command to interpret. */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 strcpy(command, optarg); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
81 strcat(command, "\n"); |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
82 break; |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
83 } |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
84 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
85 switch (c) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
86 |
|
618
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
87 case 'd': |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
88 debugging++; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
89 break; |
|
189ee3beebb5
Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents:
593
diff
changeset
|
90 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
91 case 'i': |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
92 inspect++; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
93 break; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
94 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
95 case 's': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
96 suppress_print++; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
97 break; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
98 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
99 case 'u': |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
100 unbuffered++; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
101 break; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
102 |
|
728
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
103 case 'v': |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
104 verbose++; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
105 break; |
|
76d92ebb4d82
Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents:
690
diff
changeset
|
106 |
|
560
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
107 /* This space reserved for other options */ |
|
0614d887d10a
Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents:
547
diff
changeset
|
108 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
109 default: |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
110 fprintf(stderr, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
111 "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
|
112 argv[0]); |
| 2793 | 113 #if !(defined(__CFM68K__) && defined(__MWERKS__)) |
| 114 /* 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
|
115 fprintf(stderr, "\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
116 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
117 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
|
118 -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
|
119 -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
|
120 -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
|
121 -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
|
122 -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
|
123 -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
|
124 "); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
125 /* ANSI does not allow strings > 512 chars |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
126 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
|
127 fprintf(stderr, "\ |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
128 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
|
129 - : 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
|
130 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
|
131 \n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
132 Other environment variables:\n\ |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 "); |
| 2793 | 137 #endif /* !cfm68k || !mwerks */ |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
138 exit(2); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
139 /*NOTREACHED*/ |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
140 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
141 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
142 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
143 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
144 if (unbuffered) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
145 #ifndef MPW |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
146 setbuf(stdout, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
147 setbuf(stderr, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
148 #else |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
149 /* On MPW (3.2) unbuffered seems to hang */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
150 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
151 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
152 #endif |
|
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 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
155 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
|
156 filename = argv[optind]; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
157 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
158 if (verbose || |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
159 command == NULL && filename == NULL && isatty((int)fileno(fp))) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
160 fprintf(stderr, "Python %s\n%s\n", |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
161 getversion(), getcopyright()); |
| 86 | 162 |
| 6 | 163 if (filename != NULL) { |
| 164 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
|
165 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
|
166 argv[0], filename); |
| 6 | 167 exit(2); |
| 168 } | |
| 169 } | |
| 170 | |
|
891
a8ca720fd921
Removed confusing, incorrect comment.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
171 initall(); |
| 86 | 172 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
173 if (command != NULL) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
174 /* 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
|
175 optind--; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
176 argv[optind] = "-c"; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
177 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
891
diff
changeset
|
178 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
179 setpythonargv(argc-optind, argv+optind); |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
180 |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
181 if (command) { |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
182 sts = run_command(command) != 0; |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
183 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
184 else { |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
185 if (filename == NULL && isatty((int)fileno(fp))) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
186 char *startup = getenv("PYTHONSTARTUP"); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
187 #ifdef macintosh |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
188 if (startup == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
189 startup = "PythonStartup"; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
190 #endif |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
191 if (startup != NULL && startup[0] != '\0') { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
192 FILE *fp = fopen(startup, "r"); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
193 if (fp != NULL) { |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
194 (void) run_script(fp, startup); |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
195 err_clear(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
196 fclose(fp); |
|
1014
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
197 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
198 } |
|
96acb35bb92b
Add $PYTHONSTARTUP feature.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
199 } |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
200 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
|
201 if (filename != NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
202 fclose(fp); |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
203 } |
|
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
204 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
205 if (inspect && isatty((int)fileno(stdin)) && |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
206 (filename != NULL || command != NULL)) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
207 sts = run(stdin, "<stdin>") != 0; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
208 |
|
282
d5c9ae422b41
Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents:
262
diff
changeset
|
209 goaway(sts); |
| 86 | 210 /*NOTREACHED*/ |
| 211 } |
