blob: f8b5a4aea8024bf8522f4c314ce59f2077a48d74 [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:
168 ** - Prepend the current directory (which is presumably where python lives)
169 ** - Add :
170 ** - Chdir to where the source file (if any) lives
171 */
172 static char *pythonpath;
Jack Jansen0f6ca801995-02-13 11:36:25 +0000173 char *curwd;
Jack Jansenc5b26f41994-12-14 13:45:11 +0000174 char *p, *endp;
175 int newlen;
176
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 }
207 if ( fileargument ) {
208 strcpy(curwd, fileargument);
209 endp = strrchr(curwd, ':');
210 if ( endp && endp > curwd ) {
211 *endp = '\0';
212 chdir(curwd);
213 }
214 }
215 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000216#else /* !macintosh */
217 char *path = getenv("PYTHONPATH");
218 char *defpath = PYTHONPATH;
219 char *buf;
220 char *p;
221 int n;
222
223 if (path == 0 || *path == '\0')
224 return defpath;
225 n = strlen(path) + strlen(defpath) + 2;
226 buf = malloc(n);
227 if (buf == NULL)
228 return path; /* XXX too bad -- but not likely */
229 strcpy(buf, path);
230 p = buf + strlen(buf);
231 *p++ = DELIM;
232 strcpy(p, defpath);
233 return buf;
234#endif /* !macintosh */
235}
236
237
238/* Table of built-in modules.
239 These are initialized when first imported.
240 Note: selection of optional extensions is now generally done by the
241 makesetup script. */
242
243extern void initarray();
244extern void initmath();
245extern void initparser();
246extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000247extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000248extern void initregex();
249extern void initstrop();
250extern void initstruct();
251extern void inittime();
252extern void initdbm();
253extern void initfcntl();
254extern void initnis();
255extern void initpwd();
256extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000257extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000258extern void initselect();
259extern void initsocket();
260extern void initaudioop();
261extern void initimageop();
262extern void initrgbimg();
263extern void initstdwin();
264extern void initmd5();
265extern void initmpz();
266extern void initrotor();
267extern void inital();
268extern void initcd();
269extern void initcl();
270extern void initfm();
271extern void initgl();
272extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000273extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000274extern void initsgi();
275extern void initsv();
276extern void initfl();
277extern void initthread();
278extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000279extern void initsignal();
280extern void initnew();
281extern void initdl();
282extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000283extern void initgestalt();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000284extern void initmacconsole();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000285extern void initctb();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000286extern void initmacfs();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000287extern void initmacspeech();
288extern void initmacdnr();
289extern void initmactcp();
Guido van Rossum6a5df901995-01-18 23:59:06 +0000290extern void initAE();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000291extern void initCtl();
292extern void initDlg();
293extern void initEvt();
294extern void initMenu();
Guido van Rossume6c884c1995-02-13 16:16:22 +0000295extern void initQd();
Guido van Rossumd8373d81995-01-22 18:37:45 +0000296extern void initRes();
Guido van Rossumc9a35691995-01-25 23:10:10 +0000297extern void initSnd();
298extern void initWin();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000299
300/* -- ADDMODULE MARKER 1 -- */
301
302extern void initmarshal();
Guido van Rossum99d20f61995-02-18 14:58:54 +0000303extern void initimp();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000304
305struct {
306 char *name;
307 void (*initfunc)();
308} inittab[] = {
309
310 {"array", initarray},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000311#ifndef __SC__
312/* Do this one later... */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000313 {"math", initmath},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000314#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000315 {"parser", initparser},
316 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000317 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000318 {"regex", initregex},
319 {"strop", initstrop},
320 {"struct", initstruct},
321 {"time", inittime},
322 {"audioop", initaudioop},
323 {"imageop", initimageop},
324 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000325#ifdef USE_STDWIN
326 {"stdwin", initstdwin},
327#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000328 {"md5", initmd5},
329 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000330 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000331 {"gestalt", initgestalt},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000332#ifdef THINK_C
Jack Jansenc5b26f41994-12-14 13:45:11 +0000333 {"macconsole", initmacconsole},
334#endif
Guido van Rossum99d20f61995-02-18 14:58:54 +0000335#ifndef __SC__
336/* Do this one later... */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000337 {"ctb", initctb},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000338#endif
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000339 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000340#ifdef __MWERKS__
341/* This is really "Jack Jansen" specific for now :-) */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000342 {"macspeech", initmacspeech},
Jack Jansenc5b26f41994-12-14 13:45:11 +0000343 {"macdnr", initmacdnr},
344 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000345#endif
Guido van Rossum6a5df901995-01-18 23:59:06 +0000346/* This is really "Guido van Rossum" specific... :-) */
347 {"AE", initAE},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000348 {"Ctl", initCtl},
349 {"Dlg", initDlg},
350 {"Evt", initEvt},
351 {"Menu", initMenu},
Guido van Rossume6c884c1995-02-13 16:16:22 +0000352 {"Qd", initQd},
Guido van Rossumc9a35691995-01-25 23:10:10 +0000353 {"Snd", initSnd},
354 {"Win", initWin},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000355 {"Res", initRes},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000356
357/* -- ADDMODULE MARKER 2 -- */
358
359 /* This module "lives in" with marshal.c */
360 {"marshal", initmarshal},
Guido van Rossum99d20f61995-02-18 14:58:54 +0000361
362 /* This module "lives in" with import.c */
363 {"imp", initimp},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000364
365 /* These entries are here for sys.builtin_module_names */
366 {"__main__", NULL},
367 {"__builtin__", NULL},
368 {"sys", NULL},
369
370 /* Sentinel */
371 {0, 0}
372};
373
374#ifdef USE_FROZEN
375#include "frozen.c"
376#else
377struct frozen {
378 char *name;
379 char *code;
380 int size;
381} frozen_modules[] = {
382 {0, 0, 0}
383};
384#endif