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 | * RCS: @(#) $Id: pkga.c,v 1.12 2007/12/13 15:28:42 dgp Exp $ |
---|
13 | */ |
---|
14 | |
---|
15 | #include "tcl.h" |
---|
16 | |
---|
17 | /* |
---|
18 | * Prototypes for procedures defined later in this file: |
---|
19 | */ |
---|
20 | |
---|
21 | static int Pkga_EqObjCmd(ClientData clientData, |
---|
22 | Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); |
---|
23 | static int Pkga_QuoteObjCmd(ClientData clientData, |
---|
24 | Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); |
---|
25 | |
---|
26 | /* |
---|
27 | *---------------------------------------------------------------------- |
---|
28 | * |
---|
29 | * Pkga_EqObjCmd -- |
---|
30 | * |
---|
31 | * This procedure is invoked to process the "pkga_eq" Tcl command. It |
---|
32 | * expects two arguments and returns 1 if they are the same, 0 if they |
---|
33 | * are different. |
---|
34 | * |
---|
35 | * Results: |
---|
36 | * A standard Tcl result. |
---|
37 | * |
---|
38 | * Side effects: |
---|
39 | * See the user documentation. |
---|
40 | * |
---|
41 | *---------------------------------------------------------------------- |
---|
42 | */ |
---|
43 | |
---|
44 | static int |
---|
45 | Pkga_EqObjCmd( |
---|
46 | ClientData dummy, /* Not used. */ |
---|
47 | Tcl_Interp *interp, /* Current interpreter. */ |
---|
48 | int objc, /* Number of arguments. */ |
---|
49 | Tcl_Obj *CONST objv[]) /* Argument objects. */ |
---|
50 | { |
---|
51 | int result; |
---|
52 | CONST char *str1, *str2; |
---|
53 | int len1, len2; |
---|
54 | |
---|
55 | if (objc != 3) { |
---|
56 | Tcl_WrongNumArgs(interp, 1, objv, "string1 string2"); |
---|
57 | return TCL_ERROR; |
---|
58 | } |
---|
59 | |
---|
60 | str1 = Tcl_GetStringFromObj(objv[1], &len1); |
---|
61 | str2 = Tcl_GetStringFromObj(objv[2], &len2); |
---|
62 | if (len1 == len2) { |
---|
63 | result = (Tcl_UtfNcmp(str1, str2, len1) == 0); |
---|
64 | } else { |
---|
65 | result = 0; |
---|
66 | } |
---|
67 | Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); |
---|
68 | return TCL_OK; |
---|
69 | } |
---|
70 | |
---|
71 | /* |
---|
72 | *---------------------------------------------------------------------- |
---|
73 | * |
---|
74 | * Pkga_QuoteObjCmd -- |
---|
75 | * |
---|
76 | * This procedure is invoked to process the "pkga_quote" Tcl command. It |
---|
77 | * expects one argument, which it returns as result. |
---|
78 | * |
---|
79 | * Results: |
---|
80 | * A standard Tcl result. |
---|
81 | * |
---|
82 | * Side effects: |
---|
83 | * See the user documentation. |
---|
84 | * |
---|
85 | *---------------------------------------------------------------------- |
---|
86 | */ |
---|
87 | |
---|
88 | static int |
---|
89 | Pkga_QuoteObjCmd( |
---|
90 | ClientData dummy, /* Not used. */ |
---|
91 | Tcl_Interp *interp, /* Current interpreter. */ |
---|
92 | int objc, /* Number of arguments. */ |
---|
93 | Tcl_Obj *CONST objv[]) /* Argument strings. */ |
---|
94 | { |
---|
95 | if (objc != 2) { |
---|
96 | Tcl_WrongNumArgs(interp, 1, objv, "value"); |
---|
97 | return TCL_ERROR; |
---|
98 | } |
---|
99 | Tcl_SetObjResult(interp, objv[1]); |
---|
100 | return TCL_OK; |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | *---------------------------------------------------------------------- |
---|
105 | * |
---|
106 | * Pkga_Init -- |
---|
107 | * |
---|
108 | * This is a package initialization procedure, which is called by Tcl |
---|
109 | * when this package is to be added to an interpreter. |
---|
110 | * |
---|
111 | * Results: |
---|
112 | * None. |
---|
113 | * |
---|
114 | * Side effects: |
---|
115 | * None. |
---|
116 | * |
---|
117 | *---------------------------------------------------------------------- |
---|
118 | */ |
---|
119 | |
---|
120 | int |
---|
121 | Pkga_Init( |
---|
122 | Tcl_Interp *interp) /* Interpreter in which the package is to be |
---|
123 | * made available. */ |
---|
124 | { |
---|
125 | int code; |
---|
126 | |
---|
127 | if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { |
---|
128 | return TCL_ERROR; |
---|
129 | } |
---|
130 | code = Tcl_PkgProvide(interp, "Pkga", "1.0"); |
---|
131 | if (code != TCL_OK) { |
---|
132 | return code; |
---|
133 | } |
---|
134 | Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd, |
---|
135 | (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
---|
136 | Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd, |
---|
137 | (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
---|
138 | return TCL_OK; |
---|
139 | } |
---|