OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / 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 .TH Tcl_GetIndexFromObj 3 8.1 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_GetIndexFromObj, Tcl_GetIndexFromObjStruct \- lookup string in table of keywords
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 int
17 \fBTcl_GetIndexFromObj\fR(\fIinterp, objPtr, tablePtr, msg, flags,
18 indexPtr\fR)
19 .sp
20 int
21 \fBTcl_GetIndexFromObjStruct\fR(\fIinterp, objPtr, structTablePtr, offset,
22                           msg, flags, indexPtr\fR)
23 .SH ARGUMENTS
24 .AS "const char" *structTablePtr in/out
25 .AP Tcl_Interp *interp in
26 Interpreter to use for error reporting; if NULL, then no message is
27 provided on errors.
28 .AP Tcl_Obj *objPtr in/out
29 The string value of this value is used to search through \fItablePtr\fR.
30 The internal representation is modified to hold the index of the matching
31 table entry.
32 .AP "const char *const" *tablePtr in
33 An array of null-terminated strings.  The end of the array is marked
34 by a NULL string pointer.
35 Note that references to the \fItablePtr\fR may be retained in the
36 internal representation of \fIobjPtr\fR, so this should represent the
37 address of a statically-allocated array.
38 .AP "const void" *structTablePtr in
39 An array of arbitrary type, typically some \fBstruct\fR type.
40 The first member of the structure must be a null-terminated string.
41 The size of the structure is given by \fIoffset\fR.
42 Note that references to the \fIstructTablePtr\fR may be retained in the
43 internal representation of \fIobjPtr\fR, so this should represent the
44 address of a statically-allocated array of structures.
45 .AP int offset in
46 The offset to add to structTablePtr to get to the next entry.
47 The end of the array is marked by a NULL string pointer.
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 .SH DESCRIPTION
59 .PP
60 These procedures provide an efficient way for looking up keywords,
61 switch names, option names, and similar things where the literal value of
62 a Tcl value must be chosen from a predefined set.
63 \fBTcl_GetIndexFromObj\fR compares \fIobjPtr\fR against each of
64 the strings in \fItablePtr\fR to find a match.  A match occurs if
65 \fIobjPtr\fR's string value is identical to one of the strings in
66 \fItablePtr\fR, or if it is a non-empty unique abbreviation
67 for exactly one of the strings in \fItablePtr\fR and the
68 \fBTCL_EXACT\fR flag was not specified; in either case
69 the index of the matching entry is stored at \fI*indexPtr\fR
70 and \fBTCL_OK\fR is returned.
71 .PP
72 If there is no matching entry,
73 \fBTCL_ERROR\fR is returned and an error message is left in \fIinterp\fR's
74 result if \fIinterp\fR is not NULL.  \fIMsg\fR is included in the
75 error message to indicate what was being looked up.  For example,
76 if \fImsg\fR is \fBoption\fR the error message will have a form like
77 .QW "\fBbad option \N'34'firt\N'34': must be first, second, or third\fR" .
78 .PP
79 If \fBTcl_GetIndexFromObj\fR completes successfully it modifies the
80 internal representation of \fIobjPtr\fR to hold the address of
81 the table and the index of the matching entry.  If \fBTcl_GetIndexFromObj\fR
82 is invoked again with the same \fIobjPtr\fR and \fItablePtr\fR
83 arguments (e.g. during a reinvocation of a Tcl command), it returns
84 the matching index immediately without having to redo the lookup
85 operation.  Note: \fBTcl_GetIndexFromObj\fR assumes that the entries
86 in \fItablePtr\fR are static: they must not change between
87 invocations.  If the value of \fIobjPtr\fR is the empty string,
88 \fBTcl_GetIndexFromObj\fR will treat it as a non-matching value
89 and return \fBTCL_ERROR\fR.
90 .PP
91 \fBTcl_GetIndexFromObjStruct\fR works just like
92 \fBTcl_GetIndexFromObj\fR, except that instead of treating
93 \fItablePtr\fR as an array of string pointers, it treats it as a
94 pointer to the first string in a series of strings that have
95 \fIoffset\fR bytes between them (i.e. that there is a pointer to the
96 first array of characters at \fItablePtr\fR, a pointer to the second
97 array of characters at \fItablePtr\fR+\fIoffset\fR bytes, etc.)
98 This is particularly useful when processing things like
99 \fBTk_ConfigurationSpec\fR, whose string keys are in the same place in
100 each of several array elements.
101 .SH "SEE ALSO"
102 prefix(n), Tcl_WrongNumArgs(3)
103 .SH KEYWORDS
104 index, option, value, table lookup