Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 1 | /* -*- C -*- *********************************************** |
| 2 | Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 3 | Amsterdam, The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 25 | /* Macintosh Python configuration file */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 26 | |
| 27 | #ifdef HAVE_CONFIG_H |
| 28 | #include "config.h" |
| 29 | #endif |
| 30 | |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 31 | #ifdef macintosh |
| 32 | /* The Macintosh main program is in macmain.c */ |
| 33 | #define NO_MAIN |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
| 37 | #include <string.h> |
| 38 | |
| 39 | #include "myproto.h" |
| 40 | #include "mymalloc.h" |
| 41 | #include "osdefs.h" |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 42 | #include "intrcheck.h" |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 43 | |
| 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 | |
| 54 | static char *argv0; |
| 55 | |
| 56 | main(argc, argv) |
| 57 | int argc; |
| 58 | char **argv; |
| 59 | { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 60 | argv0 = argv[0]; |
| 61 | realmain(argc, argv); |
| 62 | } |
| 63 | |
| 64 | char * |
| 65 | getprogramname() |
| 66 | { |
| 67 | return argv0; |
| 68 | } |
| 69 | |
| 70 | #endif |
| 71 | |
| 72 | |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 73 | /* 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 | |
| 89 | char * |
| 90 | getversion() |
| 91 | { |
| 92 | static char version[80]; |
| 93 | sprintf(version, VERSION, PATCHLEVEL, DATE); |
Jack Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 94 | #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 Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 101 | return version; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /* Return the copyright string. This is updated manually. */ |
| 106 | |
| 107 | char * |
| 108 | getcopyright() |
| 109 | { |
| 110 | return "Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam"; |
| 111 | } |
| 112 | |
| 113 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 114 | /* 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 Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 123 | /* Mod by Jack: \n is now separator. */ |
| 124 | #define PYTHONPATH ":\n:Lib\n:Lib:stdwin\n:Lib:test\n:Lib:mac" |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 125 | #endif /* macintosh */ |
| 126 | #endif /* !PYTHONPATH */ |
| 127 | |
| 128 | #ifndef PYTHONPATH |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 129 | #if defined(MSDOS) || defined(NT) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 130 | #define PYTHONPATH ".;..\\lib;\\python\\lib" |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 131 | #endif /* MSDOS || NT */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 132 | #endif /* !PYTHONPATH */ |
| 133 | |
| 134 | #ifndef PYTHONPATH |
| 135 | #define PYTHONPATH ".:/usr/local/lib/python" |
| 136 | #endif /* !PYTHONPATH */ |
| 137 | |
| 138 | extern char *getenv(); |
| 139 | |
| 140 | char * |
| 141 | getpythonpath() |
| 142 | { |
| 143 | #ifdef macintosh |
Jack Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 144 | /* 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 Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 196 | #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 | |
| 223 | extern void initarray(); |
| 224 | extern void initmath(); |
| 225 | extern void initparser(); |
| 226 | extern void initmac(); |
Guido van Rossum | e433c97 | 1994-09-29 10:02:56 +0000 | [diff] [blame] | 227 | extern void MacOS_Init(); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 228 | extern void initregex(); |
| 229 | extern void initstrop(); |
| 230 | extern void initstruct(); |
| 231 | extern void inittime(); |
| 232 | extern void initdbm(); |
| 233 | extern void initfcntl(); |
| 234 | extern void initnis(); |
| 235 | extern void initpwd(); |
| 236 | extern void initgrp(); |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 237 | extern void initcrypt(); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 238 | extern void initselect(); |
| 239 | extern void initsocket(); |
| 240 | extern void initaudioop(); |
| 241 | extern void initimageop(); |
| 242 | extern void initrgbimg(); |
| 243 | extern void initstdwin(); |
| 244 | extern void initmd5(); |
| 245 | extern void initmpz(); |
| 246 | extern void initrotor(); |
| 247 | extern void inital(); |
| 248 | extern void initcd(); |
| 249 | extern void initcl(); |
| 250 | extern void initfm(); |
| 251 | extern void initgl(); |
| 252 | extern void initimgfile(); |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 253 | extern void initimgformat(); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 254 | extern void initsgi(); |
| 255 | extern void initsv(); |
| 256 | extern void initfl(); |
| 257 | extern void initthread(); |
| 258 | extern void inittiming(); |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 259 | extern void initsignal(); |
| 260 | extern void initnew(); |
| 261 | extern void initdl(); |
| 262 | extern void initsyslog(); |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 263 | extern void initgestalt(); |
Jack Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 264 | #ifdef THINK |
| 265 | extern void initmacconsole(); |
| 266 | #endif |
| 267 | extern void initctb(); |
| 268 | extern void initmacspeech(); |
| 269 | extern void initmacdnr(); |
| 270 | extern void initmactcp(); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 271 | |
| 272 | /* -- ADDMODULE MARKER 1 -- */ |
| 273 | |
| 274 | extern void initmarshal(); |
| 275 | |
| 276 | struct { |
| 277 | char *name; |
| 278 | void (*initfunc)(); |
| 279 | } inittab[] = { |
| 280 | |
| 281 | {"array", initarray}, |
| 282 | {"math", initmath}, |
| 283 | {"parser", initparser}, |
| 284 | {"mac", initmac}, |
Guido van Rossum | e433c97 | 1994-09-29 10:02:56 +0000 | [diff] [blame] | 285 | {"MacOS", MacOS_Init}, |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 286 | {"regex", initregex}, |
| 287 | {"strop", initstrop}, |
| 288 | {"struct", initstruct}, |
| 289 | {"time", inittime}, |
| 290 | {"audioop", initaudioop}, |
| 291 | {"imageop", initimageop}, |
| 292 | {"rgbimg", initrgbimg}, |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 293 | #ifdef USE_STDWIN |
| 294 | {"stdwin", initstdwin}, |
| 295 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 296 | {"md5", initmd5}, |
| 297 | {"rotor", initrotor}, |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 298 | {"new", initnew}, |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 299 | {"gestalt", initgestalt}, |
Jack Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 300 | #ifdef THINK |
| 301 | {"macconsole", initmacconsole}, |
| 302 | #endif |
| 303 | {"ctb", initctb}, |
| 304 | {"macspeech", initmacspeech}, |
Guido van Rossum | 29e7af0 | 1994-08-23 13:28:34 +0000 | [diff] [blame] | 305 | {"imgformat", initimgformat}, |
Jack Jansen | c5b26f4 | 1994-12-14 13:45:11 +0000 | [diff] [blame] | 306 | {"macdnr", initmacdnr}, |
| 307 | {"mactcp", initmactcp}, |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 308 | |
| 309 | /* -- ADDMODULE MARKER 2 -- */ |
| 310 | |
| 311 | /* This module "lives in" with marshal.c */ |
| 312 | {"marshal", initmarshal}, |
| 313 | |
| 314 | /* These entries are here for sys.builtin_module_names */ |
| 315 | {"__main__", NULL}, |
| 316 | {"__builtin__", NULL}, |
| 317 | {"sys", NULL}, |
| 318 | |
| 319 | /* Sentinel */ |
| 320 | {0, 0} |
| 321 | }; |
| 322 | |
| 323 | #ifdef USE_FROZEN |
| 324 | #include "frozen.c" |
| 325 | #else |
| 326 | struct frozen { |
| 327 | char *name; |
| 328 | char *code; |
| 329 | int size; |
| 330 | } frozen_modules[] = { |
| 331 | {0, 0, 0} |
| 332 | }; |
| 333 | #endif |