blob: 224be8b0ba577054230a6f5b0d44001bd3edb57a [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
131
Guido van Rossumce9739b1994-01-05 16:17:15 +0000132/* Return the initial python search path. This is called once from
133 initsys() to initialize sys.path.
134 The environment variable PYTHONPATH is fetched and the default path
135 appended. (The Mac has no environment variables, so there the
136 default path is always returned.) The default path may be passed
137 to the preprocessor; if not, a system-dependent default is used. */
138
Guido van Rossumc9a35691995-01-25 23:10:10 +0000139#define PYTHONPATH "\
140:\n\
141:Lib\n\
142:Lib:stdwin\n\
143:Lib:test\n\
144:Lib:mac"
145
Guido van Rossumce9739b1994-01-05 16:17:15 +0000146#ifndef PYTHONPATH
147#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000148/* Mod by Jack: \n is now separator. */
Jack Jansen68f1d451995-06-18 19:57:01 +0000149#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 +0000150#endif /* macintosh */
151#endif /* !PYTHONPATH */
152
153#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000154#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000155#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000156#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000157#endif /* !PYTHONPATH */
158
159#ifndef PYTHONPATH
160#define PYTHONPATH ".:/usr/local/lib/python"
161#endif /* !PYTHONPATH */
162
163extern char *getenv();
164
165char *
166getpythonpath()
167{
168#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000169 /* Modified by Jack to do something a bit more sensible:
Jack Jansen86b40491995-02-20 15:57:12 +0000170 ** - Prepend the python home-directory (which is obtained from a Preferences
171 ** resource)
Jack Jansenc5b26f41994-12-14 13:45:11 +0000172 ** - Add :
Jack Jansenc5b26f41994-12-14 13:45:11 +0000173 */
174 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000175 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000176 char *p, *endp;
177 int newlen;
Jack Jansen76efd8e1995-02-24 22:53:16 +0000178 extern char *PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000179#ifndef USE_BUILTIN_PATH
180 extern char *PyMac_GetPythonPath();
181#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000182
183 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000184 curwd = PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000185#ifndef USE_BUILTIN_PATH
186 if ( pythonpath = PyMac_GetPythonPath(curwd) )
187 return pythonpath;
188 printf("Warning: No pythonpath resource found, using builtin default\n");
189#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000190 p = PYTHONPATH;
191 endp = p;
192 pythonpath = malloc(2);
193 if ( pythonpath == NULL ) return PYTHONPATH;
194 strcpy(pythonpath, ":");
195 while (*endp) {
196 endp = strchr(p, '\n');
197 if ( endp == NULL )
198 endp = p + strlen(p);
199 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
200 pythonpath = realloc(pythonpath, newlen+1);
201 if ( pythonpath == NULL ) return PYTHONPATH;
202 strcat(pythonpath, "\n");
203 if ( *p == ':' ) {
204 p++;
205 strcat(pythonpath, curwd);
206 strncat(pythonpath, p, (endp-p));
207 newlen--; /* Ok, ok, we've allocated one byte too much */
208 } else {
209 /* We've allocated too much in this case */
210 newlen -= strlen(curwd);
211 pythonpath = realloc(pythonpath, newlen+1);
212 if ( pythonpath == NULL ) return PYTHONPATH;
213 strncat(pythonpath, p, (endp-p));
214 }
215 pythonpath[newlen] = '\0';
216 p = endp + 1;
217 }
Jack Jansenc5b26f41994-12-14 13:45:11 +0000218 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000219#else /* !macintosh */
220 char *path = getenv("PYTHONPATH");
221 char *defpath = PYTHONPATH;
222 char *buf;
223 char *p;
224 int n;
225
226 if (path == 0 || *path == '\0')
227 return defpath;
228 n = strlen(path) + strlen(defpath) + 2;
229 buf = malloc(n);
230 if (buf == NULL)
231 return path; /* XXX too bad -- but not likely */
232 strcpy(buf, path);
233 p = buf + strlen(buf);
234 *p++ = DELIM;
235 strcpy(p, defpath);
236 return buf;
237#endif /* !macintosh */
238}
239
240
241/* Table of built-in modules.
242 These are initialized when first imported.
243 Note: selection of optional extensions is now generally done by the
244 makesetup script. */
245
246extern void initarray();
247extern void initmath();
248extern void initparser();
249extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000250extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000251extern void initregex();
252extern void initstrop();
253extern void initstruct();
254extern void inittime();
255extern void initdbm();
256extern void initfcntl();
257extern void initnis();
258extern void initpwd();
259extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000260extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000261extern void initselect();
262extern void initsocket();
263extern void initaudioop();
264extern void initimageop();
265extern void initrgbimg();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000266#ifdef USE_STDWIN
Guido van Rossumce9739b1994-01-05 16:17:15 +0000267extern void initstdwin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000268#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000269extern void initmd5();
270extern void initmpz();
271extern void initrotor();
272extern void inital();
273extern void initcd();
274extern void initcl();
275extern void initfm();
276extern void initgl();
277extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000278extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000279extern void initsgi();
280extern void initsv();
281extern void initfl();
282extern void initthread();
283extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000284extern void initsignal();
285extern void initnew();
286extern void initdl();
287extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000288extern void initgestalt();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000289extern void initmacfs();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000290#ifdef THINK
291extern void initmacconsole();
292#endif
293#ifdef USE_MACCTB
294extern void initctb();
295#endif
296#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000297extern void initmacspeech();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000298#endif
299#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000300extern void initmacdnr();
301extern void initmactcp();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000302#endif
303#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000304extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000305extern void initCtl();
306extern void initDlg();
307extern void initEvt();
308extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000309extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000310extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000311extern void initSnd();
312extern void initWin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000313#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000314
Jack Jansen3f0c1551995-06-14 14:47:21 +0000315#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000316extern void initimgcolormap();
317extern void initimgformat();
318extern void initimggif();
319extern void initimgjpeg();
320extern void initimgppm();
321extern void initimgpgm();
322extern void initimgtiff();
323extern void initimgop();
324#endif
325
Guido van Rossumce9739b1994-01-05 16:17:15 +0000326/* -- ADDMODULE MARKER 1 -- */
327
328extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000329extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000330
331struct {
332 char *name;
333 void (*initfunc)();
334} inittab[] = {
335
336 {"array", initarray},
Jack Jansenf74f63a1995-06-27 13:18:14 +0000337#ifndef SYMANTEC__CFM68K__
Guido van Rossumedea4081995-02-21 21:01:47 +0000338/* The math library seems mostly broken... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000339 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000340#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000341 {"parser", initparser},
342 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000343 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000344 {"regex", initregex},
345 {"strop", initstrop},
346 {"struct", initstruct},
347 {"time", inittime},
348 {"audioop", initaudioop},
349 {"imageop", initimageop},
350 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000351#ifdef USE_STDWIN
352 {"stdwin", initstdwin},
353#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000354 {"md5", initmd5},
355 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000356 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000357 {"gestalt", initgestalt},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000358 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000359#ifdef THINK_C
Guido van Rossumedea4081995-02-21 21:01:47 +0000360/* This is an interface to the Think runtime */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000361 {"macconsole", initmacconsole},
362#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000363#ifdef USE_MACCTB
Jack Jansenc5b26f41994-12-14 13:45:11 +0000364 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000365#endif
Guido van Rossumedea4081995-02-21 21:01:47 +0000366/* This could probably be made to work on other compilers... */
Jack Jansen3f0c1551995-06-14 14:47:21 +0000367#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000368 {"macspeech", initmacspeech},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000369#endif
370#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000371 {"macdnr", initmacdnr},
372 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000373#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000374#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000375 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000376 {"Ctl", initCtl},
377 {"Dlg", initDlg},
378 {"Evt", initEvt},
379 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000380 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000381 {"Snd", initSnd},
382 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000383 {"Res", initRes},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000384#endif
385#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000386 {"imgcolormap", initimgcolormap},
387 {"imgformat", initimgformat},
388 {"imggif", initimggif},
389 {"imgjpeg", initimgjpeg},
390 {"imgppm", initimgppm},
391 {"imgpgm", initimgpgm},
392 {"imgtiff", initimgtiff},
393 {"imgop", initimgop},
394#endif
395
Guido van Rossumce9739b1994-01-05 16:17:15 +0000396/* -- ADDMODULE MARKER 2 -- */
397
398 /* This module "lives in" with marshal.c */
399 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000400
401 /* This module "lives in" with import.c */
402 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000403
404 /* These entries are here for sys.builtin_module_names */
405 {"__main__", NULL},
406 {"__builtin__", NULL},
407 {"sys", NULL},
408
409 /* Sentinel */
410 {0, 0}
411};
412
413#ifdef USE_FROZEN
414#include "frozen.c"
415#else
416struct frozen {
417 char *name;
418 char *code;
419 int size;
420} frozen_modules[] = {
421 {0, 0, 0}
422};
423#endif