home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / CrtCommand.3 < prev    next >
Text File  |  1993-10-29  |  7KB  |  173 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/CrtCommand.3,v 1.12 93/10/29 15:52:29 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_CreateCommand tclc
  25. .BS
  26. .SH NAME
  27. Tcl_CreateCommand, Tcl_DeleteCommand, Tcl_GetCommandInfo, Tcl_SetCommandInfo \- implement new commands in C
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. \fBTcl_CreateCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR)
  33. .sp
  34. int
  35. \fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR)
  36. .sp
  37. .VS
  38. int
  39. \fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
  40. .sp
  41. int
  42. \fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
  43. .VE
  44. .SH ARGUMENTS
  45. .AS Tcl_CmdDeleteProc **deleteProcPtr
  46. .AP Tcl_Interp *interp in
  47. Interpreter in which to create new command.
  48. .AP char *cmdName in
  49. Name of command.
  50. .AP Tcl_CmdProc *proc in
  51. Implementation of new command:  \fIproc\fR will be called whenever
  52. \fIcmdName\fR is invoked as a command.
  53. .AP ClientData clientData in
  54. Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR.
  55. .AP Tcl_CmdDeleteProc *deleteProc in
  56. Procedure to call before \fIcmdName\fR is deleted from the interpreter;
  57. allows for command-specific cleanup.  If NULL, then no procedure is
  58. called before the command is deleted.
  59. .AP Tcl_CmdInfo *infoPtr in/out
  60. .VS
  61. Pointer to structure containing various information about a
  62. Tcl command.
  63. .VE
  64. .BE
  65.  
  66. .SH DESCRIPTION
  67. .PP
  68. \fBTcl_CreateCommand\fR defines a new command in \fIinterp\fR and associates
  69. it with procedure \fIproc\fR such that whenever \fIcmdName\fR is
  70. invoked as a Tcl command (via a call to \fBTcl_Eval\fR) the Tcl interpreter
  71. will call \fIproc\fR
  72. to process the command.  If there is already a command \fIcmdName\fR
  73. associated with the interpreter, it is deleted.  \fIProc\fP should
  74. have arguments and result that match the type \fBTcl_CmdProc\fR:
  75. .nf
  76. .RS
  77. typedef int Tcl_CmdProc(
  78. .RS
  79. ClientData \fIclientData\fR,
  80. Tcl_Interp *\fIinterp\fR,
  81. int \fIargc\fR,
  82. char *\fIargv\fR[]);
  83. .RE
  84. .RE
  85. .fi
  86. When \fIproc\fR is invoked the \fIclientData\fP and \fIinterp\fR
  87. parameters will be copies of the \fIclientData\fP and \fIinterp\fR
  88. arguments given to \fBTcl_CreateCommand\fR.
  89. Typically, \fIclientData\fR points to an application-specific
  90. data structure that describes what to do when the command procedure
  91. is invoked.  \fIArgc\fR and \fIargv\fR describe the arguments to
  92. the command, \fIargc\fR giving the number of arguments (including
  93. the command name) and \fIargv\fR giving the values of the arguments
  94. as strings.  The \fIargv\fR array will contain \fIargc\fR+1 values;
  95. the first \fIargc\fR values point to the argument strings, and the
  96. last value is NULL.
  97. .PP
  98. \fIProc\fR must return an integer code that is either \fBTCL_OK\fR, \fBTCL_ERROR\fR,
  99. \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.  See the Tcl overview man page
  100. for details on what these codes mean.  Most normal commands will only
  101. return \fBTCL_OK\fR or \fBTCL_ERROR\fR.  In addition, \fIproc\fR must set
  102. \fIinterp->result\fR to point to a string value;
  103. in the case of a \fBTCL_OK\fR return code this gives the result
  104. of the command, and in the case of \fBTCL_ERROR\fR it gives an error message.
  105. The \fBTcl_SetResult\fR procedure provides an easy interface for setting
  106. the return value;  for complete details on how the \fIinterp->result\fR
  107. field is managed, see the \fBTcl_Interp\fR man page.
  108. Before invoking a command procedure,
  109. \fBTcl_Eval\fR sets \fIinterp->result\fR to point to an empty string, so simple
  110. commands can return an empty result by doing nothing at all.
  111. .PP
  112. .VS
  113. The contents of the \fIargv\fR array belong to Tcl and are not
  114. guaranteed to persist once \fIproc\fR returns:  \fIproc\fR should
  115. not modify them, nor should it set \fIinterp->result\fR to point
  116. anywhere within the \fIargv\fR values.
  117. Call \fBTcl_SetResult\fR with status \fBTCL_VOLATILE\fR if you want
  118. to return something from the \fIargv\fR array.
  119. .VE
  120. .PP
  121. \fIDeleteProc\fR will be invoked when (if) \fIcmdName\fR is deleted.
  122. This can occur through a call to \fBTcl_DeleteCommand\fR or \fBTcl_DeleteInterp\fR,
  123. or by replacing \fIcmdName\fR in another call to \fBTcl_CreateCommand\fR.
  124. \fIDeleteProc\fR is invoked before the command is deleted, and gives the
  125. application an opportunity to release any structures associated
  126. with the command.  \fIDeleteProc\fR should have arguments and
  127. result that match the type \fBTcl_CmdDeleteProc\fR:
  128. .nf
  129. .RS
  130. .sp
  131. typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);
  132. .sp
  133. .RE
  134. .fi
  135. The \fIclientData\fR argument will be the same as the \fIclientData\fR
  136. argument passed to \fBTcl_CreateCommand\fR.
  137. .PP
  138. \fBTcl_DeleteCommand\fR deletes a command from a command interpreter.
  139. Once the call completes, attempts to invoke \fIcmdName\fR in
  140. \fIinterp\fR will result in errors.
  141. If \fIcmdName\fR isn't bound as a command in \fIinterp\fR then
  142. \fBTcl_DeleteCommand\fR does nothing and returns -1;  otherwise
  143. it returns 0.
  144. There are no restrictions on \fIcmdName\fR:  it may refer to
  145. a built-in command, an application-specific command, or a Tcl procedure.
  146. .PP
  147. .VS
  148. \fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argument
  149. exists as a command in \fIinterp\fR.  If not then it returns 0.
  150. Otherwise it places information about the command in the structure
  151. pointed to by \fIinfoPtr\fR and returns 1.
  152. Tcl_CmdInfo structures have fields named \fIproc\fR, \fIclientData\fR,
  153. and \fIdeleteProc\fR, which have the same meaning as the corresponding
  154. arguments to \fBTcl_CreateCommand\fR.
  155. There is also a field \fIdeleteData\fR, which is the ClientData value
  156. to pass to \fIdeleteProc\fR;  it is normally the same as
  157. \fIclientData\fR but may be set independently using the
  158. \fBTcl_SetCommandInfo\fR procedure.
  159. .PP
  160. \fBTcl_SetCommandInfo\fR is used to modify the procedures and
  161. ClientData values associated with a command.
  162. Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR.
  163. If this command exists then \fBTcl_SetCommandInfo\fR returns 0.
  164. Otherwise, it copies the information from \fI*infoPtr\fR to
  165. Tcl's internal structure for the command and returns 1.
  166. Note that this procedure allows the ClientData for a command's
  167. deletion procedure to be given a different value than the ClientData
  168. for its command procedure.
  169. .VE
  170.  
  171. .SH KEYWORDS
  172. bind, command, create, delete, interpreter
  173.