Debian Codegraph @

pTk/mTk/tclUnix/dltest/pkga.c

raw symbols SCIP
1 /*
2 * pkga.c --
3 *
4 * This file contains a simple Tcl package "pkga" that is intended
5 * for 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
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * RCS: @(#) $Id: pkga.c,v 1.4.24.2 2003/07/16 02:16:14 mdejong Exp $
13 */
14 #include "tcl.h"
15
16 /*
17 * Prototypes for procedures defined later in this file:
18 */
19
20 static int Pkga_EqObjCmd _ANSI_ARGS_((ClientData clientData,
21 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
22 static int Pkga_QuoteObjCmd _ANSI_ARGS_((ClientData clientData,
23 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
24
25 /*
26 *----------------------------------------------------------------------
27 *
28 * Pkga_EqObjCmd --
29 *
30 * This procedure is invoked to process the "pkga_eq" Tcl command.
31 * It expects two arguments and returns 1 if they are the same,
32 * 0 if they are different.
33 *
34 * Results:
35 * A standard Tcl result.
36 *
37 * Side effects:
38 * See the user documentation.
39 *
40 *----------------------------------------------------------------------
41 */
42
43 static int
44 Pkga_EqObjCmd(dummy, interp, objc, objv)
45 ClientData dummy; /* Not used. */
46 Tcl_Interp *interp; /* Current interpreter. */
47 int objc; /* Number of arguments. */
48 Tcl_Obj * CONST objv[]; /* Argument objects. */
49 {
50 int result;
51 CONST char *str1, *str2;
52 int len1, len2, n;
53
54 if (objc != 3) {
55 Tcl_WrongNumArgs(interp, 1, objv, "string1 string2");
56 return TCL_ERROR;
57 }
58
59 str1 = Tcl_GetStringFromObj(objv[1], &len1);
60 str2 = Tcl_GetStringFromObj(objv[2], &len2);
61 if (len1 == len2) {
62 result = (Tcl_UtfNcmp(str1, str2, len1) == 0);
63 } else {
64 result = 0;
65 }
66 Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
67 return TCL_OK;
68 }
69
70 /*
71 *----------------------------------------------------------------------
72 *
73 * Pkga_QuoteObjCmd --
74 *
75 * This procedure is invoked to process the "pkga_quote" Tcl command.
76 * It expects one argument, which it returns as result.
77 *
78 * Results:
79 * A standard Tcl result.
80 *
81 * Side effects:
82 * See the user documentation.
83 *
84 *----------------------------------------------------------------------
85 */
86
87 static int
88 Pkga_QuoteObjCmd(dummy, interp, objc, objv)
89 ClientData dummy; /* Not used. */
90 Tcl_Interp *interp; /* Current interpreter. */
91 int objc; /* Number of arguments. */
92 Tcl_Obj * CONST objv[]; /* Argument strings. */
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
108 * by Tcl 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 int
120 Pkga_Init(interp)
121 Tcl_Interp *interp; /* Interpreter in which the package is
122 * to be made available. */
123 {
124 int code;
125
126 if (Tcl_InitStubs(interp, TCL_VERSION, 1) == 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,
134 (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
135 Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd,
136 (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
137 return TCL_OK;
138 }