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