diff options
Diffstat (limited to 'generic/tkOption.c')
-rw-r--r-- | generic/tkOption.c | 766 |
1 files changed, 371 insertions, 395 deletions
diff --git a/generic/tkOption.c b/generic/tkOption.c index 7f1b007..a0080fc 100644 --- a/generic/tkOption.c +++ b/generic/tkOption.c @@ -1,59 +1,58 @@ -/* +/* * tkOption.c -- * - * This module contains procedures to manage the option - * database, which allows various strings to be associated - * with windows either by name or by class or both. + * This module contains functions to manage the option database, which + * allows various strings to be associated with windows either by name or + * by class or both. * * Copyright (c) 1990-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkOption.c,v 1.15 2002/08/05 04:30:40 dgp Exp $ + * RCS: @(#) $Id: tkOption.c,v 1.16 2005/08/10 22:02:22 dkf Exp $ */ #include "tkPort.h" #include "tkInt.h" /* - * The option database is stored as one tree for each main window. - * Each name or class field in an option is associated with a node or - * leaf of the tree. For example, the options "x.y.z" and "x.y*a" - * each correspond to three nodes in the tree; they share the nodes - * "x" and "x.y", but have different leaf nodes. One of the following - * structures exists for each node or leaf in the option tree. It is - * actually stored as part of the parent node, and describes a particular - * child of the parent. - * - * The structure of the option db tree is a little confusing. There are - * four different kinds of nodes in the tree: + * The option database is stored as one tree for each main window. Each name + * or class field in an option is associated with a node or leaf of the tree. + * For example, the options "x.y.z" and "x.y*a" each correspond to three nodes + * in the tree; they share the nodes "x" and "x.y", but have different leaf + * nodes. One of the following structures exists for each node or leaf in the + * option tree. It is actually stored as part of the parent node, and + * describes a particular child of the parent. + * + * The structure of the option db tree is a little confusing. There are four + * different kinds of nodes in the tree: * interior class nodes * interior name nodes * leaf class nodes * leaf name nodes * * All interior nodes refer to _window_ classes and names; all leaf nodes - * refer to _option_ classes and names. When looking for a particular option, + * refer to _option_ classes and names. When looking for a particular option, * therefore, you must compare interior node values to corresponding window * values, and compare leaf node values to corresponding option values. * * The tree is actually stored in a collection of arrays; there is one each - * combination of WILDCARD/EXACT and CLASS/NAME and NODE/LEAF. The NODE arrays + * combination of WILDCARD/EXACT and CLASS/NAME and NODE/LEAF. The NODE arrays * contain the interior nodes of the tree; each element has a pointer to an - * array of elements which are the leaves of the tree. The LEAF arrays, rather + * array of elements which are the leaves of the tree. The LEAF arrays, rather * than holding the leaves of the tree, hold a cached subset of the option * database, consisting of the values of all defined options for a single * window, and some additional information about each ancestor of the window - * (since some options may be inherited from a parent), all the way back to the - * root window. + * (since some options may be inherited from a parent), all the way back to + * the root window. * * Each time a call is made to Tk_GetOption, Tk will attempt to use the cached - * information to satisfy the lookup. If the call is for a window other than + * information to satisfy the lookup. If the call is for a window other than * that for which options are currently cached, the portion of the cache that - * contains information for common ancestors of the two windows is retained and - * the remainder is discarded and rebuilt with new information for the new + * contains information for common ancestors of the two windows is retained + * and the remainder is discarded and rebuilt with new information for the new * window. */ @@ -61,35 +60,34 @@ typedef struct Element { Tk_Uid nameUid; /* Name or class from one element of * an option spec. */ union { - struct ElArray *arrayPtr; /* If this is an intermediate node, - * a pointer to a structure describing + struct ElArray *arrayPtr; /* If this is an intermediate node, a + * pointer to a structure describing * the remaining elements of all - * options whose prefixes are the - * same up through this element. */ + * options whose prefixes are the same + * up through this element. */ Tk_Uid valueUid; /* For leaf nodes, this is the string * value of the option. */ } child; int priority; /* Used to select among matching - * options. Includes both the - * priority level and a serial #. - * Greater value means higher - * priority. Irrelevant except in - * leaf nodes. */ - int flags; /* OR-ed combination of bits. See + * options. Includes both the priority + * level and a serial #. Greater value + * means higher priority. Irrelevant + * except in leaf nodes. */ + int flags; /* OR-ed combination of bits. See * below for values. */ } Element; /* * Flags in Element structures: * - * CLASS - Non-zero means this element refers to a class, - * Zero means this element refers to a name. - * NODE - Zero means this is a leaf element (the child - * field is a value, not a pointer to another node). - * One means this is a node element. - * WILDCARD - Non-zero means this there was a star in the - * original specification just before this element. - * Zero means there was a dot. + * CLASS - Non-zero means this element refers to a class, zero + * means this element refers to a name. + * NODE - Zero means this is a leaf element (the child field is + * a value, not a pointer to another node). One means + * this is a node element. + * WILDCARD - Non-zero means this there was a star in the original + * specification just before this element. Zero means + * there was a dot. */ #define TYPE_MASK 0x7 @@ -108,25 +106,22 @@ typedef struct Element { #define WILDCARD_NODE_CLASS 0x7 /* - * The following structure is used to manage a dynamic array of - * Elements. These structures are used for two purposes: to store - * the contents of a node in the option tree, and for the option - * stacks described below. + * The following structure is used to manage a dynamic array of Elements. + * These structures are used for two purposes: to store the contents of a node + * in the option tree, and for the option stacks described below. */ typedef struct ElArray { - int arraySize; /* Number of elements actually - * allocated in the "els" array. */ - int numUsed; /* Number of elements currently in - * use out of els. */ + int arraySize; /* Number of elements actually allocated in + * the "els" array. */ + int numUsed; /* Number of elements currently in use out of + * els. */ Element *nextToUse; /* Pointer to &els[numUsed]. */ - Element els[1]; /* Array of structures describing - * children of this node. The - * array will actually contain enough - * elements for all of the children - * (and even a few extras, perhaps). - * This must be the last field in - * the structure. */ + Element els[1]; /* Array of structures describing children of + * this node. The array will actually contain + * enough elements for all of the children + * (and even a few extras, perhaps). This must + * be the last field in the structure. */ } ElArray; #define EL_ARRAY_SIZE(numEls) ((unsigned) (sizeof(ElArray) \ @@ -135,54 +130,53 @@ typedef struct ElArray { /* * In addition to the option tree, which is a relatively static structure, - * there are eight additional structures called "stacks", which are used - * to speed up queries into the option database. The stack structures - * are designed for the situation where an individual widget makes repeated - * requests for its particular options. The requests differ only in - * their last name/class, so during the first request we extract all - * the options pertaining to the particular widget and save them in a - * stack-like cache; subsequent requests for the same widget can search - * the cache relatively quickly. In fact, the cache is a hierarchical - * one, storing a list of relevant options for this widget and all of - * its ancestors up to the application root; hence the name "stack". - * - * Each of the eight stacks consists of an array of Elements, ordered in - * terms of levels in the window hierarchy. All the elements relevant - * for the top-level widget appear first in the array, followed by all - * those from the next-level widget on the path to the current widget, - * etc. down to those for the current widget. - * - * Cached information is divided into eight stacks according to the - * CLASS, NODE, and WILDCARD flags. Leaf and non-leaf information is - * kept separate to speed up individual probes (non-leaf information is - * only relevant when building the stacks, but isn't relevant when - * making probes; similarly, only non-leaf information is relevant - * when the stacks are being extended to the next widget down in the - * widget hierarchy). Wildcard elements are handled separately from - * "exact" elements because once they appear at a particular level in - * the stack they remain active for all deeper levels; exact elements - * are only relevant at a particular level. For example, when searching - * for options relevant in a particular window, the entire wildcard - * stacks get checked, but only the portions of the exact stacks that - * pertain to the window's parent. Lastly, name and class stacks are - * kept separate because different search keys are used when searching - * them; keeping them separate speeds up the searches. + * there are eight additional structures called "stacks", which are used to + * speed up queries into the option database. The stack structures are + * designed for the situation where an individual widget makes repeated + * requests for its particular options. The requests differ only in their last + * name/class, so during the first request we extract all the options + * pertaining to the particular widget and save them in a stack-like cache; + * subsequent requests for the same widget can search the cache relatively + * quickly. In fact, the cache is a hierarchical one, storing a list of + * relevant options for this widget and all of its ancestors up to the + * application root; hence the name "stack". + * + * Each of the eight stacks consists of an array of Elements, ordered in terms + * of levels in the window hierarchy. All the elements relevant for the + * top-level widget appear first in the array, followed by all those from the + * next-level widget on the path to the current widget, etc. down to those for + * the current widget. + * + * Cached information is divided into eight stacks according to the CLASS, + * NODE, and WILDCARD flags. Leaf and non-leaf information is kept separate to + * speed up individual probes (non-leaf information is only relevant when + * building the stacks, but isn't relevant when making probes; similarly, only + * non-leaf information is relevant when the stacks are being extended to the + * next widget down in the widget hierarchy). Wildcard elements are handled + * separately from "exact" elements because once they appear at a particular + * level in the stack they remain active for all deeper levels; exact elements + * are only relevant at a particular level. For example, when searching for + * options relevant in a particular window, the entire wildcard stacks get + * checked, but only the portions of the exact stacks that pertain to the + * window's parent. Lastly, name and class stacks are kept separate because + * different search keys are used when searching them; keeping them separate + * speeds up the searches. */ #define NUM_STACKS 8 /* - * One of the following structures is used to keep track of each - * level in the stacks. + * One of the following structures is used to keep track of each level in the + * stacks. */ typedef struct StackLevel { TkWindow *winPtr; /* Window corresponding to this stack * level. */ - int bases[NUM_STACKS]; /* For each stack, index of first - * element on stack corresponding to - * this level (used to restore "numUsed" - * fields when popping out of a level. */ + int bases[NUM_STACKS]; /* For each stack, index of first element on + * stack corresponding to this level (used to + * restore "numUsed" fields when popping out + * of a level. */ } StackLevel; typedef struct ThreadSpecificData { @@ -190,59 +184,51 @@ typedef struct ThreadSpecificData { * for the current thread needs to be * initialized. */ ElArray *stacks[NUM_STACKS]; - TkWindow *cachedWindow; - /* Lowest-level window currently - * loaded in stacks at present. - * NULL means stacks have never - * been used, or have been - * invalidated because of a change - * to the database. */ + TkWindow *cachedWindow; /* Lowest-level window currently loaded in + * stacks at present. NULL means stacks have + * never been used, or have been invalidated + * because of a change to the database. */ /* - * Information about all of the stack levels that are currently - * active. This array grows dynamically to become as large as needed. + * Information about all of the stack levels that are currently active. + * This array grows dynamically to become as large as needed. */ StackLevel *levels; /* Array describing current stack. */ int numLevels; /* Total space allocated. */ - int curLevel; /* Highest level currently in use. Note: - * curLevel is never 0! (I don't remember - * why anymore...) */ - /* - * The variable below is a serial number for all options entered into - * the database so far. It increments on each addition to the option - * database. It is used in computing option priorities, so that the - * most recent entry wins when choosing between options at the same - * priority level. - */ - - int serial; - Element defaultMatch; /* Special "no match" Element to use as + int curLevel; /* Highest level currently in use. Note: + * curLevel is never 0! (I don't remember why + * anymore...) */ + int serial; /* A serial number for all options entered + * into the database so far. It increments on + * each addition to the option database. It is + * used in computing option priorities, so + * that the most recent entry wins when + * choosing between options at the same + * priority level. + */ + Element defaultMatch; /* Special "no match" Element to use as * default for searches.*/ } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; /* - * Forward declarations for procedures defined in this file: + * Forward declarations for functions defined in this file: */ -static int AddFromString _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Window tkwin, char *string, int priority)); -static void ClearOptionTree _ANSI_ARGS_((ElArray *arrayPtr)); -static ElArray * ExtendArray _ANSI_ARGS_((ElArray *arrayPtr, - Element *elPtr)); -static void ExtendStacks _ANSI_ARGS_((ElArray *arrayPtr, - int leaf)); -static int GetDefaultOptions _ANSI_ARGS_((Tcl_Interp *interp, - TkWindow *winPtr)); -static ElArray * NewArray _ANSI_ARGS_((int numEls)); -static void OptionThreadExitProc _ANSI_ARGS_(( - ClientData clientData)); -static void OptionInit _ANSI_ARGS_((TkMainInfo *mainPtr)); -static int ParsePriority _ANSI_ARGS_((Tcl_Interp *interp, - char *string)); -static int ReadOptionFile _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Window tkwin, char *fileName, int priority)); -static void SetupStacks _ANSI_ARGS_((TkWindow *winPtr, int leaf)); +static int AddFromString(Tcl_Interp *interp, Tk_Window tkwin, + char *string, int priority); +static void ClearOptionTree(ElArray *arrayPtr); +static ElArray * ExtendArray(ElArray *arrayPtr, Element *elPtr); +static void ExtendStacks(ElArray *arrayPtr, int leaf); +static int GetDefaultOptions(Tcl_Interp *interp, + TkWindow *winPtr); +static ElArray * NewArray(int numEls); +static void OptionThreadExitProc(ClientData clientData); +static void OptionInit(TkMainInfo *mainPtr); +static int ParsePriority(Tcl_Interp *interp, char *string); +static int ReadOptionFile(Tcl_Interp *interp, Tk_Window tkwin, + char *fileName, int priority); +static void SetupStacks(TkWindow *winPtr, int leaf); /* *-------------------------------------------------------------- @@ -262,14 +248,14 @@ static void SetupStacks _ANSI_ARGS_((TkWindow *winPtr, int leaf)); void Tk_AddOption(tkwin, name, value, priority) - Tk_Window tkwin; /* Window token; option will be associated + Tk_Window tkwin; /* Window token; option will be associated * with main window for this window. */ CONST char *name; /* Multi-element name of option. */ CONST char *value; /* String value for option. */ - int priority; /* Overall priority level to use for - * this option, such as TK_USER_DEFAULT_PRIO - * or TK_INTERACTIVE_PRIO. Must be between - * 0 and TK_MAX_PRIO. */ + int priority; /* Overall priority level to use for this + * option, such as TK_USER_DEFAULT_PRIO or + * TK_INTERACTIVE_PRIO. Must be between 0 and + * TK_MAX_PRIO. */ { TkWindow *winPtr = ((TkWindow *) tkwin)->mainPtr->winPtr; register ElArray **arrayPtrPtr; @@ -280,18 +266,17 @@ Tk_AddOption(tkwin, name, value, priority) int count, firstField, length; #define TMP_SIZE 100 char tmp[TMP_SIZE+1]; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (winPtr->mainPtr->optionRootPtr == NULL) { OptionInit(winPtr->mainPtr); } - tsdPtr->cachedWindow = NULL; /* Invalidate the cache. */ + tsdPtr->cachedWindow = NULL;/* Invalidate the cache. */ /* - * Compute the priority for the new element, including both the - * overall level and the serial number (to disambiguate with the - * level). + * Compute the priority for the new element, including both the overall + * level and the serial number (to disambiguate with the level). */ if (priority < 0) { @@ -309,11 +294,10 @@ Tk_AddOption(tkwin, name, value, priority) arrayPtrPtr = &(((TkWindow *) tkwin)->mainPtr->optionRootPtr); p = name; for (firstField = 1; ; firstField = 0) { - /* - * Scan the next field from the name and convert it to a Tk_Uid. - * Must copy the field before calling Tk_Uid, so that a terminating - * NULL may be added without modifying the source string. + * Scan the next field from the name and convert it to a Tk_Uid. Must + * copy the field before calling Tk_Uid, so that a terminating NULL + * may be added without modifying the source string. */ if (*p == '*') { @@ -338,12 +322,10 @@ Tk_AddOption(tkwin, name, value, priority) } if (*p != 0) { - /* - * New element will be a node. If this option can't possibly - * apply to this main window, then just skip it. Otherwise, - * add it to the parent, if it isn't already there, and descend - * into it. + * New element will be a node. If this option can't possibly apply + * to this main window, then just skip it. Otherwise, add it to + * the parent, if it isn't already there, and descend into it. */ newEl.flags |= NODE; @@ -370,11 +352,10 @@ Tk_AddOption(tkwin, name, value, priority) p++; } } else { - /* - * New element is a leaf. Add it to the parent, if it isn't - * already there. If it exists already, keep whichever value - * has highest priority. + * New element is a leaf. Add it to the parent, if it isn't + * already there. If it exists already, keep whichever value has + * highest priority. */ newEl.child.valueUid = Tk_GetUid(value); @@ -405,27 +386,26 @@ Tk_AddOption(tkwin, name, value, priority) * Retrieve an option from the option database. * * Results: - * The return value is the value specified in the option - * database for the given name and class on the given - * window. If there is nothing specified in the database - * for that option, then NULL is returned. + * The return value is the value specified in the option database for the + * given name and class on the given window. If there is nothing + * specified in the database for that option, then NULL is returned. * * Side effects: - * The internal caches used to speed up option mapping - * may be modified, if this tkwin is different from the - * last tkwin used for option retrieval. + * The internal caches used to speed up option mapping may be modified, + * if this tkwin is different from the last tkwin used for option + * retrieval. * *-------------------------------------------------------------- */ Tk_Uid Tk_GetOption(tkwin, name, className) - Tk_Window tkwin; /* Token for window that option is - * associated with. */ + Tk_Window tkwin; /* Token for window that option is associated + * with. */ CONST char *name; /* Name of option. */ - CONST char *className; /* Class of option. NULL means there - * is no class for this option: just - * check for name. */ + CONST char *className; /* Class of option. NULL means there is no + * class for this option: just check for + * name. */ { Tk_Uid nameId, classId = NULL; char *masqName; @@ -433,12 +413,12 @@ Tk_GetOption(tkwin, name, className) register int count; StackLevel *levelPtr; int stackDepth[NUM_STACKS]; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* - * Note: no need to call OptionInit here: it will be done by - * the SetupStacks call below (squeeze out those nanoseconds). + * Note: no need to call OptionInit here: it will be done by the + * SetupStacks call below (squeeze out those nanoseconds). */ if (tkwin != (Tk_Window) tsdPtr->cachedWindow) { @@ -448,32 +428,33 @@ Tk_GetOption(tkwin, name, className) /* * Get a default "best" match. */ - + bestPtr = &tsdPtr->defaultMatch; /* * For megawidget support, we want to have some widget options masquerade - * as options for other widgets. For example, a combobox has a button in + * as options for other widgets. For example, a combobox has a button in * it; this button ought to pick up the *Button.background, etc., options. * But because the class of the widget is Combobox, our normal search * won't get that option. * * To work around this, the option name field syntax was extended to allow * for a "." in the name; if this character occurs in the name, then it - * indicates that this name contains a new window class and an option name, - * ie, "Button.foreground". If we see this form in the name field, we - * query the option database directly (since the option stacks will not + * indicates that this name contains a new window class and an option + * name, ie, "Button.foreground". If we see this form in the name field, + * we query the option database directly (since the option stacks will not * have the information we need). */ masqName = strchr(name, (int)'.'); if (masqName != NULL) { /* - * This option is masquerading with a different window class. - * Search the stack to the depth it was before the current window's + * This option is masquerading with a different window class. Search + * the stack to the depth it was before the current window's * information was pushed (the value for which is stored in the bases * field). */ + levelPtr = &tsdPtr->levels[tsdPtr->curLevel]; nameId = Tk_GetUid(masqName+1); for (count = 0; count < NUM_STACKS; count++) { @@ -481,9 +462,10 @@ Tk_GetOption(tkwin, name, className) } } else { /* - * No option masquerading here. Just use the current level to get the + * No option masquerading here. Just use the current level to get the * stack depths. */ + nameId = Tk_GetUid(name); for (count = 0; count < NUM_STACKS; count++) { stackDepth[count] = tsdPtr->stacks[count]->numUsed; @@ -530,11 +512,11 @@ Tk_GetOption(tkwin, name, className) } } } - + /* - * If this option was masquerading with a different window class, - * probe the option database now. Note that this will be inefficient - * if the option database is densely populated, or if the widget has many + * If this option was masquerading with a different window class, probe + * the option database now. Note that this will be inefficient if the + * option database is densely populated, or if the widget has many * masquerading options. */ @@ -543,43 +525,42 @@ Tk_GetOption(tkwin, name, className) Tk_Uid nodeId, winClassId, winNameId; unsigned int classNameLength; register Element *nodePtr, *leafPtr; - static int searchOrder[] = { EXACT_NODE_NAME, - WILDCARD_NODE_NAME, - EXACT_NODE_CLASS, - WILDCARD_NODE_CLASS, - -1 }; + static int searchOrder[] = { + EXACT_NODE_NAME, WILDCARD_NODE_NAME, EXACT_NODE_CLASS, + WILDCARD_NODE_CLASS, -1 + }; int *currentPtr, currentStack, leafCount; - + /* * Extract the masquerade class name from the name field. */ - + classNameLength = (unsigned int)(masqName - name); - masqClass = (char *)ckalloc(classNameLength + 1); + masqClass = (char *) ckalloc(classNameLength + 1); strncpy(masqClass, name, classNameLength); masqClass[classNameLength] = '\0'; - - winClassId = Tk_GetUid(masqClass); + + winClassId = Tk_GetUid(masqClass); ckfree(masqClass); - winNameId = ((TkWindow *)tkwin)->nameUid; + winNameId = ((TkWindow *)tkwin)->nameUid; levelPtr = &tsdPtr->levels[tsdPtr->curLevel]; for (currentPtr = searchOrder; *currentPtr != -1; currentPtr++) { currentStack = *currentPtr; - nodePtr = tsdPtr->stacks[currentStack]->els; - count = levelPtr->bases[currentStack]; + nodePtr = tsdPtr->stacks[currentStack]->els; + count = levelPtr->bases[currentStack]; /* - * For wildcard stacks, check all entries; for non-wildcard + * For wildcard stacks, check all entries; for non-wildcard * stacks, only check things that matched in the parent. */ - + if (!(currentStack & WILDCARD)) { nodePtr += levelPtr[-1].bases[currentStack]; count -= levelPtr[-1].bases[currentStack]; } - + if (currentStack && CLASS) { nodeId = winClassId; } else { @@ -588,8 +569,8 @@ Tk_GetOption(tkwin, name, className) for ( ; count > 0; nodePtr++, count--) { if (nodePtr->nameUid == nodeId) { - leafPtr = nodePtr->child.arrayPtr->els; - leafCount = nodePtr->child.arrayPtr->numUsed; + leafPtr = nodePtr->child.arrayPtr->els; + leafCount = nodePtr->child.arrayPtr->numUsed; for ( ; leafCount > 0; leafPtr++, leafCount--) { if (leafPtr->flags & CLASS && className != NULL) { if (leafPtr->nameUid == classId && @@ -607,7 +588,7 @@ Tk_GetOption(tkwin, name, className) } } } - + return bestPtr->child.valueUid; } @@ -616,8 +597,8 @@ Tk_GetOption(tkwin, name, className) * * Tk_OptionObjCmd -- * - * This procedure is invoked to process the "option" Tcl command. - * See the user documentation for details on what it does. + * This function is invoked to process the "option" Tcl command. See the + * user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -630,15 +611,14 @@ Tk_GetOption(tkwin, name, className) int Tk_OptionObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Main window associated with - * interpreter. */ + ClientData clientData; /* Main window associated with interpreter. */ Tcl_Interp *interp; /* Current interpreter. */ int objc; /* Number of Tcl_Obj arguments. */ Tcl_Obj *CONST objv[]; /* Tcl_Obj arguments. */ { Tk_Window tkwin = (Tk_Window) clientData; int index, result; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); static CONST char *optionCmds[] = { @@ -659,85 +639,85 @@ Tk_OptionObjCmd(clientData, interp, objc, objv) if (result != TCL_OK) { return result; } - + result = TCL_OK; switch ((enum optionVals) index) { - case OPTION_ADD: { - int priority; - if ((objc != 4) && (objc != 5)) { - Tcl_WrongNumArgs(interp, 2, objv, "pattern value ?priority?"); + case OPTION_ADD: { + int priority; + if ((objc != 4) && (objc != 5)) { + Tcl_WrongNumArgs(interp, 2, objv, "pattern value ?priority?"); + return TCL_ERROR; + } + + if (objc == 4) { + priority = TK_INTERACTIVE_PRIO; + } else { + priority = ParsePriority(interp, Tcl_GetString(objv[4])); + if (priority < 0) { return TCL_ERROR; } + } + Tk_AddOption(tkwin, Tcl_GetString(objv[2]), Tcl_GetString(objv[3]), + priority); + break; + } - if (objc == 4) { - priority = TK_INTERACTIVE_PRIO; - } else { - priority = ParsePriority(interp, Tcl_GetString(objv[4])); - if (priority < 0) { - return TCL_ERROR; - } - } - Tk_AddOption(tkwin, Tcl_GetString(objv[2]), - Tcl_GetString(objv[3]), priority); - break; + case OPTION_CLEAR: { + TkMainInfo *mainPtr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 2, objv, ""); + return TCL_ERROR; + } + mainPtr = ((TkWindow *) tkwin)->mainPtr; + if (mainPtr->optionRootPtr != NULL) { + ClearOptionTree(mainPtr->optionRootPtr); + mainPtr->optionRootPtr = NULL; } + tsdPtr->cachedWindow = NULL; + break; + } - case OPTION_CLEAR: { - TkMainInfo *mainPtr; + case OPTION_GET: { + Tk_Window window; + Tk_Uid value; - if (objc != 2) { - Tcl_WrongNumArgs(interp, 2, objv, ""); - return TCL_ERROR; - } - mainPtr = ((TkWindow *) tkwin)->mainPtr; - if (mainPtr->optionRootPtr != NULL) { - ClearOptionTree(mainPtr->optionRootPtr); - mainPtr->optionRootPtr = NULL; - } - tsdPtr->cachedWindow = NULL; - break; + if (objc != 5) { + Tcl_WrongNumArgs(interp, 2, objv, "window name class"); + return TCL_ERROR; + } + window = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); + if (window == NULL) { + return TCL_ERROR; } + value = Tk_GetOption(window, Tcl_GetString(objv[3]), + Tcl_GetString(objv[4])); + if (value != NULL) { + Tcl_SetResult(interp, (char *)value, TCL_STATIC); + } + break; + } - case OPTION_GET: { - Tk_Window window; - Tk_Uid value; - - if (objc != 5) { - Tcl_WrongNumArgs(interp, 2, objv, "window name class"); - return TCL_ERROR; - } - window = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); - if (window == NULL) { - return TCL_ERROR; - } - value = Tk_GetOption(window, Tcl_GetString(objv[3]), - Tcl_GetString(objv[4])); - if (value != NULL) { - Tcl_SetResult(interp, (char *)value, TCL_STATIC); - } - break; + case OPTION_READFILE: { + int priority; + + if ((objc != 3) && (objc != 4)) { + Tcl_WrongNumArgs(interp, 2, objv, "fileName ?priority?"); + return TCL_ERROR; } - case OPTION_READFILE: { - int priority; - - if ((objc != 3) && (objc != 4)) { - Tcl_WrongNumArgs(interp, 2, objv, "fileName ?priority?"); + if (objc == 4) { + priority = ParsePriority(interp, Tcl_GetString(objv[3])); + if (priority < 0) { return TCL_ERROR; } - - if (objc == 4) { - priority = ParsePriority(interp, Tcl_GetString(objv[3])); - if (priority < 0) { - return TCL_ERROR; - } - } else { - priority = TK_INTERACTIVE_PRIO; - } - result = ReadOptionFile(interp, tkwin, Tcl_GetString(objv[2]), - priority); - break; + } else { + priority = TK_INTERACTIVE_PRIO; } + result = ReadOptionFile(interp, tkwin, Tcl_GetString(objv[2]), + priority); + break; + } } return result; } @@ -747,16 +727,14 @@ Tk_OptionObjCmd(clientData, interp, objc, objv) * * TkOptionDeadWindow -- * - * This procedure is called whenever a window is deleted. - * It cleans up any option-related stuff associated with - * the window. + * This function is called whenever a window is deleted. It cleans up any + * option-related stuff associated with the window. * * Results: * None. * * Side effects: - * Option-related resources are freed. See code below - * for details. + * Option-related resources are freed. See code below for details. * *-------------------------------------------------------------- */ @@ -765,7 +743,7 @@ void TkOptionDeadWindow(winPtr) register TkWindow *winPtr; /* Window to be cleaned up. */ { - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* @@ -783,8 +761,7 @@ TkOptionDeadWindow(winPtr) } /* - * If this window was a main window, then delete its option - * database. + * If this window was a main window, then delete its option database. */ if ((winPtr->mainPtr != NULL) && (winPtr->mainPtr->winPtr == winPtr) @@ -799,10 +776,9 @@ TkOptionDeadWindow(winPtr) * * TkOptionClassChanged -- * - * This procedure is invoked when a window's class changes. If - * the window is on the option cache, this procedure flushes - * any information for the window, since the new class could change - * what is relevant. + * This function is invoked when a window's class changes. If the window + * is on the option cache, this function flushes any information for the + * window, since the new class could change what is relevant. * * Results: * None. @@ -819,7 +795,7 @@ TkOptionClassChanged(winPtr) { int i, j, *basePtr; ElArray *arrayPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (winPtr->optionLevel == -1) { @@ -827,8 +803,8 @@ TkOptionClassChanged(winPtr) } /* - * Find the lowest stack level that refers to this window, then - * flush all of the levels above the matching one. + * Find the lowest stack level that refers to this window, then flush all + * of the levels above the matching one. */ for (i = 1; i <= tsdPtr->curLevel; i++) { @@ -861,9 +837,9 @@ TkOptionClassChanged(winPtr) * Parse a string priority value. * * Results: - * The return value is the integer priority level corresponding - * to string, or -1 if string doesn't point to a valid priority level. - * In this case, an error message is left in the interp's result. + * The return value is the integer priority level corresponding to + * string, or -1 if string doesn't point to a valid priority level. In + * this case, an error message is left in the interp's result. * * Side effects: * None. @@ -915,17 +891,17 @@ ParsePriority(interp, string) * * AddFromString -- * - * Given a string containing lines in the standard format for - * X resources (see other documentation for details on what this - * is), parse the resource specifications and enter them as options - * for tkwin's main window. + * Given a string containing lines in the standard format for X resources + * (see other documentation for details on what this is), parse the + * resource specifications and enter them as options for tkwin's main + * window. * * Results: - * The return value is a standard Tcl return code. In the case of - * an error in parsing string, TCL_ERROR will be returned and an - * error message will be left in the interp's result. The memory at - * string is totally trashed by this procedure. If you care about - * its contents, make a copy before calling here. + * The return value is a standard Tcl return code. In the case of an + * error in parsing string, TCL_ERROR will be returned and an error + * message will be left in the interp's result. The memory at string is + * totally trashed by this function. If you care about its contents, make + * a copy before calling here. * * Side effects: * None. @@ -936,13 +912,13 @@ ParsePriority(interp, string) static int AddFromString(interp, tkwin, string, priority) Tcl_Interp *interp; /* Interpreter to use for reporting results. */ - Tk_Window tkwin; /* Token for window: options are entered - * for this window's main window. */ + Tk_Window tkwin; /* Token for window: options are entered for + * this window's main window. */ char *string; /* String containing option specifiers. */ - int priority; /* Priority level to use for options in - * this string, such as TK_USER_DEFAULT_PRIO - * or TK_INTERACTIVE_PRIO. Must be between - * 0 and TK_MAX_PRIO. */ + int priority; /* Priority level to use for options in this + * string, such as TK_USER_DEFAULT_PRIO or + * TK_INTERACTIVE_PRIO. Must be between 0 and + * TK_MAX_PRIO. */ { register char *src, *dst; char *name, *value; @@ -973,7 +949,7 @@ AddFromString(interp, tkwin, string, priority) src++; lineNum++; continue; - } + } if (*src == '\0') { break; } @@ -987,7 +963,7 @@ AddFromString(interp, tkwin, string, priority) while (*src != ':') { if ((*src == '\0') || (*src == '\n')) { char buf[32 + TCL_INTEGER_SPACE]; - + sprintf(buf, "missing colon on line %d", lineNum); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; @@ -1022,7 +998,7 @@ AddFromString(interp, tkwin, string, priority) } if (*src == '\0') { char buf[32 + TCL_INTEGER_SPACE]; - + sprintf(buf, "missing value on line %d", lineNum); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; @@ -1037,7 +1013,7 @@ AddFromString(interp, tkwin, string, priority) while (*src != '\n') { if (*src == '\0') { char buf[32 + TCL_INTEGER_SPACE]; - + sprintf(buf, "missing newline on line %d", lineNum); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; @@ -1069,13 +1045,13 @@ AddFromString(interp, tkwin, string, priority) * * ReadOptionFile -- * - * Read a file of options ("resources" in the old X terminology) - * and load them into the option database. + * Read a file of options ("resources" in the old X terminology) and load + * them into the option database. * * Results: - * The return value is a standard Tcl return code. In the case of - * an error in parsing string, TCL_ERROR will be returned and an - * error message will be left in the interp's result. + * The return value is a standard Tcl return code. In the case of an + * error in parsing string, TCL_ERROR will be returned and an error + * message will be left in the interp's result. * * Side effects: * None. @@ -1086,13 +1062,13 @@ AddFromString(interp, tkwin, string, priority) static int ReadOptionFile(interp, tkwin, fileName, priority) Tcl_Interp *interp; /* Interpreter to use for reporting results. */ - Tk_Window tkwin; /* Token for window: options are entered - * for this window's main window. */ + Tk_Window tkwin; /* Token for window: options are entered for + * this window's main window. */ char *fileName; /* Name of file containing options. */ - int priority; /* Priority level to use for options in - * this file, such as TK_USER_DEFAULT_PRIO - * or TK_INTERACTIVE_PRIO. Must be between - * 0 and TK_MAX_PRIO. */ + int priority; /* Priority level to use for options in this + * file, such as TK_USER_DEFAULT_PRIO or + * TK_INTERACTIVE_PRIO. Must be between 0 and + * TK_MAX_PRIO. */ { CONST char *realName; char *buffer; @@ -1103,13 +1079,13 @@ ReadOptionFile(interp, tkwin, fileName, priority) /* * Prevent file system access in a safe interpreter. */ - + if (Tcl_IsSafe(interp)) { Tcl_AppendResult(interp, "can't read options from a file in a", " safe interpreter", (char *) NULL); return TCL_ERROR; } - + realName = Tcl_TranslateFileName(interp, fileName, &newName); if (realName == NULL) { return TCL_ERROR; @@ -1124,10 +1100,10 @@ ReadOptionFile(interp, tkwin, fileName, priority) } /* - * Compute size of file by seeking to the end of the file. This will + * Compute size of file by seeking to the end of the file. This will * overallocate if we are performing CRLF translation. */ - + bufferSize = (int) Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_END); (void) Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_SET); @@ -1161,9 +1137,8 @@ ReadOptionFile(interp, tkwin, fileName, priority) * Create a new ElArray structure of a given size. * * Results: - * The return value is a pointer to a properly initialized - * element array with "numEls" space. The array is marked - * as having no active elements. + * The return value is a pointer to a properly initialized element array + * with "numEls" space. The array is marked as having no active elements. * * Side effects: * Memory is allocated. @@ -1189,12 +1164,11 @@ NewArray(numEls) * * ExtendArray -- * - * Add a new element to an array, extending the array if - * necessary. + * Add a new element to an array, extending the array if necessary. * * Results: - * The return value is a pointer to the new array, which - * will be different from arrayPtr if the array got expanded. + * The return value is a pointer to the new array, which will be + * different from arrayPtr if the array got expanded. * * Side effects: * Memory may be allocated or freed. @@ -1204,8 +1178,8 @@ NewArray(numEls) static ElArray * ExtendArray(arrayPtr, elPtr) - register ElArray *arrayPtr; /* Array to be extended. */ - register Element *elPtr; /* Element to be copied into array. */ + register ElArray *arrayPtr; /* Array to be extended. */ + register Element *elPtr; /* Element to be copied into array. */ { /* * If the current array has filled up, make it bigger. @@ -1235,40 +1209,40 @@ ExtendArray(arrayPtr, elPtr) * * SetupStacks -- * - * Arrange the stacks so that they cache all the option - * information for a particular window. + * Arrange the stacks so that they cache all the option information for a + * particular window. * * Results: * None. * * Side effects: - * The stacks are modified to hold information for tkwin - * and all its ancestors in the window hierarchy. + * The stacks are modified to hold information for tkwin and all its + * ancestors in the window hierarchy. * *-------------------------------------------------------------- */ static void SetupStacks(winPtr, leaf) - TkWindow *winPtr; /* Window for which information is to - * be cached. */ - int leaf; /* Non-zero means this is the leaf - * window being probed. Zero means this - * is an ancestor of the desired leaf. */ + TkWindow *winPtr; /* Window for which information is to be + * cached. */ + int leaf; /* Non-zero means this is the leaf window + * being probed. Zero means this is an + * ancestor of the desired leaf. */ { int level, i, *iPtr; register StackLevel *levelPtr; register ElArray *arrayPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* - * The following array defines the order in which the current - * stacks are searched to find matching entries to add to the - * stacks. Given the current priority-based scheme, the order - * below is no longer relevant; all that matters is that an - * element is on the list *somewhere*. The ordering is a relic - * of the old days when priorities were determined differently. + * The following array defines the order in which the current stacks are + * searched to find matching entries to add to the stacks. Given the + * current priority-based scheme, the order below is no longer relevant; + * all that matters is that an element is on the list *somewhere*. The + * ordering is a relic of the old days when priorities were determined + * differently. */ static int searchOrder[] = {WILDCARD_NODE_CLASS, WILDCARD_NODE_NAME, @@ -1279,8 +1253,7 @@ SetupStacks(winPtr, leaf) } /* - * Step 1: make sure that options are cached for this window's - * parent. + * Step 1: make sure that options are cached for this window's parent. */ if (winPtr->parentPtr != NULL) { @@ -1295,8 +1268,8 @@ SetupStacks(winPtr, leaf) } /* - * Step 2: pop extra unneeded information off the stacks and - * mark those windows as no longer having cached information. + * Step 2: pop extra unneeded information off the stacks and mark those + * windows as no longer having cached information. */ if (tsdPtr->curLevel >= level) { @@ -1314,9 +1287,9 @@ SetupStacks(winPtr, leaf) tsdPtr->curLevel = winPtr->optionLevel = level; /* - * Step 3: if the root database information isn't loaded or - * isn't valid, initialize level 0 of the stack from the - * database root (this only happens if winPtr is a main window). + * Step 3: if the root database information isn't loaded or isn't valid, + * initialize level 0 of the stack from the database root (this only + * happens if winPtr is a main window). */ if ((tsdPtr->curLevel == 1) @@ -1331,10 +1304,9 @@ SetupStacks(winPtr, leaf) } /* - * Step 4: create a new stack level; grow the level array if - * we've run out of levels. Clear the stacks for EXACT_LEAF_NAME - * and EXACT_LEAF_CLASS (anything that was there is of no use - * any more). + * Step 4: create a new stack level; grow the level array if we've run out + * of levels. Clear the stacks for EXACT_LEAF_NAME and EXACT_LEAF_CLASS + * (anything that was there is of no use any more). */ if (tsdPtr->curLevel >= tsdPtr->numLevels) { @@ -1359,10 +1331,10 @@ SetupStacks(winPtr, leaf) for (i = 0; i < NUM_STACKS; i++) { levelPtr->bases[i] = tsdPtr->stacks[i]->numUsed; } + /* * Step 5: scan the current stack level looking for matches to this - * window's name or class; where found, add new information to the - * stacks. + * window's name or class; where found, add new information to the stacks. */ for (iPtr = searchOrder; *iPtr != -1; iPtr++) { @@ -1380,8 +1352,8 @@ SetupStacks(winPtr, leaf) count = levelPtr->bases[i]; /* - * For wildcard stacks, check all entries; for non-wildcard - * stacks, only check things that matched in the parent. + * For wildcard stacks, check all entries; for non-wildcard stacks, + * only check things that matched in the parent. */ if (!(i & WILDCARD)) { @@ -1403,9 +1375,8 @@ SetupStacks(winPtr, leaf) * * ExtendStacks -- * - * Given an element array, copy all the elements from the - * array onto the system stacks (except for irrelevant leaf - * elements). + * Given an element array, copy all the elements from the array onto the + * system stacks (except for irrelevant leaf elements). * * Results: * None. @@ -1424,7 +1395,7 @@ ExtendStacks(arrayPtr, leaf) { register int count; register Element *elPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); for (elPtr = arrayPtr->els, count = arrayPtr->numUsed; @@ -1457,7 +1428,7 @@ static void OptionThreadExitProc(clientData) ClientData clientData; /* not used */ { - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (tsdPtr->initialized) { @@ -1488,20 +1459,20 @@ OptionThreadExitProc(clientData) static void OptionInit(mainPtr) - register TkMainInfo *mainPtr; /* Top-level information about - * window that isn't initialized - * yet. */ + register TkMainInfo *mainPtr; + /* Top-level information about window that + * isn't initialized yet. */ { int i; Tcl_Interp *interp; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); Element *defaultMatchPtr = &tsdPtr->defaultMatch; /* * First, once-only initialization. */ - + if (tsdPtr->initialized == 0) { tsdPtr->initialized = 1; tsdPtr->cachedWindow = NULL; @@ -1509,13 +1480,13 @@ OptionInit(mainPtr) tsdPtr->curLevel = -1; tsdPtr->serial = 0; - tsdPtr->levels = (StackLevel *) ckalloc((unsigned) + tsdPtr->levels = (StackLevel *) ckalloc((unsigned) (5*sizeof(StackLevel))); for (i = 0; i < NUM_STACKS; i++) { tsdPtr->stacks[i] = NewArray(10); tsdPtr->levels[0].bases[i] = 0; } - + defaultMatchPtr->nameUid = NULL; defaultMatchPtr->child.valueUid = NULL; defaultMatchPtr->priority = -1; @@ -1524,7 +1495,7 @@ OptionInit(mainPtr) } /* - * Then, per-main-window initialization. Create and delete dummy + * Then, per-main-window initialization. Create and delete dummy * interpreter for message logging. */ @@ -1539,23 +1510,22 @@ OptionInit(mainPtr) * * ClearOptionTree -- * - * This procedure is called to erase everything in a - * hierarchical option database. + * This function is called to erase everything in a hierarchical option + * database. * * Results: * None. * * Side effects: - * All the options associated with arrayPtr are deleted, - * along with all option subtrees. The space pointed to - * by arrayPtr is freed. + * All the options associated with arrayPtr are deleted, along with all + * option subtrees. The space pointed to by arrayPtr is freed. * *-------------------------------------------------------------- */ static void ClearOptionTree(arrayPtr) - ElArray *arrayPtr; /* Array of options; delete everything + ElArray *arrayPtr; /* Array of options; delete everything * referred to recursively by this. */ { register Element *elPtr; @@ -1575,17 +1545,16 @@ ClearOptionTree(arrayPtr) * * GetDefaultOptions -- * - * This procedure is invoked to load the default set of options - * for a window. + * This function is invoked to load the default set of options for a + * window. * * Results: * None. * * Side effects: - * Options are added to those for winPtr's main window. If - * there exists a RESOURCE_MANAGER proprety for winPtr's - * display, that is used. Otherwise, the .Xdefaults file in - * the user's home directory is used. + * Options are added to those for winPtr's main window. If there exists a + * RESOURCE_MANAGER proprety for winPtr's display, that is used. + * Otherwise, the .Xdefaults file in the user's home directory is used. * *-------------------------------------------------------------- */ @@ -1621,8 +1590,7 @@ GetDefaultOptions(interp, winPtr) } /* - * No luck there. Try a .Xdefaults file in the user's home - * directory. + * No luck there. Try a .Xdefaults file in the user's home directory. */ if (regProp != NULL) { @@ -1632,3 +1600,11 @@ GetDefaultOptions(interp, winPtr) TK_USER_DEFAULT_PRIO); return result; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |