OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / HP / util / HP / man / man3 / Tcl_GetCommandInfo.3
1 '\"
2 '\" Copyright (c) 1996-1997 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\" 
7 '\" RCS: @(#) $Id: CrtObjCmd.3,v 1.3 1999/04/16 00:46:30 stanton Exp $
8 '\" 
9 '\" The definitions below are for supplemental macros used in Tcl/Tk
10 '\" manual entries.
11 '\"
12 '\" .AP type name in/out ?indent?
13 '\"     Start paragraph describing an argument to a library procedure.
14 '\"     type is type of argument (int, etc.), in/out is either "in", "out",
15 '\"     or "in/out" to describe whether procedure reads or modifies arg,
16 '\"     and indent is equivalent to second arg of .IP (shouldn't ever be
17 '\"     needed;  use .AS below instead)
18 '\"
19 '\" .AS ?type? ?name?
20 '\"     Give maximum sizes of arguments for setting tab stops.  Type and
21 '\"     name are examples of largest possible arguments that will be passed
22 '\"     to .AP later.  If args are omitted, default tab stops are used.
23 '\"
24 '\" .BS
25 '\"     Start box enclosure.  From here until next .BE, everything will be
26 '\"     enclosed in one large box.
27 '\"
28 '\" .BE
29 '\"     End of box enclosure.
30 '\"
31 '\" .CS
32 '\"     Begin code excerpt.
33 '\"
34 '\" .CE
35 '\"     End code excerpt.
36 '\"
37 '\" .VS ?version? ?br?
38 '\"     Begin vertical sidebar, for use in marking newly-changed parts
39 '\"     of man pages.  The first argument is ignored and used for recording
40 '\"     the version when the .VS was added, so that the sidebars can be
41 '\"     found and removed when they reach a certain age.  If another argument
42 '\"     is present, then a line break is forced before starting the sidebar.
43 '\"
44 '\" .VE
45 '\"     End of vertical sidebar.
46 '\"
47 '\" .DS
48 '\"     Begin an indented unfilled display.
49 '\"
50 '\" .DE
51 '\"     End of indented unfilled display.
52 '\"
53 '\" .SO
54 '\"     Start of list of standard options for a Tk widget.  The
55 '\"     options follow on successive lines, in four columns separated
56 '\"     by tabs.
57 '\"
58 '\" .SE
59 '\"     End of list of standard options for a Tk widget.
60 '\"
61 '\" .OP cmdName dbName dbClass
62 '\"     Start of description of a specific option.  cmdName gives the
63 '\"     option's name as specified in the class command, dbName gives
64 '\"     the option's name in the option database, and dbClass gives
65 '\"     the option's class in the option database.
66 '\"
67 '\" .UL arg1 arg2
68 '\"     Print arg1 underlined, then print arg2 normally.
69 '\"
70 '\" RCS: @(#) $Id: man.macros,v 1.3 1999/04/16 00:46:35 stanton Exp $
71 '\"
72 '\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73 .if t .wh -1.3i ^B
74 .nr ^l \n(.l
75 .ad b
76 '\"     # Start an argument description
77 .de AP
78 .ie !"\\$4"" .TP \\$4
79 .el \{\
80 .   ie !"\\$2"" .TP \\n()Cu
81 .   el          .TP 15
82 .\}
83 .ta \\n()Au \\n()Bu
84 .ie !"\\$3"" \{\
85 \&\\$1  \\fI\\$2\\fP    (\\$3)
86 .\".b
87 .\}
88 .el \{\
89 .br
90 .ie !"\\$2"" \{\
91 \&\\$1  \\fI\\$2\\fP
92 .\}
93 .el \{\
94 \&\\fI\\$1\\fP
95 .\}
96 .\}
97 ..
98 '\"     # define tabbing values for .AP
99 .de AS
100 .nr )A 10n
101 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
102 .nr )B \\n()Au+15n
103 .\"
104 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105 .nr )C \\n()Bu+\\w'(in/out)'u+2n
106 ..
107 .AS Tcl_Interp Tcl_CreateInterp in/out
108 '\"     # BS - start boxed text
109 '\"     # ^y = starting y location
110 '\"     # ^b = 1
111 .de BS
112 .br
113 .mk ^y
114 .nr ^b 1u
115 .if n .nf
116 .if n .ti 0
117 .if n \l'\\n(.lu\(ul'
118 .if n .fi
119 ..
120 '\"     # BE - end boxed text (draw box now)
121 .de BE
122 .nf
123 .ti 0
124 .mk ^t
125 .ie n \l'\\n(^lu\(ul'
126 .el \{\
127 .\"     Draw four-sided box normally, but don't draw top of
128 .\"     box if the box started on an earlier page.
129 .ie !\\n(^b-1 \{\
130 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131 .\}
132 .el \}\
133 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134 .\}
135 .\}
136 .fi
137 .br
138 .nr ^b 0
139 ..
140 '\"     # VS - start vertical sidebar
141 '\"     # ^Y = starting y location
142 '\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
143 .de VS
144 .if !"\\$2"" .br
145 .mk ^Y
146 .ie n 'mc \s12\(br\s0
147 .el .nr ^v 1u
148 ..
149 '\"     # VE - end of vertical sidebar
150 .de VE
151 .ie n 'mc
152 .el \{\
153 .ev 2
154 .nf
155 .ti 0
156 .mk ^t
157 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158 .sp -1
159 .fi
160 .ev
161 .\}
162 .nr ^v 0
163 ..
164 '\"     # Special macro to handle page bottom:  finish off current
165 '\"     # box/sidebar if in box/sidebar mode, then invoked standard
166 '\"     # page bottom macro.
167 .de ^B
168 .ev 2
169 'ti 0
170 'nf
171 .mk ^t
172 .if \\n(^b \{\
173 .\"     Draw three-sided box if this is the box's first page,
174 .\"     draw two sides but no top otherwise.
175 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177 .\}
178 .if \\n(^v \{\
179 .nr ^x \\n(^tu+1v-\\n(^Yu
180 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
181 .\}
182 .bp
183 'fi
184 .ev
185 .if \\n(^b \{\
186 .mk ^y
187 .nr ^b 2
188 .\}
189 .if \\n(^v \{\
190 .mk ^Y
191 .\}
192 ..
193 '\"     # DS - begin display
194 .de DS
195 .RS
196 .nf
197 .sp
198 ..
199 '\"     # DE - end display
200 .de DE
201 .fi
202 .RE
203 .sp
204 ..
205 '\"     # SO - start of list of standard options
206 .de SO
207 .SH "STANDARD OPTIONS"
208 .LP
209 .nf
210 .ta 4c 8c 12c
211 .ft B
212 ..
213 '\"     # SE - end of list of standard options
214 .de SE
215 .fi
216 .ft R
217 .LP
218 See the \\fBoptions\\fR manual entry for details on the standard options.
219 ..
220 '\"     # OP - start of full description for a single option
221 .de OP
222 .LP
223 .nf
224 .ta 4c
225 Command-Line Name:      \\fB\\$1\\fR
226 Database Name:  \\fB\\$2\\fR
227 Database Class: \\fB\\$3\\fR
228 .fi
229 .IP
230 ..
231 '\"     # CS - begin code excerpt
232 .de CS
233 .RS
234 .nf
235 .ta .25i .5i .75i 1i
236 ..
237 '\"     # CE - end code excerpt
238 .de CE
239 .fi
240 .RE
241 ..
242 .de UL
243 \\$1\l'|0\(ul'\\$2
244 ..
245 .TH Tcl_CreateObjCommand 3 8.0 Tcl "Tcl Library Procedures"
246 .BS
247 .SH NAME
248 Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName \- implement new commands in C
249 .SH SYNOPSIS
250 .nf
251 \fB#include <tcl.h>\fR
252 .sp
253 Tcl_Command
254 \fBTcl_CreateObjCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR)
255 .sp
256 int
257 \fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR)
258 .sp
259 int
260 \fBTcl_DeleteCommandFromToken\fR(\fIinterp, token\fR)
261 .sp
262 int
263 \fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
264 .sp
265 int
266 \fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
267 .sp
268 char *
269 \fBTcl_GetCommandName\fR(\fIinterp, token\fR)
270 .SH ARGUMENTS
271 .AS Tcl_ObjCmdProc *deleteProc in/out
272 .AP Tcl_Interp *interp in
273 Interpreter in which to create a new command or that contains a command.
274 .AP char *cmdName in
275 Name of command.
276 .AP Tcl_ObjCmdProc *proc in
277 Implementation of the new command: \fIproc\fR will be called whenever
278 \fIcmdName\fR is invoked as a command.
279 .AP ClientData clientData in
280 Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR.
281 .AP Tcl_CmdDeleteProc *deleteProc in
282 Procedure to call before \fIcmdName\fR is deleted from the interpreter;
283 allows for command-specific cleanup. If NULL, then no procedure is
284 called before the command is deleted.
285 .AP Tcl_Command token in
286 Token for command, returned by previous call to \fBTcl_CreateObjCommand\fR.
287 The command must not have been deleted.
288 .AP Tcl_CmdInfo *infoPtr in/out
289 Pointer to structure containing various information about a
290 Tcl command.
291 .BE
292 .SH DESCRIPTION
293 .PP
294 \fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fR
295 and associates it with procedure \fIproc\fR
296 such that whenever \fIname\fR is
297 invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObj\fR)
298 the Tcl interpreter will call \fIproc\fR to process the command.
299 .PP
300 \fBTcl_CreateObjCommand\fR deletes any existing command
301 \fIname\fR already associated with the interpreter
302 (however see below for an exception where the existing command
303 is not deleted).
304 It returns a token that may be used to refer
305 to the command in subsequent calls to \fBTcl_GetCommandName\fR.
306 If \fIname\fR contains any \fB::\fR namespace qualifiers,
307 then the command is added to the specified namespace;
308 otherwise the command is added to the global namespace.
309 If \fBTcl_CreateObjCommand\fR is called for an interpreter that is in
310 the process of being deleted, then it does not create a new command
311 and it returns NULL.
312 \fIproc\fR should have arguments and result that match the type
313 \fBTcl_ObjCmdProc\fR:
314 .CS
315 typedef int Tcl_ObjCmdProc(
316         ClientData \fIclientData\fR,
317         Tcl_Interp *\fIinterp\fR,
318         int \fIobjc\fR,
319 .VS
320         Tcl_Obj *CONST \fIobjv\fR[]);
321 .CE
322 When \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameters
323 will be copies of the \fIclientData\fR and \fIinterp\fR arguments given to
324 \fBTcl_CreateObjCommand\fR.  Typically, \fIclientData\fR points to an
325 application-specific data structure that describes what to do when the
326 command procedure is invoked. \fIObjc\fR and \fIobjv\fR describe the
327 arguments to the command, \fIobjc\fR giving the number of argument objects
328 (including the command name) and \fIobjv\fR giving the values of the
329 arguments.  The \fIobjv\fR array will contain \fIobjc\fR values, pointing to
330 the argument objects.  Unlike \fIargv\fR[\fIargv\fR] used in a
331 string-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL.
332 .PP
333 Additionally, when \fIproc\fR is invoked, it must not modify the contents
334 of the \fIobjv\fR array by assigning new pointer values to any element of the
335 array (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this will
336 cause memory to be lost and the runtime stack to be corrupted.  The
337 \fBCONST\fR in the declaration of \fIobjv\fR will cause ANSI-compliant
338 compilers to report any such attempted assignment as an error.  However,
339 it is acceptable to modify the internal representation of any individual
340 object argument.  For instance, the user may call
341 \fBTcl_GetIntFromObj\fR on \fIobjv\fR[\fB2\fR] to obtain the integer
342 representation of that object; that call may change the type of the object
343 that \fIobjv\fR[\fB2\fR] points at, but will not change where
344 \fIobjv\fR[\fB2\fR] points.
345 .VE
346 .PP
347 \fIproc\fR must return an integer code that is either \fBTCL_OK\fR,
348 \fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.
349 See the Tcl overview man page
350 for details on what these codes mean.  Most normal commands will only
351 return \fBTCL_OK\fR or \fBTCL_ERROR\fR.
352 In addition, if \fIproc\fR needs to return a non-empty result,
353 it can call \fBTcl_SetObjResult\fR to set the interpreter's result.
354 In the case of a \fBTCL_OK\fR return code this gives the result
355 of the command,
356 and in the case of \fBTCL_ERROR\fR this gives an error message.
357 Before invoking a command procedure,
358 \fBTcl_EvalObj\fR sets interpreter's result to
359 point to an object representing an empty string, so simple
360 commands can return an empty result by doing nothing at all.
361 .PP
362 The contents of the \fIobjv\fR array belong to Tcl and are not
363 guaranteed to persist once \fIproc\fR returns: \fIproc\fR should
364 not modify them.
365 Call \fBTcl_SetObjResult\fR if you want
366 to return something from the \fIobjv\fR array.
367 .PP
368 Ordinarily, \fBTcl_CreateObjCommand\fR deletes any existing command
369 \fIname\fR already associated with the interpreter.
370 However, if the existing command was created by a previous call to
371 \fBTcl_CreateCommand\fR,
372 \fBTcl_CreateObjCommand\fR does not delete the command
373 but instead arranges for the Tcl interpreter to call the
374 \fBTcl_ObjCmdProc\fR \fIproc\fR in the future.
375 The old string-based \fBTcl_CmdProc\fR associated with the command
376 is retained and its address can be obtained by subsequent 
377 \fBTcl_GetCommandInfo\fR calls. This is done for backwards compatibility.
378 .PP
379 \fIDeleteProc\fR will be invoked when (if) \fIname\fR is deleted.
380 This can occur through a call to \fBTcl_DeleteCommand\fR,
381 \fBTcl_DeleteCommandFromToken\fR, or \fBTcl_DeleteInterp\fR,
382 or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR.
383 \fIDeleteProc\fR is invoked before the command is deleted, and gives the
384 application an opportunity to release any structures associated
385 with the command.  \fIDeleteProc\fR should have arguments and
386 result that match the type \fBTcl_CmdDeleteProc\fR:
387 .CS
388 typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);
389 .CE
390 The \fIclientData\fR argument will be the same as the \fIclientData\fR
391 argument passed to \fBTcl_CreateObjCommand\fR.
392 .PP
393 \fBTcl_DeleteCommand\fR deletes a command from a command interpreter.
394 Once the call completes, attempts to invoke \fIcmdName\fR in
395 \fIinterp\fR will result in errors.
396 If \fIcmdName\fR isn't bound as a command in \fIinterp\fR then
397 \fBTcl_DeleteCommand\fR does nothing and returns -1;  otherwise
398 it returns 0.
399 There are no restrictions on \fIcmdName\fR:  it may refer to
400 a built-in command, an application-specific command, or a Tcl procedure.
401 If \fIname\fR contains any \fB::\fR namespace qualifiers,
402 the command is deleted from the specified namespace.
403 .PP
404 Given a token returned by \fBTcl_CreateObjCommand\fR,
405 \fBTcl_DeleteCommandFromToken\fR deletes the command
406 from a command interpreter.
407 It will delete a command even if that command has been renamed.
408 Once the call completes, attempts to invoke the command in
409 \fIinterp\fR will result in errors.
410 If the command corresponding to \fItoken\fR
411 has already been deleted from \fIinterp\fR then
412 \fBTcl_DeleteCommand\fR does nothing and returns -1;
413 otherwise it returns 0.
414 .PP
415 \fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argument
416 exists as a command in \fIinterp\fR.
417 \fIcmdName\fR may include \fB::\fR namespace qualifiers
418 to identify a command in a particular namespace.
419 If the command is not found, then it returns 0.
420 Otherwise it places information about the command
421 in the \fBTcl_CmdInfo\fR structure
422 pointed to by \fIinfoPtr\fR and returns 1.
423 A \fBTcl_CmdInfo\fR structure has the following fields:
424 .CS
425 typedef struct Tcl_CmdInfo {
426     int isNativeObjectProc;
427     Tcl_ObjCmdProc *objProc;
428     ClientData objClientData;
429     Tcl_CmdProc *proc;
430     ClientData clientData;
431     Tcl_CmdDeleteProc *deleteProc;
432     ClientData deleteData;
433     Tcl_Namespace *namespacePtr;
434 } Tcl_CmdInfo;
435 .CE
436 The \fIisNativeObjectProc\fR field has the value 1
437 if \fBTcl_CreateObjCommand\fR was called to register the command;
438 it is 0 if only \fBTcl_CreateCommand\fR was called.
439 It allows a program to determine whether it is faster to
440 call \fIobjProc\fR or \fIproc\fR:
441 \fIobjProc\fR is normally faster
442 if \fIisNativeObjectProc\fR has the value 1.
443 The fields \fIobjProc\fR and \fIobjClientData\fR
444 have the same meaning as the \fIproc\fR and \fIclientData\fR
445 arguments to \fBTcl_CreateObjCommand\fR;
446 they hold information about the object-based command procedure
447 that the Tcl interpreter calls to implement the command.
448 The fields \fIproc\fR and \fIclientData\fR
449 hold information about the string-based command procedure
450 that implements the command.
451 If \fBTcl_CreateCommand\fR was called for this command,
452 this is the procedure passed to it;
453 otherwise, this is a compatibility procedure
454 registered by \fBTcl_CreateObjCommand\fR
455 that simply calls the command's
456 object-based procedure after converting its string arguments to Tcl objects.
457 The field \fIdeleteData\fR is the ClientData value
458 to pass to \fIdeleteProc\fR;  it is normally the same as
459 \fIclientData\fR but may be set independently using the
460 \fBTcl_SetCommandInfo\fR procedure.
461 The field \fInamespacePtr\fR holds a pointer to the
462 Tcl_Namespace that contains the command.
463 .PP
464 \fBTcl_SetCommandInfo\fR is used to modify the procedures and
465 ClientData values associated with a command.
466 Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR.
467 \fIcmdName\fR may include \fB::\fR namespace qualifiers
468 to identify a command in a particular namespace.
469 If this command does not exist then \fBTcl_SetCommandInfo\fR returns 0.
470 Otherwise, it copies the information from \fI*infoPtr\fR to
471 Tcl's internal structure for the command and returns 1.
472 Note that this procedure allows the ClientData for a command's
473 deletion procedure to be given a different value than the ClientData
474 for its command procedure.
475 Note that \fBTcl_SetCmdInfo\fR will not change a command's namespace;
476 you must use \fBTcl_RenameCommand\fR to do that.
477 .PP
478 \fBTcl_GetCommandName\fR provides a mechanism for tracking commands
479 that have been renamed.
480 Given a token returned by \fBTcl_CreateObjCommand\fR
481 when the command was created, \fBTcl_GetCommandName\fR returns the
482 string name of the command.  If the command has been renamed since it
483 was created, then \fBTcl_GetCommandName\fR returns the current name.
484 This name does not include any \fB::\fR namespace qualifiers.
485 The command corresponding to \fItoken\fR must not have been deleted.
486 The string returned by \fBTcl_GetCommandName\fR is in dynamic memory
487 owned by Tcl and is only guaranteed to retain its value as long as the
488 command isn't deleted or renamed;  callers should copy the string if
489 they need to keep it for a long time.
490 .PP
491
492 .SH "SEE ALSO"
493 Tcl_CreateCommand, Tcl_ResetResult, Tcl_SetObjResult
494
495 .SH KEYWORDS
496 bind, command, create, delete, namespace, object