blob: a0185517130b3b516df3638d2d7d3fd61ddcd794 [file] [log] [blame]
Guido van Rossumce9739b1994-01-05 16:17:15 +00001/***********************************************************
2Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The Netherlands.
4
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
25/* Universal Python configuration file */
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
31#include <stdio.h>
32#include <string.h>
33
34#include "myproto.h"
35#include "mymalloc.h"
36#include "osdefs.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000037
38
39#ifndef NO_MAIN
40
41/* Normally, the main program is called from here (so everything else
42 can be in libPython.a). We save a pointer to argv[0] because it
43 may be needed for dynamic loading of modules in import.c. If you
44 have your own main program and want to use non-SunOS dynamic
45 loading, you will have to provide your own version of
46 getprogramname(). */
47
48static char *argv0;
49
50main(argc, argv)
51 int argc;
52 char **argv;
53{
54#ifdef macintosh
Guido van Rossum3ce7a1a1994-05-06 15:54:52 +000055
56#ifndef MPW /* XXX RJW undefined in MPW */
Guido van Rossumce9739b1994-01-05 16:17:15 +000057 wargs(&argc, &argv);
58#endif
Guido van Rossum3ce7a1a1994-05-06 15:54:52 +000059
60#ifndef MPW_3 /* XXX RJW doesn't seem to work with MPW C 3.0 */
61 extern int std_open_hook();
62 set_open_hook (std_open_hook);
63#endif
64#endif
65
Guido van Rossumce9739b1994-01-05 16:17:15 +000066 argv0 = argv[0];
67 realmain(argc, argv);
68}
69
70char *
71getprogramname()
72{
73 return argv0;
74}
75
76#endif
77
78
79/* Return the initial python search path. This is called once from
80 initsys() to initialize sys.path.
81 The environment variable PYTHONPATH is fetched and the default path
82 appended. (The Mac has no environment variables, so there the
83 default path is always returned.) The default path may be passed
84 to the preprocessor; if not, a system-dependent default is used. */
85
86#ifndef PYTHONPATH
87#ifdef macintosh
88#define PYTHONPATH ": :Lib :Lib:stdwin :Demo"
89#endif /* macintosh */
90#endif /* !PYTHONPATH */
91
92#ifndef PYTHONPATH
93#ifdef MSDOS
94#define PYTHONPATH ".;..\\lib;\\python\\lib"
95#endif /* MSDOS */
96#endif /* !PYTHONPATH */
97
98#ifndef PYTHONPATH
99#define PYTHONPATH ".:/usr/local/lib/python"
100#endif /* !PYTHONPATH */
101
102extern char *getenv();
103
104char *
105getpythonpath()
106{
107#ifdef macintosh
108 return PYTHONPATH;
109#else /* !macintosh */
110 char *path = getenv("PYTHONPATH");
111 char *defpath = PYTHONPATH;
112 char *buf;
113 char *p;
114 int n;
115
116 if (path == 0 || *path == '\0')
117 return defpath;
118 n = strlen(path) + strlen(defpath) + 2;
119 buf = malloc(n);
120 if (buf == NULL)
121 return path; /* XXX too bad -- but not likely */
122 strcpy(buf, path);
123 p = buf + strlen(buf);
124 *p++ = DELIM;
125 strcpy(p, defpath);
126 return buf;
127#endif /* !macintosh */
128}
129
130
131/* Table of built-in modules.
132 These are initialized when first imported.
133 Note: selection of optional extensions is now generally done by the
134 makesetup script. */
135
136extern void initarray();
137extern void initmath();
138extern void initparser();
139extern void initmac();
140extern void initregex();
141extern void initstrop();
142extern void initstruct();
143extern void inittime();
144extern void initdbm();
145extern void initfcntl();
146extern void initnis();
147extern void initpwd();
148extern void initgrp();
149extern void initselect();
150extern void initsocket();
151extern void initaudioop();
152extern void initimageop();
153extern void initrgbimg();
154extern void initstdwin();
155extern void initmd5();
156extern void initmpz();
157extern void initrotor();
158extern void inital();
159extern void initcd();
160extern void initcl();
161extern void initfm();
162extern void initgl();
163extern void initimgfile();
164extern void initsgi();
165extern void initsv();
166extern void initfl();
167extern void initthread();
168extern void inittiming();
169
170/* -- ADDMODULE MARKER 1 -- */
171
172extern void initmarshal();
173
174struct {
175 char *name;
176 void (*initfunc)();
177} inittab[] = {
178
179 {"array", initarray},
180 {"math", initmath},
181 {"parser", initparser},
182 {"mac", initmac},
183 {"regex", initregex},
184 {"strop", initstrop},
185 {"struct", initstruct},
186 {"time", inittime},
187 {"audioop", initaudioop},
188 {"imageop", initimageop},
189 {"rgbimg", initrgbimg},
190 {"stdwin", initstdwin},
191 {"md5", initmd5},
192 {"rotor", initrotor},
193
194/* -- ADDMODULE MARKER 2 -- */
195
196 /* This module "lives in" with marshal.c */
197 {"marshal", initmarshal},
198
199 /* These entries are here for sys.builtin_module_names */
200 {"__main__", NULL},
201 {"__builtin__", NULL},
202 {"sys", NULL},
203
204 /* Sentinel */
205 {0, 0}
206};
207
208#ifdef USE_FROZEN
209#include "frozen.c"
210#else
211struct frozen {
212 char *name;
213 char *code;
214 int size;
215} frozen_modules[] = {
216 {0, 0, 0}
217};
218#endif