Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/GetIndex.3 @ 44

Last change on this file since 44 was 25, checked in by landauf, 18 years ago

added tcl to libs

File size: 4.3 KB
Line 
1'\"
2'\" Copyright (c) 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: GetIndex.3,v 1.22 2007/12/13 15:22:31 dgp Exp $
8'\"
9.so man.macros
10.TH Tcl_GetIndexFromObj 3 8.1 Tcl "Tcl Library Procedures"
11.BS
12.SH NAME
13Tcl_GetIndexFromObj, Tcl_GetIndexFromObjStruct \- lookup string in table of keywords
14.SH SYNOPSIS
15.nf
16\fB#include <tcl.h>\fR
17.sp
18int
19\fBTcl_GetIndexFromObj\fR(\fIinterp, objPtr, tablePtr, msg, flags,
20indexPtr\fR)
21.sp
22int
23\fBTcl_GetIndexFromObjStruct\fR(\fIinterp, objPtr, structTablePtr, offset,
24                          msg, flags, indexPtr\fR)
25.SH ARGUMENTS
26.AS "const char" *structTablePtr in/out
27.AP Tcl_Interp *interp in
28Interpreter to use for error reporting; if NULL, then no message is
29provided on errors.
30.AP Tcl_Obj *objPtr in/out
31The string value of this object is used to search through \fItablePtr\fR.
32The internal representation is modified to hold the index of the matching
33table entry.
34.AP "const char" **tablePtr in
35An array of null-terminated strings.  The end of the array is marked
36by a NULL string pointer.
37.AP "const void" *structTablePtr in
38An array of arbitrary type, typically some \fBstruct\fR type.
39The first member of the structure must be a null-terminated string.
40The size of the structure is given by \fIoffset\fR.
41.AP int offset in
42The offset to add to structTablePtr to get to the next entry.
43The end of the array is marked by a NULL string pointer.
44.AP "const char" *msg in
45Null-terminated string describing what is being looked up, such as
46\fBoption\fR.  This string is included in error messages.
47.AP int flags in
48OR-ed combination of bits providing additional information for
49operation.  The only bit that is currently defined is \fBTCL_EXACT\fR.
50.AP int *indexPtr out
51The index of the string in \fItablePtr\fR that matches the value of
52\fIobjPtr\fR is returned here.
53.BE
54
55.SH DESCRIPTION
56.PP
57This procedure provides an efficient way for looking up keywords,
58switch names, option names, and similar things where the value of
59an object must be one of a predefined set of values.
60\fIObjPtr\fR is compared against each of
61the strings in \fItablePtr\fR to find a match.  A match occurs if
62\fIobjPtr\fR's string value is identical to one of the strings in
63\fItablePtr\fR, or if it is a non-empty unique abbreviation
64for exactly one of the strings in \fItablePtr\fR and the
65\fBTCL_EXACT\fR flag was not specified; in either case
66the index of the matching entry is stored at \fI*indexPtr\fR
67and \fBTCL_OK\fR is returned.
68.PP
69If there is no matching entry,
70\fBTCL_ERROR\fR is returned and an error message is left in \fIinterp\fR's
71result if \fIinterp\fR is not NULL.  \fIMsg\fR is included in the
72error message to indicate what was being looked up.  For example,
73if \fImsg\fR is \fBoption\fR the error message will have a form like
74.QW "\fBbad option \N'34'firt\N'34': must be first, second, or third\fR" .
75.PP
76If \fBTcl_GetIndexFromObj\fR completes successfully it modifies the
77internal representation of \fIobjPtr\fR to hold the address of
78the table and the index of the matching entry.  If \fBTcl_GetIndexFromObj\fR
79is invoked again with the same \fIobjPtr\fR and \fItablePtr\fR
80arguments (e.g. during a reinvocation of a Tcl command), it returns
81the matching index immediately without having to redo the lookup
82operation.  Note: \fBTcl_GetIndexFromObj\fR assumes that the entries
83in \fItablePtr\fR are static: they must not change between
84invocations.  If the value of \fIobjPtr\fR is the empty string,
85\fBTcl_GetIndexFromObj\fR will treat it as a non-matching value
86and return \fBTCL_ERROR\fR.
87.PP
88\fBTcl_GetIndexFromObjStruct\fR works just like
89\fBTcl_GetIndexFromObj\fR, except that instead of treating
90\fItablePtr\fR as an array of string pointers, it treats it as a
91pointer to the first string in a series of strings that have
92\fIoffset\fR bytes between them (i.e. that there is a pointer to the
93first array of characters at \fItablePtr\fR, a pointer to the second
94array of characters at \fItablePtr\fR+\fIoffset\fR bytes, etc.)
95This is particularly useful when processing things like
96\fBTk_ConfigurationSpec\fR, whose string keys are in the same place in
97each of several array elements.
98
99.SH "SEE ALSO"
100Tcl_WrongNumArgs
101
102.SH KEYWORDS
103index, object, table lookup
Note: See TracBrowser for help on using the repository browser.