Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
| 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 | |
| 25 | /* Universal Python configuration file */ |
| 26 | |
| 27 | #ifdef HAVE_CONFIG_H |
| 28 | #include "config.h" |
| 29 | #endif |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | #include "myproto.h" |
| 35 | #include "mymalloc.h" |
| 36 | #include "osdefs.h" |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | #ifndef NO_MAIN |
| 40 | |
| 41 | /* Normally, the main program is called from here (so everything else |
| 42 | can be in libPython.a). We save a pointer to argv[0] because it |
| 43 | may be needed for dynamic loading of modules in import.c. If you |
| 44 | have your own main program and want to use non-SunOS dynamic |
| 45 | loading, you will have to provide your own version of |
| 46 | getprogramname(). */ |
| 47 | |
| 48 | static char *argv0; |
| 49 | |
| 50 | main(argc, argv) |
| 51 | int argc; |
| 52 | char **argv; |
| 53 | { |
| 54 | #ifdef macintosh |
Guido van Rossum | 3ce7a1a | 1994-05-06 15:54:52 +0000 | [diff] [blame] | 55 | |
| 56 | #ifndef MPW /* XXX RJW undefined in MPW */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 57 | wargs(&argc, &argv); |
| 58 | #endif |
Guido van Rossum | 3ce7a1a | 1994-05-06 15:54:52 +0000 | [diff] [blame] | 59 | |
| 60 | #ifndef MPW_3 /* XXX RJW doesn't seem to work with MPW C 3.0 */ |
| 61 | extern int std_open_hook(); |
| 62 | set_open_hook (std_open_hook); |
| 63 | #endif |
| 64 | #endif |
| 65 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 66 | argv0 = argv[0]; |
| 67 | realmain(argc, argv); |
| 68 | } |
| 69 | |
| 70 | char * |
| 71 | getprogramname() |
| 72 | { |
| 73 | return argv0; |
| 74 | } |
| 75 | |
| 76 | #endif |
| 77 | |
| 78 | |
| 79 | /* Return the initial python search path. This is called once from |
| 80 | initsys() to initialize sys.path. |
| 81 | The environment variable PYTHONPATH is fetched and the default path |
| 82 | appended. (The Mac has no environment variables, so there the |
| 83 | default path is always returned.) The default path may be passed |
| 84 | to the preprocessor; if not, a system-dependent default is used. */ |
| 85 | |
| 86 | #ifndef PYTHONPATH |
| 87 | #ifdef macintosh |
| 88 | #define PYTHONPATH ": :Lib :Lib:stdwin :Demo" |
| 89 | #endif /* macintosh */ |
| 90 | #endif /* !PYTHONPATH */ |
| 91 | |
| 92 | #ifndef PYTHONPATH |
| 93 | #ifdef MSDOS |
| 94 | #define PYTHONPATH ".;..\\lib;\\python\\lib" |
| 95 | #endif /* MSDOS */ |
| 96 | #endif /* !PYTHONPATH */ |
| 97 | |
| 98 | #ifndef PYTHONPATH |
| 99 | #define PYTHONPATH ".:/usr/local/lib/python" |
| 100 | #endif /* !PYTHONPATH */ |
| 101 | |
| 102 | extern char *getenv(); |
| 103 | |
| 104 | char * |
| 105 | getpythonpath() |
| 106 | { |
| 107 | #ifdef macintosh |
| 108 | return PYTHONPATH; |
| 109 | #else /* !macintosh */ |
| 110 | char *path = getenv("PYTHONPATH"); |
| 111 | char *defpath = PYTHONPATH; |
| 112 | char *buf; |
| 113 | char *p; |
| 114 | int n; |
| 115 | |
| 116 | if (path == 0 || *path == '\0') |
| 117 | return defpath; |
| 118 | n = strlen(path) + strlen(defpath) + 2; |
| 119 | buf = malloc(n); |
| 120 | if (buf == NULL) |
| 121 | return path; /* XXX too bad -- but not likely */ |
| 122 | strcpy(buf, path); |
| 123 | p = buf + strlen(buf); |
| 124 | *p++ = DELIM; |
| 125 | strcpy(p, defpath); |
| 126 | return buf; |
| 127 | #endif /* !macintosh */ |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /* Table of built-in modules. |
| 132 | These are initialized when first imported. |
| 133 | Note: selection of optional extensions is now generally done by the |
| 134 | makesetup script. */ |
| 135 | |
| 136 | extern void initarray(); |
| 137 | extern void initmath(); |
| 138 | extern void initparser(); |
| 139 | extern void initmac(); |
| 140 | extern void initregex(); |
| 141 | extern void initstrop(); |
| 142 | extern void initstruct(); |
| 143 | extern void inittime(); |
| 144 | extern void initdbm(); |
| 145 | extern void initfcntl(); |
| 146 | extern void initnis(); |
| 147 | extern void initpwd(); |
| 148 | extern void initgrp(); |
| 149 | extern void initselect(); |
| 150 | extern void initsocket(); |
| 151 | extern void initaudioop(); |
| 152 | extern void initimageop(); |
| 153 | extern void initrgbimg(); |
| 154 | extern void initstdwin(); |
| 155 | extern void initmd5(); |
| 156 | extern void initmpz(); |
| 157 | extern void initrotor(); |
| 158 | extern void inital(); |
| 159 | extern void initcd(); |
| 160 | extern void initcl(); |
| 161 | extern void initfm(); |
| 162 | extern void initgl(); |
| 163 | extern void initimgfile(); |
| 164 | extern void initsgi(); |
| 165 | extern void initsv(); |
| 166 | extern void initfl(); |
| 167 | extern void initthread(); |
| 168 | extern void inittiming(); |
| 169 | |
| 170 | /* -- ADDMODULE MARKER 1 -- */ |
| 171 | |
| 172 | extern void initmarshal(); |
| 173 | |
| 174 | struct { |
| 175 | char *name; |
| 176 | void (*initfunc)(); |
| 177 | } inittab[] = { |
| 178 | |
| 179 | {"array", initarray}, |
| 180 | {"math", initmath}, |
| 181 | {"parser", initparser}, |
| 182 | {"mac", initmac}, |
| 183 | {"regex", initregex}, |
| 184 | {"strop", initstrop}, |
| 185 | {"struct", initstruct}, |
| 186 | {"time", inittime}, |
| 187 | {"audioop", initaudioop}, |
| 188 | {"imageop", initimageop}, |
| 189 | {"rgbimg", initrgbimg}, |
| 190 | {"stdwin", initstdwin}, |
| 191 | {"md5", initmd5}, |
| 192 | {"rotor", initrotor}, |
| 193 | |
| 194 | /* -- ADDMODULE MARKER 2 -- */ |
| 195 | |
| 196 | /* This module "lives in" with marshal.c */ |
| 197 | {"marshal", initmarshal}, |
| 198 | |
| 199 | /* These entries are here for sys.builtin_module_names */ |
| 200 | {"__main__", NULL}, |
| 201 | {"__builtin__", NULL}, |
| 202 | {"sys", NULL}, |
| 203 | |
| 204 | /* Sentinel */ |
| 205 | {0, 0} |
| 206 | }; |
| 207 | |
| 208 | #ifdef USE_FROZEN |
| 209 | #include "frozen.c" |
| 210 | #else |
| 211 | struct frozen { |
| 212 | char *name; |
| 213 | char *code; |
| 214 | int size; |
| 215 | } frozen_modules[] = { |
| 216 | {0, 0, 0} |
| 217 | }; |
| 218 | #endif |