OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [unix/] [tclUnixInit.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tclUnixInit.c --
3
 *
4
 *      Contains the Unix-specific interpreter initialization functions.
5
 *
6
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 * RCS: @(#) $Id: tclUnixInit.c,v 1.1.1.1 2002-01-16 10:25:37 markom Exp $
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
/*
27
 * Default directory in which to look for Tcl library scripts.  The
28
 * symbol is defined by Makefile.
29
 */
30
 
31
static char defaultLibraryDir[sizeof(TCL_LIBRARY)+200] = TCL_LIBRARY;
32
 
33
/*
34
 * Directory in which to look for packages (each package is typically
35
 * installed as a subdirectory of this directory).  The symbol is
36
 * defined by Makefile.
37
 */
38
 
39
static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH;
40
 
41
/*
42
 * Is this module initialized?
43
 */
44
 
45
static int initialized = 0;
46
 
47
/*
48
 * The Init script, tclPreInitScript variable, and the routine
49
 * TclSetPreInitScript (common to Windows and Unix platforms) are defined
50
 * in generic/tclInitScript.h.
51
 */
52
 
53
#include "tclInitScript.h"
54
 
55
/*
56
 * Static routines in this file:
57
 */
58
 
59
static void     PlatformInitExitHandler _ANSI_ARGS_((ClientData clientData));
60
 
61
/*
62
 *----------------------------------------------------------------------
63
 *
64
 * PlatformInitExitHandler --
65
 *
66
 *      Uninitializes all values on unload, so that this module can
67
 *      be later reinitialized.
68
 *
69
 * Results:
70
 *      None.
71
 *
72
 * Side effects:
73
 *      Returns the module to uninitialized state.
74
 *
75
 *----------------------------------------------------------------------
76
 */
77
 
78
static void
79
PlatformInitExitHandler(clientData)
80
    ClientData clientData;              /* Unused. */
81
{
82
    initialized = 0;
83
}
84
 
85
/*
86
 *----------------------------------------------------------------------
87
 *
88
 * TclPlatformInit --
89
 *
90
 *      Performs Unix-specific interpreter initialization related to the
91
 *      tcl_library and tcl_platform variables, and other platform-
92
 *      specific things.
93
 *
94
 * Results:
95
 *      None.
96
 *
97
 * Side effects:
98
 *      Sets "tcl_library" and "tcl_platform" Tcl variables.
99
 *
100
 *----------------------------------------------------------------------
101
 */
102
 
103
void
104
TclPlatformInit(interp)
105
    Tcl_Interp *interp;
106
{
107
#ifndef NO_UNAME
108
    struct utsname name;
109
#endif
110
    int unameOK;
111
 
112
    tclPlatform = TCL_PLATFORM_UNIX;
113
    Tcl_SetVar(interp, "tclDefaultLibrary", defaultLibraryDir,
114
            TCL_GLOBAL_ONLY);
115
    Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, TCL_GLOBAL_ONLY);
116
    Tcl_SetVar2(interp, "tcl_platform", "platform", "unix", TCL_GLOBAL_ONLY);
117
    unameOK = 0;
118
#ifndef NO_UNAME
119
    if (uname(&name) >= 0) {
120
        unameOK = 1;
121
        Tcl_SetVar2(interp, "tcl_platform", "os", name.sysname,
122
                TCL_GLOBAL_ONLY);
123
        /*
124
         * The following code is a special hack to handle differences in
125
         * the way version information is returned by uname.  On most
126
         * systems the full version number is available in name.release.
127
         * However, under AIX the major version number is in
128
         * name.version and the minor version number is in name.release.
129
         */
130
 
131
        if ((strchr(name.release, '.') != NULL)
132
                || !isdigit(UCHAR(name.version[0]))) {
133
            Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release,
134
                    TCL_GLOBAL_ONLY);
135
        } else {
136
            Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.version,
137
                    TCL_GLOBAL_ONLY);
138
            Tcl_SetVar2(interp, "tcl_platform", "osVersion", ".",
139
                    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE);
140
            Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release,
141
                    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE);
142
        }
143
        Tcl_SetVar2(interp, "tcl_platform", "machine", name.machine,
144
                TCL_GLOBAL_ONLY);
145
    }
146
#endif
147
    if (!unameOK) {
148
        Tcl_SetVar2(interp, "tcl_platform", "os", "", TCL_GLOBAL_ONLY);
149
        Tcl_SetVar2(interp, "tcl_platform", "osVersion", "", TCL_GLOBAL_ONLY);
150
        Tcl_SetVar2(interp, "tcl_platform", "machine", "", TCL_GLOBAL_ONLY);
151
    }
