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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [win/] [tclWinLoad.c] - Blame information for rev 1771

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tclWinLoad.c --
3
 *
4
 *      This procedure provides a version of the TclLoadFile that
5
 *      works with the Windows "LoadLibrary" and "GetProcAddress"
6
 *      API for dynamic loading.
7
 *
8
 * Copyright (c) 1995 Sun Microsystems, Inc.
9
 *
10
 * See the file "license.terms" for information on usage and redistribution
11
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
 *
13
 * RCS: @(#) $Id: tclWinLoad.c,v 1.1.1.1 2002-01-16 10:25:38 markom Exp $
14
 */
15
 
16
#include "tclInt.h"
17
#include "tclPort.h"
18
 
19
 
20
/*
21
 *----------------------------------------------------------------------
22
 *
23
 * TclLoadFile --
24
 *
25
 *      Dynamically loads a binary code file into memory and returns
26
 *      the addresses of two procedures within that file, if they
27
 *      are defined.
28
 *
29
 * Results:
30
 *      A standard Tcl completion code.  If an error occurs, an error
31
 *      message is left in interp->result.
32
 *
33
 * Side effects:
34
 *      New code suddenly appears in memory.
35
 *
36
 *----------------------------------------------------------------------
37
 */
38
 
39
int
40
TclLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr)
41
    Tcl_Interp *interp;         /* Used for error reporting. */
42
    char *fileName;             /* Name of the file containing the desired
43
                                 * code. */
44
    char *sym1, *sym2;          /* Names of two procedures to look up in
45
                                 * the file's symbol table. */
46
    Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
47
                                /* Where to return the addresses corresponding
48
                                 * to sym1 and sym2. */
49
{
50
    HINSTANCE handle;
51
    char *buffer;
52
 
53
    handle = TclWinLoadLibrary(fileName);
54
    if (handle == NULL) {
55
        Tcl_AppendResult(interp, "couldn't load file \"", fileName,
56
                "\": ", Tcl_PosixError(interp), (char *) NULL);
57
        return TCL_ERROR;
58
    }
59
 
60
    /*
61
     * For each symbol, check for both Symbol and _Symbol, since Borland
62
     * generates C symbols with a leading '_' by default.
63
     */
64
 
65
    *proc1Ptr = (Tcl_PackageInitProc *) GetProcAddress(handle, sym1);
66
    if (*proc1Ptr == NULL) {
67
        buffer = ckalloc(strlen(sym1)+2);
68
        buffer[0] = '_';
69
        strcpy(buffer+1, sym1);
70
        *proc1Ptr = (Tcl_PackageInitProc *) GetProcAddress(handle, buffer);
71
        ckfree(buffer);
72
    }
73
 
74
    *proc2Ptr = (Tcl_PackageInitProc *) GetProcAddress(handle, sym2);
75
    if (*proc2Ptr == NULL) {
76
        buffer = ckalloc(strlen(sym2)+2);
77
        buffer[0] = '_';
78
        strcpy(buffer+1, sym2);
79
        *proc2Ptr = (Tcl_PackageInitProc *) GetProcAddress(handle, buffer);
80
        ckfree(buffer);
81
    }
82
 
83
    return TCL_OK;
84
}
85
 
86
/*
87
 *----------------------------------------------------------------------
88
 *
89
 * TclGuessPackageName --
90
 *
91
 *      If the "load" command is invoked without providing a package
92
 *      name, this procedure is invoked to try to figure it out.
93
 *
94
 * Results:
95
 *      Always returns 0 to indicate that we couldn't figure out a
96
 *      package name;  generic code will then try to guess the package
97
 *      from the file name.  A return value of 1 would have meant that
98
 *      we figured out the package name and put it in bufPtr.
99
 *
100
 * Side effects:
101
 *      None.
102
 *
103
 *----------------------------------------------------------------------
104
 */
105
 
106
int
107
TclGuessPackageName(fileName, bufPtr)
108
    char *fileName;             /* Name of file containing package (already
109
                                 * translated to local form if needed). */
110
    Tcl_DString *bufPtr;        /* Initialized empty dstring.  Append
111
                                 * package name to this if possible. */
112
{
113
    return 0;
114
}

powered by: WebSVN 2.1.0

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