blob: 385372a49508fb4cb0842f8a1d1da3eb222d1573 [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
98 strcat(version, " [MW 68K compiler]");
99#endif
100#endif
Guido van Rossumbecdbec1995-02-14 01:27:24 +0000101#ifdef THINK_C
102#ifdef __SC__
103 strcat(version, " [Symantec Think C compiler]");
104#else
105 strcat(version, " [Think C compiler]");
106#endif
107#endif
108#ifdef MPW
109#ifdef __SC__
110 strcat(version, " [Symantec MPW C compiler]");
111#else
112 strcat(version, " [Apple MPW C compiler]");
113#endif
114#endif
Guido van Rossumd4d77281994-08-19 10:51:31 +0000115 return version;
116}
117
118
119/* Return the copyright string. This is updated manually. */
120
121char *
122getcopyright()
123{
Guido van Rossumc9a35691995-01-25 23:10:10 +0000124 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossumd4d77281994-08-19 10:51:31 +0000125}
126
127
Guido van Rossumce9739b1994-01-05 16:17:15 +0000128/* Return the initial python search path. This is called once from
129 initsys() to initialize sys.path.
130 The environment variable PYTHONPATH is fetched and the default path
131 appended. (The Mac has no environment variables, so there the
132 default path is always returned.) The default path may be passed
133 to the preprocessor; if not, a system-dependent default is used. */
134
Guido van Rossumc9a35691995-01-25 23:10:10 +0000135#define PYTHONPATH "\
136:\n\
137:Lib\n\
138:Lib:stdwin\n\
139:Lib:test\n\
140:Lib:mac"
141
Guido van Rossumce9739b1994-01-05 16:17:15 +0000142#ifndef PYTHONPATH
143#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000144/* Mod by Jack: \n is now separator. */
Jack Jansen68f1d451995-06-18 19:57:01 +0000145#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 +0000146#endif /* macintosh */
147#endif /* !PYTHONPATH */
148
149#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000150#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000151#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000152#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000153#endif /* !PYTHONPATH */
154
155#ifndef PYTHONPATH
156#define PYTHONPATH ".:/usr/local/lib/python"
157#endif /* !PYTHONPATH */
158
159extern char *getenv();
160
161char *
162getpythonpath()
163{
164#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000165 /* Modified by Jack to do something a bit more sensible:
Jack Jansen86b40491995-02-20 15:57:12 +0000166 ** - Prepend the python home-directory (which is obtained from a Preferences
167 ** resource)
Jack Jansenc5b26f41994-12-14 13:45:11 +0000168 ** - Add :
Jack Jansenc5b26f41994-12-14 13:45:11 +0000169 */
170 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000171 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000172 char *p, *endp;
173 int newlen;
Jack Jansen76efd8e1995-02-24 22:53:16 +0000174 extern char *PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000175#ifndef USE_BUILTIN_PATH
176 extern char *PyMac_GetPythonPath();
177#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000178
179 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000180 curwd = PyMac_GetPythonDir();
Jack Jansen68f1d451995-06-18 19:57:01 +0000181#ifndef USE_BUILTIN_PATH
182 if ( pythonpath = PyMac_GetPythonPath(curwd) )
183 return pythonpath;
184 printf("Warning: No pythonpath resource found, using builtin default\n");
185#endif
Jack Jansenc5b26f41994-12-14 13:45:11 +0000186 p = PYTHONPATH;
187 endp = p;
188 pythonpath = malloc(2);
189 if ( pythonpath == NULL ) return PYTHONPATH;
190 strcpy(pythonpath, ":");
191 while (*endp) {
192 endp = strchr(p, '\n');
193 if ( endp == NULL )
194 endp = p + strlen(p);
195 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
196 pythonpath = realloc(pythonpath, newlen+1);
197 if ( pythonpath == NULL ) return PYTHONPATH;
198 strcat(pythonpath, "\n");
199 if ( *p == ':' ) {
200 p++;
201 strcat(pythonpath, curwd);
202 strncat(pythonpath, p, (endp-p));
203 newlen--; /* Ok, ok, we've allocated one byte too much */
204 } else {
205 /* We've allocated too much in this case */
206 newlen -= strlen(curwd);
207 pythonpath = realloc(pythonpath, newlen+1);
208 if ( pythonpath == NULL ) return PYTHONPATH;
209 strncat(pythonpath, p, (endp-p));
210 }
211 pythonpath[newlen] = '\0';
212 p = endp + 1;
213 }
Jack Jansenc5b26f41994-12-14 13:45:11 +0000214 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000215#else /* !macintosh */
216 char *path = getenv("PYTHONPATH");
217 char *defpath = PYTHONPATH;
218 char *buf;
219 char *p;
220 int n;
221
222 if (path == 0 || *path == '\0')
223 return defpath;
224 n = strlen(path) + strlen(defpath) + 2;
225 buf = malloc(n);
226 if (buf == NULL)
227 return path; /* XXX too bad -- but not likely */
228 strcpy(buf, path);
229 p = buf + strlen(buf);
230 *p++ = DELIM;
231 strcpy(p, defpath);
232 return buf;
233#endif /* !macintosh */
234}
235
236
237/* Table of built-in modules.
238 These are initialized when first imported.
239 Note: selection of optional extensions is now generally done by the
240 makesetup script. */
241
242extern void initarray();
243extern void initmath();
244extern void initparser();
245extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000246extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000247extern void initregex();
248extern void initstrop();
249extern void initstruct();
250extern void inittime();
251extern void initdbm();
252extern void initfcntl();
253extern void initnis();
254extern void initpwd();
255extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000256extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000257extern void initselect();
258extern void initsocket();
259extern void initaudioop();
260extern void initimageop();
261extern void initrgbimg();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000262#ifdef USE_STDWIN
Guido van Rossumce9739b1994-01-05 16:17:15 +0000263extern void initstdwin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000264#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000265extern void initmd5();
266extern void initmpz();
267extern void initrotor();
268extern void inital();
269extern void initcd();
270extern void initcl();
271extern void initfm();
272extern void initgl();
273extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000274extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000275extern void initsgi();
276extern void initsv();
277extern void initfl();
278extern void initthread();
279extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000280extern void initsignal();
281extern void initnew();
282extern void initdl();
283extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000284extern void initgestalt();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000285extern void initmacfs();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000286#ifdef THINK
287extern void initmacconsole();
288#endif
289#ifdef USE_MACCTB
290extern void initctb();
291#endif
292#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000293extern void initmacspeech();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000294#endif
295#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000296extern void initmacdnr();
297extern void initmactcp();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000298#endif
299#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000300extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000301extern void initCtl();
302extern void initDlg();
303extern void initEvt();
304extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000305extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000306extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000307extern void initSnd();
308extern void initWin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000309#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000310
Jack Jansen3f0c1551995-06-14 14:47:21 +0000311#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000312extern void initimgcolormap();
313extern void initimgformat();
314extern void initimggif();
315extern void initimgjpeg();
316extern void initimgppm();
317extern void initimgpgm();
318extern void initimgtiff();
319extern void initimgop();
320#endif
321
Guido van Rossumce9739b1994-01-05 16:17:15 +0000322/* -- ADDMODULE MARKER 1 -- */
323
324extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000325extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000326
327struct {
328 char *name;
329 void (*initfunc)();
330} inittab[] = {
331
332 {"array", initarray},
Guido van Rossumedea4081995-02-21 21:01:47 +0000333#ifndef __CFM68K__
334/* The math library seems mostly broken... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000335 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000336#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000337 {"parser", initparser},
338 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000339 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000340 {"regex", initregex},
341 {"strop", initstrop},
342 {"struct", initstruct},
343 {"time", inittime},
344 {"audioop", initaudioop},
345 {"imageop", initimageop},
346 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000347#ifdef USE_STDWIN
348 {"stdwin", initstdwin},
349#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000350 {"md5", initmd5},
351 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000352 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000353 {"gestalt", initgestalt},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000354 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000355#ifdef THINK_C
Guido van Rossumedea4081995-02-21 21:01:47 +0000356/* This is an interface to the Think runtime */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000357 {"macconsole", initmacconsole},
358#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000359#ifdef USE_MACCTB
Jack Jansenc5b26f41994-12-14 13:45:11 +0000360 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000361#endif
Guido van Rossumedea4081995-02-21 21:01:47 +0000362/* This could probably be made to work on other compilers... */
Jack Jansen3f0c1551995-06-14 14:47:21 +0000363#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000364 {"macspeech", initmacspeech},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000365#endif
366#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000367 {"macdnr", initmacdnr},
368 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000369#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000370#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000371 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000372 {"Ctl", initCtl},
373 {"Dlg", initDlg},
374 {"Evt", initEvt},
375 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000376 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000377 {"Snd", initSnd},
378 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000379 {"Res", initRes},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000380#endif
381#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000382 {"imgcolormap", initimgcolormap},
383 {"imgformat", initimgformat},
384 {"imggif", initimggif},
385 {"imgjpeg", initimgjpeg},
386 {"imgppm", initimgppm},
387 {"imgpgm", initimgpgm},
388 {"imgtiff", initimgtiff},
389 {"imgop", initimgop},
390#endif
391
Guido van Rossumce9739b1994-01-05 16:17:15 +0000392/* -- ADDMODULE MARKER 2 -- */
393
394 /* This module "lives in" with marshal.c */
395 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000396
397 /* This module "lives in" with import.c */
398 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000399
400 /* These entries are here for sys.builtin_module_names */
401 {"__main__", NULL},
402 {"__builtin__", NULL},
403 {"sys", NULL},
404
405 /* Sentinel */
406 {0, 0}
407};
408
409#ifdef USE_FROZEN
410#include "frozen.c"
411#else
412struct frozen {
413 char *name;
414 char *code;
415 int size;
416} frozen_modules[] = {
417 {0, 0, 0}
418};
419#endif