1/*----------------------------------------------------------------------------
2|   Copyright (c) 2007 Rolf Ade (rolf@pointsman.de)
3+-----------------------------------------------------------------------------
4|
5|   $Id: tdomStubLib.c,v 1.8 2007/08/12 11:29:25 rolf Exp $
6|
7|   Implements entry point, which has to be called by C coded extensions
8|   to tDOM. Following http://wiki.tcl.tk/3358.
9|
10|   The contents of this file are subject to the Mozilla Public License
11|   Version 1.1 (the "License"); you may not use this file except in
12|   compliance with the License. You may obtain a copy of the License at
13|   http://www.mozilla.org/MPL/
14|
15|   Software distributed under the License is distributed on an "AS IS"
16|   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
17|   License for the specific language governing rights and limitations
18|   under the License.
19|
20|   The Original Code is tDOM.
21|
22|   The Initial Developer of the Original Code is Jochen Loewer
23|   Portions created by Jochen Loewer are Copyright (C) 1998, 1999
24|   Jochen Loewer. All Rights Reserved.
25|
26|   Contributor(s):
27|
28|
29|   written by Rolf Ade
30|   August, 2007
31|
32\---------------------------------------------------------------------------*/
33
34#ifndef USE_TCL_STUBS
35#  define USE_TCL_STUBS
36#endif
37#undef USE_TCL_STUB_PROCS
38
39#include <tdom.h>
40
41/*
42 * Ensure that Tdom_InitStubs is built as an exported symbol.  The other stub
43 * functions should be built as non-exported symbols.
44 */
45
46#undef TCL_STORAGE_CLASS
47#define TCL_STORAGE_CLASS DLLEXPORT
48
49TdomStubs *tdomStubsPtr;
50
51/*----------------------------------------------------------------------------
52|   Tdom_InitStubs
53|
54\---------------------------------------------------------------------------*/
55
56CONST char *
57Tdom_InitStubs (
58    Tcl_Interp *interp,
59    char *version,
60    int exact
61    )
62{
63    CONST char *actualVersion;
64    ClientData clientData = NULL;
65
66#if (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION == 0)
67    Tcl_SetResult(interp, "Too old Tcl version. Binary extensions "
68                  "to tDOM are not possible, with a that outdated "
69                  "Tcl version.", TCL_STATIC);
70    return NULL;
71#else
72    actualVersion = Tcl_PkgRequireEx(interp, "tdom", version, exact,
73                                     (ClientData*) &clientData);
74    tdomStubsPtr = (TdomStubs*)clientData;
75
76    if (!actualVersion) {
77        return NULL;
78    }
79    if (!tdomStubsPtr) {
80        Tcl_SetResult(interp, "This implementation of Tdom does not "
81                      "support stubs", TCL_STATIC);
82        return NULL;
83    }
84
85    return actualVersion;
86#endif
87}
88