blob: 7019043772a3df3242d64409ce72cab9e2f40db3 [file] [log] [blame]
Guido van Rossumd4d77281994-08-19 10:51:31 +00001/* -*- C -*- ***********************************************
Guido van Rossum99546991995-01-08 14:33:34 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumce9739b1994-01-05 16:17:15 +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 Rossum29e7af01994-08-23 13:28:34 +000025/* Macintosh Python configuration file */
Guido van Rossumce9739b1994-01-05 16:17:15 +000026
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
Guido van Rossum29e7af01994-08-23 13:28:34 +000031#ifdef macintosh
32/* The Macintosh main program is in macmain.c */
33#define NO_MAIN
Jack Jansen0f6ca801995-02-13 11:36:25 +000034char *fileargument; /* So main() can tell us the program name */
Guido van Rossum29e7af01994-08-23 13:28:34 +000035#endif
36
Guido van Rossumce9739b1994-01-05 16:17:15 +000037#include <stdio.h>
38#include <string.h>
39
40#include "myproto.h"
41#include "mymalloc.h"
42#include "osdefs.h"
Guido van Rossumd4d77281994-08-19 10:51:31 +000043#include "intrcheck.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000044
Jack Jansen0f6ca801995-02-13 11:36:25 +000045char *PyMac_GetPythonDir();
Guido van Rossumce9739b1994-01-05 16:17:15 +000046
47#ifndef NO_MAIN
48
49/* Normally, the main program is called from here (so everything else
50 can be in libPython.a). We save a pointer to argv[0] because it
51 may be needed for dynamic loading of modules in import.c. If you
52 have your own main program and want to use non-SunOS dynamic
53 loading, you will have to provide your own version of
54 getprogramname(). */
55
56static char *argv0;
57
58main(argc, argv)
59 int argc;
60 char **argv;
61{
Guido van Rossumce9739b1994-01-05 16:17:15 +000062 argv0 = argv[0];
63 realmain(argc, argv);
64}
65
66char *
67getprogramname()
68{
69 return argv0;
70}
71
72#endif
73
74
Guido van Rossumd4d77281994-08-19 10:51:31 +000075/* Python version information */
76
77#include "patchlevel.h"
78
79/* Return the version string. This is constructed from the official
80 version number (from patchlevel.h), and the current date (if known
81 to the compiler, else a manually inserted date). */
82
83#define VERSION "%s (%s)"
84
85#ifdef __DATE__
86#define DATE __DATE__
87#else
88#define DATE "Aug 17 1994"
89#endif
90
91char *
92getversion()
93{
94 static char version[80];
95 sprintf(version, VERSION, PATCHLEVEL, DATE);
Jack Jansenc5b26f41994-12-14 13:45:11 +000096#ifdef __MWERKS__
97#ifdef __powerc
98 strcat(version, " [MW PPC compiler]");
99#else
100 strcat(version, " [MW 68K compiler]");
101#endif
102#endif
Guido van Rossumd4d77281994-08-19 10:51:31 +0000103 return version;
104}
105
106
107/* Return the copyright string. This is updated manually. */
108
109char *
110getcopyright()
111{
Guido van Rossumc9a35691995-01-25 23:10:10 +0000112 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossumd4d77281994-08-19 10:51:31 +0000113}
114
115
Guido van Rossumce9739b1994-01-05 16:17:15 +0000116/* Return the initial python search path. This is called once from
117 initsys() to initialize sys.path.
118 The environment variable PYTHONPATH is fetched and the default path
119 appended. (The Mac has no environment variables, so there the
120 default path is always returned.) The default path may be passed
121 to the preprocessor; if not, a system-dependent default is used. */
122
Guido van Rossumc9a35691995-01-25 23:10:10 +0000123#define PYTHONPATH "\
124:\n\
125:Lib\n\
126:Lib:stdwin\n\
127:Lib:test\n\
128:Lib:mac"
129
Guido van Rossumce9739b1994-01-05 16:17:15 +0000130#ifndef PYTHONPATH
131#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000132/* Mod by Jack: \n is now separator. */
133#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac"
Guido van Rossumce9739b1994-01-05 16:17:15 +0000134#endif /* macintosh */
135#endif /* !PYTHONPATH */
136
137#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000138#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000139#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000140#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000141#endif /* !PYTHONPATH */
142
143#ifndef PYTHONPATH
144#define PYTHONPATH ".:/usr/local/lib/python"
145#endif /* !PYTHONPATH */
146
147extern char *getenv();
148
149char *
150getpythonpath()
151{
152#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000153 /* Modified by Jack to do something a bit more sensible:
154 ** - Prepend the current directory (which is presumably where python lives)
155 ** - Add :
156 ** - Chdir to where the source file (if any) lives
157 */
158 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000159 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000160 char *p, *endp;
161 int newlen;
162
163 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000164 curwd = PyMac_GetPythonDir();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000165 p = PYTHONPATH;
166 endp = p;
167 pythonpath = malloc(2);
168 if ( pythonpath == NULL ) return PYTHONPATH;
169 strcpy(pythonpath, ":");
170 while (*endp) {
171 endp = strchr(p, '\n');
172 if ( endp == NULL )
173 endp = p + strlen(p);
174 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
175 pythonpath = realloc(pythonpath, newlen+1);
176 if ( pythonpath == NULL ) return PYTHONPATH;
177 strcat(pythonpath, "\n");
178 if ( *p == ':' ) {
179 p++;
180 strcat(pythonpath, curwd);
181 strncat(pythonpath, p, (endp-p));
182 newlen--; /* Ok, ok, we've allocated one byte too much */
183 } else {
184 /* We've allocated too much in this case */
185 newlen -= strlen(curwd);
186 pythonpath = realloc(pythonpath, newlen+1);
187 if ( pythonpath == NULL ) return PYTHONPATH;
188 strncat(pythonpath, p, (endp-p));
189 }
190 pythonpath[newlen] = '\0';
191 p = endp + 1;
192 }
193 if ( fileargument ) {
194 strcpy(curwd, fileargument);
195 endp = strrchr(curwd, ':');
196 if ( endp && endp > curwd ) {
197 *endp = '\0';
198 chdir(curwd);
199 }
200 }
201 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000202#else /* !macintosh */
203 char *path = getenv("PYTHONPATH");
204 char *defpath = PYTHONPATH;
205 char *buf;
206 char *p;
207 int n;
208
209 if (path == 0 || *path == '\0')
210 return defpath;
211 n = strlen(path) + strlen(defpath) + 2;
212 buf = malloc(n);
213 if (buf == NULL)
214 return path; /* XXX too bad -- but not likely */
215 strcpy(buf, path);
216 p = buf + strlen(buf);
217 *p++ = DELIM;
218 strcpy(p, defpath);
219 return buf;
220#endif /* !macintosh */
221}
222
223
224/* Table of built-in modules.
225 These are initialized when first imported.
226 Note: selection of optional extensions is now generally done by the
227 makesetup script. */
228
229extern void initarray();
230extern void initmath();
231extern void initparser();
232extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000233extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000234extern void initregex();
235extern void initstrop();
236extern void initstruct();
237extern void inittime();
238extern void initdbm();
239extern void initfcntl();
240extern void initnis();
241extern void initpwd();
242extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000243extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000244extern void initselect();
245extern void initsocket();
246extern void initaudioop();
247extern void initimageop();
248extern void initrgbimg();
249extern void initstdwin();
250extern void initmd5();
251extern void initmpz();
252extern void initrotor();
253extern void inital();
254extern void initcd();
255extern void initcl();
256extern void initfm();
257extern void initgl();
258extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000259extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000260extern void initsgi();
261extern void initsv();
262extern void initfl();
263extern void initthread();
264extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000265extern void initsignal();
266extern void initnew();
267extern void initdl();
268extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000269extern void initgestalt();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000270extern void initmacconsole();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000271extern void initctb();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000272extern void initmacfs();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000273extern void initmacspeech();
274extern void initmacdnr();
275extern void initmactcp();
Guido van Rossum6a5df901995-01-18 23:59:06 +0000276extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000277extern void initCtl();
278extern void initDlg();
279extern void initEvt();
280extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000281extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000282extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000283extern void initSnd();
284extern void initWin();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000285
286/* -- ADDMODULE MARKER 1 -- */
287
288extern void initmarshal();
289
290struct {
291 char *name;
292 void (*initfunc)();
293} inittab[] = {
294
295 {"array", initarray},
296 {"math", initmath},
297 {"parser", initparser},
298 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000299 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000300 {"regex", initregex},
301 {"strop", initstrop},
302 {"struct", initstruct},
303 {"time", inittime},
304 {"audioop", initaudioop},
305 {"imageop", initimageop},
306 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000307#ifdef USE_STDWIN
308 {"stdwin", initstdwin},
309#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000310 {"md5", initmd5},
311 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000312 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000313 {"gestalt", initgestalt},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000314#ifdef THINK_C
Jack Jansenc5b26f41994-12-14 13:45:11 +0000315 {"macconsole", initmacconsole},
316#endif
317 {"ctb", initctb},
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000318 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000319#ifdef __MWERKS__
320/* This is really "Jack Jansen" specific for now :-) */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000321 {"macspeech", initmacspeech},
Jack Jansenc5b26f41994-12-14 13:45:11 +0000322 {"macdnr", initmacdnr},
323 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000324#endif
Guido van Rossum6a5df901995-01-18 23:59:06 +0000325/* This is really "Guido van Rossum" specific... :-) */
326 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000327 {"Ctl", initCtl},
328 {"Dlg", initDlg},
329 {"Evt", initEvt},
330 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000331 {"Qd", initQd},
Guido van Rossumd8373d81995-01-22 18:37:45 +0000332 {"Res", initRes},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000333 {"Snd", initSnd},
334 {"Win", initWin},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000335
336/* -- ADDMODULE MARKER 2 -- */
337
338 /* This module "lives in" with marshal.c */
339 {"marshal", initmarshal},
340
341 /* These entries are here for sys.builtin_module_names */
342 {"__main__", NULL},
343 {"__builtin__", NULL},
344 {"sys", NULL},
345
346 /* Sentinel */
347 {0, 0}
348};
349
350#ifdef USE_FROZEN
351#include "frozen.c"
352#else
353struct frozen {
354 char *name;
355 char *code;
356 int size;
357} frozen_modules[] = {
358 {0, 0, 0}
359};
360#endif