1Tcl_GetIndexFromObj(3)      Tcl Library Procedures      Tcl_GetIndexFromObj(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_GetIndexFromObj, Tcl_GetIndexFromObjStruct - lookup string in table
9       of keywords
10

SYNOPSIS

12       #include <tcl.h>
13
14       int
15       Tcl_GetIndexFromObj(interp, objPtr, tablePtr, msg, flags,
16       indexPtr)
17
18       int                                                                     │
19       Tcl_GetIndexFromObjStruct(interp, objPtr, structTablePtr, offset,
20       msg, flags, indexPtr)                                                   │
21

ARGUMENTS

23       Tcl_Interp   *interp      (in)      Interpreter  to   use   for   error
24                                           reporting; if NULL, then no message
25                                           is provided on errors.
26
27       Tcl_Obj      *objPtr      (in/out)  The string value of this object  is
28                                           used  to  search  through tablePtr.
29                                           The internal representation is mod‐
30                                           ified  to  hold  the  index  of the
31                                           matching table entry.
32
33       CONST char   **tablePtr   (in)      An   array    of    null-terminated
34                                           strings.   The  end of the array is
35                                           marked by a NULL string pointer.
36
37       CONST VOID   *structTablePtr(in)    An array of arbitrary  type,  typi‐
38                                           cally  some struct type.  The first
39                                           member of the structure must  be  a
40                                           null-terminated  string.   The size
41                                           of the structure is given  by  off‐
42                                           set.                                │
43
44       int          offset       (in)                                          │
45                                           The offset to add to structTablePtr │
46                                           to get to the next entry.  The  end │
47                                           of  the  array  is marked by a NULL │
48                                           string pointer.
49
50       CONST char   *msg         (in)      Null-terminated  string  describing
51                                           what  is  being  looked up, such as
52                                           option.  This string is included in
53                                           error messages.
54
55       int          flags        (in)      OR-ed combination of bits providing
56                                           additional information  for  opera‐
57                                           tion.   The  only  bit that is cur‐
58                                           rently defined is TCL_EXACT.
59
60       int          *indexPtr    (out)     The index of the string in tablePtr
61                                           that matches the value of objPtr is
62                                           returned here.
63_________________________________________________________________
64
65

DESCRIPTION

67       This procedure provides an  efficient  way  for  looking  up  keywords,
68       switch  names,  option  names, and similar things where the value of an
69       object must be one of a predefined set of values.  ObjPtr  is  compared
70       against  each  of  the  strings  in  tablePtr to find a match.  A match
71       occurs if objPtr's string value is identical to one of the  strings  in
72       tablePtr,  or  if it is a non-empty unique abbreviation for exactly one
73       of the strings in tablePtr and the TCL_EXACT flag was not specified; in
74       either  case the index of the matching entry is stored at *indexPtr and
75       TCL_OK is returned.
76
77       If there is no matching entry, TCL_ERROR is returned and an error  mes‐
78       sage  is left in interp's result if interp isn't NULL.  Msg is included
79       in the error message to indicate what was being looked up.   For  exam‐
80       ple,  if  msg  is  option  the  error message will have a form like bad
81       option "firt": must be first, second, or third.
82
83       If Tcl_GetIndexFromObj completes successfully it modifies the  internal
84       representation of objPtr to hold the address of the table and the index
85       of the matching entry.  If Tcl_GetIndexFromObj is  invoked  again  with
86       the same objPtr and tablePtr arguments (e.g. during a reinvocation of a
87       Tcl command), it returns the matching index immediately without  having
88       to  redo  the lookup operation.  Note: Tcl_GetIndexFromObj assumes that
89       the entries in tablePtr are static: they must not change between  invo‐
90       cations.   If the value of objPtr is the empty string, Tcl_GetIndexFro‐
91       mObj will treat it as a non-matching value and return TCL_ERROR.        │
92
93       Tcl_GetIndexFromObjStruct works just like  Tcl_GetIndexFromObj,  except │
94       that  instead  of  treating tablePtr as an array of string pointers, it │
95       treats it as the first in a series of string ptrs that are spaced apart │
96       by  offset  bytes.  This  is particularly useful when processing things │
97       like Tk_ConfigurationSpec, whose string keys are in the same  place  in │
98       each of several array elements.
99
100

SEE ALSO

102       Tcl_WrongNumArgs
103
104

KEYWORDS

106       index, object, table lookup
107
108
109
110Tcl                                   8.1               Tcl_GetIndexFromObj(3)
Impressum