blob: d625067d9e4a360f0494989a8b7cb9e93e5d50c1 [file] [log] [blame]
Guido van Rossumb6775db1994-08-01 11:34:53 +00001/* -*- C -*- ***********************************************
Guido van Rossume333d161995-03-14 15:04:19 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossum524b5881995-01-04 19:10:35 +00003The 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 Rossum6c1874f1995-01-10 17:43:33 +000044#if defined(__cplusplus)
45extern "C" {
46#endif
Guido van Rossum9b4e1b31991-12-30 01:43:49 +000047
Guido van Rossumb6775db1994-08-01 11:34:53 +000048#ifndef NO_MAIN
Guido van Rossumaa011411991-12-16 13:05:20 +000049
Guido van Rossumb6775db1994-08-01 11:34:53 +000050/* Normally, the main program is called from here (so everything else
51 can be in libPython.a). We save a pointer to argv[0] because it
52 may be needed for dynamic loading of modules in import.c. If you
53 have your own main program and want to use non-SunOS dynamic
54 loading, you will have to provide your own version of
55 getprogramname(). */
Guido van Rossum9f462af1991-12-10 13:54:12 +000056
Guido van Rossumb6775db1994-08-01 11:34:53 +000057static char *argv0;
Guido van Rossumaa011411991-12-16 13:05:20 +000058
Guido van Rossum7b1e9741994-08-29 10:46:42 +000059/* These are made available for other modules that might need them.
60 This is rare, but it is needed by the secureware module. */
61
62static char **orig_argv;
63static int orig_argc;
64
Guido van Rossum6c1874f1995-01-10 17:43:33 +000065#if defined(__cplusplus)
66int realmain(int, char**);
67main(int argc, char **argv)
68#else
Guido van Rossumb6775db1994-08-01 11:34:53 +000069main(argc, argv)
70 int argc;
71 char **argv;
Guido van Rossum6c1874f1995-01-10 17:43:33 +000072#endif
Guido van Rossumaec78551990-12-20 23:03:58 +000073{
Guido van Rossum7b1e9741994-08-29 10:46:42 +000074 orig_argc = argc;
75 orig_argv = argv;
Guido van Rossumb6775db1994-08-01 11:34:53 +000076 argv0 = argv[0];
77 realmain(argc, argv);
78}
Guido van Rossum34679b71993-01-26 13:33:44 +000079
Guido van Rossumb6775db1994-08-01 11:34:53 +000080char *
81getprogramname()
82{
83 return argv0;
84}
Guido van Rossum34679b71993-01-26 13:33:44 +000085
Guido van Rossum7b1e9741994-08-29 10:46:42 +000086void
Guido van Rossum6c1874f1995-01-10 17:43:33 +000087#if defined(__cplusplus)
88getargcargv(int *argc, char ***argv)
89#else
Guido van Rossum7b1e9741994-08-29 10:46:42 +000090getargcargv(argc,argv)
91 int *argc;
92 char ***argv;
Guido van Rossum6c1874f1995-01-10 17:43:33 +000093#endif
Guido van Rossum7b1e9741994-08-29 10:46:42 +000094{
95 *argc = orig_argc;
96 *argv = orig_argv;
97}
98
Guido van Rossum34679b71993-01-26 13:33:44 +000099#endif
100
Guido van Rossumb6775db1994-08-01 11:34:53 +0000101
Guido van Rossum72824ba1994-08-19 12:03:04 +0000102/* Python version information */
103
104#include "patchlevel.h"
105
106/* Return the version string. This is constructed from the official
107 version number (from patchlevel.h), and the current date (if known
108 to the compiler, else a manually inserted date). */
109
Guido van Rossum57c33af1995-02-13 17:10:11 +0000110#define VERSION "%s (%s)%s"
Guido van Rossum72824ba1994-08-19 12:03:04 +0000111
112#ifdef __DATE__
113#define DATE __DATE__
114#else
Guido van Rossum57c33af1995-02-13 17:10:11 +0000115#define DATE "Feb 13 1995"
116#endif
117
118#ifdef THINK_C
119#define COMPILER " [THINK C]"
120#endif
121
122#ifdef __MWERKS__
123#ifdef __powerc
124#define COMPILER " [CW PPC]"
125#else
126#define COMPILER " [CW 68K]"
127#endif
128#endif
129
130#ifdef MPW
131#ifdef __SC__
132#define COMPILER " [Symantec MPW]"
133#else
134#define COMPILER " [Apple MPW]"
135#endif
136#endif
137
138#ifdef __GNUC__
Guido van Rossum9e575ff1995-02-17 15:11:57 +0000139#define COMPILER " [GCC " __VERSION__ "]"
Guido van Rossum57c33af1995-02-13 17:10:11 +0000140#endif
141
142#ifndef COMPILER
143#define COMPILER ""
Guido van Rossum72824ba1994-08-19 12:03:04 +0000144#endif
145
146char *
147getversion()
148{
149 static char version[80];
Guido van Rossum57c33af1995-02-13 17:10:11 +0000150 sprintf(version, VERSION, PATCHLEVEL, DATE, COMPILER);
Guido van Rossum72824ba1994-08-19 12:03:04 +0000151 return version;
152}
153
154
155/* Return the copyright string. This is updated manually. */
156
157char *
158getcopyright()
159{
Guido van Rossum524b5881995-01-04 19:10:35 +0000160 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossum72824ba1994-08-19 12:03:04 +0000161}
162
163
Guido van Rossumb6775db1994-08-01 11:34:53 +0000164/* Return the initial python search path. This is called once from
165 initsys() to initialize sys.path.
166 The environment variable PYTHONPATH is fetched and the default path
167 appended. (The Mac has no environment variables, so there the
168 default path is always returned.) The default path may be passed
169 to the preprocessor; if not, a system-dependent default is used. */
170
171#ifndef PYTHONPATH
172#ifdef macintosh
Guido van Rossum9731d441994-08-23 13:48:30 +0000173#define PYTHONPATH ": :Lib :Lib:stdwin :Lib:test :Lib:mac"
Guido van Rossumb6775db1994-08-01 11:34:53 +0000174#endif /* macintosh */
175#endif /* !PYTHONPATH */
176
177#ifndef PYTHONPATH
178#if defined(MSDOS) || defined(NT)
179#define PYTHONPATH ".;..\\lib;\\python\\lib"
180#endif /* MSDOS || NT */
181#endif /* !PYTHONPATH */
182
183#ifndef PYTHONPATH
184#define PYTHONPATH ".:/usr/local/lib/python"
Guido van Rossum0b0db8e1993-01-21 16:07:51 +0000185#endif /* !PYTHONPATH */
Guido van Rossumaec78551990-12-20 23:03:58 +0000186
Guido van Rossum6c1874f1995-01-10 17:43:33 +0000187#ifndef __cplusplus
Guido van Rossumaec78551990-12-20 23:03:58 +0000188extern char *getenv();
Guido van Rossum6c1874f1995-01-10 17:43:33 +0000189#endif
Guido van Rossumaec78551990-12-20 23:03:58 +0000190
191char *
192getpythonpath()
193{
Guido van Rossum6c1874f1995-01-10 17:43:33 +0000194#ifdef __cplusplus
195 void fatal(char *);
196#endif
Guido van Rossumaec78551990-12-20 23:03:58 +0000197 char *path = getenv("PYTHONPATH");
Guido van Rossumc888bf71992-06-03 17:05:13 +0000198 char *defpath = PYTHONPATH;
Guido van Rossum6e890b81994-10-05 12:25:12 +0000199 static char *buf = NULL;
Guido van Rossum34679b71993-01-26 13:33:44 +0000200 char *p;
Guido van Rossumc888bf71992-06-03 17:05:13 +0000201 int n;
202
Guido van Rossum6e890b81994-10-05 12:25:12 +0000203 if (path == NULL)
204 path = "";
Guido van Rossumc888bf71992-06-03 17:05:13 +0000205 n = strlen(path) + strlen(defpath) + 2;
Guido van Rossum6e890b81994-10-05 12:25:12 +0000206 if (buf != NULL) {
207 free(buf);
208 buf = NULL;
209 }
Guido van Rossumc888bf71992-06-03 17:05:13 +0000210 buf = malloc(n);
211 if (buf == NULL)
Guido van Rossum6e890b81994-10-05 12:25:12 +0000212 fatal("not enough memory to copy module search path");
Guido van Rossumc888bf71992-06-03 17:05:13 +0000213 strcpy(buf, path);
Guido van Rossum34679b71993-01-26 13:33:44 +0000214 p = buf + strlen(buf);
Guido van Rossume8a1e8c1994-10-05 14:48:22 +0000215 if (p != buf)
216 *p++ = DELIM;
Guido van Rossum34679b71993-01-26 13:33:44 +0000217 strcpy(p, defpath);
Guido van Rossumc888bf71992-06-03 17:05:13 +0000218 return buf;
Guido van Rossumaec78551990-12-20 23:03:58 +0000219}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000220
221
222/* Table of built-in modules.
Guido van Rossumb6775db1994-08-01 11:34:53 +0000223 These are initialized when first imported.
224 Note: selection of optional extensions is now generally done by the
225 makesetup script. */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000226
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000227/* -- ADDMODULE MARKER 1 -- */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000228
Guido van Rossumb6775db1994-08-01 11:34:53 +0000229extern void initmarshal();
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000230extern void initimp();
Guido van Rossumb6775db1994-08-01 11:34:53 +0000231
Guido van Rossum59e53a51991-02-19 12:22:24 +0000232struct {
233 char *name;
234 void (*initfunc)();
235} inittab[] = {
236
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000237/* -- ADDMODULE MARKER 2 -- */
238
Guido van Rossumb6775db1994-08-01 11:34:53 +0000239 /* This module "lives in" with marshal.c */
240 {"marshal", initmarshal},
241
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000242 /* This lives it with import.c */
243 {"imp", initimp},
244
Guido van Rossumb6775db1994-08-01 11:34:53 +0000245 /* These entries are here for sys.builtin_module_names */
246 {"__main__", NULL},
247 {"__builtin__", NULL},
248 {"sys", NULL},
249
250 /* Sentinel */
251 {0, 0}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000252};
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000253
Guido van Rossume8a1e8c1994-10-05 14:48:22 +0000254#ifndef USE_FROZEN
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000255struct frozen {
256 char *name;
257 char *code;
258 int size;
259} frozen_modules[] = {
260 {0, 0, 0}
261};
262#endif
Guido van Rossum6c1874f1995-01-10 17:43:33 +0000263
264#if defined(__cplusplus)
265}
266#endif