OSDN Git Service

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