| 1 |
/* |
| 2 |
* pkgd.c -- |
| 3 |
* |
| 4 |
* This file contains a simple Tcl package "pkgd" that is intended for |
| 5 |
* testing the Tcl dynamic loading facilities. It can be used in both |
| 6 |
* safe and unsafe interpreters. |
| 7 |
* |
| 8 |
* Copyright (c) 1995 Sun Microsystems, Inc. |
| 9 |
* |
| 10 |
* See the file "license.terms" for information on usage and redistribution of |
| 11 |
* this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 12 |
*/ |
| 13 |
|
| 14 |
#undef STATIC_BUILD |
| 15 |
#include "tcl.h" |
| 16 |
|
| 17 |
/* |
| 18 |
*---------------------------------------------------------------------- |
| 19 |
* |
| 20 |
* Pkgd_SubObjCmd -- |
| 21 |
* |
| 22 |
* This procedure is invoked to process the "pkgd_sub" Tcl command. It |
| 23 |
* expects two arguments and returns their difference. |
| 24 |
* |
| 25 |
* Results: |
| 26 |
* A standard Tcl result. |
| 27 |
* |
| 28 |
* Side effects: |
| 29 |
* See the user documentation. |
| 30 |
* |
| 31 |
*---------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
static int |
| 35 |
Pkgd_SubObjCmd( |
| 36 |
void *dummy, /* Not used. */ |
| 37 |
Tcl_Interp *interp, /* Current interpreter. */ |
| 38 |
int objc, /* Number of arguments. */ |
| 39 |
Tcl_Obj *const objv[]) /* Argument objects. */ |
| 40 |
{ |
| 41 |
int first, second; |
| 42 |
(void)dummy; |
| 43 |
|
| 44 |
if (objc != 3) { |
| 45 |
Tcl_WrongNumArgs(interp, 1, objv, "num num"); |
| 46 |
return TCL_ERROR; |
| 47 |
} |
| 48 |
if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) |
| 49 |
|| (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { |
| 50 |
return TCL_ERROR; |
| 51 |
} |
| 52 |
Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); |
| 53 |
return TCL_OK; |
| 54 |
} |
| 55 |
|
| 56 |
/* |
| 57 |
*---------------------------------------------------------------------- |
| 58 |
* |
| 59 |
* Pkgd_UnsafeCmd -- |
| 60 |
* |
| 61 |
* This procedure is invoked to process the "pkgd_unsafe" Tcl command. It |
| 62 |
* just returns a constant string. |
| 63 |
* |
| 64 |
* Results: |
| 65 |
* A standard Tcl result. |
| 66 |
* |
| 67 |
* Side effects: |
| 68 |
* See the user documentation. |
| 69 |
* |
| 70 |
*---------------------------------------------------------------------- |
| 71 |
*/ |
| 72 |
|
| 73 |
static int |
| 74 |
Pkgd_UnsafeObjCmd( |
| 75 |
void *dummy, /* Not used. */ |
| 76 |
Tcl_Interp *interp, /* Current interpreter. */ |
| 77 |
int objc, /* Number of arguments. */ |
| 78 |
Tcl_Obj *const objv[]) /* Argument objects. */ |
| 79 |
{ |
| 80 |
(void)dummy; |
| 81 |
(void)objc; |
| 82 |
(void)objv; |
| 83 |
|
| 84 |
Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); |
| 85 |
return TCL_OK; |
| 86 |
} |
| 87 |
|
| 88 |
/* |
| 89 |
*---------------------------------------------------------------------- |
| 90 |
* |
| 91 |
* Pkgd_Init -- |
| 92 |
* |
| 93 |
* This is a package initialization procedure, which is called by Tcl |
| 94 |
* when this package is to be added to an interpreter. |
| 95 |
* |
| 96 |
* Results: |
| 97 |
* None. |
| 98 |
* |
| 99 |
* Side effects: |
| 100 |
* None. |
| 101 |
* |
| 102 |
*---------------------------------------------------------------------- |
| 103 |
*/ |
| 104 |
|
| 105 |
DLLEXPORT int |
| 106 |
Pkgd_Init( |
| 107 |
Tcl_Interp *interp) /* Interpreter in which the package is to be |
| 108 |
* made available. */ |
| 109 |
{ |
| 110 |
int code; |
| 111 |
|
| 112 |
if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) { |
| 113 |
return TCL_ERROR; |
| 114 |
} |
| 115 |
code = Tcl_PkgProvide(interp, "pkgd", "7.3"); |
| 116 |
if (code != TCL_OK) { |
| 117 |
return code; |
| 118 |
} |
| 119 |
Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, NULL, NULL); |
| 120 |
Tcl_CreateObjCommand(interp, "pkgd_unsafe", Pkgd_UnsafeObjCmd, NULL, |
| 121 |
NULL); |
| 122 |
return TCL_OK; |
| 123 |
} |
| 124 |
|
| 125 |
/* |
| 126 |
*---------------------------------------------------------------------- |
| 127 |
* |
| 128 |
* Pkgd_SafeInit -- |
| 129 |
* |
| 130 |
* This is a package initialization procedure, which is called by Tcl |
| 131 |
* when this package is to be added to a safe interpreter. |
| 132 |
* |
| 133 |
* Results: |
| 134 |
* None. |
| 135 |
* |
| 136 |
* Side effects: |
| 137 |
* None. |
| 138 |
* |
| 139 |
*---------------------------------------------------------------------- |
| 140 |
*/ |
| 141 |
|
| 142 |
DLLEXPORT int |
| 143 |
Pkgd_SafeInit( |
| 144 |
Tcl_Interp *interp) /* Interpreter in which the package is to be |
| 145 |
* made available. */ |
| 146 |
{ |
| 147 |
int code; |
| 148 |
|
| 149 |
if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) { |
| 150 |
return TCL_ERROR; |
| 151 |
} |
| 152 |
code = Tcl_PkgProvide(interp, "pkgd", "7.3"); |
| 153 |
if (code != TCL_OK) { |
| 154 |
return code; |
| 155 |
} |
| 156 |
Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, NULL, NULL); |
| 157 |
return TCL_OK; |
| 158 |
} |