Rewrote atom functions in kernel32

svn path=/trunk/; revision=1926
This commit is contained in:
Eric Kohl 2001-05-27 15:40:31 +00:00
parent 4790ca37b0
commit eb7f6b07c8
6 changed files with 461 additions and 480 deletions

View file

@ -1,58 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: include/kernel32/atom.h
* PURPOSE: Include file for lib/kernel32/atom.c
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
* UPDATE HISTORY:
* Created 01/11/98
*/
/********************************************************************
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
********************************************************************/
#ifndef Atoms__h
#define Atoms__h
#include <windows.h>
//#include <ctype.h>
//#include <types.h>
typedef unsigned long ATOMID;
typedef struct {
ATOMID q; /* what a string 'hashes' to */
long idx; /* index into data table */
long refcnt; /* how many clients have it */
long idsize; /* space used by this slot */
} ATOMENTRY;
typedef ATOMENTRY *LPATOMENTRY;
typedef struct {
ATOMENTRY *AtomTable; /* pointer to table data */
WCHAR *AtomData; /* pointer to name data */
unsigned long TableSize; /* number items in this table */
unsigned long DataSize; /* space used by string data */
LPVOID lpDrvData;
} ATOMTABLE;
typedef ATOMTABLE *LPATOMTABLE;
#endif /* Atoms__h */

View file

