OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tcl/] [doc/] [SetVar.3] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1989-1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: SetVar.3,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tcl_SetVar 3 7.4 Tcl "Tcl Library Procedures"
12
.BS
13
.SH NAME
14
Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
char *
20
\fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
21
.sp
22
char *
23
\fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
24
.sp
25
char *
26
\fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
27
.sp
28
char *
29
\fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
30
.sp
31
int
32
\fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
33
.sp
34
int
35
\fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
36
.SH ARGUMENTS
37
.AS Tcl_Interp *newValue
38
.AP Tcl_Interp *interp in
39
Interpreter containing variable.
40
.AP char *varName in
41
Name of variable.
42
May include a series of \fB::\fR namespace qualifiers
43
to specify a variable in a particular namespace.
44
May refer to a scalar variable or an element of
45
an array variable.
46
If the name references an element of an array, then it
47
must be in writable memory:  Tcl will make temporary modifications
48
to it while looking up the name.
49
.AP char *newValue in
50
New value for variable.
51
.AP int flags in
52
OR-ed combination of bits providing additional information for
53
operation. See below for valid values.
54
.AP char *name1 in
55
Name of scalar variable, or name of array variable if \fIname2\fR
56
is non-NULL.
57
May include a series of \fB::\fR namespace qualifiers
58
to specify a variable in a particular namespace.
59
.AP char *name2 in
60
If non-NULL, gives name of element within array and \fIname1\fR
61
must refer to an array variable.
62
.BE
63
 
