mshtml: Added possibility for node implementations to add default event handlers.
[wine] / dlls / msvcp90 / misc.c
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <limits.h>
23
24 #include "msvcp90.h"
25
26 #include "windef.h"
27 #include "winbase.h"
28
29 typedef struct {
30     void *mutex;
31 } mutex;
32
33 /* ??0_Mutex@std@@QAE@XZ */
34 /* ??0_Mutex@std@@QEAA@XZ */
35 DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
36 mutex* __thiscall mutex_ctor(mutex *this)
37 {
38     this->mutex = CreateMutexW(NULL, FALSE, NULL);
39     return this;
40 }
41
42 /* ??1_Mutex@std@@QAE@XZ */
43 /* ??1_Mutex@std@@QEAA@XZ */
44 DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
45 void __thiscall mutex_dtor(mutex *this)
46 {
47     CloseHandle(this->mutex);
48 }
49
50 /* ?_Lock@_Mutex@std@@QAEXXZ */
51 /* ?_Lock@_Mutex@std@@QEAAXXZ */
52 DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
53 void __thiscall mutex_lock(mutex *this)
54 {
55     WaitForSingleObject(this->mutex, INFINITE);
56 }
57
58 /* ?_Unlock@_Mutex@std@@QAEXXZ */
59 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
60 DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
61 void __thiscall mutex_unlock(mutex *this)
62 {
63     ReleaseMutex(this->mutex);
64 }
65
66 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
67 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
68 void CDECL mutex_mutex_lock(mutex *m)
69 {
70     mutex_lock(m);
71 }
72
73 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
74 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
75 void CDECL mutex_mutex_unlock(mutex *m)
76 {
77     mutex_unlock(m);
78 }
79
80 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
81 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
82 void CDECL mutex_mutex_ctor(mutex *m)
83 {
84     mutex_ctor(m);
85 }
86
87 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
88 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
89 void CDECL mutex_mutex_dtor(mutex *m)
90 {
91     mutex_dtor(m);
92 }
93
94 #define _LOCK_LOCALE 0
95 #define _LOCK_MALLOC 1
96 #define _LOCK_STREAM 2
97 #define _LOCK_DEBUG 3
98 #define _MAX_LOCK 4
99 static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
100
101 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
102 void __cdecl _Lockit_init(int locktype) {
103     InitializeCriticalSection(&lockit_cs[locktype]);
104     lockit_cs[locktype].DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
105 }
106
107 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
108 void __cdecl _Lockit_free(int locktype)
109 {
110     lockit_cs[locktype].DebugInfo->Spare[0] = (DWORD_PTR)0;
111     DeleteCriticalSection(&lockit_cs[locktype]);
112 }
113
114 void init_lockit(void) {
115     int i;
116
117     for(i=0; i<_MAX_LOCK; i++)
118         _Lockit_init(i);
119 }
120
121 void free_lockit(void) {
122     int i;
123
124     for(i=0; i<_MAX_LOCK; i++)
125         _Lockit_free(i);
126 }
127
128 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
129 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
130 void __cdecl _Lockit__Lockit_ctor_locktype(_Lockit *lockit, int locktype)
131 {
132     lockit->locktype = locktype;
133     EnterCriticalSection(&lockit_cs[locktype]);
134 }
135
136 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
137 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
138 void __cdecl _Lockit__Lockit_ctor(_Lockit *lockit)
139 {
140     _Lockit__Lockit_ctor_locktype(lockit, 0);
141 }
142
143 /* ??0_Lockit@std@@QAE@H@Z */
144 /* ??0_Lockit@std@@QEAA@H@Z */
145 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype, 8)
146 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
147 {
148     _Lockit__Lockit_ctor_locktype(this, locktype);
149     return this;
150 }
151
152 /* ??0_Lockit@std@@QAE@XZ */
153 /* ??0_Lockit@std@@QEAA@XZ */
154 DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
155 _Lockit* __thiscall _Lockit_ctor(_Lockit *this)
156 {
157     _Lockit__Lockit_ctor_locktype(this, 0);
158     return this;
159 }
160
161 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
162 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
163 void __cdecl _Lockit__Lockit_dtor(_Lockit *lockit)
164 {
165     LeaveCriticalSection(&lockit_cs[lockit->locktype]);
166 }
167
168 /* ??1_Lockit@std@@QAE@XZ */
169 /* ??1_Lockit@std@@QEAA@XZ */
170 DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
171 void __thiscall _Lockit_dtor(_Lockit *this)
172 {
173     _Lockit__Lockit_dtor(this);
174 }
175
176 /* wctype */
177 unsigned short __cdecl wctype(const char *property)
178 {
179     static const struct {
180         const char *name;
181         unsigned short mask;
182     } properties[] = {
183         { "alnum", _DIGIT|_ALPHA },
184         { "alpha", _ALPHA },
185         { "cntrl", _CONTROL },
186         { "digit", _DIGIT },
187         { "graph", _DIGIT|_PUNCT|_ALPHA },
188         { "lower", _LOWER },
189         { "print", _DIGIT|_PUNCT|_BLANK|_ALPHA },
190         { "punct", _PUNCT },
191         { "space", _SPACE },
192         { "upper", _UPPER },
193         { "xdigit", _HEX }
194     };
195     int i;
196
197     for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
198         if(!strcmp(property, properties[i].name))
199             return properties[i].mask;
200
201     return 0;
202 }