Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1 | /* -*- C -*- *********************************************** |
| 2 | Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
Guido van Rossum | e35399e | 1993-01-10 18:33:56 +0000 | [diff] [blame] | 3 | Amsterdam, The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 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 | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 25 | /* Universal Python configuration file */ |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 27 | #ifdef HAVE_CONFIG_H |
| 28 | #include "config.h" |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
Guido van Rossum | 9731d44 | 1994-08-23 13:48:30 +0000 | [diff] [blame] | 31 | #ifdef macintosh |
| 32 | /* The Macintosh main program is in macmain.c */ |
| 33 | #define NO_MAIN |
| 34 | #endif |
| 35 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 37 | #include <string.h> |
Guido van Rossum | 97f0277 | 1992-09-03 20:49:55 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 39 | #include "myproto.h" |
Guido van Rossum | b001f7a | 1992-08-19 16:44:41 +0000 | [diff] [blame] | 40 | #include "mymalloc.h" |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 41 | #include "osdefs.h" |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 42 | #include "intrcheck.h" |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | 9b4e1b3 | 1991-12-30 01:43:49 +0000 | [diff] [blame] | 44 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 45 | #ifndef NO_MAIN |
Guido van Rossum | aa01141 | 1991-12-16 13:05:20 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 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(). */ |
Guido van Rossum | 9f462af | 1991-12-10 13:54:12 +0000 | [diff] [blame] | 53 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 54 | static char *argv0; |
Guido van Rossum | aa01141 | 1991-12-16 13:05:20 +0000 | [diff] [blame] | 55 | |
Guido van Rossum | 7b1e974 | 1994-08-29 10:46:42 +0000 | [diff] [blame] | 56 | /* These are made available for other modules that might need them. |
| 57 | This is rare, but it is needed by the secureware module. */ |
| 58 | |
| 59 | static char **orig_argv; |
| 60 | static int orig_argc; |
| 61 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 62 | main(argc, argv) |
| 63 | int argc; |
| 64 | char **argv; |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 65 | { |
Guido van Rossum | 7b1e974 | 1994-08-29 10:46:42 +0000 | [diff] [blame] | 66 | orig_argc = argc; |
| 67 | orig_argv = argv; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 68 | argv0 = argv[0]; |
| 69 | realmain(argc, argv); |
| 70 | } |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 72 | char * |
| 73 | getprogramname() |
| 74 | { |
| 75 | return argv0; |
| 76 | } |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 77 | |
Guido van Rossum | 7b1e974 | 1994-08-29 10:46:42 +0000 | [diff] [blame] | 78 | void |
| 79 | getargcargv(argc,argv) |
| 80 | int *argc; |
| 81 | char ***argv; |
| 82 | { |
| 83 | *argc = orig_argc; |
| 84 | *argv = orig_argv; |
| 85 | } |
| 86 | |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 89 | |
Guido van Rossum | 72824ba | 1994-08-19 12:03:04 +0000 | [diff] [blame] | 90 | /* Python version information */ |
| 91 | |
| 92 | #include "patchlevel.h" |
| 93 | |
| 94 | /* Return the version string. This is constructed from the official |
| 95 | version number (from patchlevel.h), and the current date (if known |
| 96 | to the compiler, else a manually inserted date). */ |
| 97 | |
| 98 | #define VERSION "%s (%s)" |
| 99 | |
| 100 | #ifdef __DATE__ |
| 101 | #define DATE __DATE__ |
| 102 | #else |
| 103 | #define DATE "Aug 17 1994" |
| 104 | #endif |
| 105 | |
| 106 | char * |
| 107 | getversion() |
| 108 | { |
| 109 | static char version[80]; |
| 110 | sprintf(version, VERSION, PATCHLEVEL, DATE); |
| 111 | return version; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /* Return the copyright string. This is updated manually. */ |
| 116 | |
| 117 | char * |
| 118 | getcopyright() |
| 119 | { |
| 120 | return "Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam"; |
| 121 | } |
| 122 | |
| 123 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 124 | /* Return the initial python search path. This is called once from |
| 125 | initsys() to initialize sys.path. |
| 126 | The environment variable PYTHONPATH is fetched and the default path |
| 127 | appended. (The Mac has no environment variables, so there the |
| 128 | default path is always returned.) The default path may be passed |
| 129 | to the preprocessor; if not, a system-dependent default is used. */ |
| 130 | |
| 131 | #ifndef PYTHONPATH |
| 132 | #ifdef macintosh |
Guido van Rossum | 9731d44 | 1994-08-23 13:48:30 +0000 | [diff] [blame] | 133 | #define PYTHONPATH ": :Lib :Lib:stdwin :Lib:test :Lib:mac" |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 134 | #endif /* macintosh */ |
| 135 | #endif /* !PYTHONPATH */ |
| 136 | |
| 137 | #ifndef PYTHONPATH |
| 138 | #if defined(MSDOS) || defined(NT) |
| 139 | #define PYTHONPATH ".;..\\lib;\\python\\lib" |
| 140 | #endif /* MSDOS || NT */ |
| 141 | #endif /* !PYTHONPATH */ |
| 142 | |
| 143 | #ifndef PYTHONPATH |
| 144 | #define PYTHONPATH ".:/usr/local/lib/python" |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 145 | #endif /* !PYTHONPATH */ |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 146 | |
| 147 | extern char *getenv(); |
| 148 | |
| 149 | char * |
| 150 | getpythonpath() |
| 151 | { |
| 152 | char *path = getenv("PYTHONPATH"); |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 153 | char *defpath = PYTHONPATH; |
Guido van Rossum | 6e890b8 | 1994-10-05 12:25:12 +0000 | [diff] [blame^] | 154 | static char *buf = NULL; |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 155 | char *p; |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 156 | int n; |
| 157 | |
Guido van Rossum | 6e890b8 | 1994-10-05 12:25:12 +0000 | [diff] [blame^] | 158 | if (path == NULL) |
| 159 | path = ""; |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 160 | n = strlen(path) + strlen(defpath) + 2; |
Guido van Rossum | 6e890b8 | 1994-10-05 12:25:12 +0000 | [diff] [blame^] | 161 | if (buf != NULL) { |
| 162 | free(buf); |
| 163 | buf = NULL; |
| 164 | } |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 165 | buf = malloc(n); |
| 166 | if (buf == NULL) |
Guido van Rossum | 6e890b8 | 1994-10-05 12:25:12 +0000 | [diff] [blame^] | 167 | fatal("not enough memory to copy module search path"); |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 168 | strcpy(buf, path); |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 169 | p = buf + strlen(buf); |
| 170 | *p++ = DELIM; |
| 171 | strcpy(p, defpath); |
Guido van Rossum | c888bf7 | 1992-06-03 17:05:13 +0000 | [diff] [blame] | 172 | return buf; |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 173 | } |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 174 | |
| 175 | |
| 176 | /* Table of built-in modules. |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 177 | These are initialized when first imported. |
| 178 | Note: selection of optional extensions is now generally done by the |
| 179 | makesetup script. */ |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 180 | |
Guido van Rossum | 3a40ae4 | 1992-09-25 21:54:05 +0000 | [diff] [blame] | 181 | /* -- ADDMODULE MARKER 1 -- */ |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 182 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 183 | extern void initmarshal(); |
| 184 | |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 185 | struct { |
| 186 | char *name; |
| 187 | void (*initfunc)(); |
| 188 | } inittab[] = { |
| 189 | |
Guido van Rossum | 3a40ae4 | 1992-09-25 21:54:05 +0000 | [diff] [blame] | 190 | /* -- ADDMODULE MARKER 2 -- */ |
| 191 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 192 | /* This module "lives in" with marshal.c */ |
| 193 | {"marshal", initmarshal}, |
| 194 | |
| 195 | /* These entries are here for sys.builtin_module_names */ |
| 196 | {"__main__", NULL}, |
| 197 | {"__builtin__", NULL}, |
| 198 | {"sys", NULL}, |
| 199 | |
| 200 | /* Sentinel */ |
| 201 | {0, 0} |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 202 | }; |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 203 | |
| 204 | #ifdef USE_FROZEN |
| 205 | #include "frozen.c" |
| 206 | #else |
| 207 | struct frozen { |
| 208 | char *name; |
| 209 | char *code; |
| 210 | int size; |
| 211 | } frozen_modules[] = { |
| 212 | {0, 0, 0} |
| 213 | }; |
| 214 | #endif |