152
 
153
    if (!initialized) {
154
 
155
        /*
156
         * Create an exit handler so that uninitialization will be done
157
         * on unload.
158
         */
159
 
160
        Tcl_CreateExitHandler(PlatformInitExitHandler, NULL);
161
 
162
        /*
163
         * The code below causes SIGPIPE (broken pipe) errors to
164
         * be ignored.  This is needed so that Tcl processes don't
165
         * die if they create child processes (e.g. using "exec" or
166
         * "open") that terminate prematurely.  The signal handler
167
         * is only set up when the first interpreter is created;
168
         * after this the application can override the handler with
169
         * a different one of its own, if it wants.
170
         */
171
 
172
#ifdef SIGPIPE
173
        (void) signal(SIGPIPE, SIG_IGN);
174
#endif /* SIGPIPE */
175
 
176
#ifdef __FreeBSD__
177
        fpsetround(FP_RN);
178
        fpsetmask(0L);
179
#endif
180
 
181
#if defined(__bsdi__) && (_BSDI_VERSION > 199501)
182
        /*
183
         * Find local symbols. Don't report an error if we fail.
184
         */
185
        (void) dlopen (NULL, RTLD_NOW);
186
#endif
187
        initialized = 1;
188
    }
189
}
190
 
191
/*
192
 *----------------------------------------------------------------------
193
 *
194
 * Tcl_Init --
195
 *
196
 *      This procedure is typically invoked by Tcl_AppInit procedures
197
 *      to perform additional initialization for a Tcl interpreter,
198
 *      such as sourcing the "init.tcl" script.
199
 *
200
 * Results:
201
 *      Returns a standard Tcl completion code and sets interp->result
202
 *      if there is an error.
203
 *
204
 * Side effects:
205
 *      Depends on what's in the init.tcl script.
206
 *
207
 *----------------------------------------------------------------------
208
 */
209
 
210
int
211
Tcl_Init(interp)
212
    Tcl_Interp *interp;         /* Interpreter to initialize. */
213
{
214
    if (tclPreInitScript != NULL) {
215
        if (Tcl_Eval(interp, tclPreInitScript) == TCL_ERROR) {
216
            return (TCL_ERROR);
217
        };
218
    }
219
    return(Tcl_Eval(interp, initScript));
220
}
221
 
222
/*
223
 *----------------------------------------------------------------------
224
 *
225
 * Tcl_SourceRCFile --
226
 *
227
 *      This procedure is typically invoked by Tcl_Main of Tk_Main
228
 *      procedure to source an application specific rc file into the
229
 *      interpreter at startup time.
230
 *
231
 * Results:
232
 *      None.
233
 *
234
 * Side effects:
235
 *      Depends on what's in the rc script.
236
 *
237
 *----------------------------------------------------------------------
238
 */
239
 
240
void
241
Tcl_SourceRCFile(interp)
242
    Tcl_Interp *interp;         /* Interpreter to source rc file into. */
243
{
244
    Tcl_DString temp;
245
    char *fileName;
246
    Tcl_Channel errChannel;
247
 
248
    fileName = Tcl_GetVar(interp, "tcl_rcFileName", TCL_GLOBAL_ONLY);
249
 
250
    if (fileName != NULL) {
251
        Tcl_Channel c;
252
        char *fullName;
253
 
254
        Tcl_DStringInit(&temp);
255
        fullName = Tcl_TranslateFileName(interp, fileName, &temp);
256
        if (fullName == NULL) {
257
            /*
258
             * Couldn't translate the file name (e.g. it referred to a
259
             * bogus user or there was no HOME environment variable).
260
             * Just do nothing.
261
             */
262
        } else {
263
 
264
            /*
265
             * Test for the existence of the rc file before trying to read it.
266
             */
267
 
268
            c = Tcl_OpenFileChannel(NULL, fullName, "r", 0);
269
            if (c != (Tcl_Channel) NULL) {
270
                Tcl_Close(NULL, c);
271
                if (Tcl_EvalFile(interp, fullName) != TCL_OK) {
272
                    errChannel = Tcl_GetStdChannel(TCL_STDERR);
273
                    if (errChannel) {
274
                        Tcl_Write(errChannel, interp->result, -1);
275
                        Tcl_Write(errChannel, "\n", 1);
276
                    }
277
                }
278
            }
279
        }
280
        Tcl_DStringFree(&temp);
281
    }
282
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.