@ -391,6 +391,7 @@ typedef const unsigned short *LPCWSTR;
typedef unsigned short RTL_ATOM;
typedef unsigned short *PRTL_ATOM;
typedef WORD ATOM;
typedef struct _COORD {
SHORT X;

View file

@ -39,7 +39,6 @@
#include <ntos/console.h>
#include <ntos/keyboard.h>
#include <ntos/heap.h>
#include <ntos/atom.h>
#include <ntos/mm.h>
#include <ntos/file.h>
#include <ntos/ps.h>

View file

@ -1,494 +1,536 @@
/* $Id: atom.c,v 1.12 2001/03/31 01:17:29 dwelch Exp $
/* $Id: atom.c,v 1.13 2001/05/27 15:40:31 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/kernel32/misc/atom.c
* PURPOSE: Atom functions
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
* modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ]
* PROGRAMMER: Eric Kohl ( ariadne@xs4all.nl)
* UPDATE HISTORY:
* Created 01/11/98
* Full rewrite 27/05/2001
*/
#include <ddk/ntddk.h>
#include <kernel32/atom.h>
#include <kernel32/proc.h>
#include <kernel32/thread.h>
#include <wchar.h>
#include <string.h>
//#include <stdlib.h>
#include <windows.h>
#include <kernel32/error.h>
/*
* System global and local atom tables.
* What does "global" mean? The scope is
* the attached process or ANY process?
* In the second case, we need to call
* csrss.exe.
*/
#define iswlower(c) (c >= L'a' && c <= L'z')
#if 1
static ATOMTABLE GlobalAtomTable;
static ATOMTABLE LocalAtomTable;
/* internal functions */
ATOM GLDeleteAtom(ATOMTABLE *at, ATOM nAtom);
ATOM AWGLAddAtom( ATOMTABLE *at, const WCHAR *lpString);
ATOM AWGLFindAtom(ATOMTABLE *at, const WCHAR *lpString);
UINT AWGLGetAtomName(ATOMTABLE *at,ATOM atom, WCHAR *lpString, int nSize);
static ATOMENTRY *GetAtomPointer(ATOMTABLE *,int);
static ATOMID AtomHashString(const WCHAR *,int *);
#define ATOMBASE 0xcc00
int unicode2ansi( char *ansi,const WCHAR *uni, int s);
int ansi2unicode( WCHAR *uni,const char *ansi, int s);
#define NDEBUG
#include <kernel32/kernel32.h>
ATOM STDCALL
GlobalDeleteAtom(ATOM nAtom)
{
return GLDeleteAtom(&GlobalAtomTable, nAtom);
}
/* GLOBALS *******************************************************************/
static PRTL_ATOM_TABLE LocalAtomTable = NULL;
static PRTL_ATOM_TABLE GetLocalAtomTable(VOID);
BOOL STDCALL
InitAtomTable(DWORD nSize)
{
/* nSize should be a prime number */
if ( nSize < 4 || nSize >= 512 )
{
nSize = 37;
}
if (LocalAtomTable.lpDrvData == NULL)
{
LocalAtomTable.lpDrvData =
RtlAllocateHeap(GetProcessHeap(),
(HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY),
(nSize * sizeof (ATOMENTRY)));
}
return TRUE;
}
ATOM STDCALL
DeleteAtom(ATOM nAtom)
{
return GLDeleteAtom(&LocalAtomTable, nAtom);
}
/* FUNCTIONS *****************************************************************/
ATOM STDCALL
GlobalAddAtomA(LPCSTR lpString)
{
UINT BufLen = strlen(lpString);
WCHAR* lpBuffer;
ATOM atom;
lpBuffer =
(WCHAR *) RtlAllocateHeap(GetProcessHeap(),
(HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY),
(BufLen * sizeof (WCHAR)));
ansi2unicode(lpBuffer, lpString, BufLen);
atom = AWGLAddAtom(&GlobalAtomTable, lpBuffer);
RtlFreeHeap(GetProcessHeap(), 0, lpBuffer);
return(atom);
UNICODE_STRING AtomName;
NTSTATUS Status;
ATOM Atom;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
RtlCreateUnicodeStringFromAsciiz(&AtomName,
(LPSTR)lpString);
Status = NtAddAtom(AtomName.Buffer,
&Atom);
RtlFreeUnicodeString(&AtomName);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
GlobalAddAtomW(LPCWSTR lpString)
{
return AWGLAddAtom(&GlobalAtomTable, lpString);
ATOM Atom;
NTSTATUS Status;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
Status = NtAddAtom((LPWSTR)lpString,
&Atom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
GlobalDeleteAtom(ATOM nAtom)
{
NTSTATUS Status;
if (nAtom < 0xC000)
{
return 0;
}
Status = NtDeleteAtom(nAtom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return nAtom;
}
return 0;
}
ATOM STDCALL
GlobalFindAtomA(LPCSTR lpString)
{
ATOM a;
UINT BufLen = strlen(lpString);
WCHAR *lpBuffer = (WCHAR *)RtlAllocateHeap(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*sizeof(WCHAR));
ansi2unicode(lpBuffer, lpString,BufLen);
a = AWGLFindAtom(&GlobalAtomTable, lpBuffer);
RtlFreeHeap(GetProcessHeap(),0,lpBuffer);
return a;
UNICODE_STRING AtomName;
NTSTATUS Status;
ATOM Atom;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
RtlCreateUnicodeStringFromAsciiz(&AtomName,
(LPSTR)lpString);
Status = NtFindAtom(AtomName.Buffer,
&Atom);
RtlFreeUnicodeString(&AtomName);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
GlobalFindAtomW(const WCHAR *lpString)
GlobalFindAtomW(LPCWSTR lpString)
{
return AWGLFindAtom(&GlobalAtomTable, lpString);
}
ATOM Atom;
NTSTATUS Status;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
Status = NtFindAtom((LPWSTR)lpString,
&Atom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
UINT STDCALL
GlobalGetAtomNameA(ATOM nAtom,
char *lpBuffer,
LPSTR lpBuffer,
int nSize)
{
WCHAR *lpUnicode = (WCHAR *)RtlAllocateHeap(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,nSize *sizeof(WCHAR));
UINT x = AWGLGetAtomName(&GlobalAtomTable,nAtom, lpUnicode,nSize);
unicode2ansi(lpBuffer,lpUnicode,nSize);
RtlFreeHeap(GetProcessHeap(),0,lpUnicode);
return x;
{
PATOM_BASIC_INFORMATION Buffer;
UNICODE_STRING AtomNameU;
ANSI_STRING AtomName;
ULONG BufferSize;
ULONG ReturnLength;
NTSTATUS Status;
BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
BufferSize);
Status = NtQueryInformationAtom(nAtom,
AtomBasicInformation,
(PVOID)&Buffer,
BufferSize,
&ReturnLength);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return 0;
}
RtlInitUnicodeString(&AtomNameU,
Buffer->Name);
AtomName.Buffer = lpBuffer;
AtomName.Length = 0;
AtomName.MaximumLength = nSize;
RtlUnicodeStringToAnsiString(&AtomName,
&AtomNameU,
FALSE);
ReturnLength = AtomName.Length;
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return ReturnLength;
}
UINT STDCALL
GlobalGetAtomNameW(ATOM nAtom,
WCHAR * lpBuffer,
LPWSTR lpBuffer,
int nSize)
{
return AWGLGetAtomName(&GlobalAtomTable, nAtom, lpBuffer, nSize);
PATOM_BASIC_INFORMATION Buffer;
ULONG BufferSize;
ULONG ReturnLength;
NTSTATUS Status;
BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
BufferSize);
Status = NtQueryInformationAtom(nAtom,
AtomBasicInformation,
(PVOID)&Buffer,
BufferSize,
&ReturnLength);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return 0;
}
wcscpy(lpBuffer, Buffer->Name);
ReturnLength = Buffer->NameLength / sizeof(WCHAR);
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return ReturnLength;
}
static PRTL_ATOM_TABLE
GetLocalAtomTable(VOID)
{
if (LocalAtomTable != NULL)
{
return LocalAtomTable;
}
RtlCreateAtomTable(37,
&LocalAtomTable);
return LocalAtomTable;
}
BOOL STDCALL
InitAtomTable(DWORD nSize)
{
NTSTATUS Status;
/* nSize should be a prime number */
if ( nSize < 4 || nSize >= 512 )
{
nSize = 37;
}
if (LocalAtomTable == NULL)
{
Status = RtlCreateAtomTable(nSize,
&LocalAtomTable);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
}
}
return TRUE;
}
ATOM STDCALL
AddAtomA(const char *lpString)
AddAtomA(LPCSTR lpString)
{
UINT BufLen = strlen(lpString);
WCHAR *lpBuffer = (WCHAR*)RtlAllocateHeap(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*2);
ATOM a;
ansi2unicode(lpBuffer, lpString,BufLen);
a = AWGLAddAtom(&LocalAtomTable, lpBuffer);
RtlFreeHeap(GetProcessHeap(),0,lpBuffer);
return a;
PRTL_ATOM_TABLE AtomTable;
UNICODE_STRING AtomName;
NTSTATUS Status;
ATOM Atom;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
AtomTable = GetLocalAtomTable();
RtlCreateUnicodeStringFromAsciiz(&AtomName,
(LPSTR)lpString);
Status = RtlAddAtomToAtomTable(AtomTable,
AtomName.Buffer,
&Atom);
RtlFreeUnicodeString(&AtomName);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
AddAtomW(const WCHAR * lpString)
AddAtomW(LPCWSTR lpString)
{
return AWGLAddAtom(&LocalAtomTable, lpString);
PRTL_ATOM_TABLE AtomTable;
ATOM Atom;
NTSTATUS Status;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
AtomTable = GetLocalAtomTable();
Status = RtlAddAtomToAtomTable(AtomTable,
(LPWSTR)lpString,
&Atom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
FindAtomA(const char *lpString)
{
UINT BufLen = strlen(lpString);
WCHAR *lpBuffer = (WCHAR *)RtlAllocateHeap(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*2);
ATOM a;
ansi2unicode(lpBuffer, lpString,BufLen);
a = AWGLFindAtom(&LocalAtomTable, lpBuffer);
RtlFreeHeap(GetProcessHeap(),0,lpBuffer);
return a;
}
ATOM STDCALL
FindAtomW(const WCHAR * lpString)
DeleteAtom(ATOM nAtom)
{
return AWGLFindAtom(&LocalAtomTable, lpString);
PRTL_ATOM_TABLE AtomTable;
NTSTATUS Status;
if (nAtom < 0xC000)
{
return 0;
}
AtomTable = GetLocalAtomTable();
Status = RtlDeleteAtomFromAtomTable(AtomTable,
nAtom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return nAtom;
}
return 0;
}
ATOM STDCALL
FindAtomA(LPCSTR lpString)
{
PRTL_ATOM_TABLE AtomTable;
UNICODE_STRING AtomName;
NTSTATUS Status;
ATOM Atom;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
AtomTable = GetLocalAtomTable();
RtlCreateUnicodeStringFromAsciiz(&AtomName,
(LPSTR)lpString);
Status = RtlLookupAtomInAtomTable(AtomTable,
AtomName.Buffer,
&Atom);
RtlFreeUnicodeString(&AtomName);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
ATOM STDCALL
FindAtomW(LPCWSTR lpString)
{
PRTL_ATOM_TABLE AtomTable;
ATOM Atom;
NTSTATUS Status;
if (HIWORD((ULONG)lpString) == 0)
{
if ((ULONG)lpString >= 0xC000)
{
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
return (ATOM)0;
}
return (ATOM)LOWORD((ULONG)lpString);
}
AtomTable = GetLocalAtomTable();
Status = RtlLookupAtomInAtomTable(AtomTable,
(LPWSTR)lpString,
&Atom);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return (ATOM)0;
}
return Atom;
}
UINT STDCALL
GetAtomNameA(ATOM nAtom,
char *lpBuffer,
LPSTR lpBuffer,
int nSize)
{
LPWSTR lpUnicode = (WCHAR *)RtlAllocateHeap(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,nSize *2);
UINT x = AWGLGetAtomName(&GlobalAtomTable, nAtom,lpUnicode,nSize);
unicode2ansi(lpBuffer,lpUnicode,nSize);
RtlFreeHeap(GetProcessHeap(),0,lpUnicode);
return x;
PRTL_ATOM_TABLE AtomTable;
PWCHAR Buffer;
UNICODE_STRING AtomNameU;
ANSI_STRING AtomName;
ULONG NameLength;
NTSTATUS Status;
AtomTable = GetLocalAtomTable();
NameLength = nSize * sizeof(WCHAR);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
NameLength);
Status = RtlQueryAtomInAtomTable(AtomTable,
nAtom,
NULL,
NULL,
Buffer,
&NameLength);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return 0;
}
RtlInitUnicodeString(&AtomNameU,
Buffer);
AtomName.Buffer = lpBuffer;
AtomName.Length = 0;
AtomName.MaximumLength = nSize;
RtlUnicodeStringToAnsiString(&AtomName,
&AtomNameU,
FALSE);
NameLength = AtomName.Length;
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return NameLength;
}
UINT STDCALL
GetAtomNameW(ATOM nAtom,
WCHAR * lpBuffer,
LPWSTR lpBuffer,
int nSize)
{
return AWGLGetAtomName(&LocalAtomTable,nAtom,lpBuffer, nSize);
}
PRTL_ATOM_TABLE AtomTable;
ULONG NameLength;
NTSTATUS Status;
ATOM
GLDeleteAtom(ATOMTABLE *at, ATOM nAtom)
{
ATOMENTRY *lp;
/* a free slot has q == 0 && refcnt == 0 */
if((lp = GetAtomPointer(at,nAtom - ATOMBASE))) {
if(lp->idsize)
lp->refcnt--;
if(lp->refcnt == 0) {
RtlFreeHeap(GetProcessHeap(),0,at->AtomTable);
at->AtomTable = NULL;
RtlFreeHeap(GetProcessHeap(),0,at->AtomData);
at->AtomData = NULL;
return lp->q = 0;
}
}
return nAtom;
}
AtomTable = GetLocalAtomTable();
ATOM
AWGLAddAtom(ATOMTABLE *at, const WCHAR *lpString)
{
ATOM atom;
ATOMID q;
LPATOMENTRY lp,lpfree;
int index,freeindex;
int atomlen;
int newlen;
/* if we already have it, bump refcnt */
if((atom = AWGLFindAtom(at, lpString )))
{
lp = GetAtomPointer(at,atom - ATOMBASE);
if(lp->idsize) lp->refcnt++;
return atom;
}
/* add to a free slot */
q = AtomHashString(lpString,&atomlen);
lpfree = 0;
freeindex = 0;
for(index = 0;(lp = GetAtomPointer(at,index));index++)
{
if(lp->q == 0 && lp->refcnt == 0)
{
if(lp->idsize > atomlen)
{
if ((lpfree == 0) ||
(lpfree->idsize > lp->idsize))
{
lpfree = lp;
freeindex = index;
}
}
}
}
/* intatoms do not take space in data, but do get new entries */
/* an INTATOM will have length of 0 */
if(lpfree && atomlen)
{
lpfree->q = q;
lpfree->refcnt = 1;
lstrcpynW(&at->AtomData[lpfree->idx],lpString,atomlen);
return freeindex + ATOMBASE;
}
/* no space was available, or we have an INTATOM */
/* so expand or create the table */
if(at->AtomTable == 0)
{
at->AtomTable =
(ATOMENTRY*) RtlAllocateHeap(GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
sizeof(ATOMENTRY));
at->TableSize = 1;
lp = at->AtomTable;
index = 0;
}
else
{
at->TableSize++;
at->AtomTable =
(ATOMENTRY*) RtlReAllocateHeap(GetProcessHeap(),0,
(LPVOID) at->AtomTable,
at->TableSize * sizeof(ATOMENTRY));
lp = &at->AtomTable[at->TableSize - 1];
}
/* set in the entry */
lp->refcnt = 1;
lp->q = q;
lp->idsize = atomlen;
lp->idx = 0;
/* add an entry if not intatom... */
if(atomlen) {
newlen = at->DataSize + atomlen;
if(at->AtomData == 0) {
at->AtomData =
(WCHAR*)RtlAllocateHeap(GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
newlen*2);
if (at->AtomData == NULL)
{
return(0);
}
lp->idx = 0;
} else {
at->AtomData =
(WCHAR*)RtlReAllocateHeap(GetProcessHeap(), 0, at->AtomData, newlen*2);
if (at->AtomData == NULL)
{
return(0);
}
lp->idx = at->DataSize;
}
lstrcpyW(&at->AtomData[lp->idx],lpString);
at->DataSize = newlen;
}
return index + ATOMBASE;
}
ATOM
AWGLFindAtom(ATOMTABLE *at, const WCHAR *lpString)
{
ATOMID q;
LPATOMENTRY lp;
int index;
int atomlen;
/* convert string to 'q', and get length */
q = AtomHashString(lpString,&atomlen);
/* find the q value, note: this could be INTATOM */
/* if q matches, then do case insensitive compare*/
for(index = 0;(lp = GetAtomPointer(at,index));index++) {
if(lp->q == q) {
if(HIWORD(lpString) == 0)
return ATOMBASE + index;
if(lstrcmpiW(&at->AtomData[lp->idx],lpString) == 0)
return ATOMBASE + index;
}
}
return 0;
}
UINT
AWGLGetAtomName(ATOMTABLE *at, ATOM atom, WCHAR *lpString,int len)
{
ATOMENTRY *lp;
WCHAR *atomstr;
int atomlen;
/* return the atom name, or create the INTATOM */
if((lp = GetAtomPointer(at,atom - ATOMBASE))) {
if(lp->idsize) {
atomlen = lstrlenW(atomstr = &at->AtomData[lp->idx]);
if (atomlen < len)
lstrcpyW(lpString,atomstr);
else {
lstrcpynW(lpString,atomstr,len-1);
lpString[len-1] = '\0';
}
return (UINT)lstrlenW(lpString);
} else {
//wsprintf((wchar *)lpString,"#%d",lp->q);
return (UINT)lstrlenW(lpString);
}
}
NameLength = nSize * sizeof(WCHAR);
Status = RtlQueryAtomInAtomTable(AtomTable,
nAtom,
NULL,
NULL,
lpBuffer,
&NameLength);
if (!NT_SUCCESS(Status))
{
return 0;
}
return(NameLength / sizeof(WCHAR));
}
/********************************************************/
/* convert alphanumeric string to a 'q' value. */
/* 'q' values do not need to be unique, they just limit */
/* the search we need to make to find a string */
/********************************************************/
static ATOMID
AtomHashString(const WCHAR * lp,int *lplen)
{
ATOMID q;
WCHAR *p,ch;
int len;
/* if we have an intatom... */
if(HIWORD(lp) == 0) {
if(lplen) *lplen = 0;
return (ATOMID)lp;
}
/* convert the string to an internal representation */
for(p=(WCHAR *)lp,q=0,len=0;(p++,ch=*p++);len++)
q = (q<<1) + iswlower(ch)?towupper(ch):ch;
/* 0 is reserved for empty slots */
if(q == 0)
q++;
/* avoid strlen later */
/* check out with unicode */
if(lplen) {
*lplen = ++len;
}
return q;
}
/********************************************************/
/* convert an atom index into a pointer into an */
/* atom table. This validates the pointer is in */
/* range, and that the data is accessible */
/********************************************************/
static ATOMENTRY *
GetAtomPointer(ATOMTABLE *at,int index)
{
ATOMENTRY *lp;
/* if no table, then no pointers */
if(at->AtomTable == 0)
return 0;
/* bad index */
if((index < 0) || (index >= at->TableSize))
return 0;
/* we have a pointer */
lp = &at->AtomTable[index];
/* is the index past stored data, validity check */
/* LATER: is the size of the entry within the available space */
if(lp->idx > at->DataSize)
return 0;
return lp;
}
int ansi2unicode( WCHAR *uni,const char *ansi, int s)
{
register int i;
for(i=0;i<=s;i++)
uni[i] = (WCHAR)ansi[i];
return i;
}
int
unicode2ansi( char *ansi,const WCHAR *uni, int s)
{
register int i;
for(i=0;i<=s;i++)
ansi[i] = (char)uni[i];
return i;
}
#endif
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: comm.c,v 1.1 2001/03/31 01:17:29 dwelch Exp $
/* $Id: comm.c,v 1.2 2001/05/27 15:40:31 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -11,7 +11,6 @@
*/
#include <ddk/ntddk.h>
#include <kernel32/atom.h>
#include <kernel32/proc.h>
#include <kernel32/thread.h>
#include <wchar.h>

View file

@ -1,4 +1,4 @@
/* $Id: profile.c,v 1.1 2001/03/31 01:17:29 dwelch Exp $
/* $Id: profile.c,v 1.2 2001/05/27 15:40:31 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -11,16 +11,14 @@
*/
#include <ddk/ntddk.h>
#include <kernel32/atom.h>
#include <kernel32/proc.h>
#include <kernel32/thread.h>
#include <wchar.h>
#include <string.h>
//#include <stdlib.h>
BOOL
STDCALL
CloseProfileUserMapping ( VOID)
BOOL STDCALL
CloseProfileUserMapping (VOID)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;