Debian Codegraph @

unix/dltest/pkga.c

raw
1 /*
2 * pkga.c --
3 *
4 * This file contains a simple Tcl package "pkga" that is intended for
5 * testing the Tcl dynamic loading facilities.
6 *
7 * Copyright (c) 1995 Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and redistribution of
10 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 */
12
13 #undef STATIC_BUILD
14 #include "tcl.h"
15
16 #if TCL_MAJOR_VERSION < 9
17 # define Tcl_Size int
18 #endif
19
20 /*
21 *----------------------------------------------------------------------
22 *
23 * Pkga_EqObjCmd --
24 *
25 * This procedure is invoked to process the "pkga_eq" Tcl command. It
26 * expects two arguments and returns 1 if they are the same, 0 if they
27 * are different.
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 Pkga_EqObjCmd(
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 result;
46 const char *str1, *str2;
47 Tcl_Size len1, len2;
48 (void)dummy;
49
50 if (objc != 3) {
51 Tcl_WrongNumArgs(interp, 1, objv, "string1 string2");
52 return TCL_ERROR;
53 }
54
55 str1 = Tcl_GetStringFromObj(objv[1], &len1);
56 str2 = Tcl_GetStringFromObj(objv[2], &len2);
57 len1 = Tcl_NumUtfChars(str1, len1);
58 len2 = Tcl_NumUtfChars(str2, len2);
59 if (len1 == len2) {
60 result = (Tcl_UtfNcmp(str1, str2, (size_t)len1) == 0);
61 } else {
62 result = 0;
63 }
64 Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
65 return TCL_OK;
66 }
67
68 /*
69 *----------------------------------------------------------------------
70 *
71 * Pkga_QuoteObjCmd --
72 *
73 * This procedure is invoked to process the "pkga_quote" Tcl command. It
74 * expects one argument, which it returns as result.
75 *
76 * Results:
77 * A standard Tcl result.
78 *
79 * Side effects:
80 * See the user documentation.
81 *
82 *----------------------------------------------------------------------
83 */
84
85 static int
86 Pkga_QuoteObjCmd(
87 void *dummy, /* Not used. */
88 Tcl_Interp *interp, /* Current interpreter. */
89 int objc, /* Number of arguments. */
90 Tcl_Obj *const objv[]) /* Argument strings. */
91 {
92 (void)dummy;
93
94 if (objc != 2) {
95 Tcl_WrongNumArgs(interp, 1, objv, "value");
96 return TCL_ERROR;
97 }
98 Tcl_SetObjResult(interp, objv[1]);
99 return TCL_OK;
100 }
101
102 /*
103 *----------------------------------------------------------------------
104 *
105 * Pkga_Init --
106 *
107 * This is a package initialization procedure, which is called by Tcl
108 * when this package is to be added to an interpreter.
109 *
110 * Results:
111 * None.
112 *
113 * Side effects:
114 * None.
115 *
116 *----------------------------------------------------------------------
117 */
118
119 DLLEXPORT int
120 Pkga_Init(
121 Tcl_Interp *interp) /* Interpreter in which the package is to be
122 * made available. */
123 {
124 int code;
125
126 if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) {
127 return TCL_ERROR;
128 }
129 code = Tcl_PkgProvide(interp, "pkga", "1.0");
130 if (code != TCL_OK) {
131 return code;
132 }
133 Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd, NULL, NULL);
134 Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd, NULL,
135 NULL);
136 return TCL_OK;
137 }