annotate Python/pythonmain.c @ 944:222f04f55083 legacy-trunk

Changes so that user-defined classes can implement operations invoked by special syntax: you can now define your own numbers, sequences and mappings.
author Guido van Rossum <guido@python.org>
date Wed, 12 Aug 1992 15:35:34 +0000
parents c156d4960c2b
children 96acb35bb92b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
1 /***********************************************************
795
0cd197947d81 Copyright for 1992 added
Guido van Rossum <guido@python.org>
parents: 728
diff changeset
2 Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
3 Netherlands.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
6
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
8 documentation for any purpose and without fee is hereby granted,
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
9 provided that the above copyright notice appear in all copies and that
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
10 both that copyright notice and this permission notice appear in
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
13 distribution of the software without specific, written prior permission.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
22
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
23 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 94
diff changeset
24
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Python interpreter main program */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
29 extern int debugging; /* Needed by parser.c */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
30 extern int verbose; /* Needed by import.c */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
32 /* Interface to getopt(): */
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
33 extern int optind;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
34 extern char *optarg;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
35 extern int getopt PROTO((int, char **, char *));
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
36
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 main(argc, argv)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 int argc;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 char **argv;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 {
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
41 int c;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
42 int sts;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
43 char *command = NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 char *filename = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 FILE *fp = stdin;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
46
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
47 initargs(&argc, &argv); /* Defined in config*.c */
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
48
728
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
49 while ((c = getopt(argc, argv, "c:dv")) != EOF) {
560
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
50 if (c == 'c') {
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
51 /* -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
52 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
53 the command to interpret. */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
54 command = malloc(strlen(optarg) + 2);
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
55 /* Ignore malloc errors this early... */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
56 strcpy(command, optarg);
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
57 strcat(command, "\n");
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
58 break;
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
59 }
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
60
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
61 switch (c) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
62
618
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
63 case 'd':
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
64 debugging++;
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
65 break;
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
66
728
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
67 case 'v':
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
68 verbose++;
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
69 break;
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
70
560
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
71 /* This space reserved for other options */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
72
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
73 default:
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
74 fprintf(stderr,
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
75 "usage: %s [-c cmd | file | -] [arg] ...\n",
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
76 argv[0]);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
77 exit(2);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
78 /*NOTREACHED*/
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
79
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
80 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
81 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
83 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
84 filename = argv[optind];
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
85
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 if (filename != NULL) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 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
88 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
89 argv[0], filename);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 exit(2);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
891
a8ca720fd921 Removed confusing, incorrect comment.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
94 initall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
95
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
96 if (command != NULL) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
97 /* 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
98 optind--;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
99 argv[optind] = "-c";
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
100 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
101
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
102 setpythonargv(argc-optind, argv+optind);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
103
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
104 if (command) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
105 sts = run_command(command) != 0;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
106 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
107 else {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
108 sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
109 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
110
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
111 goaway(sts);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
112 /*NOTREACHED*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
113 }