annotate Python/pythonmain.c @ 923:72aceed365d4 legacy-trunk

* Makefile adapted to changes below. * split pythonmain.c in two: most stuff goes to pythonrun.c, in the library. * new optional built-in threadmodule.c, build upon Sjoerd's thread.{c,h}. * new module from Sjoerd: mmmodule.c (dynamically loaded). * new module from Sjoerd: sv (svgen.py, svmodule.c.proto). * new files thread.{c,h} (from Sjoerd). * new xxmodule.c (example only). * myselect.h: bzero -> memset * select.c: bzero -> memset; removed global variable
author Guido van Rossum <guido@python.org>
date Tue, 04 Aug 1992 12:41:02 +0000
parents a8ca720fd921
children c156d4960c2b
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
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
29 extern char *getpythonpath();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
31 extern int debugging; /* Needed by parser.c */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
32 extern int verbose; /* Needed by import.c */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
34 /* Interface to getopt(): */
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
35 extern int optind;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
36 extern char *optarg;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
37 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
38
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 main(argc, argv)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 int argc;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 char **argv;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 {
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
43 int c;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
44 int sts;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
45 char *command = NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 char *filename = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 FILE *fp = stdin;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
48
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
49 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
50
728
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
51 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
52 if (c == 'c') {
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
53 /* -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
54 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
55 the command to interpret. */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
56 command = malloc(strlen(optarg) + 2);
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
57 /* Ignore malloc errors this early... */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
58 strcpy(command, optarg);
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
59 strcat(command, "\n");
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
60 break;
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
61 }
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
62
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
63 switch (c) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
64
618
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
65 case 'd':
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
66 debugging++;
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
67 break;
189ee3beebb5 Added -d option (increments debugging variable); mostly to get rid
Guido van Rossum <guido@python.org>
parents: 593
diff changeset
68
728
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
69 case 'v':
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
70 verbose++;
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
71 break;
76d92ebb4d82 Add -v option (verbose) and get rid of finaloutput() function (unused)
Guido van Rossum <guido@python.org>
parents: 690
diff changeset
72
560
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
73 /* This space reserved for other options */
0614d887d10a Stop option processing immediately after "-c command",
Guido van Rossum <guido@python.org>
parents: 547
diff changeset
74
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
75 default:
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
76 fprintf(stderr,
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
77 "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
78 argv[0]);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
79 exit(2);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
80 /*NOTREACHED*/
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
81
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
82 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
83 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
85 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
86 filename = argv[optind];
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
87
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 if (filename != NULL) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 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
90 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
91 argv[0], filename);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 exit(2);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
891
a8ca720fd921 Removed confusing, incorrect comment.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
96 initall();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
97
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
98 if (command != NULL) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
99 /* 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
100 optind--;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
101 argv[optind] = "-c";
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
102 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 891
diff changeset
103
282
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
104 setpythonargv(argc-optind, argv+optind);
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
105
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
106 if (command) {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
107 sts = run_command(command) != 0;
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
108 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
109 else {
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
110 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
111 }
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
112
d5c9ae422b41 Add run_command() to implement "-c command".
Guido van Rossum <guido@python.org>
parents: 262
diff changeset
113 goaway(sts);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
114 /*NOTREACHED*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 81
diff changeset
115 }