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 | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 8 | * Warning: The code assumes that LocalAlloc() returns a block aligned |
| 9 | * on a 4-bytes boundary (because of the shifting done in |
| 10 | * HANDLETOATOM). If this is not the case, the allocation code will |
| 11 | * have to be changed. |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <stdlib.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 16 | #include <string.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 17 | #include <ctype.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 18 | |
Patrik Stridvall | fdcfdb9 | 1999-06-12 14:55:11 +0000 | [diff] [blame] | 19 | #include "wine/winbase16.h" |
| 20 | #include "wine/winuser16.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 21 | #include "winuser.h" |
Patrik Stridvall | 1ed4ecf | 1999-06-26 14:58:24 +0000 | [diff] [blame] | 22 | #include "global.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 23 | #include "instance.h" |
| 24 | #include "ldt.h" |
| 25 | #include "stackframe.h" |
| 26 | #include "user.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 27 | #include "debugtools.h" |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 28 | |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 29 | #ifdef CONFIG_IPC |
| 30 | #include "dde_atom.h" |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 33 | DEFAULT_DEBUG_CHANNEL(atom) |
| 34 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 35 | #define DEFAULT_ATOMTABLE_SIZE 37 |
| 36 | #define MIN_STR_ATOM 0xc000 |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 37 | #define MAX_ATOM_LEN 255 |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 39 | #define ATOMTOHANDLE(atom) ((HANDLE16)(atom) << 2) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 40 | #define HANDLETOATOM(handle) ((ATOM)(0xc000 | ((handle) >> 2))) |
| 41 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 42 | #define HAS_ATOM_TABLE(sel) \ |
| 43 | ((INSTANCEDATA*)PTR_SEG_OFF_TO_LIN(sel,0))->atomtable != 0) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 44 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 45 | #define GET_ATOM_TABLE(sel) ((ATOMTABLE*)PTR_SEG_OFF_TO_LIN(sel, \ |
| 46 | ((INSTANCEDATA*)PTR_SEG_OFF_TO_LIN(sel,0))->atomtable)) |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 47 | |
| 48 | typedef struct |
| 49 | { |
| 50 | HANDLE16 next; |
| 51 | WORD refCount; |
| 52 | BYTE length; |
| 53 | BYTE str[1]; |
| 54 | } ATOMENTRY; |
| 55 | |
| 56 | typedef struct |
| 57 | { |
| 58 | WORD size; |
| 59 | HANDLE16 entries[1]; |
| 60 | } ATOMTABLE; |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 61 | |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 62 | static WORD ATOM_GlobalTable = 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 63 | |
| 64 | /*********************************************************************** |
| 65 | * ATOM_InitTable |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 66 | * |
| 67 | * NOTES |
| 68 | * Should this validate the value of entries to be 0 < x < 0x3fff? |
| 69 | * |
| 70 | * RETURNS |
| 71 | * Handle: Success |
| 72 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 73 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 74 | static HANDLE16 ATOM_InitTable( |
| 75 | WORD selector, /* [in] Segment */ |
| 76 | WORD entries /* [in] Size of atom table */ |
| 77 | ) { |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 78 | int i; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 79 | HANDLE16 handle; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 80 | ATOMTABLE *table; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 81 | |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 82 | /* We consider the first table to be initialized as the global table. |
| 83 | * This works, as USER (both built-in and native) is the first one to |
| 84 | * register ... |
| 85 | */ |
| 86 | |
| 87 | if (!ATOM_GlobalTable) ATOM_GlobalTable = selector; |
| 88 | |
| 89 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 90 | /* Allocate the table */ |
| 91 | |
| 92 | handle = LOCAL_Alloc( selector, LMEM_FIXED, |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 93 | sizeof(ATOMTABLE) + (entries-1) * sizeof(HANDLE16) ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 94 | if (!handle) return 0; |
| 95 | table = (ATOMTABLE *)PTR_SEG_OFF_TO_LIN( selector, handle ); |
| 96 | table->size = entries; |
| 97 | for (i = 0; i < entries; i++) table->entries[i] = 0; |
| 98 | |
| 99 | /* Store a pointer to the table in the instance data */ |
| 100 | |
| 101 | ((INSTANCEDATA *)PTR_SEG_OFF_TO_LIN( selector, 0 ))->atomtable = handle; |
| 102 | return handle; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 105 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 106 | /*********************************************************************** |
| 107 | * ATOM_Init |
| 108 | * |
| 109 | * Global table initialisation. |
| 110 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 111 | BOOL ATOM_Init( WORD globalTableSel ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 112 | { |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 113 | return ATOM_InitTable( globalTableSel, DEFAULT_ATOMTABLE_SIZE ) != 0; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | /*********************************************************************** |
| 118 | * ATOM_GetTable |
| 119 | * |
| 120 | * Return a pointer to the atom table of a given segment, creating |
| 121 | * it if necessary. |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 122 | * |
| 123 | * RETURNS |
| 124 | * Pointer to table: Success |
| 125 | * NULL: Failure |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 126 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 127 | static ATOMTABLE *ATOM_GetTable( |
| 128 | WORD selector, /* [in] Segment */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 129 | BOOL create /* [in] Create */ ) |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 130 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 131 | INSTANCEDATA *ptr = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN( selector, 0 ); |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 132 | if (ptr->atomtable) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 133 | { |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 134 | ATOMTABLE *table = (ATOMTABLE *)((char *)ptr + ptr->atomtable); |
| 135 | if (table->size) return table; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 136 | } |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 137 | if (!create) return NULL; |
| 138 | if (!ATOM_InitTable( selector, DEFAULT_ATOMTABLE_SIZE )) return NULL; |
| 139 | /* Reload ptr in case it moved in linear memory */ |
| 140 | ptr = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN( selector, 0 ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 141 | return (ATOMTABLE *)((char *)ptr + ptr->atomtable); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
| 145 | /*********************************************************************** |
| 146 | * ATOM_MakePtr |
| 147 | * |
| 148 | * Make an ATOMENTRY pointer from a handle (obtained from GetAtomHandle()). |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 149 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 150 | static ATOMENTRY *ATOM_MakePtr( |
| 151 | WORD selector, /* [in] Segment */ |
| 152 | HANDLE16 handle /* [in] Handle */ |
| 153 | ) { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 154 | return (ATOMENTRY *)PTR_SEG_OFF_TO_LIN( selector, handle ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | /*********************************************************************** |
| 159 | * ATOM_Hash |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 160 | * RETURNS |
| 161 | * The hash value for the input string |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 162 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 163 | static WORD ATOM_Hash( |
| 164 | WORD entries, /* [in] Total number of entries */ |
| 165 | LPCSTR str, /* [in] Pointer to string to hash */ |
| 166 | WORD len /* [in] Length of string */ |
| 167 | ) { |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 168 | WORD i, hash = 0; |
| 169 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 170 | TRACE("%x, %s, %x\n", entries, str, len); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 171 | |
Alexandre Julliard | cdd0923 | 1994-01-12 11:12:51 +0000 | [diff] [blame] | 172 | for (i = 0; i < len; i++) hash ^= toupper(str[i]) + i; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 173 | return hash % entries; |
| 174 | } |
| 175 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 176 | static BOOL ATOM_IsIntAtom(LPCSTR atomstr,WORD *atomid) { |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 177 | LPSTR xend; |
| 178 | |
| 179 | if (!HIWORD(atomstr)) { |
| 180 | *atomid = LOWORD(atomstr); |
| 181 | return TRUE; |
| 182 | } |
| 183 | if (atomstr[0]!='#') |
| 184 | return FALSE; |
| 185 | *atomid=strtol(atomstr+1,&xend,10); |
| 186 | if (*xend) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 187 | FIXME("found atom named '%s'\n",atomstr); |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 188 | return FALSE; |
| 189 | } |
| 190 | return TRUE; |
| 191 | } |
| 192 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 193 | |
| 194 | /*********************************************************************** |
| 195 | * ATOM_AddAtom |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 196 | * |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 197 | * Windows DWORD aligns the atom entry size. |
| 198 | * The remaining unused string space created by the alignment |
| 199 | * gets padded with '\0's in a certain way to ensure |
| 200 | * that at least one trailing '\0' remains. |
| 201 | * |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 202 | * RETURNS |
| 203 | * Atom: Success |
| 204 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 205 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 206 | static ATOM ATOM_AddAtom( |
| 207 | WORD selector, /* [in] Segment */ |
| 208 | LPCSTR str /* [in] Pointer to the string to add */ |
| 209 | ) { |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 210 | WORD hash; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 211 | HANDLE16 entry; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 212 | ATOMENTRY * entryPtr; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 213 | ATOMTABLE * table; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 214 | int len, ae_len; |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 215 | WORD iatom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 216 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 217 | TRACE("0x%x, %s\n", selector, str); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 218 | |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 219 | if (ATOM_IsIntAtom(str,&iatom)) |
| 220 | return iatom; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 221 | if ((len = strlen( str )) > MAX_ATOM_LEN) len = MAX_ATOM_LEN; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 222 | if (!(table = ATOM_GetTable( selector, TRUE ))) return 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 223 | hash = ATOM_Hash( table->size, str, len ); |
| 224 | entry = table->entries[hash]; |
| 225 | while (entry) |
| 226 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 227 | entryPtr = ATOM_MakePtr( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 228 | if ((entryPtr->length == len) && |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 229 | (!lstrncmpiA( entryPtr->str, str, len ))) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 230 | { |
| 231 | entryPtr->refCount++; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 232 | TRACE("-- existing 0x%x\n", entry); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 233 | return HANDLETOATOM( entry ); |
| 234 | } |
| 235 | entry = entryPtr->next; |
| 236 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 237 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 238 | ae_len = (sizeof(ATOMENTRY)+len+3) & ~3; |
| 239 | entry = LOCAL_Alloc( selector, LMEM_FIXED, ae_len); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 240 | if (!entry) return 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 241 | /* Reload the table ptr in case it moved in linear memory */ |
| 242 | table = ATOM_GetTable( selector, FALSE ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 243 | entryPtr = ATOM_MakePtr( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 244 | entryPtr->next = table->entries[hash]; |
| 245 | entryPtr->refCount = 1; |
| 246 | entryPtr->length = len; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 247 | strncpy( entryPtr->str, str, ae_len - sizeof(ATOMENTRY) + 1); /* always use strncpy ('\0's padding) */ |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 248 | table->entries[hash] = entry; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 249 | TRACE("-- new 0x%x\n", entry); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 250 | return HANDLETOATOM( entry ); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | /*********************************************************************** |
| 255 | * ATOM_DeleteAtom |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 256 | * RETURNS |
| 257 | * 0: Success |
| 258 | * Atom: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 259 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 260 | static ATOM ATOM_DeleteAtom( |
| 261 | WORD selector, /* [in] Segment */ |
| 262 | ATOM atom /* [in] Atom to delete */ |
| 263 | ) { |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 264 | ATOMENTRY * entryPtr; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 265 | ATOMTABLE * table; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 266 | HANDLE16 entry, *prevEntry; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 267 | WORD hash; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 268 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 269 | TRACE("0x%x, 0x%x\n", selector, atom); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 270 | |
| 271 | if (atom < MIN_STR_ATOM) return 0; /* Integer atom */ |
| 272 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 273 | if (!(table = ATOM_GetTable( selector, FALSE ))) return 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 274 | entry = ATOMTOHANDLE( atom ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 275 | entryPtr = ATOM_MakePtr( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 276 | |
| 277 | /* Find previous atom */ |
| 278 | hash = ATOM_Hash( table->size, entryPtr->str, entryPtr->length ); |
| 279 | prevEntry = &table->entries[hash]; |
| 280 | while (*prevEntry && *prevEntry != entry) |
| 281 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 282 | ATOMENTRY * prevEntryPtr = ATOM_MakePtr( selector, *prevEntry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 283 | prevEntry = &prevEntryPtr->next; |
| 284 | } |
| 285 | if (!*prevEntry) return atom; |
| 286 | |
| 287 | /* Delete atom */ |
| 288 | if (--entryPtr->refCount == 0) |
| 289 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 290 | *prevEntry = entryPtr->next; |
| 291 | LOCAL_Free( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 292 | } |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /*********************************************************************** |
| 298 | * ATOM_FindAtom |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 299 | * RETURNS |
| 300 | * Atom: Success |
| 301 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 302 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 303 | static ATOM ATOM_FindAtom( |
| 304 | WORD selector, /* [in] Segment */ |
| 305 | LPCSTR str /* [in] Pointer to string to find */ |
| 306 | ) { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 307 | ATOMTABLE * table; |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 308 | WORD hash,iatom; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 309 | HANDLE16 entry; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 310 | int len; |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 311 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 312 | TRACE("%x, %s\n", selector, str); |
Marcus Meissner | 88065ba | 1998-12-02 10:00:48 +0000 | [diff] [blame] | 313 | if (ATOM_IsIntAtom(str,&iatom)) |
| 314 | return iatom; |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 315 | if ((len = strlen( str )) > 255) len = 255; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 316 | if (!(table = ATOM_GetTable( selector, FALSE ))) return 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 317 | hash = ATOM_Hash( table->size, str, len ); |
| 318 | entry = table->entries[hash]; |
| 319 | while (entry) |
| 320 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 321 | ATOMENTRY * entryPtr = ATOM_MakePtr( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 322 | if ((entryPtr->length == len) && |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 323 | (!lstrncmpiA( entryPtr->str, str, len ))) |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 324 | { TRACE("-- found %x\n", entry); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 325 | return HANDLETOATOM( entry ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 326 | } |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 327 | entry = entryPtr->next; |
| 328 | } |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 329 | TRACE("-- not found\n"); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /*********************************************************************** |
| 335 | * ATOM_GetAtomName |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 336 | * RETURNS |
| 337 | * Length of string copied to buffer: Success |
| 338 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 339 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 340 | static UINT ATOM_GetAtomName( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 341 | WORD selector, /* [in] Segment */ |
| 342 | ATOM atom, /* [in] Atom identifier */ |
| 343 | LPSTR buffer, /* [out] Pointer to buffer for atom string */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 344 | INT count /* [in] Size of buffer */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 345 | ) { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 346 | ATOMTABLE * table; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 347 | ATOMENTRY * entryPtr; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 348 | HANDLE16 entry; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 349 | char * strPtr; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 350 | UINT len; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 351 | char text[8]; |
| 352 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 353 | TRACE("%x, %x\n", selector, atom); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 354 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 355 | if (!count) return 0; |
| 356 | if (atom < MIN_STR_ATOM) |
| 357 | { |
| 358 | sprintf( text, "#%d", atom ); |
| 359 | len = strlen(text); |
| 360 | strPtr = text; |
| 361 | } |
| 362 | else |
| 363 | { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 364 | if (!(table = ATOM_GetTable( selector, FALSE ))) return 0; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 365 | entry = ATOMTOHANDLE( atom ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 366 | entryPtr = ATOM_MakePtr( selector, entry ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 367 | len = entryPtr->length; |
| 368 | strPtr = entryPtr->str; |
| 369 | } |
| 370 | if (len >= count) len = count-1; |
| 371 | memcpy( buffer, strPtr, len ); |
| 372 | buffer[len] = '\0'; |
| 373 | return len; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 378 | * InitAtomTable16 (KERNEL.68) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 379 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 380 | WORD WINAPI InitAtomTable16( WORD entries ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 381 | { |
Alexandre Julliard | 737fa07 | 1998-11-15 17:29:15 +0000 | [diff] [blame] | 382 | if (!entries) entries = DEFAULT_ATOMTABLE_SIZE; /* sanity check */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 383 | return ATOM_InitTable( CURRENT_DS, entries ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | |
| 387 | /*********************************************************************** |
| 388 | * GetAtomHandle (KERNEL.73) |
| 389 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 390 | HANDLE16 WINAPI GetAtomHandle16( ATOM atom ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 391 | { |
| 392 | if (atom < MIN_STR_ATOM) return 0; |
| 393 | return ATOMTOHANDLE( atom ); |
| 394 | } |
| 395 | |
| 396 | |
| 397 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 398 | * AddAtom16 (KERNEL.70) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 399 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 400 | ATOM WINAPI AddAtom16( SEGPTR str ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 401 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 402 | ATOM atom; |
| 403 | HANDLE16 ds = CURRENT_DS; |
| 404 | |
| 405 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
| 406 | if (SELECTOR_TO_ENTRY(LOWORD(str)) == SELECTOR_TO_ENTRY(ds)) |
| 407 | { |
| 408 | /* If the string is in the same data segment as the atom table, make */ |
| 409 | /* a copy of the string to be sure it doesn't move in linear memory. */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 410 | char buffer[MAX_ATOM_LEN+1]; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 411 | lstrcpynA( buffer, (char *)PTR_SEG_TO_LIN(str), sizeof(buffer) ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 412 | atom = ATOM_AddAtom( ds, buffer ); |
| 413 | } |
| 414 | else atom = ATOM_AddAtom( ds, (LPCSTR)PTR_SEG_TO_LIN(str) ); |
| 415 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
| 419 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 420 | * AddAtom32A (KERNEL32.0) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 421 | * Adds a string to the atom table and returns the atom identifying the |
| 422 | * string. |
| 423 | * |
| 424 | * RETURNS |
| 425 | * Atom: Success |
| 426 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 427 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 428 | ATOM WINAPI AddAtomA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 429 | LPCSTR str /* [in] Pointer to string to add */ |
| 430 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 431 | return GlobalAddAtomA( str ); /* FIXME */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
| 435 | /*********************************************************************** |
| 436 | * AddAtom32W (KERNEL32.1) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 437 | * See AddAtom32A |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 438 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 439 | ATOM WINAPI AddAtomW( LPCWSTR str ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 440 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 441 | return GlobalAddAtomW( str ); /* FIXME */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
| 445 | /*********************************************************************** |
| 446 | * DeleteAtom16 (KERNEL.71) |
| 447 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 448 | ATOM WINAPI DeleteAtom16( ATOM atom ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 449 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 450 | return ATOM_DeleteAtom( CURRENT_DS, atom ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
| 454 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 455 | * DeleteAtom32 (KERNEL32.69) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 456 | * Decrements the reference count of a string atom. If count becomes |
| 457 | * zero, the string associated with the atom is removed from the table. |
| 458 | * |
| 459 | * RETURNS |
| 460 | * 0: Success |
| 461 | * Atom: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 462 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 463 | ATOM WINAPI DeleteAtom( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 464 | ATOM atom /* [in] Atom to delete */ |
| 465 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 466 | return GlobalDeleteAtom( atom ); /* FIXME */ |
| 467 | } |
| 468 | |
| 469 | |
| 470 | /*********************************************************************** |
| 471 | * FindAtom16 (KERNEL.69) |
| 472 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 473 | ATOM WINAPI FindAtom16( SEGPTR str ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 474 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 475 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
| 476 | return ATOM_FindAtom( CURRENT_DS, (LPCSTR)PTR_SEG_TO_LIN(str) ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 481 | * FindAtom32A (KERNEL32.117) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 482 | * Searches the local atom table for the string and returns the atom |
| 483 | * associated with that string. |
| 484 | * |
| 485 | * RETURNS |
| 486 | * Atom: Success |
| 487 | * 0: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 488 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 489 | ATOM WINAPI FindAtomA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 490 | LPCSTR str /* [in] Pointer to string to find */ |
| 491 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 492 | return GlobalFindAtomA( str ); /* FIXME */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | |
| 496 | /*********************************************************************** |
| 497 | * FindAtom32W (KERNEL32.118) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 498 | * See FindAtom32A |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 499 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 500 | ATOM WINAPI FindAtomW( LPCWSTR str ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 501 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 502 | return GlobalFindAtomW( str ); /* FIXME */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
| 506 | /*********************************************************************** |
| 507 | * GetAtomName16 (KERNEL.72) |
| 508 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 509 | UINT16 WINAPI GetAtomName16( ATOM atom, LPSTR buffer, INT16 count ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 510 | { |
| 511 | return (UINT16)ATOM_GetAtomName( CURRENT_DS, atom, buffer, count ); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /*********************************************************************** |
| 516 | * GetAtomName32A (KERNEL32.149) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 517 | * Retrieves a copy of the string associated with the atom. |
| 518 | * |
| 519 | * RETURNS |
| 520 | * Length of string: Success |
| 521 | * 0: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 522 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 523 | UINT WINAPI GetAtomNameA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 524 | ATOM atom, /* [in] Atom */ |
| 525 | LPSTR buffer, /* [out] Pointer to string for atom string */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 526 | INT count /* [in] Size of buffer */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 527 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 528 | return GlobalGetAtomNameA( atom, buffer, count ); /* FIXME */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
| 532 | /*********************************************************************** |
| 533 | * GetAtomName32W (KERNEL32.150) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 534 | * See GetAtomName32A |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 535 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 536 | UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 537 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 538 | return GlobalGetAtomNameW( atom, buffer, count ); /* FIXME */ |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | |
| 542 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 543 | * GlobalAddAtom16 (USER.268) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 544 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 545 | ATOM WINAPI GlobalAddAtom16( SEGPTR str ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 546 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 547 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 548 | #ifdef CONFIG_IPC |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 549 | return DDE_GlobalAddAtom( str ); |
| 550 | #else |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 551 | return ATOM_AddAtom( ATOM_GlobalTable, (LPCSTR)PTR_SEG_TO_LIN(str) ); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 552 | #endif |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | |
| 556 | /*********************************************************************** |
| 557 | * GlobalAddAtom32A (KERNEL32.313) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 558 | * Adds a character string to the global atom table and returns a unique |
| 559 | * value identifying the string. |
| 560 | * |
| 561 | * RETURNS |
| 562 | * Atom: Success |
| 563 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 564 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 565 | ATOM WINAPI GlobalAddAtomA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 566 | LPCSTR str /* [in] Pointer to string to add */ |
| 567 | ) { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 568 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 569 | return ATOM_AddAtom( ATOM_GlobalTable, str ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
| 573 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 574 | * GlobalAddAtom32W (KERNEL32.314) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 575 | * See GlobalAddAtom32A |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 576 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 577 | ATOM WINAPI GlobalAddAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 578 | { |
| 579 | char buffer[MAX_ATOM_LEN+1]; |
| 580 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 581 | lstrcpynWtoA( buffer, str, sizeof(buffer) ); |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 582 | return ATOM_AddAtom( ATOM_GlobalTable, buffer ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | /*********************************************************************** |
| 587 | * GlobalDeleteAtom (USER.269) (KERNEL32.317) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 588 | * Decrements the reference count of a string atom. If the count is |
| 589 | * zero, the string associated with the atom is removed from the table. |
| 590 | * |
| 591 | * RETURNS |
| 592 | * 0: Success |
| 593 | * Atom: Failure |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 594 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 595 | ATOM WINAPI GlobalDeleteAtom( |
| 596 | ATOM atom /* [in] Atom to delete */ |
| 597 | ) { |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 598 | #ifdef CONFIG_IPC |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 599 | return DDE_GlobalDeleteAtom( atom ); |
| 600 | #else |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 601 | return ATOM_DeleteAtom( ATOM_GlobalTable, atom ); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 602 | #endif |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
| 606 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 607 | * GlobalFindAtom16 (USER.270) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 608 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 609 | ATOM WINAPI GlobalFindAtom16( SEGPTR str ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 610 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 611 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 612 | #ifdef CONFIG_IPC |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 613 | return DDE_GlobalFindAtom( str ); |
| 614 | #else |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 615 | return ATOM_FindAtom( ATOM_GlobalTable, (LPCSTR)PTR_SEG_TO_LIN(str) ); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 616 | #endif |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | |
| 620 | /*********************************************************************** |
| 621 | * GlobalFindAtom32A (KERNEL32.318) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 622 | * Searches the atom table for the string and returns the atom |
| 623 | * associated with it. |
| 624 | * |
| 625 | * RETURNS |
| 626 | * Atom: Success |
| 627 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 628 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 629 | ATOM WINAPI GlobalFindAtomA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 630 | LPCSTR str /* [in] Pointer to string to search for */ |
| 631 | ) { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 632 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 633 | return ATOM_FindAtom( ATOM_GlobalTable, str ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | |
| 637 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 638 | * GlobalFindAtom32W (KERNEL32.319) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 639 | * See GlobalFindAtom32A |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 640 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 641 | ATOM WINAPI GlobalFindAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 642 | { |
| 643 | char buffer[MAX_ATOM_LEN+1]; |
| 644 | if (!HIWORD(str)) return (ATOM)LOWORD(str); /* Integer atom */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 645 | lstrcpynWtoA( buffer, str, sizeof(buffer) ); |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 646 | return ATOM_FindAtom( ATOM_GlobalTable, buffer ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | /*********************************************************************** |
| 651 | * GlobalGetAtomName16 (USER.271) |
| 652 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 653 | UINT16 WINAPI GlobalGetAtomName16( ATOM atom, LPSTR buffer, INT16 count ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 654 | { |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 655 | #ifdef CONFIG_IPC |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 656 | return DDE_GlobalGetAtomName( atom, buffer, count ); |
| 657 | #else |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 658 | return (UINT16)ATOM_GetAtomName( ATOM_GlobalTable, atom, buffer, count ); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 659 | #endif |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | |
| 663 | /*********************************************************************** |
| 664 | * GlobalGetAtomName32A (KERNEL32.323) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 665 | * Retrieves a copy of the string associated with an atom. |
| 666 | * |
| 667 | * RETURNS |
| 668 | * Length of string in characters: Success |
| 669 | * 0: Failure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 670 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 671 | UINT WINAPI GlobalGetAtomNameA( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 672 | ATOM atom, /* [in] Atom identifier */ |
| 673 | LPSTR buffer, /* [out] Pointer to buffer for atom string */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 674 | INT count /* [in] Size of buffer */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 675 | ) { |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 676 | return ATOM_GetAtomName( ATOM_GlobalTable, atom, buffer, count ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 677 | } |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 678 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 679 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 680 | /*********************************************************************** |
| 681 | * GlobalGetAtomName32W (KERNEL32.324) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 682 | * See GlobalGetAtomName32A |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 683 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 684 | UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 685 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 686 | char tmp[MAX_ATOM_LEN+1]; |
Ulrich Weigand | 9e29021 | 1998-11-01 18:00:09 +0000 | [diff] [blame] | 687 | ATOM_GetAtomName( ATOM_GlobalTable, atom, tmp, sizeof(tmp) ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 688 | lstrcpynAtoW( buffer, tmp, count ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 689 | return lstrlenW( buffer ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 690 | } |