blob: 90221d383f65c9ad15ddb7e758c84592dcace566 [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. */
145#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac"
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();
175 extern char *PyMac_GetScriptPath();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000176
177 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000178 curwd = PyMac_GetPythonDir();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000179 p = PYTHONPATH;
180 endp = p;
181 pythonpath = malloc(2);
182 if ( pythonpath == NULL ) return PYTHONPATH;
183 strcpy(pythonpath, ":");
184 while (*endp) {
185 endp = strchr(p, '\n');
186 if ( endp == NULL )
187 endp = p + strlen(p);
188 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
189 pythonpath = realloc(pythonpath, newlen+1);
190 if ( pythonpath == NULL ) return PYTHONPATH;
191 strcat(pythonpath, "\n");
192 if ( *p == ':' ) {
193 p++;
194 strcat(pythonpath, curwd);
195 strncat(pythonpath, p, (endp-p));
196 newlen--; /* Ok, ok, we've allocated one byte too much */
197 } else {
198 /* We've allocated too much in this case */
199 newlen -= strlen(curwd);
200 pythonpath = realloc(pythonpath, newlen+1);
201 if ( pythonpath == NULL ) return PYTHONPATH;
202 strncat(pythonpath, p, (endp-p));
203 }
204 pythonpath[newlen] = '\0';
205 p = endp + 1;
206 }
Jack Jansenc5b26f41994-12-14 13:45:11 +0000207 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000208#else /* !macintosh */
209 char *path = getenv("PYTHONPATH");
210 char *defpath = PYTHONPATH;
211 char *buf;
212 char *p;
213 int n;
214
215 if (path == 0 || *path == '\0')
216 return defpath;
217 n = strlen(path) + strlen(defpath) + 2;
218 buf = malloc(n);
219 if (buf == NULL)
220 return path; /* XXX too bad -- but not likely */
221 strcpy(buf, path);
222 p = buf + strlen(buf);
223 *p++ = DELIM;
224 strcpy(p, defpath);
225 return buf;
226#endif /* !macintosh */
227}
228
229
230/* Table of built-in modules.
231 These are initialized when first imported.
232 Note: selection of optional extensions is now generally done by the
233 makesetup script. */
234
235extern void initarray();
236extern void initmath();
237extern void initparser();
238extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000239extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000240extern void initregex();
241extern void initstrop();
242extern void initstruct();
243extern void inittime();
244extern void initdbm();
245extern void initfcntl();
246extern void initnis();
247extern void initpwd();
248extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000249extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000250extern void initselect();
251extern void initsocket();
252extern void initaudioop();
253extern void initimageop();
254extern void initrgbimg();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000255#ifdef USE_STDWIN
Guido van Rossumce9739b1994-01-05 16:17:15 +0000256extern void initstdwin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000257#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000258extern void initmd5();
259extern void initmpz();
260extern void initrotor();
261extern void inital();
262extern void initcd();
263extern void initcl();
264extern void initfm();
265extern void initgl();
266extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000267extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000268extern void initsgi();
269extern void initsv();
270extern void initfl();
271extern void initthread();
272extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000273extern void initsignal();
274extern void initnew();
275extern void initdl();
276extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000277extern void initgestalt();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000278extern void initmacfs();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000279#ifdef THINK
280extern void initmacconsole();
281#endif
282#ifdef USE_MACCTB
283extern void initctb();
284#endif
285#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000286extern void initmacspeech();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000287#endif
288#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000289extern void initmacdnr();
290extern void initmactcp();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000291#endif
292#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000293extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000294extern void initCtl();
295extern void initDlg();
296extern void initEvt();
297extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000298extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000299extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000300extern void initSnd();
301extern void initWin();
Jack Jansen3f0c1551995-06-14 14:47:21 +0000302#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000303
Jack Jansen3f0c1551995-06-14 14:47:21 +0000304#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000305extern void initimgcolormap();
306extern void initimgformat();
307extern void initimggif();
308extern void initimgjpeg();
309extern void initimgppm();
310extern void initimgpgm();
311extern void initimgtiff();
312extern void initimgop();
313#endif
314
Guido van Rossumce9739b1994-01-05 16:17:15 +0000315/* -- ADDMODULE MARKER 1 -- */
316
317extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000318extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000319
320struct {
321 char *name;
322 void (*initfunc)();
323} inittab[] = {
324
325 {"array", initarray},
Guido van Rossumedea4081995-02-21 21:01:47 +0000326#ifndef __CFM68K__
327/* The math library seems mostly broken... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000328 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000329#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000330 {"parser", initparser},
331 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000332 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000333 {"regex", initregex},
334 {"strop", initstrop},
335 {"struct", initstruct},
336 {"time", inittime},
337 {"audioop", initaudioop},
338 {"imageop", initimageop},
339 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000340#ifdef USE_STDWIN
341 {"stdwin", initstdwin},
342#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000343 {"md5", initmd5},
344 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000345 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000346 {"gestalt", initgestalt},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000347 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000348#ifdef THINK_C
Guido van Rossumedea4081995-02-21 21:01:47 +0000349/* This is an interface to the Think runtime */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000350 {"macconsole", initmacconsole},
351#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000352#ifdef USE_MACCTB
Jack Jansenc5b26f41994-12-14 13:45:11 +0000353 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000354#endif
Guido van Rossumedea4081995-02-21 21:01:47 +0000355/* This could probably be made to work on other compilers... */
Jack Jansen3f0c1551995-06-14 14:47:21 +0000356#ifdef USE_MACSPEECH
Jack Jansenc5b26f41994-12-14 13:45:11 +0000357 {"macspeech", initmacspeech},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000358#endif
359#ifdef USE_MACTCP
Jack Jansenc5b26f41994-12-14 13:45:11 +0000360 {"macdnr", initmacdnr},
361 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000362#endif
Jack Jansen3f0c1551995-06-14 14:47:21 +0000363#ifdef USE_BGEN
Guido van Rossum6a5df901995-01-18 23:59:06 +0000364 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000365 {"Ctl", initCtl},
366 {"Dlg", initDlg},
367 {"Evt", initEvt},
368 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000369 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000370 {"Snd", initSnd},
371 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000372 {"Res", initRes},
Jack Jansen3f0c1551995-06-14 14:47:21 +0000373#endif
374#ifdef USE_IMG
Jack Jansenf301dca1995-06-03 21:16:40 +0000375 {"imgcolormap", initimgcolormap},
376 {"imgformat", initimgformat},
377 {"imggif", initimggif},
378 {"imgjpeg", initimgjpeg},
379 {"imgppm", initimgppm},
380 {"imgpgm", initimgpgm},
381 {"imgtiff", initimgtiff},
382 {"imgop", initimgop},
383#endif
384
Guido van Rossumce9739b1994-01-05 16:17:15 +0000385/* -- ADDMODULE MARKER 2 -- */
386
387 /* This module "lives in" with marshal.c */
388 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000389
390 /* This module "lives in" with import.c */
391 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000392
393 /* These entries are here for sys.builtin_module_names */
394 {"__main__", NULL},
395 {"__builtin__", NULL},
396 {"sys", NULL},
397
398 /* Sentinel */
399 {0, 0}
400};
401
402#ifdef USE_FROZEN
403#include "frozen.c"
404#else
405struct frozen {
406 char *name;
407 char *code;
408 int size;
409} frozen_modules[] = {
410 {0, 0, 0}
411};
412#endif