| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "tclInt.h" |
|---|
| 15 | #include "tclPort.h" |
|---|
| 16 | #if defined(__FreeBSD__) |
|---|
| 17 | # include <floatingpoint.h> |
|---|
| 18 | #endif |
|---|
| 19 | #if defined(__bsdi__) |
|---|
| 20 | # include <sys/param.h> |
|---|
| 21 | # if _BSDI_VERSION > 199501 |
|---|
| 22 | # include <dlfcn.h> |
|---|
| 23 | # endif |
|---|
| 24 | #endif |
|---|
| 25 | |
|---|
| 26 | extern char lib_history[]; |
|---|
| 27 | extern char lib_init[]; |
|---|
| 28 | extern char lib_ldAout[]; |
|---|
| 29 | extern char lib_http[]; |
|---|
| 30 | extern char lib_optparse[]; |
|---|
| 31 | extern char lib_parray[]; |
|---|
| 32 | extern char lib_safe[]; |
|---|
| 33 | extern char lib_word[]; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | static char defaultLibraryDir[sizeof(TCL_LIBRARY)+200] = TCL_LIBRARY; |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | static int initialized = 0; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | #include "tclInitScript.h" |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | static void PlatformInitExitHandler _ANSI_ARGS_((ClientData clientData)); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | static void |
|---|
| 88 | PlatformInitExitHandler(clientData) |
|---|
| 89 | ClientData clientData; |
|---|
| 90 | { |
|---|
| 91 | initialized = 0; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | void |
|---|
| 113 | TclPlatformInit(interp) |
|---|
| 114 | Tcl_Interp *interp; |
|---|
| 115 | { |
|---|
| 116 | #ifndef NO_UNAME |
|---|
| 117 | struct utsname name; |
|---|
| 118 | #endif |
|---|
| 119 | int unameOK; |
|---|
| 120 | |
|---|
| 121 | tclPlatform = TCL_PLATFORM_UNIX; |
|---|
| 122 | Tcl_SetVar(interp, "tclDefaultLibrary", defaultLibraryDir, |
|---|
| 123 | TCL_GLOBAL_ONLY); |
|---|
| 124 | Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, TCL_GLOBAL_ONLY); |
|---|
| 125 | Tcl_SetVar2(interp, "tcl_platform", "platform", "unix", TCL_GLOBAL_ONLY); |
|---|
| 126 | unameOK = 0; |
|---|
| 127 | #ifndef NO_UNAME |
|---|
| 128 | if (uname(&name) >= 0) { |
|---|
| 129 | unameOK = 1; |
|---|
| 130 | Tcl_SetVar2(interp, "tcl_platform", "os", name.sysname, |
|---|
| 131 | TCL_GLOBAL_ONLY); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | if ((strchr(name.release, '.') != NULL) |
|---|
| 141 | || !isdigit(UCHAR(name.version[0]))) { |
|---|
| 142 | Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, |
|---|
| 143 | TCL_GLOBAL_ONLY); |
|---|
| 144 | } else { |
|---|
| 145 | Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.version, |
|---|
| 146 | TCL_GLOBAL_ONLY); |
|---|
| 147 | Tcl_SetVar2(interp, "tcl_platform", "osVersion", ".", |
|---|
| 148 | TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); |
|---|
| 149 | Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, |
|---|
| 150 | TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); |
|---|
| 151 | } |
|---|
| 152 | Tcl_SetVar2(interp, "tcl_platform", "machine", name.machine, |
|---|
| 153 | TCL_GLOBAL_ONLY); |
|---|
| 154 | } |
|---|
| 155 | #endif |
|---|
| 156 | if (!unameOK) { |
|---|
| 157 | Tcl_SetVar2(interp, "tcl_platform", "os", "", TCL_GLOBAL_ONLY); |
|---|
| 158 | Tcl_SetVar2(interp, "tcl_platform", "osVersion", "", TCL_GLOBAL_ONLY); |
|---|
| 159 | Tcl_SetVar2(interp, "tcl_platform", "machine", "", TCL_GLOBAL_ONLY); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | if (!initialized) { |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | Tcl_CreateExitHandler(PlatformInitExitHandler, NULL); |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | #ifdef SIGPIPE |
|---|
| 182 | (void) signal(SIGPIPE, SIG_IGN); |
|---|
| 183 | #endif |
|---|
| 184 | |
|---|
| 185 | #ifdef __FreeBSD__ |
|---|
| 186 | fpsetround(FP_RN); |
|---|
| 187 | fpsetmask(0L); |
|---|
| 188 | #endif |
|---|
| 189 | |
|---|
| 190 | #if defined(__bsdi__) && (_BSDI_VERSION > 199501) |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | (void) dlopen (NULL, RTLD_NOW); |
|---|
| 195 | #endif |
|---|
| 196 | initialized = 1; |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | int |
|---|
| 220 | Tcl_Init(interp) |
|---|
| 221 | Tcl_Interp *interp; |
|---|
| 222 | { |
|---|
| 223 | if (tclPreInitScript != NULL) { |
|---|
| 224 | if (Tcl_Eval(interp, tclPreInitScript) == TCL_ERROR) { |
|---|
| 225 | return (TCL_ERROR); |
|---|
| 226 | }; |
|---|
| 227 | } |
|---|
| 228 | if (Tcl_Eval(interp, lib_init) != TCL_OK) { |
|---|
| 229 | return TCL_ERROR; |
|---|
| 230 | } |
|---|
| 231 | if (Tcl_Eval(interp, lib_optparse) != TCL_OK) { |
|---|
| 232 | return TCL_ERROR; |
|---|
| 233 | } |
|---|
| 234 | if (Tcl_Eval(interp, lib_safe) != TCL_OK) { |
|---|
| 235 | return TCL_ERROR; |
|---|
| 236 | } |
|---|
| 237 | if (Tcl_Eval(interp, lib_history) != TCL_OK) { |
|---|
| 238 | return TCL_ERROR; |
|---|
| 239 | } |
|---|
| 240 | if (Tcl_Eval(interp, lib_ldAout) != TCL_OK) { |
|---|
| 241 | return TCL_ERROR; |
|---|
| 242 | } |
|---|
| 243 | if (Tcl_Eval(interp, lib_parray) != TCL_OK) { |
|---|
| 244 | return TCL_ERROR; |
|---|
| 245 | } |
|---|
| 246 | if (Tcl_Eval(interp, lib_word) != TCL_OK) { |
|---|
| 247 | return TCL_ERROR; |
|---|
| 248 | } |
|---|
| 249 | if (Tcl_Eval(interp, lib_http) != TCL_OK) { |
|---|
| 250 | return TCL_ERROR; |
|---|
| 251 | } |
|---|
| 252 | return(Tcl_Eval(interp, initScript)); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | void |
|---|
| 274 | Tcl_SourceRCFile(interp) |
|---|
| 275 | Tcl_Interp *interp; |
|---|
| 276 | { |
|---|
| 277 | Tcl_DString temp; |
|---|
| 278 | char *fileName; |
|---|
| 279 | Tcl_Channel errChannel; |
|---|
| 280 | |
|---|
| 281 | fileName = Tcl_GetVar(interp, "tcl_rcFileName", TCL_GLOBAL_ONLY); |
|---|
| 282 | |
|---|
| 283 | if (fileName != NULL) { |
|---|
| 284 | Tcl_Channel c; |
|---|
| 285 | char *fullName; |
|---|
| 286 | |
|---|
| 287 | Tcl_DStringInit(&temp); |
|---|
| 288 | fullName = Tcl_TranslateFileName(interp, fileName, &temp); |
|---|
| 289 | if (fullName == NULL) { |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | } else { |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | c = Tcl_OpenFileChannel(NULL, fullName, "r", 0); |
|---|
| 302 | if (c != (Tcl_Channel) NULL) { |
|---|
| 303 | Tcl_Close(NULL, c); |
|---|
| 304 | if (Tcl_EvalFile(interp, fullName) != TCL_OK) { |
|---|
| 305 | errChannel = Tcl_GetStdChannel(TCL_STDERR); |
|---|
| 306 | if (errChannel) { |
|---|
| 307 | Tcl_Write(errChannel, interp->result, -1); |
|---|
| 308 | Tcl_Write(errChannel, "\n", 1); |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | } |
|---|
| 313 | Tcl_DStringFree(&temp); |
|---|
| 314 | } |
|---|
| 315 | } |
|---|