blob: 32313a72f02b9045c3b86bfeaaed0e30c8b0aaa9 [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
Jack Jansen0f6ca801995-02-13 11:36:25 +000034char *fileargument; /* So main() can tell us the program name */
Guido van Rossum29e7af01994-08-23 13:28:34 +000035#endif
36
Guido van Rossumce9739b1994-01-05 16:17:15 +000037#include <stdio.h>
38#include <string.h>
39
40#include "myproto.h"
41#include "mymalloc.h"
42#include "osdefs.h"
Guido van Rossumd4d77281994-08-19 10:51:31 +000043#include "intrcheck.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000044
Jack Jansen0f6ca801995-02-13 11:36:25 +000045char *PyMac_GetPythonDir();
Guido van Rossumce9739b1994-01-05 16:17:15 +000046
47#ifndef NO_MAIN
48
49/* Normally, the main program is called from here (so everything else
50 can be in libPython.a). We save a pointer to argv[0] because it
51 may be needed for dynamic loading of modules in import.c. If you
52 have your own main program and want to use non-SunOS dynamic
53 loading, you will have to provide your own version of
54 getprogramname(). */
55
56static char *argv0;
57
58main(argc, argv)
59 int argc;
60 char **argv;
61{
Guido van Rossumce9739b1994-01-05 16:17:15 +000062 argv0 = argv[0];
63 realmain(argc, argv);
64}
65
66char *
67getprogramname()
68{
69 return argv0;
70}
71
72#endif
73
74
Guido van Rossumd4d77281994-08-19 10:51:31 +000075/* Python version information */
76
77#include "patchlevel.h"
78
79/* Return the version string. This is constructed from the official
80 version number (from patchlevel.h), and the current date (if known
81 to the compiler, else a manually inserted date). */
82
83#define VERSION "%s (%s)"
84
85#ifdef __DATE__
86#define DATE __DATE__
87#else
88#define DATE "Aug 17 1994"
89#endif
90
91char *
92getversion()
93{
94 static char version[80];
95 sprintf(version, VERSION, PATCHLEVEL, DATE);
Jack Jansenc5b26f41994-12-14 13:45:11 +000096#ifdef __MWERKS__
97#ifdef __powerc
98 strcat(version, " [MW PPC compiler]");
99#else
100 strcat(version, " [MW 68K compiler]");
101#endif
102#endif
Guido van Rossumbecdbec1995-02-14 01:27:24 +0000103#ifdef THINK_C
104#ifdef __SC__
105 strcat(version, " [Symantec Think C compiler]");
106#else
107 strcat(version, " [Think C compiler]");
108#endif
109#endif
110#ifdef MPW
111#ifdef __SC__
112 strcat(version, " [Symantec MPW C compiler]");
113#else
114 strcat(version, " [Apple MPW C compiler]");
115#endif
116#endif
Guido van Rossumd4d77281994-08-19 10:51:31 +0000117 return version;
118}
119
120
121/* Return the copyright string. This is updated manually. */
122
123char *
124getcopyright()
125{
Guido van Rossumc9a35691995-01-25 23:10:10 +0000126 return "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam";
Guido van Rossumd4d77281994-08-19 10:51:31 +0000127}
128
129
Guido van Rossumce9739b1994-01-05 16:17:15 +0000130/* Return the initial python search path. This is called once from
131 initsys() to initialize sys.path.
132 The environment variable PYTHONPATH is fetched and the default path
133 appended. (The Mac has no environment variables, so there the
134 default path is always returned.) The default path may be passed
135 to the preprocessor; if not, a system-dependent default is used. */
136
Guido van Rossumc9a35691995-01-25 23:10:10 +0000137#define PYTHONPATH "\
138:\n\
139:Lib\n\
140:Lib:stdwin\n\
141:Lib:test\n\
142:Lib:mac"
143
Guido van Rossumce9739b1994-01-05 16:17:15 +0000144#ifndef PYTHONPATH
145#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000146/* Mod by Jack: \n is now separator. */
147#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac"
Guido van Rossumce9739b1994-01-05 16:17:15 +0000148#endif /* macintosh */
149#endif /* !PYTHONPATH */
150
151#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000152#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000153#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000154#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000155#endif /* !PYTHONPATH */
156
157#ifndef PYTHONPATH
158#define PYTHONPATH ".:/usr/local/lib/python"
159#endif /* !PYTHONPATH */
160
161extern char *getenv();
162
163char *
164getpythonpath()
165{
166#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000167 /* Modified by Jack to do something a bit more sensible:
Jack Jansen86b40491995-02-20 15:57:12 +0000168 ** - Prepend the python home-directory (which is obtained from a Preferences
169 ** resource)
Jack Jansenc5b26f41994-12-14 13:45:11 +0000170 ** - Add :
171 ** - Chdir to where the source file (if any) lives
172 */
173 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000174 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000175 char *p, *endp;
176 int newlen;
177
178 if ( pythonpath ) return pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000179 curwd = PyMac_GetPythonDir();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000180 p = PYTHONPATH;
181 endp = p;
182 pythonpath = malloc(2);
183 if ( pythonpath == NULL ) return PYTHONPATH;
184 strcpy(pythonpath, ":");
185 while (*endp) {
186 endp = strchr(p, '\n');
187 if ( endp == NULL )
188 endp = p + strlen(p);
189 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
190 pythonpath = realloc(pythonpath, newlen+1);
191 if ( pythonpath == NULL ) return PYTHONPATH;
192 strcat(pythonpath, "\n");
193 if ( *p == ':' ) {
194 p++;
195 strcat(pythonpath, curwd);
196 strncat(pythonpath, p, (endp-p));
197 newlen--; /* Ok, ok, we've allocated one byte too much */
198 } else {
199 /* We've allocated too much in this case */
200 newlen -= strlen(curwd);
201 pythonpath = realloc(pythonpath, newlen+1);
202 if ( pythonpath == NULL ) return PYTHONPATH;
203 strncat(pythonpath, p, (endp-p));
204 }
205 pythonpath[newlen] = '\0';
206 p = endp + 1;
207 }
208 if ( fileargument ) {
209 strcpy(curwd, fileargument);
210 endp = strrchr(curwd, ':');
211 if ( endp && endp > curwd ) {
212 *endp = '\0';
213 chdir(curwd);
214 }
215 }
216 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000217#else /* !macintosh */
218 char *path = getenv("PYTHONPATH");
219 char *defpath = PYTHONPATH;
220 char *buf;
221 char *p;
222 int n;
223
224 if (path == 0 || *path == '\0')
225 return defpath;
226 n = strlen(path) + strlen(defpath) + 2;
227 buf = malloc(n);
228 if (buf == NULL)
229 return path; /* XXX too bad -- but not likely */
230 strcpy(buf, path);
231 p = buf + strlen(buf);
232 *p++ = DELIM;
233 strcpy(p, defpath);
234 return buf;
235#endif /* !macintosh */
236}
237
238
239/* Table of built-in modules.
240 These are initialized when first imported.
241 Note: selection of optional extensions is now generally done by the
242 makesetup script. */
243
244extern void initarray();
245extern void initmath();
246extern void initparser();
247extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000248extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000249extern void initregex();
250extern void initstrop();
251extern void initstruct();
252extern void inittime();
253extern void initdbm();
254extern void initfcntl();
255extern void initnis();
256extern void initpwd();
257extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000258extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000259extern void initselect();
260extern void initsocket();
261extern void initaudioop();
262extern void initimageop();
263extern void initrgbimg();
264extern void initstdwin();
265extern 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();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000285extern void initmacconsole();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000286extern void initctb();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000287extern void initmacfs();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000288extern void initmacspeech();
289extern void initmacdnr();
290extern void initmactcp();
Guido van Rossum6a5df901995-01-18 23:59:06 +0000291extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000292extern void initCtl();
293extern void initDlg();
294extern void initEvt();
295extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000296extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000297extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000298extern void initSnd();
299extern void initWin();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000300
301/* -- ADDMODULE MARKER 1 -- */
302
303extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000304extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000305
306struct {
307 char *name;
308 void (*initfunc)();
309} inittab[] = {
310
311 {"array", initarray},
Guido van Rossumedea4081995-02-21 21:01:47 +0000312#ifndef __CFM68K__
313/* The math library seems mostly broken... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000314 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000315#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000316 {"parser", initparser},
317 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000318 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000319 {"regex", initregex},
320 {"strop", initstrop},
321 {"struct", initstruct},
322 {"time", inittime},
323 {"audioop", initaudioop},
324 {"imageop", initimageop},
325 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000326#ifdef USE_STDWIN
327 {"stdwin", initstdwin},
328#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000329 {"md5", initmd5},
330 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000331 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000332 {"gestalt", initgestalt},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000333#ifdef THINK_C
Guido van Rossumedea4081995-02-21 21:01:47 +0000334/* This is an interface to the Think runtime */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000335 {"macconsole", initmacconsole},
336#endif
Guido van Rossumedea4081995-02-21 21:01:47 +0000337#ifndef MPW
Guido van Rossum99d20f61995-02-18 14:58:54 +0000338/* Do this one later... */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000339 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000340#endif
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000341 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000342#ifdef __MWERKS__
Guido van Rossumedea4081995-02-21 21:01:47 +0000343/* This could probably be made to work on other compilers... */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000344 {"macspeech", initmacspeech},
Jack Jansenc5b26f41994-12-14 13:45:11 +0000345 {"macdnr", initmacdnr},
346 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000347#endif
Guido van Rossum6a5df901995-01-18 23:59:06 +0000348 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000349 {"Ctl", initCtl},
350 {"Dlg", initDlg},
351 {"Evt", initEvt},
352 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000353 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000354 {"Snd", initSnd},
355 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000356 {"Res", initRes},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000357
358/* -- ADDMODULE MARKER 2 -- */
359
360 /* This module "lives in" with marshal.c */
361 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000362
363 /* This module "lives in" with import.c */
364 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000365
366 /* These entries are here for sys.builtin_module_names */
367 {"__main__", NULL},
368 {"__builtin__", NULL},
369 {"sys", NULL},
370
371 /* Sentinel */
372 {0, 0}
373};
374
375#ifdef USE_FROZEN
376#include "frozen.c"
377#else
378struct frozen {
379 char *name;
380 char *code;
381 int size;
382} frozen_modules[] = {
383 {0, 0, 0}
384};
385#endif