blob: ba8b9d78a5e8528f88bfbb3b7f300903bc7739de [file] [log] [blame]
Guido van Rossumb6775db1994-08-01 11:34:53 +00001/* -*- C -*- ***********************************************
Guido van Rossum524b5881995-01-04 19:10:35 +00002Copyright 1991-1994 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
Guido van Rossum524b5881995-01-04 19:10:35 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossum524b5881995-01-04 19:10:35 +000010both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000011supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossumb6775db1994-08-01 11:34:53 +000025/* Universal Python configuration file */
Guido van Rossumaec78551990-12-20 23:03:58 +000026
Guido van Rossumb6775db1994-08-01 11:34:53 +000027#ifdef HAVE_CONFIG_H
28#include "config.h"
Guido van Rossum34679b71993-01-26 13:33:44 +000029#endif
30
Guido van Rossum9731d441994-08-23 13:48:30 +000031#ifdef macintosh
32/* The Macintosh main program is in macmain.c */
33#define NO_MAIN
34#endif
35
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000036#include <stdio.h>
Guido van Rossumb6775db1994-08-01 11:34:53 +000037#include <string.h>
Guido van Rossum97f02771992-09-03 20:49:55 +000038
Guido van Rossumb6775db1994-08-01 11:34:53 +000039#include "myproto.h"
Guido van Rossumb001f7a1992-08-19 16:44:41 +000040#include "mymalloc.h"
Guido van Rossum34679b71993-01-26 13:33:44 +000041#include "osdefs.h"
Guido van Rossumb6775db1994-08-01 11:34:53 +000042#include "intrcheck.h"
Guido van Rossumc888bf71992-06-03 17:05:13 +000043
Guido van Rossum9b4e1b31991-12-30 01:43:49 +000044
Guido van Rossumb6775db1994-08-01 11:34:53 +000045#ifndef NO_MAIN
Guido van Rossumaa011411991-12-16 13:05:20 +000046
Guido van Rossumb6775db1994-08-01 11:34:53 +000047/* Normally, the main program is called from here (so everything else
48 can be in libPython.a). We save a pointer to argv[0] because it
49 may be needed for dynamic loading of modules in import.c. If you
50 have your own main program and want to use non-SunOS dynamic
51 loading, you will have to provide your own version of
52 getprogramname(). */
Guido van Rossum9f462af1991-12-10 13:54:12 +000053
Guido van Rossumb6775db1994-08-01 11:34:53 +000054static char *argv0;
Guido van Rossumaa011411991-12-16 13:05:20 +000055
Guido van Rossum7b1e9741994-08-29 10:46:42 +000056/* These are made available for other modules that might need them.
57 This is rare, but it is needed by the secureware module. */
58
59static char **orig_argv;
60static int orig_argc;
61
Guido van Rossumb6775db1994-08-01 11:34:53 +000062main(argc, argv)
63 int argc;
64 char **argv;
Guido van Rossumaec78551990-12-20 23:03:58 +000065{
Guido van Rossum7b1e9741994-08-29 10:46:42 +000066 orig_argc = argc;
67 orig_argv = argv;
Guido van Rossumb6775db1994-08-01 11:34:53 +000068 argv0 = argv[0];
69 realmain(argc, argv);
70}
Guido van Rossum34679b71993-01-26 13:33:44 +000071
Guido van Rossumb6775db1994-08-01 11:34:53 +000072char *
73getprogramname()
74{
75 return argv0;
76}
Guido van Rossum34679b71993-01-26 13:33:44 +000077
Guido van Rossum7b1e9741994-08-29 10:46:42 +000078void
79getargcargv(argc,argv)
80 int *argc;
81 char ***argv;
82{
83 *argc = orig_argc;
84 *argv = orig_argv;
85}
86
Guido van Rossum34679b71993-01-26 13:33:44 +000087#endif
88
Guido van Rossumb6775db1994-08-01 11:34:53 +000089
Guido van Rossum72824ba1994-08-19 12:03:04 +000090/* Python version information */
91
92#include "patchlevel.h"
93
94/* Return the version string. This is constructed from the official
95 version number (from patchlevel.h), and the current date (if known
96 to the compiler, else a manually inserted date). */
97
98#define VERSION "%s (%s)"
99
100#ifdef __DATE__
101#define DATE __DATE__
102#else
103#define DATE "Aug 17 1994"
104#endif
105
106char *
107getversion()
108{
109 static char version[80];
110 sprintf(version, VERSION, PATCHLEVEL, DATE);
111 return version;
112}
113
114
115/* Return the copyright string. This is updated manually. */
116
117char *
118getcopyright()
119{
Guido van Rossum524b5881995-01-04 19:10:35 +0000120 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossum72824ba1994-08-19 12:03:04 +0000121}
122
123
Guido van Rossumb6775db1994-08-01 11:34:53 +0000124/* Return the initial python search path. This is called once from
125 initsys() to initialize sys.path.
126 The environment variable PYTHONPATH is fetched and the default path
127 appended. (The Mac has no environment variables, so there the
128 default path is always returned.) The default path may be passed
129 to the preprocessor; if not, a system-dependent default is used. */
130
131#ifndef PYTHONPATH
132#ifdef macintosh
Guido van Rossum9731d441994-08-23 13:48:30 +0000133#define PYTHONPATH ": :Lib :Lib:stdwin :Lib:test :Lib:mac"
Guido van Rossumb6775db1994-08-01 11:34:53 +0000134#endif /* macintosh */
135#endif /* !PYTHONPATH */
136
137#ifndef PYTHONPATH
138#if defined(MSDOS) || defined(NT)
139#define PYTHONPATH ".;..\\lib;\\python\\lib"
140#endif /* MSDOS || NT */
141#endif /* !PYTHONPATH */
142
143#ifndef PYTHONPATH
144#define PYTHONPATH ".:/usr/local/lib/python"
Guido van Rossum0b0db8e1993-01-21 16:07:51 +0000145#endif /* !PYTHONPATH */
Guido van Rossumaec78551990-12-20 23:03:58 +0000146
147extern char *getenv();
148
149char *
150getpythonpath()
151{
152 char *path = getenv("PYTHONPATH");
Guido van Rossumc888bf71992-06-03 17:05:13 +0000153 char *defpath = PYTHONPATH;
Guido van Rossum6e890b81994-10-05 12:25:12 +0000154 static char *buf = NULL;
Guido van Rossum34679b71993-01-26 13:33:44 +0000155 char *p;
Guido van Rossumc888bf71992-06-03 17:05:13 +0000156 int n;
157
Guido van Rossum6e890b81994-10-05 12:25:12 +0000158 if (path == NULL)
159 path = "";
Guido van Rossumc888bf71992-06-03 17:05:13 +0000160 n = strlen(path) + strlen(defpath) + 2;
Guido van Rossum6e890b81994-10-05 12:25:12 +0000161 if (buf != NULL) {
162 free(buf);
163 buf = NULL;
164 }
Guido van Rossumc888bf71992-06-03 17:05:13 +0000165 buf = malloc(n);
166 if (buf == NULL)
Guido van Rossum6e890b81994-10-05 12:25:12 +0000167 fatal("not enough memory to copy module search path");
Guido van Rossumc888bf71992-06-03 17:05:13 +0000168 strcpy(buf, path);
Guido van Rossum34679b71993-01-26 13:33:44 +0000169 p = buf + strlen(buf);
Guido van Rossume8a1e8c1994-10-05 14:48:22 +0000170 if (p != buf)
171 *p++ = DELIM;
Guido van Rossum34679b71993-01-26 13:33:44 +0000172 strcpy(p, defpath);
Guido van Rossumc888bf71992-06-03 17:05:13 +0000173 return buf;
Guido van Rossumaec78551990-12-20 23:03:58 +0000174}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000175
176
177/* Table of built-in modules.
Guido van Rossumb6775db1994-08-01 11:34:53 +0000178 These are initialized when first imported.
179 Note: selection of optional extensions is now generally done by the
180 makesetup script. */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000181
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000182/* -- ADDMODULE MARKER 1 -- */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000183
Guido van Rossumb6775db1994-08-01 11:34:53 +0000184extern void initmarshal();
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000185extern void initimp();
Guido van Rossumb6775db1994-08-01 11:34:53 +0000186
Guido van Rossum59e53a51991-02-19 12:22:24 +0000187struct {
188 char *name;
189 void (*initfunc)();
190} inittab[] = {
191
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000192/* -- ADDMODULE MARKER 2 -- */
193
Guido van Rossumb6775db1994-08-01 11:34:53 +0000194 /* This module "lives in" with marshal.c */
195 {"marshal", initmarshal},
196
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000197 /* This lives it with import.c */
198 {"imp", initimp},
199
Guido van Rossumb6775db1994-08-01 11:34:53 +0000200 /* These entries are here for sys.builtin_module_names */
201 {"__main__", NULL},
202 {"__builtin__", NULL},
203 {"sys", NULL},
204
205 /* Sentinel */
206 {0, 0}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000207};
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000208
Guido van Rossume8a1e8c1994-10-05 14:48:22 +0000209#ifndef USE_FROZEN
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000210struct frozen {
211 char *name;
212 char *code;
213 int size;
214} frozen_modules[] = {
215 {0, 0, 0}
216};
217#endif