blob: 098ff4f81e8b8036ffff4fef8b138dbfddbda46f [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
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 Rossumd4d77281994-08-19 10:51:31 +0000101 return version;
102}
103
104
105/* Return the copyright string. This is updated manually. */
106
107char *
108getcopyright()
109{
Guido van Rossumc9a35691995-01-25 23:10:10 +0000110 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossumd4d77281994-08-19 10:51:31 +0000111}
112
113
Guido van Rossumce9739b1994-01-05 16:17:15 +0000114/* Return the initial python search path. This is called once from
115 initsys() to initialize sys.path.
116 The environment variable PYTHONPATH is fetched and the default path
117 appended. (The Mac has no environment variables, so there the
118 default path is always returned.) The default path may be passed
119 to the preprocessor; if not, a system-dependent default is used. */
120
Guido van Rossumc9a35691995-01-25 23:10:10 +0000121#define PYTHONPATH "\
122:\n\
123:Lib\n\
124:Lib:stdwin\n\
125:Lib:test\n\
126:Lib:mac"
127
Guido van Rossumce9739b1994-01-05 16:17:15 +0000128#ifndef PYTHONPATH
129#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000130/* Mod by Jack: \n is now separator. */
131#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac"
Guido van Rossumce9739b1994-01-05 16:17:15 +0000132#endif /* macintosh */
133#endif /* !PYTHONPATH */
134
135#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000136#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000137#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000138#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000139#endif /* !PYTHONPATH */
140
141#ifndef PYTHONPATH
142#define PYTHONPATH ".:/usr/local/lib/python"
143#endif /* !PYTHONPATH */
144
145extern char *getenv();
146
147char *
148getpythonpath()
149{
150#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000151 /* Modified by Jack to do something a bit more sensible:
152 ** - Prepend the current directory (which is presumably where python lives)
153 ** - Add :
154 ** - Chdir to where the source file (if any) lives
155 */
156 static char *pythonpath;
157 extern char *fileargument;
158 char curwd[256];
159 char *p, *endp;
160 int newlen;
161
162 if ( pythonpath ) return pythonpath;
163 if (getwd(curwd) < 0 ) {
164 return PYTHONPATH;
165 }
166 p = PYTHONPATH;
167 endp = p;
168 pythonpath = malloc(2);
169 if ( pythonpath == NULL ) return PYTHONPATH;
170 strcpy(pythonpath, ":");
171 while (*endp) {
172 endp = strchr(p, '\n');
173 if ( endp == NULL )
174 endp = p + strlen(p);
175 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
176 pythonpath = realloc(pythonpath, newlen+1);
177 if ( pythonpath == NULL ) return PYTHONPATH;
178 strcat(pythonpath, "\n");
179 if ( *p == ':' ) {
180 p++;
181 strcat(pythonpath, curwd);
182 strncat(pythonpath, p, (endp-p));
183 newlen--; /* Ok, ok, we've allocated one byte too much */
184 } else {
185 /* We've allocated too much in this case */
186 newlen -= strlen(curwd);
187 pythonpath = realloc(pythonpath, newlen+1);
188 if ( pythonpath == NULL ) return PYTHONPATH;
189 strncat(pythonpath, p, (endp-p));
190 }
191 pythonpath[newlen] = '\0';
192 p = endp + 1;
193 }
194 if ( fileargument ) {
195 strcpy(curwd, fileargument);
196 endp = strrchr(curwd, ':');
197 if ( endp && endp > curwd ) {
198 *endp = '\0';
199 chdir(curwd);
200 }
201 }
202 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000203#else /* !macintosh */
204 char *path = getenv("PYTHONPATH");
205 char *defpath = PYTHONPATH;
206 char *buf;
207 char *p;
208 int n;
209
210 if (path == 0 || *path == '\0')
211 return defpath;
212 n = strlen(path) + strlen(defpath) + 2;
213 buf = malloc(n);
214 if (buf == NULL)
215 return path; /* XXX too bad -- but not likely */
216 strcpy(buf, path);
217 p = buf + strlen(buf);
218 *p++ = DELIM;
219 strcpy(p, defpath);
220 return buf;
221#endif /* !macintosh */
222}
223
224
225/* Table of built-in modules.
226 These are initialized when first imported.
227 Note: selection of optional extensions is now generally done by the
228 makesetup script. */
229
230extern void initarray();
231extern void initmath();
232extern void initparser();
233extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000234extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000235extern void initregex();
236extern void initstrop();
237extern void initstruct();
238extern void inittime();
239extern void initdbm();
240extern void initfcntl();
241extern void initnis();
242extern void initpwd();
243extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000244extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000245extern void initselect();
246extern void initsocket();
247extern void initaudioop();
248extern void initimageop();
249extern void initrgbimg();
250extern void initstdwin();
251extern void initmd5();
252extern void initmpz();
253extern void initrotor();
254extern void inital();
255extern void initcd();
256extern void initcl();
257extern void initfm();
258extern void initgl();
259extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000260extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000261extern void initsgi();
262extern void initsv();
263extern void initfl();
264extern void initthread();
265extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000266extern void initsignal();
267extern void initnew();
268extern void initdl();
269extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000270extern void initgestalt();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000271extern void initmacconsole();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000272extern void initctb();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000273extern void initmacfs();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000274extern void initmacspeech();
275extern void initmacdnr();
276extern void initmactcp();
Guido van Rossum6a5df901995-01-18 23:59:06 +0000277extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000278extern void initCtl();
279extern void initDlg();
280extern void initEvt();
281extern void initMenu();
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
325#ifdef THINK_C
326/* This is really "Guido van Rossum" specific... :-) */
327 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000328 {"Ctl", initCtl},
329 {"Dlg", initDlg},
330 {"Evt", initEvt},
331 {"Menu", initMenu},
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 Rossum6a5df901995-01-18 23:59:06 +0000335#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000336
337/* -- ADDMODULE MARKER 2 -- */
338
339 /* This module "lives in" with marshal.c */
340 {"marshal", initmarshal},
341
342 /* These entries are here for sys.builtin_module_names */
343 {"__main__", NULL},
344 {"__builtin__", NULL},
345 {"sys", NULL},
346
347 /* Sentinel */
348 {0, 0}
349};
350
351#ifdef USE_FROZEN
352#include "frozen.c"
353#else
354struct frozen {
355 char *name;
356 char *code;
357 int size;
358} frozen_modules[] = {
359 {0, 0, 0}
360};
361#endif