Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / Tcl_SetCommandInfo.3
CommitLineData
920dae64
AT
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.7.2.1 2004/05/05 20:54:47 dkf 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.4 2000/08/25 06:18:32 ericm 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 5.5c 11c
211.ft B
212..
213'\" # SE - end of list of standard options
214.de SE
215.fi
216.ft R
217.LP
218See 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
225Command-Line Name: \\fB\\$1\\fR
226Database Name: \\fB\\$2\\fR
227Database 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
248Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_GetCommandInfoFromToken, Tcl_SetCommandInfo, Tcl_SetCommandInfoFromToken, Tcl_GetCommandName, Tcl_GetCommandFullName, Tcl_GetCommandFromObj \- implement new commands in C
249.SH SYNOPSIS
250.nf
251\fB#include <tcl.h>\fR
252.sp
253Tcl_Command
254\fBTcl_CreateObjCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR)
255.sp
256int
257\fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR)
258.sp
259int
260\fBTcl_DeleteCommandFromToken\fR(\fIinterp, token\fR)
261.sp
262int
263\fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
264.sp
265int
266\fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
267.sp
268.VS 8.4
269int
270\fBTcl_GetCommandInfoFromToken\fR(\fItoken, infoPtr\fR)
271.sp
272int
273\fBTcl_SetCommandInfoFromToken\fR(\fItoken, infoPtr\fR)
274.VE
275.sp
276.VS 8.4
277CONST char *
278.VE
279\fBTcl_GetCommandName\fR(\fIinterp, token\fR)
280.sp
281void
282\fBTcl_GetCommandFullName\fR(\fIinterp, token, objPtr\fR)
283.sp
284Tcl_Command
285\fBTcl_GetCommandFromObj\fR(\fIinterp, objPtr\fR)
286.SH ARGUMENTS
287.AS Tcl_ObjCmdProc *deleteProc in/out
288.AP Tcl_Interp *interp in
289Interpreter in which to create a new command or that contains a command.
290.VS 8.4
291.AP char *cmdName in
292.VE
293Name of command.
294.AP Tcl_ObjCmdProc *proc in
295Implementation of the new command: \fIproc\fR will be called whenever
296\fIcmdName\fR is invoked as a command.
297.AP ClientData clientData in
298Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR.
299.AP Tcl_CmdDeleteProc *deleteProc in
300Procedure to call before \fIcmdName\fR is deleted from the interpreter;
301allows for command-specific cleanup. If NULL, then no procedure is
302called before the command is deleted.
303.AP Tcl_Command token in
304Token for command, returned by previous call to \fBTcl_CreateObjCommand\fR.
305The command must not have been deleted.
306.AP Tcl_CmdInfo *infoPtr in/out
307Pointer to structure containing various information about a
308Tcl command.
309.AP Tcl_Obj *objPtr in
310Object containing the name of a Tcl command.
311.BE
312.SH DESCRIPTION
313.PP
314\fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fR
315and associates it with procedure \fIproc\fR
316such that whenever \fIname\fR is
317invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObjEx\fR)
318the Tcl interpreter will call \fIproc\fR to process the command.
319.PP
320\fBTcl_CreateObjCommand\fR deletes any existing command
321\fIname\fR already associated with the interpreter
322(however see below for an exception where the existing command
323is not deleted).
324It returns a token that may be used to refer
325to the command in subsequent calls to \fBTcl_GetCommandName\fR.
326If \fIname\fR contains any \fB::\fR namespace qualifiers,
327then the command is added to the specified namespace;
328otherwise the command is added to the global namespace.
329If \fBTcl_CreateObjCommand\fR is called for an interpreter that is in
330the process of being deleted, then it does not create a new command
331and it returns NULL.
332\fIproc\fR should have arguments and result that match the type
333\fBTcl_ObjCmdProc\fR:
334.CS
335typedef int Tcl_ObjCmdProc(
336 ClientData \fIclientData\fR,
337 Tcl_Interp *\fIinterp\fR,
338 int \fIobjc\fR,
339.VS
340 Tcl_Obj *CONST \fIobjv\fR[]);
341.CE
342When \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameters
343will be copies of the \fIclientData\fR and \fIinterp\fR arguments given to
344\fBTcl_CreateObjCommand\fR. Typically, \fIclientData\fR points to an
345application-specific data structure that describes what to do when the
346command procedure is invoked. \fIObjc\fR and \fIobjv\fR describe the
347arguments to the command, \fIobjc\fR giving the number of argument objects
348(including the command name) and \fIobjv\fR giving the values of the
349arguments. The \fIobjv\fR array will contain \fIobjc\fR values, pointing to
350the argument objects. Unlike \fIargv\fR[\fIargv\fR] used in a
351string-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL.
352.PP
353Additionally, when \fIproc\fR is invoked, it must not modify the contents
354of the \fIobjv\fR array by assigning new pointer values to any element of the
355array (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this will
356cause memory to be lost and the runtime stack to be corrupted. The
357\fBCONST\fR in the declaration of \fIobjv\fR will cause ANSI-compliant
358compilers to report any such attempted assignment as an error. However,
359it is acceptable to modify the internal representation of any individual
360object argument. For instance, the user may call
361\fBTcl_GetIntFromObj\fR on \fIobjv\fR[\fB2\fR] to obtain the integer
362representation of that object; that call may change the type of the object
363that \fIobjv\fR[\fB2\fR] points at, but will not change where
364\fIobjv\fR[\fB2\fR] points.
365.VE
366.PP
367\fIproc\fR must return an integer code that is either \fBTCL_OK\fR,
368\fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.
369See the Tcl overview man page
370for details on what these codes mean. Most normal commands will only
371return \fBTCL_OK\fR or \fBTCL_ERROR\fR.
372In addition, if \fIproc\fR needs to return a non-empty result,
373it can call \fBTcl_SetObjResult\fR to set the interpreter's result.
374In the case of a \fBTCL_OK\fR return code this gives the result
375of the command,
376and in the case of \fBTCL_ERROR\fR this gives an error message.
377Before invoking a command procedure,
378\fBTcl_EvalObjEx\fR sets interpreter's result to
379point to an object representing an empty string, so simple
380commands can return an empty result by doing nothing at all.
381.PP
382The contents of the \fIobjv\fR array belong to Tcl and are not
383guaranteed to persist once \fIproc\fR returns: \fIproc\fR should
384not modify them.
385Call \fBTcl_SetObjResult\fR if you want
386to return something from the \fIobjv\fR array.
387.PP
388Ordinarily, \fBTcl_CreateObjCommand\fR deletes any existing command
389\fIname\fR already associated with the interpreter.
390However, if the existing command was created by a previous call to
391\fBTcl_CreateCommand\fR,
392\fBTcl_CreateObjCommand\fR does not delete the command
393but instead arranges for the Tcl interpreter to call the
394\fBTcl_ObjCmdProc\fR \fIproc\fR in the future.
395The old string-based \fBTcl_CmdProc\fR associated with the command
396is retained and its address can be obtained by subsequent
397\fBTcl_GetCommandInfo\fR calls. This is done for backwards compatibility.
398.PP
399\fIDeleteProc\fR will be invoked when (if) \fIname\fR is deleted.
400This can occur through a call to \fBTcl_DeleteCommand\fR,
401\fBTcl_DeleteCommandFromToken\fR, or \fBTcl_DeleteInterp\fR,
402or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR.
403\fIDeleteProc\fR is invoked before the command is deleted, and gives the
404application an opportunity to release any structures associated
405with the command. \fIDeleteProc\fR should have arguments and
406result that match the type \fBTcl_CmdDeleteProc\fR:
407.CS
408typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);
409.CE
410The \fIclientData\fR argument will be the same as the \fIclientData\fR
411argument passed to \fBTcl_CreateObjCommand\fR.
412.PP
413\fBTcl_DeleteCommand\fR deletes a command from a command interpreter.
414Once the call completes, attempts to invoke \fIcmdName\fR in
415\fIinterp\fR will result in errors.
416If \fIcmdName\fR isn't bound as a command in \fIinterp\fR then
417\fBTcl_DeleteCommand\fR does nothing and returns -1; otherwise
418it returns 0.
419There are no restrictions on \fIcmdName\fR: it may refer to
420a built-in command, an application-specific command, or a Tcl procedure.
421If \fIname\fR contains any \fB::\fR namespace qualifiers,
422the command is deleted from the specified namespace.
423.PP
424Given a token returned by \fBTcl_CreateObjCommand\fR,
425\fBTcl_DeleteCommandFromToken\fR deletes the command
426from a command interpreter.
427It will delete a command even if that command has been renamed.
428Once the call completes, attempts to invoke the command in
429\fIinterp\fR will result in errors.
430If the command corresponding to \fItoken\fR
431has already been deleted from \fIinterp\fR then
432\fBTcl_DeleteCommand\fR does nothing and returns -1;
433otherwise it returns 0.
434.PP
435\fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argument
436exists as a command in \fIinterp\fR.
437\fIcmdName\fR may include \fB::\fR namespace qualifiers
438to identify a command in a particular namespace.
439If the command is not found, then it returns 0.
440Otherwise it places information about the command
441in the \fBTcl_CmdInfo\fR structure
442pointed to by \fIinfoPtr\fR and returns 1.
443A \fBTcl_CmdInfo\fR structure has the following fields:
444.CS
445typedef struct Tcl_CmdInfo {
446 int isNativeObjectProc;
447 Tcl_ObjCmdProc *objProc;
448 ClientData objClientData;
449 Tcl_CmdProc *proc;
450 ClientData clientData;
451 Tcl_CmdDeleteProc *deleteProc;
452 ClientData deleteData;
453 Tcl_Namespace *namespacePtr;
454} Tcl_CmdInfo;
455.CE
456The \fIisNativeObjectProc\fR field has the value 1
457if \fBTcl_CreateObjCommand\fR was called to register the command;
458it is 0 if only \fBTcl_CreateCommand\fR was called.
459It allows a program to determine whether it is faster to
460call \fIobjProc\fR or \fIproc\fR:
461\fIobjProc\fR is normally faster
462if \fIisNativeObjectProc\fR has the value 1.
463The fields \fIobjProc\fR and \fIobjClientData\fR
464have the same meaning as the \fIproc\fR and \fIclientData\fR
465arguments to \fBTcl_CreateObjCommand\fR;
466they hold information about the object-based command procedure
467that the Tcl interpreter calls to implement the command.
468The fields \fIproc\fR and \fIclientData\fR
469hold information about the string-based command procedure
470that implements the command.
471If \fBTcl_CreateCommand\fR was called for this command,
472this is the procedure passed to it;
473otherwise, this is a compatibility procedure
474registered by \fBTcl_CreateObjCommand\fR
475that simply calls the command's
476object-based procedure after converting its string arguments to Tcl objects.
477The field \fIdeleteData\fR is the ClientData value
478to pass to \fIdeleteProc\fR; it is normally the same as
479\fIclientData\fR but may be set independently using the
480\fBTcl_SetCommandInfo\fR procedure.
481The field \fInamespacePtr\fR holds a pointer to the
482Tcl_Namespace that contains the command.
483.PP
484\fBTcl_GetCommandInfoFromToken\fR is identical to
485\fBTcl_GetCommandInfo\fR except that it uses a command token returned
486from \fBTcl_CreateObjCommand\fR in place of the command name. If the
487\fItoken\fR parameter is NULL, it returns 0; otherwise, it returns 1
488and fills in the structure designated by \fIinfoPtr\fR.
489.PP
490\fBTcl_SetCommandInfo\fR is used to modify the procedures and
491ClientData values associated with a command.
492Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR.
493\fIcmdName\fR may include \fB::\fR namespace qualifiers
494to identify a command in a particular namespace.
495If this command does not exist then \fBTcl_SetCommandInfo\fR returns 0.
496Otherwise, it copies the information from \fI*infoPtr\fR to
497Tcl's internal structure for the command and returns 1.
498.PP
499\fBTcl_SetCommandInfoFromToken\fR is identical to
500\fBTcl_SetCommandInfo\fR except that it takes a command token as
501returned by \fBTcl_CreateObjCommand\fR instead of the command name.
502If the \fItoken\fR parameter is NULL, it returns 0. Otherwise, it
503copies the information from \fI*infoPtr\fR to Tcl's internal structure
504for the command and returns 1.
505.PP
506Note that \fBTcl_SetCommandInfo\fR and
507\fBTcl_SetCommandInfoFromToken\fR both allow the ClientData for a
508command's deletion procedure to be given a different value than the
509ClientData for its command procedure.
510.PP
511Note that neither \fBTcl_SetCommandInfo\fR nor
512\fBTcl_SetCommandInfoFromToken\fR will change a command's namespace.
513Use \fBTcl_Eval\fR to call the \fBrename\fR command to do that.
514.PP
515\fBTcl_GetCommandName\fR provides a mechanism for tracking commands
516that have been renamed.
517Given a token returned by \fBTcl_CreateObjCommand\fR
518when the command was created, \fBTcl_GetCommandName\fR returns the
519string name of the command. If the command has been renamed since it
520was created, then \fBTcl_GetCommandName\fR returns the current name.
521This name does not include any \fB::\fR namespace qualifiers.
522The command corresponding to \fItoken\fR must not have been deleted.
523The string returned by \fBTcl_GetCommandName\fR is in dynamic memory
524owned by Tcl and is only guaranteed to retain its value as long as the
525command isn't deleted or renamed; callers should copy the string if
526they need to keep it for a long time.
527.PP
528\fBTcl_GetCommandFullName\fR produces the fully-qualified name
529of a command from a command token.
530The name, including all namespace prefixes,
531is appended to the object specified by \fIobjPtr\fP.
532.PP
533\fBTcl_GetCommandFromObj\fR returns a token for the command
534specified by the name in a \fBTcl_Obj\fP.
535The command name is resolved relative to the current namespace.
536Returns NULL if the command is not found.
537.SH "SEE ALSO"
538Tcl_CreateCommand, Tcl_ResetResult, Tcl_SetObjResult
539
540.SH KEYWORDS
541bind, command, create, delete, namespace, object