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