blob: e7418eb56c08f8116ad7b8262646c8bcbd9699b8 [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{
110 return "Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam";
111}
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
121#ifndef PYTHONPATH
122#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000123/* Mod by Jack: \n is now separator. */
124#define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac"
Guido van Rossumce9739b1994-01-05 16:17:15 +0000125#endif /* macintosh */
126#endif /* !PYTHONPATH */
127
128#ifndef PYTHONPATH
Guido van Rossumd4d77281994-08-19 10:51:31 +0000129#if defined(MSDOS) || defined(NT)
Guido van Rossumce9739b1994-01-05 16:17:15 +0000130#define PYTHONPATH ".;..\\lib;\\python\\lib"
Guido van Rossumd4d77281994-08-19 10:51:31 +0000131#endif /* MSDOS || NT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000132#endif /* !PYTHONPATH */
133
134#ifndef PYTHONPATH
135#define PYTHONPATH ".:/usr/local/lib/python"
136#endif /* !PYTHONPATH */
137
138extern char *getenv();
139
140char *
141getpythonpath()
142{
143#ifdef macintosh
Jack Jansenc5b26f41994-12-14 13:45:11 +0000144 /* Modified by Jack to do something a bit more sensible:
145 ** - Prepend the current directory (which is presumably where python lives)
146 ** - Add :
147 ** - Chdir to where the source file (if any) lives
148 */
149 static char *pythonpath;
150 extern char *fileargument;
151 char curwd[256];
152 char *p, *endp;
153 int newlen;
154
155 if ( pythonpath ) return pythonpath;
156 if (getwd(curwd) < 0 ) {
157 return PYTHONPATH;
158 }
159 p = PYTHONPATH;
160 endp = p;
161 pythonpath = malloc(2);
162 if ( pythonpath == NULL ) return PYTHONPATH;
163 strcpy(pythonpath, ":");
164 while (*endp) {
165 endp = strchr(p, '\n');
166 if ( endp == NULL )
167 endp = p + strlen(p);
168 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
169 pythonpath = realloc(pythonpath, newlen+1);
170 if ( pythonpath == NULL ) return PYTHONPATH;
171 strcat(pythonpath, "\n");
172 if ( *p == ':' ) {
173 p++;
174 strcat(pythonpath, curwd);
175 strncat(pythonpath, p, (endp-p));
176 newlen--; /* Ok, ok, we've allocated one byte too much */
177 } else {
178 /* We've allocated too much in this case */
179 newlen -= strlen(curwd);
180 pythonpath = realloc(pythonpath, newlen+1);
181 if ( pythonpath == NULL ) return PYTHONPATH;
182 strncat(pythonpath, p, (endp-p));
183 }
184 pythonpath[newlen] = '\0';
185 p = endp + 1;
186 }
187 if ( fileargument ) {
188 strcpy(curwd, fileargument);
189 endp = strrchr(curwd, ':');
190 if ( endp && endp > curwd ) {
191 *endp = '\0';
192 chdir(curwd);
193 }
194 }
195 return pythonpath;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000196#else /* !macintosh */
197 char *path = getenv("PYTHONPATH");
198 char *defpath = PYTHONPATH;
199 char *buf;
200 char *p;
201 int n;
202
203 if (path == 0 || *path == '\0')
204 return defpath;
205 n = strlen(path) + strlen(defpath) + 2;
206 buf = malloc(n);
207 if (buf == NULL)
208 return path; /* XXX too bad -- but not likely */
209 strcpy(buf, path);
210 p = buf + strlen(buf);
211 *p++ = DELIM;
212 strcpy(p, defpath);
213 return buf;
214#endif /* !macintosh */
215}
216
217
218/* Table of built-in modules.
219 These are initialized when first imported.
220 Note: selection of optional extensions is now generally done by the
221 makesetup script. */
222
223extern void initarray();
224extern void initmath();
225extern void initparser();
226extern void initmac();
Guido van Rossume433c971994-09-29 10:02:56 +0000227extern void MacOS_Init();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000228extern void initregex();
229extern void initstrop();
230extern void initstruct();
231extern void inittime();
232extern void initdbm();
233extern void initfcntl();
234extern void initnis();
235extern void initpwd();
236extern void initgrp();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000237extern void initcrypt();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000238extern void initselect();
239extern void initsocket();
240extern void initaudioop();
241extern void initimageop();
242extern void initrgbimg();
243extern void initstdwin();
244extern void initmd5();
245extern void initmpz();
246extern void initrotor();
247extern void inital();
248extern void initcd();
249extern void initcl();
250extern void initfm();
251extern void initgl();
252extern void initimgfile();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000253extern void initimgformat();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000254extern void initsgi();
255extern void initsv();
256extern void initfl();
257extern void initthread();
258extern void inittiming();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000259extern void initsignal();
260extern void initnew();
261extern void initdl();
262extern void initsyslog();
Guido van Rossum29e7af01994-08-23 13:28:34 +0000263extern void initgestalt();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000264extern void initmacconsole();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000265extern void initctb();
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000266extern void initmacfs();
Jack Jansenc5b26f41994-12-14 13:45:11 +0000267extern void initmacspeech();
268extern void initmacdnr();
269extern void initmactcp();
Guido van Rossum6a5df901995-01-18 23:59:06 +0000270extern void initAE();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000271
272/* -- ADDMODULE MARKER 1 -- */
273
274extern void initmarshal();
275
276struct {
277 char *name;
278 void (*initfunc)();
279} inittab[] = {
280
281 {"array", initarray},
282 {"math", initmath},
283 {"parser", initparser},
284 {"mac", initmac},
Guido van Rossume433c971994-09-29 10:02:56 +0000285 {"MacOS", MacOS_Init},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000286 {"regex", initregex},
287 {"strop", initstrop},
288 {"struct", initstruct},
289 {"time", inittime},
290 {"audioop", initaudioop},
291 {"imageop", initimageop},
292 {"rgbimg", initrgbimg},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000293#ifdef USE_STDWIN
294 {"stdwin", initstdwin},
295#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000296 {"md5", initmd5},
297 {"rotor", initrotor},
Guido van Rossumd4d77281994-08-19 10:51:31 +0000298 {"new", initnew},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000299 {"gestalt", initgestalt},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000300#ifdef THINK_C
Jack Jansenc5b26f41994-12-14 13:45:11 +0000301 {"macconsole", initmacconsole},
302#endif
303 {"ctb", initctb},
Guido van Rossum9aa3d131995-01-21 13:46:04 +0000304 {"macfs", initmacfs},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000305#ifdef __MWERKS__
306/* This is really "Jack Jansen" specific for now :-) */
Jack Jansenc5b26f41994-12-14 13:45:11 +0000307 {"macspeech", initmacspeech},
Guido van Rossum29e7af01994-08-23 13:28:34 +0000308 {"imgformat", initimgformat},
Jack Jansenc5b26f41994-12-14 13:45:11 +0000309 {"macdnr", initmacdnr},
310 {"mactcp", initmactcp},
Guido van Rossum6a5df901995-01-18 23:59:06 +0000311#endif
312#ifdef THINK_C
313/* This is really "Guido van Rossum" specific... :-) */
314 {"AE", initAE},
315#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000316
317/* -- ADDMODULE MARKER 2 -- */
318
319 /* This module "lives in" with marshal.c */
320 {"marshal", initmarshal},
321
322 /* These entries are here for sys.builtin_module_names */
323 {"__main__", NULL},
324 {"__builtin__", NULL},
325 {"sys", NULL},
326
327 /* Sentinel */
328 {0, 0}
329};
330
331#ifdef USE_FROZEN
332#include "frozen.c"
333#else
334struct frozen {
335 char *name;
336 char *code;
337 int size;
338} frozen_modules[] = {
339 {0, 0, 0}
340};
341#endif