Release 960705
[wine] / misc / toolhelp.c
1 /*
2  * Misc Toolhelp functions
3  *
4  * Copyright 1996 Marcus Meissner
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #include "windows.h"
13 #include "win.h"
14 #include "toolhelp.h"
15 #include "stddebug.h"
16 #include "debug.h"
17 #include "xmalloc.h"
18
19 /* FIXME: to make this working, we have to callback all these registered 
20  * functions from all over the WINE code. Someone with more knowledge than
21  * me please do that. -Marcus
22  */
23 static struct notify
24 {
25     HTASK    htask;
26     FARPROC  lpfnCallback;
27     WORD     wFlags;
28 } *notifys = NULL;
29
30 static int nrofnotifys = 0;
31
32 BOOL16 NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback, WORD wFlags )
33 {
34     int i;
35
36     dprintf_toolhelp( stddeb, "NotifyRegister(%x,%lx,%x) called.\n",
37                       htask, (DWORD)lpfnCallback, wFlags );
38     for (i=0;i<nrofnotifys;i++)
39         if (notifys[i].htask==htask)
40             break;
41     if (i==nrofnotifys) {
42         if (notifys==NULL)
43             notifys=(struct notify*)xmalloc(sizeof(struct notify));
44         else
45             notifys=(struct notify*)xrealloc(notifys,sizeof(struct notify)*(nrofnotifys+1));
46         nrofnotifys++;
47     }
48     notifys[i].htask=htask;
49     notifys[i].lpfnCallback=lpfnCallback;
50     notifys[i].wFlags=wFlags;
51     return TRUE;
52 }
53
54 BOOL
55 NotifyUnregister(HTASK htask)
56 {
57     int i;
58     
59     dprintf_toolhelp( stddeb, "NotifyUnregister(%x) called.\n", htask );
60     for (i=nrofnotifys;i--;)
61         if (notifys[i].htask==htask)
62             break;
63     if (i==-1)
64         return FALSE;
65     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
66     notifys=(struct notify*)xrealloc(notifys,(nrofnotifys-1)*sizeof(struct notify));
67     nrofnotifys--;
68     return TRUE;
69 }