OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / man / man3 / Tcl_ListObjLength.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 .TH Tcl_ListObj 3 8.0 Tcl "Tcl Library Procedures"
8 .\" The -*- nroff -*- definitions below are for supplemental macros used
9 .\" in Tcl/Tk manual entries.
10 .\"
11 .\" .AP type name in/out ?indent?
12 .\"     Start paragraph describing an argument to a library procedure.
13 .\"     type is type of argument (int, etc.), in/out is either "in", "out",
14 .\"     or "in/out" to describe whether procedure reads or modifies arg,
15 .\"     and indent is equivalent to second arg of .IP (shouldn't ever be
16 .\"     needed;  use .AS below instead)
17 .\"
18 .\" .AS ?type? ?name?
19 .\"     Give maximum sizes of arguments for setting tab stops.  Type and
20 .\"     name are examples of largest possible arguments that will be passed
21 .\"     to .AP later.  If args are omitted, default tab stops are used.
22 .\"
23 .\" .BS
24 .\"     Start box enclosure.  From here until next .BE, everything will be
25 .\"     enclosed in one large box.
26 .\"
27 .\" .BE
28 .\"     End of box enclosure.
29 .\"
30 .\" .CS
31 .\"     Begin code excerpt.
32 .\"
33 .\" .CE
34 .\"     End code excerpt.
35 .\"
36 .\" .VS ?version? ?br?
37 .\"     Begin vertical sidebar, for use in marking newly-changed parts
38 .\"     of man pages.  The first argument is ignored and used for recording
39 .\"     the version when the .VS was added, so that the sidebars can be
40 .\"     found and removed when they reach a certain age.  If another argument
41 .\"     is present, then a line break is forced before starting the sidebar.
42 .\"
43 .\" .VE
44 .\"     End of vertical sidebar.
45 .\"
46 .\" .DS
47 .\"     Begin an indented unfilled display.
48 .\"
49 .\" .DE
50 .\"     End of indented unfilled display.
51 .\"
52 .\" .SO ?manpage?
53 .\"     Start of list of standard options for a Tk widget. The manpage
54 .\"     argument defines where to look up the standard options; if
55 .\"     omitted, defaults to "options". The options follow on successive
56 .\"     lines, in three columns separated 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 .\" .QW arg1 ?arg2?
71 .\"     Print arg1 in quotes, then arg2 normally (for trailing punctuation).
72 .\"
73 .\" .PQ arg1 ?arg2?
74 .\"     Print an open parenthesis, arg1 in quotes, then arg2 normally
75 .\"     (for trailing punctuation) and then a closing parenthesis.
76 .\"
77 .\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
78 .if t .wh -1.3i ^B
79 .nr ^l \n(.l
80 .ad b
81 .\"     # Start an argument description
82 .de AP
83 .ie !"\\$4"" .TP \\$4
84 .el \{\
85 .   ie !"\\$2"" .TP \\n()Cu
86 .   el          .TP 15
87 .\}
88 .ta \\n()Au \\n()Bu
89 .ie !"\\$3"" \{\
90 \&\\$1 \\fI\\$2\\fP (\\$3)
91 .\".b
92 .\}
93 .el \{\
94 .br
95 .ie !"\\$2"" \{\
96 \&\\$1  \\fI\\$2\\fP
97 .\}
98 .el \{\
99 \&\\fI\\$1\\fP
100 .\}
101 .\}
102 ..
103 .\"     # define tabbing values for .AP
104 .de AS
105 .nr )A 10n
106 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
107 .nr )B \\n()Au+15n
108 .\"
109 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
110 .nr )C \\n()Bu+\\w'(in/out)'u+2n
111 ..
112 .AS Tcl_Interp Tcl_CreateInterp in/out
113 .\"     # BS - start boxed text
114 .\"     # ^y = starting y location
115 .\"     # ^b = 1
116 .de BS
117 .br
118 .mk ^y
119 .nr ^b 1u
120 .if n .nf
121 .if n .ti 0
122 .if n \l'\\n(.lu\(ul'
123 .if n .fi
124 ..
125 .\"     # BE - end boxed text (draw box now)
126 .de BE
127 .nf
128 .ti 0
129 .mk ^t
130 .ie n \l'\\n(^lu\(ul'
131 .el \{\
132 .\"     Draw four-sided box normally, but don't draw top of
133 .\"     box if the box started on an earlier page.
134 .ie !\\n(^b-1 \{\
135 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
136 .\}
137 .el \}\
138 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
139 .\}
140 .\}
141 .fi
142 .br
143 .nr ^b 0
144 ..
145 .\"     # VS - start vertical sidebar
146 .\"     # ^Y = starting y location
147 .\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
148 .de VS
149 .if !"\\$2"" .br
150 .mk ^Y
151 .ie n 'mc \s12\(br\s0
152 .el .nr ^v 1u
153 ..
154 .\"     # VE - end of vertical sidebar
155 .de VE
156 .ie n 'mc
157 .el \{\
158 .ev 2
159 .nf
160 .ti 0
161 .mk ^t
162 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
163 .sp -1
164 .fi
165 .ev
166 .\}
167 .nr ^v 0
168 ..
169 .\"     # Special macro to handle page bottom:  finish off current
170 .\"     # box/sidebar if in box/sidebar mode, then invoked standard
171 .\"     # page bottom macro.
172 .de ^B
173 .ev 2
174 'ti 0
175 'nf
176 .mk ^t
177 .if \\n(^b \{\
178 .\"     Draw three-sided box if this is the box's first page,
179 .\"     draw two sides but no top otherwise.
180 .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
181 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
182 .\}
183 .if \\n(^v \{\
184 .nr ^x \\n(^tu+1v-\\n(^Yu
185 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
186 .\}
187 .bp
188 'fi
189 .ev
190 .if \\n(^b \{\
191 .mk ^y
192 .nr ^b 2
193 .\}
194 .if \\n(^v \{\
195 .mk ^Y
196 .\}
197 ..
198 .\"     # DS - begin display
199 .de DS
200 .RS
201 .nf
202 .sp
203 ..
204 .\"     # DE - end display
205 .de DE
206 .fi
207 .RE
208 .sp
209 ..
210 .\"     # SO - start of list of standard options
211 .de SO
212 'ie '\\$1'' .ds So \\fBoptions\\fR
213 'el .ds So \\fB\\$1\\fR
214 .SH "STANDARD OPTIONS"
215 .LP
216 .nf
217 .ta 5.5c 11c
218 .ft B
219 ..
220 .\"     # SE - end of list of standard options
221 .de SE
222 .fi
223 .ft R
224 .LP
225 See the \\*(So manual entry for details on the standard options.
226 ..
227 .\"     # OP - start of full description for a single option
228 .de OP
229 .LP
230 .nf
231 .ta 4c
232 Command-Line Name:      \\fB\\$1\\fR
233 Database Name:  \\fB\\$2\\fR
234 Database Class: \\fB\\$3\\fR
235 .fi
236 .IP
237 ..
238 .\"     # CS - begin code excerpt
239 .de CS
240 .RS
241 .nf
242 .ta .25i .5i .75i 1i
243 ..
244 .\"     # CE - end code excerpt
245 .de CE
246 .fi
247 .RE
248 ..
249 .\"     # UL - underline word
250 .de UL
251 \\$1\l'|0\(ul'\\$2
252 ..
253 .\"     # QW - apply quotation marks to word
254 .de QW
255 .ie '\\*(lq'"' ``\\$1''\\$2
256 .\"" fix emacs highlighting
257 .el \\*(lq\\$1\\*(rq\\$2
258 ..
259 .\"     # PQ - apply parens and quotation marks to word
260 .de PQ
261 .ie '\\*(lq'"' (``\\$1''\\$2)\\$3
262 .\"" fix emacs highlighting
263 .el (\\*(lq\\$1\\*(rq\\$2)\\$3
264 ..
265 .\"     # QR - quoted range
266 .de QR
267 .ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
268 .\"" fix emacs highlighting
269 .el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
270 ..
271 .\"     # MT - "empty" string
272 .de MT
273 .QW ""
274 ..
275 .BS
276 .SH NAME
277 Tcl_ListObjAppendList, Tcl_ListObjAppendElement, Tcl_NewListObj, Tcl_SetListObj, Tcl_ListObjGetElements, Tcl_ListObjLength, Tcl_ListObjIndex, Tcl_ListObjReplace \- manipulate Tcl values as lists
278 .SH SYNOPSIS
279 .nf
280 \fB#include <tcl.h>\fR
281 .sp
282 int
283 \fBTcl_ListObjAppendList\fR(\fIinterp, listPtr, elemListPtr\fR)
284 .sp
285 int
286 \fBTcl_ListObjAppendElement\fR(\fIinterp, listPtr, objPtr\fR)
287 .sp
288 Tcl_Obj *
289 \fBTcl_NewListObj\fR(\fIobjc, objv\fR)
290 .sp
291 \fBTcl_SetListObj\fR(\fIobjPtr, objc, objv\fR)
292 .sp
293 int
294 \fBTcl_ListObjGetElements\fR(\fIinterp, listPtr, objcPtr, objvPtr\fR)
295 .sp
296 int
297 \fBTcl_ListObjLength\fR(\fIinterp, listPtr, intPtr\fR)
298 .sp
299 int
300 \fBTcl_ListObjIndex\fR(\fIinterp, listPtr, index, objPtrPtr\fR)
301 .sp
302 int
303 \fBTcl_ListObjReplace\fR(\fIinterp, listPtr, first, count, objc, objv\fR)
304 .SH ARGUMENTS
305 .AS "Tcl_Obj *const" *elemListPtr in/out
306 .AP Tcl_Interp *interp in
307 If an error occurs while converting a value to be a list value,
308 an error message is left in the interpreter's result value
309 unless \fIinterp\fR is NULL.
310 .AP Tcl_Obj *listPtr in/out
311 Points to the list value to be manipulated.
312 If \fIlistPtr\fR does not already point to a list value,
313 an attempt will be made to convert it to one.
314 .AP Tcl_Obj *elemListPtr in/out
315 For \fBTcl_ListObjAppendList\fR, this points to a list value
316 containing elements to be appended onto \fIlistPtr\fR.
317 Each element of *\fIelemListPtr\fR will
318 become a new element of \fIlistPtr\fR.
319 If *\fIelemListPtr\fR is not NULL and
320 does not already point to a list value,
321 an attempt will be made to convert it to one.
322 .AP Tcl_Obj *objPtr in
323 For \fBTcl_ListObjAppendElement\fR,
324 points to the Tcl value that will be appended to \fIlistPtr\fR.
325 For \fBTcl_SetListObj\fR,
326 this points to the Tcl value that will be converted to a list value
327 containing the \fIobjc\fR elements of the array referenced by \fIobjv\fR.
328 .AP int *objcPtr in
329 Points to location where \fBTcl_ListObjGetElements\fR
330 stores the number of element values in \fIlistPtr\fR.
331 .AP Tcl_Obj ***objvPtr out
332 A location where \fBTcl_ListObjGetElements\fR stores a pointer to an array
333 of pointers to the element values of \fIlistPtr\fR.  
334 .AP int objc in
335 The number of Tcl values that \fBTcl_NewListObj\fR
336 will insert into a new list value,
337 and \fBTcl_ListObjReplace\fR will insert into \fIlistPtr\fR.
338 For \fBTcl_SetListObj\fR,
339 the number of Tcl values to insert into \fIobjPtr\fR.
340 .AP "Tcl_Obj *const" objv[] in
341 An array of pointers to values.
342 \fBTcl_NewListObj\fR will insert these values into a new list value
343 and \fBTcl_ListObjReplace\fR will insert them into an existing \fIlistPtr\fR.
344 Each value will become a separate list element.  
345 .AP int *intPtr out
346 Points to location where \fBTcl_ListObjLength\fR
347 stores the length of the list.
348 .AP int index in
349 Index of the list element that \fBTcl_ListObjIndex\fR
350 is to return.
351 The first element has index 0.
352 .AP Tcl_Obj **objPtrPtr out
353 Points to place where \fBTcl_ListObjIndex\fR is to store
354 a pointer to the resulting list element value.
355 .AP int first in
356 Index of the starting list element that \fBTcl_ListObjReplace\fR
357 is to replace.
358 The list's first element has index 0.
359 .AP int count in
360 The number of elements that \fBTcl_ListObjReplace\fR
361 is to replace.
362 .BE
363
364 .SH DESCRIPTION
365 .PP
366 Tcl list values have an internal representation that supports
367 the efficient indexing and appending.
368 The procedures described in this man page are used to
369 create, modify, index, and append to Tcl list values from C code.
370 .PP
371 \fBTcl_ListObjAppendList\fR and \fBTcl_ListObjAppendElement\fR
372 both add one or more values
373 to the end of the list value referenced by \fIlistPtr\fR.
374 \fBTcl_ListObjAppendList\fR appends each element of the list value
375 referenced by \fIelemListPtr\fR while
376 \fBTcl_ListObjAppendElement\fR appends the single value
377 referenced by \fIobjPtr\fR.
378 Both procedures will convert the value referenced by \fIlistPtr\fR
379 to a list value if necessary.
380 If an error occurs during conversion,
381 both procedures return \fBTCL_ERROR\fR and leave an error message
382 in the interpreter's result value if \fIinterp\fR is not NULL.
383 Similarly, if \fIelemListPtr\fR does not already refer to a list value,
384 \fBTcl_ListObjAppendList\fR will attempt to convert it to one
385 and if an error occurs during conversion,
386 will return \fBTCL_ERROR\fR
387 and leave an error message in the interpreter's result value
388 if interp is not NULL.
389 Both procedures invalidate any old string representation of \fIlistPtr\fR
390 and, if it was converted to a list value,
391 free any old internal representation.
392 Similarly, \fBTcl_ListObjAppendList\fR frees any old internal representation
393 of \fIelemListPtr\fR if it converts it to a list value.
394 After appending each element in \fIelemListPtr\fR,
395 \fBTcl_ListObjAppendList\fR increments the element's reference count
396 since \fIlistPtr\fR now also refers to it.
397 For the same reason, \fBTcl_ListObjAppendElement\fR
398 increments \fIobjPtr\fR's reference count.
399 If no error occurs,
400 the two procedures return \fBTCL_OK\fR after appending the values.
401 .PP
402 \fBTcl_NewListObj\fR and \fBTcl_SetListObj\fR
403 create a new value or modify an existing value to hold 
404 the \fIobjc\fR elements of the array referenced by \fIobjv\fR
405 where each element is a pointer to a Tcl value.
406 If \fIobjc\fR is less than or equal to zero,
407 they return an empty value.
408 The new value's string representation is left invalid.
409 The two procedures increment the reference counts
410 of the elements in \fIobjc\fR since the list value now refers to them.
411 The new list value returned by \fBTcl_NewListObj\fR
412 has reference count zero.
413 .PP
414 \fBTcl_ListObjGetElements\fR returns a count and a pointer to an array of
415 the elements in a list value.  It returns the count by storing it in the
416 address \fIobjcPtr\fR.  Similarly, it returns the array pointer by storing
417 it in the address \fIobjvPtr\fR.
418 The memory pointed to is managed by Tcl and should not be freed or written
419 to by the caller. If the list is empty, 0 is stored at \fIobjcPtr\fR
420 and NULL at \fIobjvPtr\fR.
421 If \fIlistPtr\fR is not already a list value, \fBTcl_ListObjGetElements\fR
422 will attempt to convert it to one; if the conversion fails, it returns
423 \fBTCL_ERROR\fR and leaves an error message in the interpreter's result
424 value if \fIinterp\fR is not NULL.
425 Otherwise it returns \fBTCL_OK\fR after storing the count and array pointer.
426 .PP
427 \fBTcl_ListObjLength\fR returns the number of elements in the list value
428 referenced by \fIlistPtr\fR.
429 It returns this count by storing an integer in the address \fIintPtr\fR.
430 If the value is not already a list value,
431 \fBTcl_ListObjLength\fR will attempt to convert it to one;
432 if the conversion fails, it returns \fBTCL_ERROR\fR
433 and leaves an error message in the interpreter's result value
434 if \fIinterp\fR is not NULL.
435 Otherwise it returns \fBTCL_OK\fR after storing the list's length.
436 .PP
437 The procedure \fBTcl_ListObjIndex\fR returns a pointer to the value
438 at element \fIindex\fR in the list referenced by \fIlistPtr\fR.
439 It returns this value by storing a pointer to it
440 in the address \fIobjPtrPtr\fR.
441 If \fIlistPtr\fR does not already refer to a list value,
442 \fBTcl_ListObjIndex\fR will attempt to convert it to one;
443 if the conversion fails, it returns \fBTCL_ERROR\fR
444 and leaves an error message in the interpreter's result value
445 if \fIinterp\fR is not NULL.
446 If the index is out of range,
447 that is, \fIindex\fR is negative or
448 greater than or equal to the number of elements in the list,
449 \fBTcl_ListObjIndex\fR stores a NULL in \fIobjPtrPtr\fR
450 and returns \fBTCL_OK\fR.
451 Otherwise it returns \fBTCL_OK\fR after storing the element's
452 value pointer.
453 The reference count for the list element is not incremented;
454 the caller must do that if it needs to retain a pointer to the element.
455 .PP
456 \fBTcl_ListObjReplace\fR replaces zero or more elements
457 of the list referenced by \fIlistPtr\fR
458 with the \fIobjc\fR values in the array referenced by \fIobjv\fR.
459 If \fIlistPtr\fR does not point to a list value,
460 \fBTcl_ListObjReplace\fR will attempt to convert it to one;
461 if the conversion fails, it returns \fBTCL_ERROR\fR
462 and leaves an error message in the interpreter's result value
463 if \fIinterp\fR is not NULL.
464 Otherwise, it returns \fBTCL_OK\fR after replacing the values.
465 If \fIobjv\fR is NULL, no new elements are added.
466 If the argument \fIfirst\fR is zero or negative,
467 it refers to the first element.
468 If \fIfirst\fR is greater than or equal to the
469 number of elements in the list, then no elements are deleted;
470 the new elements are appended to the list.
471 \fIcount\fR gives the number of elements to replace.
472 If \fIcount\fR is zero or negative then no elements are deleted;
473 the new elements are simply inserted before the one
474 designated by \fIfirst\fR.
475 \fBTcl_ListObjReplace\fR invalidates \fIlistPtr\fR's
476 old string representation.
477 The reference counts of any elements inserted from \fIobjv\fR
478 are incremented since the resulting list now refers to them.
479 Similarly, the reference counts for any replaced values are decremented.
480 .PP
481 Because \fBTcl_ListObjReplace\fR combines
482 both element insertion and deletion,
483 it can be used to implement a number of list operations.
484 For example, the following code inserts the \fIobjc\fR values
485 referenced by the array of value pointers \fIobjv\fR
486 just before the element \fIindex\fR of the list referenced by \fIlistPtr\fR:
487 .PP
488 .CS
489 result = \fBTcl_ListObjReplace\fR(interp, listPtr, index, 0,
490         objc, objv);
491 .CE
492 .PP
493 Similarly, the following code appends the \fIobjc\fR values
494 referenced by the array \fIobjv\fR
495 to the end of the list \fIlistPtr\fR:
496 .PP
497 .CS
498 result = \fBTcl_ListObjLength\fR(interp, listPtr, &length);
499 if (result == TCL_OK) {
500     result = \fBTcl_ListObjReplace\fR(interp, listPtr, length, 0,
501             objc, objv);
502 }
503 .CE
504 .PP
505 The \fIcount\fR list elements starting at \fIfirst\fR can be deleted
506 by simply calling \fBTcl_ListObjReplace\fR
507 with a NULL \fIobjvPtr\fR:
508 .PP
509 .CS
510 result = \fBTcl_ListObjReplace\fR(interp, listPtr, first, count,
511         0, NULL);
512 .CE
513 .SH "SEE ALSO"
514 Tcl_NewObj(3), Tcl_DecrRefCount(3), Tcl_IncrRefCount(3), Tcl_GetObjResult(3)
515 .SH KEYWORDS
516 append, index, insert, internal representation, length, list, list value,
517 list type, value, value type, replace, string representation