blob: cc2371af86faa9238222c9f444e436bc6dddd8b6 [file] [log] [blame]
Guido van Rossumb6775db1994-08-01 11:34:53 +00001/* -*- C -*- ***********************************************
2Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Guido van Rossume35399e1993-01-10 18:33:56 +00003Amsterdam, The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting 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 Rossum0b0db8e1993-01-21 16:07:51 +000031#include <stdio.h>
Guido van Rossumb6775db1994-08-01 11:34:53 +000032#include <string.h>
Guido van Rossum97f02771992-09-03 20:49:55 +000033
Guido van Rossumb6775db1994-08-01 11:34:53 +000034#include "myproto.h"
Guido van Rossumb001f7a1992-08-19 16:44:41 +000035#include "mymalloc.h"
Guido van Rossum34679b71993-01-26 13:33:44 +000036#include "osdefs.h"
Guido van Rossumb6775db1994-08-01 11:34:53 +000037#include "intrcheck.h"
Guido van Rossumc888bf71992-06-03 17:05:13 +000038
Guido van Rossum9b4e1b31991-12-30 01:43:49 +000039
Guido van Rossumb6775db1994-08-01 11:34:53 +000040#ifndef NO_MAIN
Guido van Rossumaa011411991-12-16 13:05:20 +000041
Guido van Rossumb6775db1994-08-01 11:34:53 +000042/* Normally, the main program is called from here (so everything else
43 can be in libPython.a). We save a pointer to argv[0] because it
44 may be needed for dynamic loading of modules in import.c. If you
45 have your own main program and want to use non-SunOS dynamic
46 loading, you will have to provide your own version of
47 getprogramname(). */
Guido van Rossum9f462af1991-12-10 13:54:12 +000048
Guido van Rossumb6775db1994-08-01 11:34:53 +000049static char *argv0;
Guido van Rossumaa011411991-12-16 13:05:20 +000050
Guido van Rossumb6775db1994-08-01 11:34:53 +000051main(argc, argv)
52 int argc;
53 char **argv;
Guido van Rossumaec78551990-12-20 23:03:58 +000054{
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000055#ifdef macintosh
Guido van Rossumb6775db1994-08-01 11:34:53 +000056 wargs(&argc, &argv);
57#endif
58 argv0 = argv[0];
59 realmain(argc, argv);
60}
Guido van Rossum34679b71993-01-26 13:33:44 +000061
Guido van Rossumb6775db1994-08-01 11:34:53 +000062char *
63getprogramname()
64{
65 return argv0;
66}
Guido van Rossum34679b71993-01-26 13:33:44 +000067
Guido van Rossum34679b71993-01-26 13:33:44 +000068#endif
69
Guido van Rossumb6775db1994-08-01 11:34:53 +000070
71/* Return the initial python search path. This is called once from
72 initsys() to initialize sys.path.
73 The environment variable PYTHONPATH is fetched and the default path
74 appended. (The Mac has no environment variables, so there the
75 default path is always returned.) The default path may be passed
76 to the preprocessor; if not, a system-dependent default is used. */
77
78#ifndef PYTHONPATH
79#ifdef macintosh
80#define PYTHONPATH ": :Lib :Lib:stdwin :Demo"
81#endif /* macintosh */
82#endif /* !PYTHONPATH */
83
84#ifndef PYTHONPATH
85#if defined(MSDOS) || defined(NT)
86#define PYTHONPATH ".;..\\lib;\\python\\lib"
87#endif /* MSDOS || NT */
88#endif /* !PYTHONPATH */
89
90#ifndef PYTHONPATH
91#define PYTHONPATH ".:/usr/local/lib/python"
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000092#endif /* !PYTHONPATH */
Guido van Rossumaec78551990-12-20 23:03:58 +000093
94extern char *getenv();
95
96char *
97getpythonpath()
98{
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000099#ifdef macintosh
100 return PYTHONPATH;
101#else /* !macintosh */
Guido van Rossumaec78551990-12-20 23:03:58 +0000102 char *path = getenv("PYTHONPATH");
Guido van Rossumc888bf71992-06-03 17:05:13 +0000103 char *defpath = PYTHONPATH;
104 char *buf;
Guido van Rossum34679b71993-01-26 13:33:44 +0000105 char *p;
Guido van Rossumc888bf71992-06-03 17:05:13 +0000106 int n;
107
108 if (path == 0 || *path == '\0')
109 return defpath;
110 n = strlen(path) + strlen(defpath) + 2;
111 buf = malloc(n);
112 if (buf == NULL)
113 return path; /* XXX too bad -- but not likely */
114 strcpy(buf, path);
Guido van Rossum34679b71993-01-26 13:33:44 +0000115 p = buf + strlen(buf);
116 *p++ = DELIM;
117 strcpy(p, defpath);
Guido van Rossumc888bf71992-06-03 17:05:13 +0000118 return buf;
Guido van Rossum0b0db8e1993-01-21 16:07:51 +0000119#endif /* !macintosh */
Guido van Rossumaec78551990-12-20 23:03:58 +0000120}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000121
122
123/* Table of built-in modules.
Guido van Rossumb6775db1994-08-01 11:34:53 +0000124 These are initialized when first imported.
125 Note: selection of optional extensions is now generally done by the
126 makesetup script. */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000127
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000128/* -- ADDMODULE MARKER 1 -- */
Guido van Rossum59e53a51991-02-19 12:22:24 +0000129
Guido van Rossumb6775db1994-08-01 11:34:53 +0000130extern void initmarshal();
131
Guido van Rossum59e53a51991-02-19 12:22:24 +0000132struct {
133 char *name;
134 void (*initfunc)();
135} inittab[] = {
136
Guido van Rossum3a40ae41992-09-25 21:54:05 +0000137/* -- ADDMODULE MARKER 2 -- */
138
Guido van Rossumb6775db1994-08-01 11:34:53 +0000139 /* This module "lives in" with marshal.c */
140 {"marshal", initmarshal},
141
142 /* These entries are here for sys.builtin_module_names */
143 {"__main__", NULL},
144 {"__builtin__", NULL},
145 {"sys", NULL},
146
147 /* Sentinel */
148 {0, 0}
Guido van Rossum59e53a51991-02-19 12:22:24 +0000149};
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000150
151#ifdef USE_FROZEN
152#include "frozen.c"
153#else
154struct frozen {
155 char *name;
156 char *code;
157 int size;
158} frozen_modules[] = {
159 {0, 0, 0}
160};
161#endif