blob: a0baf2334b3c0b4cabb968b059b3462fbbd28807 [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
Jack Jansen76efd8e1995-02-24 22:53:16 +000032/* The Macintosh main program is in either macapplet.c or macapplication.c */
Guido van Rossum29e7af01994-08-23 13:28:34 +000033#define NO_MAIN
Guido van Rossum29e7af01994-08-23 13:28:34 +000034#endif
35
Guido van Rossumce9739b1994-01-05 16:17:15 +000036#include <stdio.h>
37#include <string.h>
38
39#include "myproto.h"
40#include "mymalloc.h"
41#include "osdefs.h"
Guido van Rossumd4d77281994-08-19 10:51:31 +000042#include "intrcheck.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000043
44
45#ifndef NO_MAIN
46
47/* 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(). */
53
54static char *argv0;
55
56main(argc, argv)
57 int argc;
58 char **argv;
59{
Guido van Rossumce9739b1994-01-05 16:17:15 +000060 argv0 = argv[0];
61 realmain(argc, argv);
62}
63
64char *
65getprogramname()
66{
67 return argv0;
68}
69
70#endif
71
72
Guido van Rossumd4d77281994-08-19 10:51:31 +000073/* Python version information */
74
75#include "patchlevel.h"
76
77/* Return the version string. This is constructed from the official
78 version number (from patchlevel.h), and the current date (if known
79 to the compiler, else a manually inserted date). */
80
81#define VERSION "%s (%s)"
82
83#ifdef __DATE__
84#define DATE __DATE__
85#else
86#define DATE "Aug 17 1994"
87#endif
88
89char *
90getversion()
91{
92 static char version[80];
93 sprintf(version, VERSION, PATCHLEVEL, DATE);
Jack Jansenc5b26f41994-12-14 13:45:11 +000094#ifdef __MWERKS__
95#ifdef __powerc
96 strcat(version, " [MW PPC compiler]");
97#else
Jack Jansenf74f63a1995-06-27 13:18:14 +000098#ifdef __CFM68K__
99 strcat(version, " [MW CFM68K compiler]");
100#else
Jack Jansenc5b26f41994-12-14 13:45:11 +0000101 strcat(version, " [MW 68K compiler]");
102#endif
103#endif
Jack Jansenf74f63a1995-06-27 13:18:14 +0000104#endif
Guido van Rossumbecdbec1995-02-14 01:27:24 +0000105#ifdef THINK_C
106#ifdef __SC__
107 strcat(version, " [Symantec Think C compiler]");
108#else
109 strcat(version, " [Think C compiler]");
110#endif
111#endif
112#ifdef MPW
113#ifdef __SC__
114 strcat(version, " [Symantec MPW C compiler]");
115#else
116 strcat(version, " [Apple MPW C compiler]");
117#endif
118#endif
Guido van Rossumd4d77281994-08-19 10:51:31 +0000119 return version;
120}
121
122
123/* Return the copyright string. This is updated manually. */
124
125char *
126getcopyright()
127{
Guido van Rossumc9a35691995-01-25 23:10:10 +0000128 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossumd4d77281994-08-19 10:51:31 +0000129}
130
Jack Jansen4cae5e61995-07-28 11:29:54 +0000131char *
132getplatform()
133{
134 return "mac";
135}
Guido van Rossumd4d77281994-08-19 10:51:31 +0000136
Guido van Rossumce9739b1994-01-05 16:17:15 +0000137/* Return the initial python search path. This is called once from
138 initsys() to initialize sys.path.
139 The environment variable PYTHONPATH is fetched and the default path
140 appended. (The Mac has no environment variables, so there the
141 default path is always returned.) The default path may be passed
142 to the preprocessor; if not, a system-dependent default is used. */
143
Guido van Rossumc9a35691995-01-25 23:10:10 +0000144#define PYTHONPATH "\
145:\n\
146:Lib\n\
147:Lib:stdwin\n\
148:Lib:test\n\
149:Lib:mac"
150
Guido van Rossumce9739b1994-01-05 16:17:15 +0000151#ifndef PYTHONPATH
152#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000153/* Mod by Jack: \n is now separator. */
Jack Jansen68f1d451995-06-18 19:57:01 +0000154#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac\n:PackedLib\n:PlugIns"
Guido van Rossumce9739b1994-01-05 16:17:15 +0000155#endif /* macintosh */
156#endif /* !PYTHONPATH */
157
158#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000159#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000160#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000161#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000162#endif /* !PYTHONPATH */
163
164#ifndef PYTHONPATH
165#define PYTHONPATH ".:/usr/local/lib/python"
166#endif /* !PYTHONPATH */
167
168extern char *getenv();
169
170char *
171getpythonpath()
172{
173#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000174 /* Modified by Jack to do something a bit more sensible:
Jack Jansen86b40491995-02-20 15:57:12 +0000175 ** - Prepend the python home-directory (which is obtained from a Preferences
176 ** resource)
Jack Jansenc5b26f41994-12-14 13:45:11 +0000177 ** - Add :
Jack Jansenc5b26f41994-12-14 13:45:11 +0000178 */
179 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000180 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000181 char *p, *endp;
182 int newlen;
Jack Jansen76efd8e1995-02-24 22:53:16 +0000183 extern char *PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000184#ifndef USE_BUILTIN_PATH
185 extern char *PyMac_GetPythonPath();
186#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000187
188 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000189 curwd = PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000190#ifndef USE_BUILTIN_PATH
191 if ( pythonpath = PyMac_GetPythonPath(curwd) )
192 return pythonpath;
193 printf("Warning: No pythonpath resource found, using builtin default\n");
194#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000195 p = PYTHONPATH;
196 endp = p;
197 pythonpath = malloc(2);
198 if ( pythonpath == NULL ) return PYTHONPATH;
199 strcpy(pythonpath, ":");
200 while (*endp) {
201 endp = strchr(p, '\n');
202 if ( endp == NULL )
203 endp = p + strlen(p);
204 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
205 pythonpath = realloc(pythonpath, newlen+1);
206 if ( pythonpath == NULL ) return PYTHONPATH;
207 strcat(pythonpath, "\n");
208 if ( *p == ':' ) {
209 p++;
210 strcat(pythonpath, curwd);
211 strncat(pythonpath, p, (endp-p));
212 newlen--; /* Ok, ok, we've allocated one byte too much */
213 } else {
214 /* We've allocated too much in this case */
215 newlen -= strlen(curwd);
216 pythonpath = realloc(pythonpath, newlen+1);
217 if ( pythonpath == NULL ) return PYTHONPATH;
218 strncat(pythonpath, p, (endp-p));
219 }
220 pythonpath[newlen] = '\0';
221 p = endp + 1;
222 }
Jack Jansenc5b26f41994-12-14 13:45:11 +0000223 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000224#else /* !macintosh */
225 char *path = getenv("PYTHONPATH");
226 char *defpath = PYTHONPATH;
227 char *buf;
228 char *p;
229 int n;
230
231 if (path == 0 || *path == '\0')
232 return defpath;
233 n = strlen(path) + strlen(defpath) + 2;
234 buf = malloc(n);
235 if (buf == NULL)
236 return path; /* XXX too bad -- but not likely */
237 strcpy(buf, path);
238 p = buf + strlen(buf);
239 *p++ = DELIM;
240 strcpy(p, defpath);
241 return buf;
242#endif /* !macintosh */
243}
244
245
246/* Table of built-in modules.
247 These are initialized when first imported.
248 Note: selection of optional extensions is now generally done by the
249 makesetup script. */
250
251extern void initarray();
252extern void initmath();
253extern void initparser();
254extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000255extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000256extern void initregex();
257extern void initstrop();
258extern void initstruct();
259extern void inittime();
260extern void initdbm();
261extern void initfcntl();
262extern void initnis();
263extern void initpwd();
264extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000265extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000266extern void initselect();
267extern void initsocket();
268extern void initaudioop();
269extern void initimageop();
270extern void initrgbimg();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000271#ifdef USE_STDWIN
Guido van Rossumce9739b1994-01-05 16:17:15 +0000272extern void initstdwin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000273#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000274extern void initmd5();
275extern void initmpz();
276extern void initrotor();
277extern void inital();
278extern void initcd();
279extern void initcl();
280extern void initfm();
281extern void initgl();
282extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000283extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000284extern void initsgi();
285extern void initsv();
286extern void initfl();
287extern void initthread();
288extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000289extern void initsignal();
Jack Jansen4cae5e61995-07-28 11:29:54 +0000290#if 0
Guido van Rossumd4d77281994-08-19 10:51:31 +0000291extern void initnew();
Jack Jansen4cae5e61995-07-28 11:29:54 +0000292#endif
Guido van Rossumd4d77281994-08-19 10:51:31 +0000293extern void initdl();
294extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000295extern void initgestalt();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000296extern void initmacfs();
Jack Jansena7b6a821995-08-07 14:35:24 +0000297extern void initbinascii();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000298#ifdef THINK
299extern void initmacconsole();
300#endif
301#ifdef USE_MACCTB
302extern void initctb();
303#endif
304#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000305extern void initmacspeech();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000306#endif
307#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000308extern void initmacdnr();
309extern void initmactcp();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000310#endif
311#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000312extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000313extern void initCtl();
314extern void initDlg();
315extern void initEvt();
316extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000317extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000318extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000319extern void initSnd();
320extern void initWin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000321#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000322
Jack Jansen3f0c1551995-06-14 14:47:21 +0000323#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000324extern void initimgcolormap();
325extern void initimgformat();
326extern void initimggif();
327extern void initimgjpeg();
328extern void initimgppm();
329extern void initimgpgm();
330extern void initimgtiff();
331extern void initimgop();
332#endif
333
Guido van Rossumce9739b1994-01-05 16:17:15 +0000334/* -- ADDMODULE MARKER 1 -- */
335
336extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000337extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000338
339struct {
340 char *name;
341 void (*initfunc)();
342} inittab[] = {
343
344 {"array", initarray},
Jack Jansenf74f63a1995-06-27 13:18:14 +0000345#ifndef SYMANTEC__CFM68K__
Guido van Rossumedea4081995-02-21 21:01:47 +0000346/* The math library seems mostly broken... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000347 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000348#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000349 {"parser", initparser},
350 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000351 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000352 {"regex", initregex},
353 {"strop", initstrop},
354 {"struct", initstruct},
355 {"time", inittime},
356 {"audioop", initaudioop},
357 {"imageop", initimageop},
358 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000359#ifdef USE_STDWIN
360 {"stdwin", initstdwin},
361#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000362 {"md5", initmd5},
363 {"rotor", initrotor},
Jack Jansen4cae5e61995-07-28 11:29:54 +0000364#if 0
Guido van Rossumd4d77281994-08-19 10:51:31 +0000365 {"new", initnew},
Jack Jansen4cae5e61995-07-28 11:29:54 +0000366#endif
Guido van Rossum29e7af01994-08-23 13:28:34 +0000367 {"gestalt", initgestalt},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000368 {"macfs", initmacfs},
Jack Jansena7b6a821995-08-07 14:35:24 +0000369 {"binascii", initbinascii},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000370#ifdef THINK_C
Guido van Rossumedea4081995-02-21 21:01:47 +0000371/* This is an interface to the Think runtime */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000372 {"macconsole", initmacconsole},
373#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000374#ifdef USE_MACCTB
Jack Jansenc5b26f41994-12-14 13:45:11 +0000375 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000376#endif
Guido van Rossumedea4081995-02-21 21:01:47 +0000377/* This could probably be made to work on other compilers... */
Jack Jansen3f0c1551995-06-14 14:47:21 +0000378#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000379 {"macspeech", initmacspeech},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000380#endif
381#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000382 {"macdnr", initmacdnr},
383 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000384#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000385#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000386 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000387 {"Ctl", initCtl},
388 {"Dlg", initDlg},
389 {"Evt", initEvt},
390 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000391 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000392 {"Snd", initSnd},
393 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000394 {"Res", initRes},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000395#endif
396#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000397 {"imgcolormap", initimgcolormap},
398 {"imgformat", initimgformat},
399 {"imggif", initimggif},
400 {"imgjpeg", initimgjpeg},
401 {"imgppm", initimgppm},
402 {"imgpgm", initimgpgm},
403 {"imgtiff", initimgtiff},
404 {"imgop", initimgop},
405#endif
406
Guido van Rossumce9739b1994-01-05 16:17:15 +0000407/* -- ADDMODULE MARKER 2 -- */
408
409 /* This module "lives in" with marshal.c */
410 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000411
412 /* This module "lives in" with import.c */
413 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000414
415 /* These entries are here for sys.builtin_module_names */
416 {"__main__", NULL},
417 {"__builtin__", NULL},
418 {"sys", NULL},
419
420 /* Sentinel */
421 {0, 0}
422};
423
424#ifdef USE_FROZEN
425#include "frozen.c"
426#else
427struct frozen {
428 char *name;
429 char *code;
430 int size;
431} frozen_modules[] = {
432 {0, 0, 0}
433};
434#endif