Initer.c

Go to the documentation of this file.
00001 /* $Xorg: Initer.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1988, 1989, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/Initer.c,v 1.6 2001/01/17 19:42:56 dawes Exp $ */
00029 
00030 /* Created By:  Chris D. Peterson
00031  *              MIT X Consortium
00032  * Date:        May 8, 1989
00033  */
00034 
00035 #include <X11/Intrinsic.h>
00036 #include <X11/Xmu/Initer.h>
00037 
00038 struct InitializerList {
00039   XmuInitializerProc function;  /* function to call */
00040   XPointer data;                /* Data to pass the function. */
00041   XtAppContext * app_con_list;  /* a null terminated list of app_contexts. */
00042 };
00043   
00044 /*
00045  * Prototypes
00046  */
00047 static Bool AddToAppconList(XtAppContext**, XtAppContext);
00048   
00049 static struct InitializerList * init_list = NULL;
00050 static Cardinal init_list_length = 0;
00051 
00052 void
00053 XmuAddInitializer(XmuInitializerProc func, XPointer data)
00054 {
00055   init_list_length++;
00056   init_list = (struct InitializerList *) XtRealloc( (char *) init_list, 
00057                                             (sizeof(struct InitializerList) * 
00058                                              init_list_length) );
00059 
00060   init_list[init_list_length - 1].function = func;
00061   init_list[init_list_length - 1].data = data;
00062   init_list[init_list_length - 1].app_con_list = NULL;
00063 }
00064 
00065 void
00066 XmuCallInitializers(XtAppContext app_con)
00067 {
00068   unsigned i;
00069 
00070   for (i = 0 ; i < init_list_length ; i++) {
00071     if (AddToAppconList(&(init_list[i].app_con_list), app_con))
00072       (init_list[i].function) (app_con, init_list[i].data);
00073   }
00074 }
00075 
00076 /*
00077  * Function:
00078  *      AddToAppconList
00079  *
00080  * Parameters:
00081  *      app_list - NULL terminated list of application contexts
00082  *      app_con  - application context to test
00083  *
00084  * Description:
00085  *        Adds an action to the application context list and
00086  *      returns True, if this app_con is already on the list then
00087  *      it is NOT added and False is returned.
00088  *
00089  * Returns:
00090  *      True if not found, False if found
00091  */
00092 static Bool
00093 AddToAppconList(XtAppContext **app_list, XtAppContext app_con)
00094 {
00095   int i;
00096   XtAppContext *local_list;
00097 
00098   i = 0;
00099   local_list = *app_list;
00100   if (*app_list != NULL) {
00101     for ( ; *local_list != NULL ; i++, local_list++) {
00102       if (*local_list == app_con)
00103         return (False);
00104     }
00105   }
00106 
00107   *app_list = (XtAppContext *)  XtRealloc((char *)(*app_list),
00108                                           sizeof(XtAppContext *) * (i + 2) );
00109   (*app_list)[i++] = app_con;
00110   (*app_list)[i] = NULL;
00111 
00112   return (True);
00113 }
00114   

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1