Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Atom table functions |
| 3 | * |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 4 | * Copyright 1993, 1994, 1995 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 22 | * Warning: The code assumes that LocalAlloc() returns a block aligned |
| 23 | * on a 4-bytes boundary (because of the shifting done in |
| 24 | * HANDLETOATOM). If this is not the case, the allocation code will |
| 25 | * have to be changed. |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 28 | #include "config.h" |
Patrik Stridvall | 51e6c0c | 2002-08-31 19:04:14 +0000 | [diff] [blame] | 29 | #include "wine/port.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 30 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 31 | #include <stdlib.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 33 | #include <string.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 34 | #include <ctype.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 35 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 36 | #include "windef.h" |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 37 | #include "winbase.h" |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 38 | #include "winerror.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 39 | |
| 40 | #include "wine/server.h" |
| 41 | #include "wine/unicode.h" |
| 42 | #include "wine/winbase16.h" |
| 43 | #include "global.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 44 | #include "instance.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 45 | #include "stackframe.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 46 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 47 | #include "wine/debug.h" |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 48 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 49 | WINE_DEFAULT_DEBUG_CHANNEL(atom); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 51 | #define DEFAULT_ATOMTABLE_SIZE 37 |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 52 | #define MAX_ATOM_LEN 255 |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 53 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 54 | #define ATOMTOHANDLE(atom) ((HANDLE16)(atom) << 2) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 55 | #define HANDLETOATOM(handle) ((ATOM)(0xc000 | ((handle) >> 2))) |
| 56 | |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 57 | typedef struct |
| 58 | { |
| 59 | HANDLE16 next; |
| 60 | WORD refCount; |
| 61 | BYTE length; |
| 62 | BYTE str[1]; |
| 63 | } ATOMENTRY; |
| 64 | |
| 65 | typedef struct |
| 66 | { |
| 67 | WORD size; |
| 68 | HANDLE16 entries[1]; |
| 69 | } ATOMTABLE; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 70 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 71 | |
| 72 | /*********************************************************************** |
| 73 | * ATOM_GetTable |
| 74 | * |
| 75 | * Return a pointer to the atom table of a given segment, creating |
| 76 | * it if necessary. |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 77 | * |
| 78 | * RETURNS |
| 79 | * Pointer to table: Success |
| 80 | * NULL: Failure |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 81 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 82 | static ATOMTABLE *ATOM_GetTable( BOOL create /* [in] Create */ ) |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 83 | { |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 84 | INSTANCEDATA *ptr = MapSL( MAKESEGPTR( CURRENT_DS, 0 ) ); |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 85 | if (ptr->atomtable) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 86 | { |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 87 | ATOMTABLE *table = (ATOMTABLE *)((char *)ptr + ptr->atomtable); |
| 88 | if (table->size) return table; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 89 | } |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 90 | if (!create) return NULL; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 91 | if (!InitAtomTable16( 0 )) return NULL; |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 92 | /* Reload ptr in case it moved in linear memory */ |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 93 | ptr = MapSL( MAKESEGPTR( CURRENT_DS, 0 ) ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 94 | return (ATOMTABLE *)((char *)ptr + ptr->atomtable); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
| 98 | /*********************************************************************** |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 99 | * ATOM_Hash |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 100 | * RETURNS |
| 101 | * The hash value for the input string |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 102 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 103 | static WORD ATOM_Hash( |
| 104 | WORD entries, /* [in] Total number of entries */ |
| 105 | LPCSTR str, /* [in] Pointer to string to hash */ |
| 106 | WORD len /* [in] Length of string */ |
| 107 | ) { |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 108 | WORD i, hash = 0; |
| 109 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 110 | TRACE("%x, %s, %x\n", entries, str, len); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 111 | |
Alexandre Julliard | cdd0923 | 1994-01-12 11:12:51 +0000 | [diff] [blame] | 112 | for (i = 0; i < len; i++) hash ^= toupper(str[i]) + i; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 113 | return hash % entries; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /*********************************************************************** |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 118 | * ATOM_IsIntAtomA |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 119 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 120 | static BOOL ATOM_IsIntAtomA(LPCSTR atomstr,WORD *atomid) |
| 121 | { |
| 122 | UINT atom = 0; |
| 123 | if (!HIWORD(atomstr)) atom = LOWORD(atomstr); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 124 | else |
| 125 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 126 | if (*atomstr++ != '#') return FALSE; |
| 127 | while (*atomstr >= '0' && *atomstr <= '9') |
| 128 | { |
| 129 | atom = atom * 10 + *atomstr - '0'; |
| 130 | atomstr++; |
| 131 | } |
| 132 | if (*atomstr) return FALSE; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 133 | } |
Dmitry Timoshkov | c8ab54d | 2002-10-04 17:45:00 +0000 | [diff] [blame] | 134 | if (atom >= MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 135 | { |
| 136 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 137 | atom = 0; |
| 138 | } |
| 139 | *atomid = atom; |
| 140 | return TRUE; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /*********************************************************************** |
| 145 | * ATOM_IsIntAtomW |
| 146 | */ |
| 147 | static BOOL ATOM_IsIntAtomW(LPCWSTR atomstr,WORD *atomid) |
| 148 | { |
| 149 | UINT atom = 0; |
| 150 | if (!HIWORD(atomstr)) atom = LOWORD(atomstr); |
| 151 | else |
| 152 | { |
| 153 | if (*atomstr++ != '#') return FALSE; |
| 154 | while (*atomstr >= '0' && *atomstr <= '9') |
| 155 | { |
| 156 | atom = atom * 10 + *atomstr - '0'; |
| 157 | atomstr++; |
| 158 | } |
| 159 | if (*atomstr) return FALSE; |
| 160 | } |
Dmitry Timoshkov | c8ab54d | 2002-10-04 17:45:00 +0000 | [diff] [blame] | 161 | if (atom >= MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 162 | { |
| 163 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 164 | atom = 0; |
| 165 | } |
| 166 | *atomid = atom; |
| 167 | return TRUE; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | /*********************************************************************** |
| 172 | * ATOM_MakePtr |
| 173 | * |
| 174 | * Make an ATOMENTRY pointer from a handle (obtained from GetAtomHandle()). |
| 175 | */ |
| 176 | static inline ATOMENTRY *ATOM_MakePtr( HANDLE16 handle /* [in] Handle */ ) |
| 177 | { |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 178 | return MapSL( MAKESEGPTR( CURRENT_DS, handle ) ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
| 182 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 183 | * InitAtomTable (KERNEL.68) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 184 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 185 | WORD WINAPI InitAtomTable16( WORD entries ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 186 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 187 | int i; |
| 188 | HANDLE16 handle; |
| 189 | ATOMTABLE *table; |
| 190 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 191 | /* Allocate the table */ |
| 192 | |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 193 | if (!entries) entries = DEFAULT_ATOMTABLE_SIZE; /* sanity check */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 194 | handle = LocalAlloc16( LMEM_FIXED, sizeof(ATOMTABLE) + (entries-1) * sizeof(HANDLE16) ); |
| 195 | if (!handle) return 0; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 196 | table = MapSL( MAKESEGPTR( CURRENT_DS, handle ) ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 197 | table->size = entries; |
| 198 | for (i = 0; i < entries; i++) table->entries[i] = 0; |
| 199 | |
| 200 | /* Store a pointer to the table in the instance data */ |
| 201 | |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 202 | ((INSTANCEDATA *)MapSL( MAKESEGPTR( CURRENT_DS, 0 )))->atomtable = handle; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 203 | return handle; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 206 | /*********************************************************************** |
| 207 | * GetAtomHandle (KERNEL.73) |
| 208 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 209 | HANDLE16 WINAPI GetAtomHandle16( ATOM atom ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 210 | { |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 211 | if (atom < MAXINTATOM) return 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 212 | return ATOMTOHANDLE( atom ); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 217 | * AddAtom (KERNEL.70) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 218 | * |
| 219 | * Windows DWORD aligns the atom entry size. |
| 220 | * The remaining unused string space created by the alignment |
| 221 | * gets padded with '\0's in a certain way to ensure |
| 222 | * that at least one trailing '\0' remains. |
| 223 | * |
| 224 | * RETURNS |
| 225 | * Atom: Success |
| 226 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 227 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 228 | ATOM WINAPI AddAtom16( LPCSTR str ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 229 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 230 | char buffer[MAX_ATOM_LEN+1]; |
| 231 | WORD hash; |
| 232 | HANDLE16 entry; |
| 233 | ATOMENTRY * entryPtr; |
| 234 | ATOMTABLE * table; |
| 235 | int len, ae_len; |
| 236 | WORD iatom; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 237 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 238 | if (ATOM_IsIntAtomA( str, &iatom )) return iatom; |
| 239 | |
| 240 | TRACE("%s\n",debugstr_a(buffer)); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 241 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 242 | /* Make a copy of the string to be sure it doesn't move in linear memory. */ |
| 243 | lstrcpynA( buffer, str, sizeof(buffer) ); |
| 244 | |
| 245 | len = strlen( buffer ); |
| 246 | if (!(table = ATOM_GetTable( TRUE ))) return 0; |
Alexandre Julliard | bcb7f4e | 2000-02-19 20:51:29 +0000 | [diff] [blame] | 247 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 248 | hash = ATOM_Hash( table->size, buffer, len ); |
| 249 | entry = table->entries[hash]; |
| 250 | while (entry) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 251 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 252 | entryPtr = ATOM_MakePtr( entry ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 253 | if ((entryPtr->length == len) && |
Alexandre Julliard | 072dfb5 | 2000-09-25 23:30:56 +0000 | [diff] [blame] | 254 | (!strncasecmp( entryPtr->str, buffer, len ))) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 255 | { |
| 256 | entryPtr->refCount++; |
| 257 | TRACE("-- existing 0x%x\n", entry); |
| 258 | return HANDLETOATOM( entry ); |
| 259 | } |
| 260 | entry = entryPtr->next; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 261 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 262 | |
| 263 | ae_len = (sizeof(ATOMENTRY)+len+3) & ~3; |
| 264 | entry = LocalAlloc16( LMEM_FIXED, ae_len ); |
| 265 | if (!entry) return 0; |
| 266 | /* Reload the table ptr in case it moved in linear memory */ |
| 267 | table = ATOM_GetTable( FALSE ); |
| 268 | entryPtr = ATOM_MakePtr( entry ); |
| 269 | entryPtr->next = table->entries[hash]; |
| 270 | entryPtr->refCount = 1; |
| 271 | entryPtr->length = len; |
| 272 | /* Some applications _need_ the '\0' padding provided by this strncpy */ |
| 273 | strncpy( entryPtr->str, buffer, ae_len - sizeof(ATOMENTRY) + 1 ); |
| 274 | entryPtr->str[ae_len - sizeof(ATOMENTRY)] = '\0'; |
| 275 | table->entries[hash] = entry; |
| 276 | TRACE("-- new 0x%x\n", entry); |
| 277 | return HANDLETOATOM( entry ); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 282 | * DeleteAtom (KERNEL.71) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 283 | */ |
| 284 | ATOM WINAPI DeleteAtom16( ATOM atom ) |
| 285 | { |
| 286 | ATOMENTRY * entryPtr; |
| 287 | ATOMTABLE * table; |
| 288 | HANDLE16 entry, *prevEntry; |
| 289 | WORD hash; |
| 290 | |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 291 | if (atom < MAXINTATOM) return 0; /* Integer atom */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 292 | |
| 293 | TRACE("0x%x\n",atom); |
| 294 | |
| 295 | if (!(table = ATOM_GetTable( FALSE ))) return 0; |
| 296 | entry = ATOMTOHANDLE( atom ); |
| 297 | entryPtr = ATOM_MakePtr( entry ); |
| 298 | |
| 299 | /* Find previous atom */ |
| 300 | hash = ATOM_Hash( table->size, entryPtr->str, entryPtr->length ); |
| 301 | prevEntry = &table->entries[hash]; |
| 302 | while (*prevEntry && *prevEntry != entry) |
| 303 | { |
| 304 | ATOMENTRY * prevEntryPtr = ATOM_MakePtr( *prevEntry ); |
| 305 | prevEntry = &prevEntryPtr->next; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 306 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 307 | if (!*prevEntry) return atom; |
| 308 | |
| 309 | /* Delete atom */ |
| 310 | if (--entryPtr->refCount == 0) |
| 311 | { |
| 312 | *prevEntry = entryPtr->next; |
| 313 | LocalFree16( entry ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 314 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 320 | * FindAtom (KERNEL.69) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 321 | */ |
| 322 | ATOM WINAPI FindAtom16( LPCSTR str ) |
| 323 | { |
| 324 | ATOMTABLE * table; |
| 325 | WORD hash,iatom; |
| 326 | HANDLE16 entry; |
| 327 | int len; |
| 328 | |
Alexandre Julliard | 0aa28b5 | 2002-05-17 02:55:48 +0000 | [diff] [blame] | 329 | TRACE("%s\n",debugstr_a(str)); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 330 | |
| 331 | if (ATOM_IsIntAtomA( str, &iatom )) return iatom; |
| 332 | if ((len = strlen( str )) > 255) len = 255; |
| 333 | if (!(table = ATOM_GetTable( FALSE ))) return 0; |
| 334 | hash = ATOM_Hash( table->size, str, len ); |
| 335 | entry = table->entries[hash]; |
| 336 | while (entry) |
| 337 | { |
| 338 | ATOMENTRY * entryPtr = ATOM_MakePtr( entry ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 339 | if ((entryPtr->length == len) && |
Alexandre Julliard | 072dfb5 | 2000-09-25 23:30:56 +0000 | [diff] [blame] | 340 | (!strncasecmp( entryPtr->str, str, len ))) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 341 | { |
| 342 | TRACE("-- found %x\n", entry); |
| 343 | return HANDLETOATOM( entry ); |
| 344 | } |
| 345 | entry = entryPtr->next; |
| 346 | } |
| 347 | TRACE("-- not found\n"); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | |
| 352 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 353 | * GetAtomName (KERNEL.72) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 354 | */ |
| 355 | UINT16 WINAPI GetAtomName16( ATOM atom, LPSTR buffer, INT16 count ) |
| 356 | { |
| 357 | ATOMTABLE * table; |
| 358 | ATOMENTRY * entryPtr; |
| 359 | HANDLE16 entry; |
| 360 | char * strPtr; |
| 361 | UINT len; |
| 362 | char text[8]; |
| 363 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 364 | TRACE("%x\n",atom); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 365 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 366 | if (!count) return 0; |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 367 | if (atom < MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 368 | { |
| 369 | sprintf( text, "#%d", atom ); |
| 370 | len = strlen(text); |
| 371 | strPtr = text; |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | if (!(table = ATOM_GetTable( FALSE ))) return 0; |
| 376 | entry = ATOMTOHANDLE( atom ); |
| 377 | entryPtr = ATOM_MakePtr( entry ); |
| 378 | len = entryPtr->length; |
| 379 | strPtr = entryPtr->str; |
| 380 | } |
| 381 | if (len >= count) len = count-1; |
| 382 | memcpy( buffer, strPtr, len ); |
| 383 | buffer[len] = '\0'; |
| 384 | return len; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 387 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 388 | * InitAtomTable (KERNEL32.@) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 389 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 390 | BOOL WINAPI InitAtomTable( DWORD entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 391 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 392 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 393 | SERVER_START_REQ( init_atom_table ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 394 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 395 | req->entries = entries; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 396 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 397 | } |
| 398 | SERVER_END_REQ; |
| 399 | return ret; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 403 | static ATOM ATOM_AddAtomA( LPCSTR str, BOOL local ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 404 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 405 | ATOM atom = 0; |
| 406 | if (!ATOM_IsIntAtomA( str, &atom )) |
| 407 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 408 | WCHAR buffer[MAX_ATOM_LEN]; |
| 409 | |
| 410 | DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN ); |
| 411 | if (!len) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 412 | { |
| 413 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 414 | return 0; |
| 415 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 416 | SERVER_START_REQ( add_atom ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 417 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 418 | wine_server_add_data( req, buffer, len * sizeof(WCHAR) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 419 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 420 | if (!wine_server_call_err(req)) atom = reply->atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 421 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 422 | SERVER_END_REQ; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 423 | } |
Alexandre Julliard | 0aa28b5 | 2002-05-17 02:55:48 +0000 | [diff] [blame] | 424 | TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_a(str), atom ); |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 425 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
| 429 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 430 | * GlobalAddAtomA (KERNEL32.@) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 431 | * |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 432 | * Adds a character string to the global atom table and returns a unique |
| 433 | * value identifying the string. |
| 434 | * |
| 435 | * RETURNS |
| 436 | * Atom: Success |
| 437 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 438 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 439 | ATOM WINAPI GlobalAddAtomA( LPCSTR str /* [in] Pointer to string to add */ ) |
| 440 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 441 | return ATOM_AddAtomA( str, FALSE ); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 446 | * AddAtomA (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 447 | * Adds a string to the atom table and returns the atom identifying the |
| 448 | * string. |
| 449 | * |
| 450 | * RETURNS |
| 451 | * Atom: Success |
| 452 | * 0: Failure |
| 453 | */ |
| 454 | ATOM WINAPI AddAtomA( LPCSTR str /* [in] Pointer to string to add */ ) |
| 455 | { |
| 456 | return ATOM_AddAtomA( str, TRUE ); |
| 457 | } |
| 458 | |
| 459 | |
| 460 | static ATOM ATOM_AddAtomW( LPCWSTR str, BOOL local ) |
| 461 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 462 | ATOM atom = 0; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 463 | if (!ATOM_IsIntAtomW( str, &atom )) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 464 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 465 | DWORD len = strlenW(str); |
| 466 | if (len > MAX_ATOM_LEN) |
| 467 | { |
| 468 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 469 | return 0; |
| 470 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 471 | SERVER_START_REQ( add_atom ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 472 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 473 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 474 | wine_server_add_data( req, str, len * sizeof(WCHAR) ); |
| 475 | if (!wine_server_call_err(req)) atom = reply->atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 476 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 477 | SERVER_END_REQ; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 478 | } |
Alexandre Julliard | 0aa28b5 | 2002-05-17 02:55:48 +0000 | [diff] [blame] | 479 | TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_w(str), atom ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 480 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
| 484 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 485 | * GlobalAddAtomW (KERNEL32.@) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 486 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 487 | ATOM WINAPI GlobalAddAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 488 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 489 | return ATOM_AddAtomW( str, FALSE ); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 494 | * AddAtomW (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 495 | */ |
| 496 | ATOM WINAPI AddAtomW( LPCWSTR str ) |
| 497 | { |
| 498 | return ATOM_AddAtomW( str, TRUE ); |
| 499 | } |
| 500 | |
| 501 | |
| 502 | static ATOM ATOM_DeleteAtom( ATOM atom, BOOL local) |
| 503 | { |
Andreas Mohr | c9cf70d | 2001-01-26 20:40:50 +0000 | [diff] [blame] | 504 | TRACE( "(%s) %x\n", local ? "local" : "global", atom ); |
Dmitry Timoshkov | c8ab54d | 2002-10-04 17:45:00 +0000 | [diff] [blame] | 505 | if (atom >= MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 506 | { |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 507 | SERVER_START_REQ( delete_atom ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 508 | { |
Alexandre Julliard | d8a8c11 | 2001-10-12 18:45:29 +0000 | [diff] [blame] | 509 | req->atom = atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 510 | req->local = local; |
Dmitry Timoshkov | c8ab54d | 2002-10-04 17:45:00 +0000 | [diff] [blame] | 511 | wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 512 | } |
| 513 | SERVER_END_REQ; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 514 | } |
Dmitry Timoshkov | c8ab54d | 2002-10-04 17:45:00 +0000 | [diff] [blame] | 515 | return 0; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | |
| 519 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 520 | * GlobalDeleteAtom (KERNEL32.@) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 521 | * Decrements the reference count of a string atom. If the count is |
| 522 | * zero, the string associated with the atom is removed from the table. |
| 523 | * |
| 524 | * RETURNS |
| 525 | * 0: Success |
| 526 | * Atom: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 527 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 528 | ATOM WINAPI GlobalDeleteAtom( ATOM atom /* [in] Atom to delete */ ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 529 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 530 | return ATOM_DeleteAtom( atom, FALSE); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 535 | * DeleteAtom (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 536 | * Decrements the reference count of a string atom. If count becomes |
| 537 | * zero, the string associated with the atom is removed from the table. |
| 538 | * |
| 539 | * RETURNS |
| 540 | * 0: Success |
| 541 | * Atom: Failure |
| 542 | */ |
| 543 | ATOM WINAPI DeleteAtom( ATOM atom /* [in] Atom to delete */ ) |
| 544 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 545 | return ATOM_DeleteAtom( atom, TRUE ); |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
| 549 | static ATOM ATOM_FindAtomA( LPCSTR str, BOOL local ) |
| 550 | { |
| 551 | ATOM atom = 0; |
| 552 | if (!ATOM_IsIntAtomA( str, &atom )) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 553 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 554 | WCHAR buffer[MAX_ATOM_LEN]; |
| 555 | |
| 556 | DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN ); |
| 557 | if (!len) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 558 | { |
| 559 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 560 | return 0; |
| 561 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 562 | SERVER_START_REQ( find_atom ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 563 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 564 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 565 | wine_server_add_data( req, buffer, len * sizeof(WCHAR) ); |
| 566 | if (!wine_server_call_err(req)) atom = reply->atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 567 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 568 | SERVER_END_REQ; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 569 | } |
Alexandre Julliard | 0aa28b5 | 2002-05-17 02:55:48 +0000 | [diff] [blame] | 570 | TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_a(str), atom ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 571 | return atom; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
| 575 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 576 | * GlobalFindAtomA (KERNEL32.@) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 577 | * |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 578 | * Searches the atom table for the string and returns the atom |
| 579 | * associated with it. |
| 580 | * |
| 581 | * RETURNS |
| 582 | * Atom: Success |
| 583 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 584 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 585 | ATOM WINAPI GlobalFindAtomA( LPCSTR str /* [in] Pointer to string to search for */ ) |
| 586 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 587 | return ATOM_FindAtomA( str, FALSE ); |
| 588 | } |
| 589 | |
| 590 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 591 | * FindAtomA (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 592 | * Searches the local atom table for the string and returns the atom |
| 593 | * associated with that string. |
| 594 | * |
| 595 | * RETURNS |
| 596 | * Atom: Success |
| 597 | * 0: Failure |
| 598 | */ |
| 599 | ATOM WINAPI FindAtomA( LPCSTR str /* [in] Pointer to string to find */ ) |
| 600 | { |
| 601 | return ATOM_FindAtomA( str, TRUE ); |
| 602 | } |
| 603 | |
| 604 | |
| 605 | static ATOM ATOM_FindAtomW( LPCWSTR str, BOOL local ) |
| 606 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 607 | ATOM atom = 0; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 608 | if (!ATOM_IsIntAtomW( str, &atom )) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 609 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 610 | DWORD len = strlenW(str); |
| 611 | if (len > MAX_ATOM_LEN) |
| 612 | { |
| 613 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 614 | return 0; |
| 615 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 616 | SERVER_START_REQ( find_atom ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 617 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 618 | wine_server_add_data( req, str, len * sizeof(WCHAR) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 619 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 620 | if (!wine_server_call_err( req )) atom = reply->atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 621 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 622 | SERVER_END_REQ; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 623 | } |
Alexandre Julliard | 0aa28b5 | 2002-05-17 02:55:48 +0000 | [diff] [blame] | 624 | TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_w(str), atom ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 625 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
| 629 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 630 | * GlobalFindAtomW (KERNEL32.@) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 631 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 632 | ATOM WINAPI GlobalFindAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 633 | { |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 634 | return ATOM_FindAtomW( str, FALSE ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
| 638 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 639 | * FindAtomW (KERNEL32.@) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 640 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 641 | ATOM WINAPI FindAtomW( LPCWSTR str ) |
| 642 | { |
| 643 | return ATOM_FindAtomW( str, TRUE ); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | static UINT ATOM_GetAtomNameA( ATOM atom, LPSTR buffer, INT count, BOOL local ) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 648 | { |
| 649 | INT len; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 650 | |
| 651 | if (count <= 0) |
| 652 | { |
| 653 | SetLastError( ERROR_MORE_DATA ); |
| 654 | return 0; |
| 655 | } |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 656 | if (atom < MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 657 | { |
| 658 | char name[8]; |
| 659 | if (!atom) |
| 660 | { |
| 661 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 662 | return 0; |
| 663 | } |
| 664 | len = sprintf( name, "#%d", atom ); |
| 665 | lstrcpynA( buffer, name, count ); |
| 666 | } |
| 667 | else |
| 668 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 669 | WCHAR full_name[MAX_ATOM_LEN]; |
| 670 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 671 | len = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 672 | SERVER_START_REQ( get_atom_name ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 673 | { |
Alexandre Julliard | d8a8c11 | 2001-10-12 18:45:29 +0000 | [diff] [blame] | 674 | req->atom = atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 675 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 676 | wine_server_set_reply( req, full_name, sizeof(full_name) ); |
| 677 | if (!wine_server_call_err( req )) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 678 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 679 | len = WideCharToMultiByte( CP_ACP, 0, full_name, |
| 680 | wine_server_reply_size(reply) / sizeof(WCHAR), |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 681 | buffer, count - 1, NULL, NULL ); |
| 682 | if (!len) len = count; /* overflow */ |
| 683 | else buffer[len] = 0; |
| 684 | } |
| 685 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 686 | SERVER_END_REQ; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 687 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 688 | |
| 689 | if (len && count <= len) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 690 | { |
| 691 | SetLastError( ERROR_MORE_DATA ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 692 | buffer[count-1] = 0; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 693 | return 0; |
| 694 | } |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 695 | TRACE( "(%s) %x -> %s\n", local ? "local" : "global", atom, debugstr_a(buffer) ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 696 | return len; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 697 | } |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 698 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 699 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 700 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 701 | * GlobalGetAtomNameA (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 702 | * |
| 703 | * Retrieves a copy of the string associated with an atom. |
| 704 | * |
| 705 | * RETURNS |
| 706 | * Length of string in characters: Success |
| 707 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 708 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 709 | UINT WINAPI GlobalGetAtomNameA( |
| 710 | ATOM atom, /* [in] Atom identifier */ |
| 711 | LPSTR buffer, /* [out] Pointer to buffer for atom string */ |
| 712 | INT count ) /* [in] Size of buffer */ |
| 713 | { |
| 714 | return ATOM_GetAtomNameA( atom, buffer, count, FALSE ); |
| 715 | } |
| 716 | |
| 717 | |
| 718 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 719 | * GetAtomNameA (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 720 | * Retrieves a copy of the string associated with the atom. |
| 721 | * |
| 722 | * RETURNS |
| 723 | * Length of string: Success |
| 724 | * 0: Failure |
| 725 | */ |
| 726 | UINT WINAPI GetAtomNameA( |
| 727 | ATOM atom, /* [in] Atom */ |
| 728 | LPSTR buffer, /* [out] Pointer to string for atom string */ |
| 729 | INT count) /* [in] Size of buffer */ |
| 730 | { |
| 731 | return ATOM_GetAtomNameA( atom, buffer, count, TRUE ); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | static UINT ATOM_GetAtomNameW( ATOM atom, LPWSTR buffer, INT count, BOOL local ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 736 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 737 | INT len; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 738 | |
| 739 | if (count <= 0) |
| 740 | { |
| 741 | SetLastError( ERROR_MORE_DATA ); |
| 742 | return 0; |
| 743 | } |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 744 | if (atom < MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 745 | { |
| 746 | char name[8]; |
| 747 | if (!atom) |
| 748 | { |
| 749 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 750 | return 0; |
| 751 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 752 | sprintf( name, "#%d", atom ); |
| 753 | len = MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, count ); |
| 754 | if (!len) buffer[count-1] = 0; /* overflow */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 755 | } |
| 756 | else |
| 757 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 758 | WCHAR full_name[MAX_ATOM_LEN]; |
| 759 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 760 | len = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 761 | SERVER_START_REQ( get_atom_name ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 762 | { |
Alexandre Julliard | d8a8c11 | 2001-10-12 18:45:29 +0000 | [diff] [blame] | 763 | req->atom = atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 764 | req->local = local; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 765 | wine_server_set_reply( req, full_name, sizeof(full_name) ); |
| 766 | if (!wine_server_call_err( req )) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 767 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 768 | len = wine_server_reply_size(reply) / sizeof(WCHAR); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 769 | if (count > len) count = len + 1; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 770 | memcpy( buffer, full_name, (count-1) * sizeof(WCHAR) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 771 | buffer[count-1] = 0; |
| 772 | } |
| 773 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 774 | SERVER_END_REQ; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 775 | if (!len) return 0; |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 776 | } |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 777 | TRACE( "(%s) %x -> %s\n", local ? "local" : "global", atom, debugstr_w(buffer) ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 778 | return len; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 779 | } |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 780 | |
| 781 | |
| 782 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 783 | * GlobalGetAtomNameW (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 784 | */ |
| 785 | UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
| 786 | { |
| 787 | return ATOM_GetAtomNameW( atom, buffer, count, FALSE); |
| 788 | } |
| 789 | |
| 790 | |
| 791 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 792 | * GetAtomNameW (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 793 | */ |
| 794 | UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
| 795 | { |
| 796 | return ATOM_GetAtomNameW( atom, buffer, count, TRUE ); |
| 797 | } |