home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / Initer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-28  |  2.8 KB  |  96 lines

  1. /* $XConsortium: Initer.c,v 1.7 91/05/28 16:08:34 converse Exp $ */
  2.  
  3. /* 
  4.  * Copyright 1988, 1989 by the Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided 
  8.  * that the above copyright notice appear in all copies and that both that 
  9.  * copyright notice and this permission notice appear in supporting 
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific, 
  12.  * written prior permission. M.I.T. makes no representations about the 
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  */
  17.  
  18. /* Created By:  Chris D. Peterson
  19.  *              MIT X Consortium
  20.  * Date:        May 8, 1989
  21.  */
  22.  
  23. #include <X11/Intrinsic.h>
  24. #include <X11/Xmu/Initer.h>
  25.  
  26. struct InitializerList {
  27.   XmuInitializerProc function;    /* function to call */
  28.   caddr_t data;            /* Data to pass the function. */
  29.   XtAppContext * app_con_list;    /* a null terminated list of app_contexts. */
  30. };
  31.   
  32. static struct InitializerList * init_list = NULL;
  33. static Cardinal init_list_length = 0;
  34.  
  35. static Boolean AddToAppconList();
  36.  
  37. void
  38. XmuAddInitializer(func, data) 
  39. XmuInitializerProc func;
  40. caddr_t data;
  41. {
  42.   init_list_length++;
  43.   init_list = (struct InitializerList *) XtRealloc( (char *) init_list, 
  44.                         (sizeof(struct InitializerList) * 
  45.                          init_list_length) );
  46.  
  47.   init_list[init_list_length - 1].function = func;
  48.   init_list[init_list_length - 1].data = data;
  49.   init_list[init_list_length - 1].app_con_list = NULL;
  50. }
  51.  
  52. void
  53. XmuCallInitializers(app_con)
  54. XtAppContext app_con;
  55. {
  56.   int i;
  57.  
  58.   for (i = 0 ; i < init_list_length ; i++) {
  59.     if (AddToAppconList(&(init_list[i].app_con_list), app_con))
  60.       (init_list[i].function) (app_con, init_list[i].data);
  61.   }
  62. }
  63.  
  64. /*    Function Name: AddToAppconList
  65.  *    Description: Adds an action to the application context list and
  66.  *                   returns TRUE, if this app_con is already on the list then
  67.  *                   it is NOT added and FALSE is returned.
  68.  *    Arguments: app_list - a NULL terminated list of application contexts.
  69.  *                 app_con - an application context to test.
  70.  *    Returns: TRUE if not found, FALSE if found.
  71.  */
  72.  
  73. static Boolean
  74. AddToAppconList(app_list, app_con)
  75. XtAppContext **app_list, app_con;
  76. {
  77.   int i;
  78.   XtAppContext *local_list;
  79.  
  80.   i = 0;
  81.   local_list = *app_list;
  82.   if (*app_list != NULL) {
  83.     for ( ; *local_list != NULL ; i++, local_list++) {
  84.       if (*local_list == app_con)
  85.     return(FALSE);
  86.     }
  87.   }
  88.  
  89.   *app_list = (XtAppContext *)  XtRealloc((char *)(*app_list),
  90.                       sizeof(XtAppContext *) * (i + 2) );
  91.   (*app_list)[i++] = app_con;
  92.   (*app_list)[i] = NULL;
  93.   return(TRUE);
  94. }
  95.   
  96.