Debian Codegraph @

unix/dltest/pkgc.c

raw
1 /*
2 * pkgc.c --
3 *
4 * This file contains a simple Tcl package "pkgc" 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 #if TCL_MAJOR_VERSION < 9
18 # define Tcl_Size int
19 #endif
20
21 /*
22 *----------------------------------------------------------------------
23 *
24 * Pkgc_SubObjCmd --
25 *
26 * This procedure is invoked to process the "pkgc_sub" Tcl command. It
27 * expects two arguments and returns their difference.
28 *
29 * Results:
30 * A standard Tcl result.
31 *
32 * Side effects:
33 * See the user documentation.
34 *
35 *----------------------------------------------------------------------
36 */
37
38 static int
39 Pkgc_SubObjCmd(
40 void *dummy, /* Not used. */
41 Tcl_Interp *interp, /* Current interpreter. */
42 int objc, /* Number of arguments. */
43 Tcl_Obj *const objv[]) /* Argument objects. */
44 {
45 int first, second;
46 (void)dummy;
47
48 if (objc != 3) {
49 Tcl_WrongNumArgs(interp, 1, objv, "num num");
50 return TCL_ERROR;
51 }
52 if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK)
53 || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) {
54 return TCL_ERROR;
55 }
56 Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second));
57 return TCL_OK;
58 }
59
60 /*
61 *----------------------------------------------------------------------
62 *
63 * Pkgc_UnsafeCmd --
64 *
65 * This procedure is invoked to process the "pkgc_unsafe" Tcl command. It
66 * just returns a constant string.
67 *
68 * Results:
69 * A standard Tcl result.
70 *
71 * Side effects:
72 * See the user documentation.
73 *
74 *----------------------------------------------------------------------
75 */
76
77 static int
78 Pkgc_UnsafeObjCmd(
79 void *dummy, /* Not used. */
80 Tcl_Interp *interp, /* Current interpreter. */
81 int objc, /* Number of arguments. */
82 Tcl_Obj *const objv[]) /* Argument objects. */
83 {
84 (void)dummy;
85 (void)objc;
86 (void)objv;
87
88 Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
89 return TCL_OK;
90 }
91
92 /*
93 *----------------------------------------------------------------------
94 *
95 * Pkgc_Init --
96 *
97 * This is a package initialization procedure, which is called by Tcl
98 * when this package is to be added to an interpreter.
99 *
100 * Results:
101 * None.
102 *
103 * Side effects:
104 * None.
105 *
106 *----------------------------------------------------------------------
107 */
108
109 DLLEXPORT int
110 Pkgc_Init(
111 Tcl_Interp *interp) /* Interpreter in which the package is to be
112 * made available. */
113 {
114 int code;
115
116 if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) {
117 return TCL_ERROR;
118 }
119 code = Tcl_PkgProvide(interp, "pkgc", "1.7.2");
120 if (code != TCL_OK) {
121 return code;
122 }
123 Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, NULL, NULL);
124 Tcl_CreateObjCommand(interp, "pkgc_unsafe", Pkgc_UnsafeObjCmd, NULL,
125 NULL);
126 return TCL_OK;
127 }
128
129 /*
130 *----------------------------------------------------------------------
131 *
132 * Pkgc_SafeInit --
133 *
134 * This is a package initialization procedure, which is called by Tcl
135 * when this package is to be added to a safe interpreter.
136 *
137 * Results:
138 * None.
139 *
140 * Side effects:
141 * None.
142 *
143 *----------------------------------------------------------------------
144 */
145
146 DLLEXPORT int
147 Pkgc_SafeInit(
148 Tcl_Interp *interp) /* Interpreter in which the package is to be
149 * made available. */
150 {
151 int code;
152
153 if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) {
154 return TCL_ERROR;
155 }
156 code = Tcl_PkgProvide(interp, "pkgc", "1.7.2");
157 if (code != TCL_OK) {
158 return code;
159 }
160 Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, NULL, NULL);
161 return TCL_OK;
162 }