Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The |
| 3 | 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 | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 25 | /* Configurable Python configuration file */ |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 29 | #ifdef USE_STDWIN |
| 30 | #include <stdwin.h> |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 31 | |
| 32 | static int use_stdwin; |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 33 | #endif |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 34 | |
| 35 | /*ARGSUSED*/ |
| 36 | void |
| 37 | initargs(p_argc, p_argv) |
| 38 | int *p_argc; |
| 39 | char ***p_argv; |
| 40 | { |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 41 | #ifdef USE_STDWIN |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 42 | extern char *getenv(); |
| 43 | char *display; |
Guido van Rossum | 6607f44 | 1991-01-02 13:50:48 +0000 | [diff] [blame] | 44 | |
| 45 | /* Ignore an initial argument of '-s', for backward compatibility */ |
| 46 | if (*p_argc > 1 && strcmp((*p_argv)[1], "-s") == 0) { |
| 47 | (*p_argv)[1] = (*p_argv)[0]; |
| 48 | (*p_argc)--, (*p_argv)++; |
| 49 | } |
| 50 | |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 51 | /* Assume we have to initialize stdwin if either of the following |
| 52 | conditions holds: |
| 53 | - the environment variable $DISPLAY is set |
| 54 | - there is an argument "-display" somewhere |
| 55 | */ |
| 56 | |
| 57 | display = getenv("DISPLAY"); |
| 58 | if (display != 0) |
| 59 | use_stdwin = 1; |
| 60 | else { |
| 61 | int i; |
| 62 | /* Scan through the arguments looking for "-display" */ |
| 63 | for (i = 1; i < *p_argc; i++) { |
| 64 | if (strcmp((*p_argv)[i], "-display") == 0) { |
| 65 | use_stdwin = 1; |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (use_stdwin) |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 72 | wargs(p_argc, p_argv); |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 73 | #endif |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
| 77 | initcalls() |
| 78 | { |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
| 82 | donecalls() |
| 83 | { |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 84 | #ifdef USE_STDWIN |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 85 | if (use_stdwin) |
| 86 | wdone(); |
Guido van Rossum | 28a83ab | 1991-01-18 15:32:01 +0000 | [diff] [blame] | 87 | #endif |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 88 | #ifdef USE_AUDIO |
| 89 | asa_done(); |
| 90 | #endif |
| 91 | } |
| 92 | |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 93 | #ifdef USE_STDWIN |
| 94 | static void |
| 95 | maybeinitstdwin() |
| 96 | { |
| 97 | if (use_stdwin) |
| 98 | initstdwin(); |
| 99 | else |
| 100 | fprintf(stderr, |
| 101 | "No $DISPLAY nor -display arg -- stdwin not available\n"); |
| 102 | } |
| 103 | #endif |
| 104 | |
Guido van Rossum | aec7855 | 1990-12-20 23:03:58 +0000 | [diff] [blame] | 105 | #ifndef PYTHONPATH |
| 106 | #define PYTHONPATH ".:/usr/local/lib/python" |
| 107 | #endif |
| 108 | |
| 109 | extern char *getenv(); |
| 110 | |
| 111 | char * |
| 112 | getpythonpath() |
| 113 | { |
| 114 | char *path = getenv("PYTHONPATH"); |
| 115 | if (path == 0) |
| 116 | path = PYTHONPATH; |
| 117 | return path; |
| 118 | } |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 119 | |
| 120 | |
| 121 | /* Table of built-in modules. |
| 122 | These are initialized when first imported. */ |
| 123 | |
| 124 | /* Standard modules */ |
| 125 | extern void inittime(); |
| 126 | extern void initmath(); |
| 127 | extern void initregexp(); |
| 128 | extern void initposix(); |
| 129 | #ifdef USE_AUDIO |
| 130 | extern void initaudio(); |
| 131 | #endif |
| 132 | #ifdef USE_AMOEBA |
| 133 | extern void initamoeba(); |
| 134 | #endif |
| 135 | #ifdef USE_GL |
| 136 | extern void initgl(); |
Guido van Rossum | 2abc7a6 | 1991-04-03 19:01:18 +0000 | [diff] [blame] | 137 | #ifdef USE_FM |
| 138 | extern void initfm(); |
| 139 | #endif |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 140 | #ifdef USE_PANEL |
| 141 | extern void initpanel(); |
| 142 | #endif |
| 143 | #endif |
| 144 | #ifdef USE_STDWIN |
| 145 | extern void maybeinitstdwin(); |
| 146 | #endif |
| 147 | |
| 148 | struct { |
| 149 | char *name; |
| 150 | void (*initfunc)(); |
| 151 | } inittab[] = { |
| 152 | |
| 153 | /* Standard modules */ |
| 154 | |
| 155 | {"time", inittime}, |
| 156 | {"math", initmath}, |
| 157 | {"regexp", initregexp}, |
| 158 | {"posix", initposix}, |
| 159 | |
| 160 | |
| 161 | /* Optional modules */ |
| 162 | |
| 163 | #ifdef USE_AUDIO |
| 164 | {"audio", initaudio}, |
| 165 | #endif |
| 166 | |
| 167 | #ifdef USE_AMOEBA |
| 168 | {"amoeba", initamoeba}, |
| 169 | #endif |
| 170 | |
| 171 | #ifdef USE_GL |
| 172 | {"gl", initgl}, |
Guido van Rossum | 2abc7a6 | 1991-04-03 19:01:18 +0000 | [diff] [blame] | 173 | #ifdef USE_FM |
| 174 | {"fm", initfm}, |
| 175 | #endif |
Guido van Rossum | 59e53a5 | 1991-02-19 12:22:24 +0000 | [diff] [blame] | 176 | #ifdef USE_PANEL |
| 177 | {"pnl", initpanel}, |
| 178 | #endif |
| 179 | #endif |
| 180 | |
| 181 | #ifdef USE_STDWIN |
| 182 | {"stdwin", maybeinitstdwin}, |
| 183 | #endif |
| 184 | |
| 185 | {0, 0} /* Sentinel */ |
| 186 | }; |