Initer.c revision 6c321187
1/* $Xorg: Initer.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */ 2 3/* 4 5Copyright 1988, 1989, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27*/ 28/* $XFree86: xc/lib/Xmu/Initer.c,v 1.6 2001/01/17 19:42:56 dawes Exp $ */ 29 30/* Created By: Chris D. Peterson 31 * MIT X Consortium 32 * Date: May 8, 1989 33 */ 34 35#ifdef HAVE_CONFIG_H 36#include <config.h> 37#endif 38#include <X11/Intrinsic.h> 39#include <X11/Xmu/Initer.h> 40 41struct InitializerList { 42 XmuInitializerProc function; /* function to call */ 43 XPointer data; /* Data to pass the function. */ 44 XtAppContext * app_con_list; /* a null terminated list of app_contexts. */ 45}; 46 47/* 48 * Prototypes 49 */ 50static Bool AddToAppconList(XtAppContext**, XtAppContext); 51 52static struct InitializerList * init_list = NULL; 53static Cardinal init_list_length = 0; 54 55void 56XmuAddInitializer(XmuInitializerProc func, XPointer data) 57{ 58 init_list_length++; 59 init_list = (struct InitializerList *) XtRealloc( (char *) init_list, 60 (sizeof(struct InitializerList) * 61 init_list_length) ); 62 63 init_list[init_list_length - 1].function = func; 64 init_list[init_list_length - 1].data = data; 65 init_list[init_list_length - 1].app_con_list = NULL; 66} 67 68void 69XmuCallInitializers(XtAppContext app_con) 70{ 71 unsigned i; 72 73 for (i = 0 ; i < init_list_length ; i++) { 74 if (AddToAppconList(&(init_list[i].app_con_list), app_con)) 75 (init_list[i].function) (app_con, init_list[i].data); 76 } 77} 78 79/* 80 * Function: 81 * AddToAppconList 82 * 83 * Parameters: 84 * app_list - NULL terminated list of application contexts 85 * app_con - application context to test 86 * 87 * Description: 88 * Adds an action to the application context list and 89 * returns True, if this app_con is already on the list then 90 * it is NOT added and False is returned. 91 * 92 * Returns: 93 * True if not found, False if found 94 */ 95static Bool 96AddToAppconList(XtAppContext **app_list, XtAppContext app_con) 97{ 98 int i; 99 XtAppContext *local_list; 100 101 i = 0; 102 local_list = *app_list; 103 if (*app_list != NULL) { 104 for ( ; *local_list != NULL ; i++, local_list++) { 105 if (*local_list == app_con) 106 return (False); 107 } 108 } 109 110 *app_list = (XtAppContext *) XtRealloc((char *)(*app_list), 111 sizeof(XtAppContext *) * (i + 2) ); 112 (*app_list)[i++] = app_con; 113 (*app_list)[i] = NULL; 114 115 return (True); 116} 117 118