64
.SH DESCRIPTION
65
.PP
66
These procedures may be used to create, modify, read, and delete
67
Tcl variables from C code.
68
.PP
69
Note that \fBTcl_GetVar\fR and \fBTcl_SetVar\fR
70
have been largely replaced by the
71
object-based procedures \fBTcl_ObjGetVar2\fR and \fBTcl_ObjSetVar2\fR.
72
Those object-based procedures read, modify, and create
73
a variable whose name is held in a Tcl object instead of a string.
74
They also return a pointer to the object
75
which is the variable's value instead of returning a string.
76
Operations on objects can be faster since objects
77
hold an internal representation that can be manipulated more efficiently.
78
.PP
79
\fBTcl_SetVar\fR and \fBTcl_SetVar2\fR
80
will create a new variable or modify an existing one.
81
Both of these procedures set the given variable to the value
82
given by \fInewValue\fR, and they return a pointer to a
83
copy of the variable's new value, which is stored in Tcl's
84
variable structure.
85
Tcl keeps a private copy of the variable's value, so the caller
86
may change \fInewValue\fR after these procedures return without
87
affecting the value of the variable.
88
If an error occurs in setting the variable (e.g. an array
89
variable is referenced without giving an index into the array),
90
they return NULL.
91
.PP
92
The name of the variable may be specified to
93
\fBTcl_SetVar\fR and \fBTcl_SetVar2\fR in either of two ways.
94
If \fBTcl_SetVar\fR is called, the variable name is given as
95
a single string, \fIvarName\fR.
96
If \fIvarName\fR contains an open parenthesis and ends with a
97
close parenthesis, then the value between the parentheses is
98
treated as an index (which can have any string value) and
99
the characters before the first open
100
parenthesis are treated as the name of an array variable.
101
If \fIvarName\fR doesn't have parentheses as described above, then
102
the entire string is treated as the name of a scalar variable.
103
If \fBTcl_SetVar2\fR is called, then the array name and index
104
have been separated by the caller into two separate strings,
105
\fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
106
zero it means that a scalar variable is being referenced.
107
.PP
108
The \fIflags\fR argument may be used to specify any of several
109
options to the procedures.
110
It consists of an OR-ed combination of the following bits.
111
Note that the flag bit TCL_PARSE_PART1 is only meaningful
112
for the procedures Tcl_SetVar2 and Tcl_GetVar2.
113
.TP
114
\fBTCL_GLOBAL_ONLY\fR
115
Under normal circumstances the procedures look up variables as follows:
116
If a procedure call is active in \fIinterp\fR,
117
a variable is looked up at the current level of procedure call.
118
Otherwise, a variable is looked up first in the current namespace,
119
then in the global namespace.
120
However, if this bit is set in \fIflags\fR then the variable
121
is looked up only in the global namespace
122
even if there is a procedure call active.
123
If both \fBTCL_GLOBAL_ONLY\fR and \fBTCL_NAMESPACE_ONLY\fR are given,
124
\fBTCL_GLOBAL_ONLY\fR is ignored.
125
.TP
126
\fBTCL_NAMESPACE_ONLY\fR
127
Under normal circumstances the procedures look up variables as follows:
128
If a procedure call is active in \fIinterp\fR,
129
a variable is looked up at the current level of procedure call.
130
Otherwise, a variable is looked up first in the current namespace,
131
then in the global namespace.
132
However, if this bit is set in \fIflags\fR then the variable
133
is looked up only in the current namespace
134
even if there is a procedure call active.
135
.TP
136
\fBTCL_LEAVE_ERR_MSG\fR
137
If an error is returned and this bit is set in \fIflags\fR, then
138
an error message will be left in the interpreter's result,
139
where it can be retrieved with \fBTcl_GetObjResult\fR
140
or \fBTcl_GetStringResult\fR.
141
If this flag bit isn't set then no error message is left
142
and the interpreter's result will not be modified.
143
.TP
144
\fBTCL_APPEND_VALUE\fR
145
If this bit is set then \fInewValue\fR is appended to the current
146
value, instead of replacing it.
147
If the variable is currently undefined, then this bit is ignored.
148
.TP
149
\fBTCL_LIST_ELEMENT\fR
150
If this bit is set, then \fInewValue\fR is converted to a valid
151
Tcl list element before setting (or appending to) the variable.
152
A separator space is appended before the new list element unless
153
the list element is going to be the first element in a list or
154
sublist (i.e. the variable's current value is empty, or contains
155
the single character ``{'', or ends in `` }'').
156
.TP
157
\fBTCL_PARSE_PART1\fR
158
If this bit is set when calling \fITcl_SetVar2\fR and \fITcl_GetVar2\fR,
159
\fIname1\fR may contain both an array and an element name:
160
if the name contains an open parenthesis and ends with a
161
close parenthesis, then the value between the parentheses is
162
treated as an element name (which can have any string value) and
163
the characters before the first open
164
parenthesis are treated as the name of an array variable.
165
If the flag TCL_PARSE_PART1 is given,
166
\fIname2\fR should be NULL since the array and element names
167
are taken from \fIname1\fR.
168
.PP
169
\fBTcl_GetVar\fR and \fBTcl_GetVar2\fR
170
return the current value of a variable.
171
The arguments to these procedures are treated in the same way
172
as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
173
Under normal circumstances, the return value is a pointer
174
to the variable's value (which is stored in Tcl's variable
175
structure and will not change before the next call to \fBTcl_SetVar\fR
176
or \fBTcl_SetVar2\fR).
177
\fBTcl_GetVar\fR and \fBTcl_GetVar2\fR use the flag bits TCL_GLOBAL_ONLY
178
and TCL_LEAVE_ERR_MSG, both of
179
which have
180
the same meaning as for \fBTcl_SetVar\fR.
181
In addition, \fBTcl_GetVar2\fR uses the bit TCL_PARSE_PART1,
182
which has the same meaning as for \fBTcl_SetVar2\fR.
183
If an error occurs in reading the variable (e.g. the variable
184
doesn't exist or an array element is specified for a scalar
185
variable), then NULL is returned.
186
.PP
187
\fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
188
a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
189
for the variable will return an error.
190
The arguments to these procedures are treated in the same way
191
as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
192
If the variable is successfully removed then TCL_OK is returned.
193
If the variable cannot be removed because it doesn't exist then
194
TCL_ERROR is returned.
195
If an array element is specified, the given element is removed
196
but the array remains.
197
If an array name is specified without an index, then the entire
198
array is removed.
199
 
200
.SH "SEE ALSO"
201
Tcl_GetObjResult, Tcl_GetStringResult, Tcl_ObjGetVar2, Tcl_ObjSetVar2, Tcl_TraceVar
202
 
203
.SH KEYWORDS
204
array, interpreter, object, scalar, set, unset, variable

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.