home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / SetVar.3 < prev    next >
Text File  |  1993-06-05  |  7KB  |  167 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/SetVar.3,v 1.15 93/06/05 15:40:17 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_SetVar tclc 7.0
  25. .BS
  26. .SH NAME
  27. Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. char *
  33. \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
  34. .sp
  35. char *
  36. \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
  37. .sp
  38. char *
  39. \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
  40. .sp
  41. char *
  42. \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
  43. .sp
  44. int
  45. \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
  46. .sp
  47. int
  48. \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
  49. .SH ARGUMENTS
  50. .AS Tcl_Interp *newValue
  51. .AP Tcl_Interp *interp in
  52. Interpreter containing variable.
  53. .AP char *varName in
  54. Name of variable.  May refer to a scalar variable or an element of
  55. an array variable.
  56. .AP char *newValue in
  57. New value for variable.
  58. .AP int flags in
  59. OR-ed combination of bits providing additional information for
  60. operation. See below for valid values.
  61. .AP char *name1 in
  62. Name of scalar variable, or name of array variable if \fIname2\fR
  63. is non-NULL.
  64. .AP char *name2 in
  65. If non-NULL, gives name of element within array and \fIname1\fR
  66. must refer to an array variable.
  67. .BE
  68.  
  69. .SH DESCRIPTION
  70. .PP
  71. These procedures may be used to create, modify, read, and delete
  72. Tcl variables from C code.
  73. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR will create a new variable
  74. or modify an existing one.
  75. Both of these procedures set the given variable to the value
  76. given by \fInewValue\fR, and they return a pointer to a
  77. copy of the variable's new value, which is stored in Tcl's
  78. variable structure.
  79. Tcl keeps a private copy of the variable's value, so the caller
  80. may change \fInewValue\fR after these procedures return without
  81. affecting the value of the variable.
  82. If an error occurs in setting the variable (e.g. an array
  83. variable is referenced without giving an index into the array),
  84. then NULL is returned.
  85. .PP
  86. The name of the variable may be specified in either of two ways.
  87. If \fBTcl_SetVar\fR is called, the variable name is given as
  88. a single string, \fIvarName\fR.
  89. If \fIvarName\fR contains an open parenthesis and ends with a
  90. close parenthesis, then the value between the parentheses is
  91. treated as an index (which can have any string value) and
  92. the characters before the first open
  93. parenthesis are treated as the name of an array variable.
  94. If \fIvarName\fR doesn't have parentheses as described above, then
  95. the entire string is treated as the name of a scalar variable.
  96. If \fBTcl_SetVar2\fR is called, then the array name and index
  97. have been separated by the caller into two separate strings,
  98. \fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
  99. zero it means that a scalar variable is being referenced.
  100. .PP
  101. The \fIflags\fR argument may be used to specify any of several
  102. options to the procedures.
  103. It consists of an OR-ed combination of any of the following
  104. bits:
  105. .IP TCL_GLOBAL_ONLY
  106. Under normal circumstances the procedures look up variables
  107. at the current level of procedure call for \fIinterp\fR, or
  108. at global level if there is no call active.
  109. However, if this bit is set in \fIflags\fR then the variable
  110. is looked up at global level even if there is a procedure
  111. call active.
  112. .IP TCL_LEAVE_ERR_MSG
  113. If an error is returned and this bit is set in \fIflags\fR, then
  114. an error message will be left in \fI\%interp->result\fR.  If this
  115. flag bit isn't set then no error message is left (\fI\%interp->result\fR
  116. will not be modified).
  117. .IP TCL_APPEND_VALUE
  118. If this bit is set then \fInewValue\fR is appended to the current
  119. value, instead of replacing it.
  120. If the variable is currently undefined, then this bit is ignored.
  121. .IP TCL_LIST_ELEMENT
  122. If this bit is set, then \fInewValue\fR is converted to a valid
  123. Tcl list element before setting (or appending to) the variable.
  124. A separator space is appended before the new list element unless
  125. .VS
  126. the list element is going to be the first element in a list or
  127. sublist (i.e. the variable's current value is empty, or contains
  128. the single character ``{'', or ends in `` }'').
  129. .VE
  130. .PP
  131. \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR return the current value
  132. of a variable.
  133. The arguments to these procedures are treated in the same way
  134. as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
  135. Under normal circumstances, the return value is a pointer
  136. to the variable's value (which is stored in Tcl's variable
  137. structure and will not change before the next call to \fBTcl_SetVar\fR
  138. or \fBTcl_SetVar2\fR).
  139. The only bits of \fIflags\fR that are used are TCL_GLOBAL_ONLY
  140. and TCL_LEAVE_ERR_MSG, both of
  141. which have
  142. the same meaning as for \fBTcl_SetVar\fR.
  143. If an error occurs in reading the variable (e.g. the variable
  144. doesn't exist or an array element is specified for a scalar
  145. variable), then NULL is returned.
  146. .PP
  147. \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
  148. a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
  149. for the variable will return an error.
  150. The arguments to these procedures are treated in the same way
  151. as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
  152. .VS
  153. If the variable is successfully removed then TCL_OK is returned.
  154. If the variable cannot be removed because it doesn't exist then
  155. TCL_ERROR is returned.
  156. .VE
  157. If an array element is specified, the given element is removed
  158. but the array remains.
  159. If an array name is specified without an index, then the entire
  160. array is removed.
  161.  
  162. .SH "SEE ALSO"
  163. Tcl_TraceVar
  164.  
  165. .SH KEYWORDS
  166. array, interpreter, scalar, set, unset, variable
  167.