From: Alex M. <ale...@us...> - 2004-12-22 20:26:11
|
Update of /cvsroot/win32forth/win32forth-extsrc/extsrc/wincon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22808/extsrc/wincon Added Files: BUILD.BAT BUILD.C LCC.TXT README.TXT TEST.F TestWinconVersion.f WINCON.C WINCON.DEF WINCON.DSP WINCON.DSW resource.h wincon.aps wincon.i wincon.rc wincon.txt Log Message: Commit of base Win32Forth-extsrc --- NEW FILE: WINCON.DEF --- LIBRARY WINCON EXPORTS wcFindWin32Constant wcEnumWin32Constants wcDllGetVersion FindWin32Constant EnumWin32Constants --- NEW FILE: BUILD.BAT --- @echo off rem Build wincon.dll rem Create wincon.i from standard windows headers. rem Also creates wincon.x for all the non-included constants rem Change the -I option to point to your windows include directory. rem cpp.exe -I/msdev/include build.c > nul cpp.exe -Id:/vc/include build.c > nul rem rebuild the dll nmake /f wincon.mak CFG="wincon - Win32 Release" rem copy the files to the current directory copy release\wincon.dll . copy release\wincon.lib . --- NEW FILE: LCC.TXT --- The authors of this software are Christopher W. Fraser and David R. Hanson. Copyright (c) 1991,1992,1993,1994,1995 by AT&T, Christopher W. Fraser, and David R. Hanson. All Rights Reserved. Permission to use, copy, modify, and distribute this software for any purpose, subject to the provisions described below, without fee is hereby granted, provided that this entire notice is included in all copies of any software that is or includes a copy or modification of this software and in all copies of the supporting documentation for such software. THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. lcc is not public-domain software, shareware, and it is not protected by a `copyleft' agreement, like the code from the Free Software Foundation. lcc is available free for your personal research and instructional use under the `fair use' provisions of the copyright law. You may, however, redistribute lcc in whole or in part provided you acknowledge its source and include this CPYRIGHT file. You may, for example, include the distribution in a CDROM of free software, provided you charge only for the media, or mirror the distribution files at your site. You may not sell lcc or any product derived from it in which it is a significant part of the value of the product. Using the lcc front end to build a C syntax checker is an example of this kind of product. You may use parts of lcc in products as long as you charge for only those components that are entirely your own and you acknowledge the use of lcc clearly in all product documentation and distribution media. You must state clearly that your product uses or is based on parts of lcc and that lcc is available free of charge. You must also request that bug reports on your product be reported to you. Using the lcc front end to build a C compiler for the Motorola 88000 chip and charging for and distributing only the 88000 code generator is an example of this kind of product. Using parts of lcc in other products is more problematic. For example, using parts of lcc in a C++ compiler could save substantial time and effort and therefore contribute significantly to the profitability of the product. This kind of use, or any use where others stand to make a profit from what is primarily our work, is subject to negotiation. Chris Fraser / cw...@be... David Hanson / dr...@cs... Tue Apr 2 15:37:45 PST 1996 --- NEW FILE: BUILD.C --- // precompiler input to load windows constants // required predefined values #define WINVER 0x0400 #define _WIN32 #define _M_IX86 300 #define _STDCALL_SUPPORTED // optional to make the dll smaller //#define WIN32_LEAN_AND_MEAN //#define NOMCX // Modem Configuration Extensions //#define NOKANJI // Kanji support stuff //#define NOIME #include <windows.h> #include <commctrl.h> --- NEW FILE: TEST.F --- \ test WINCON.dll : HAVE ( -- f ) BL WORD FIND NIP ; HAVE ^IMAGE [IF] ( Win32Forth ) WINLIBRARY WINCON.DLL VARIABLE VAL : FIND-CONSTANT ( addr len -- n f ) 2>R VAL REL>ABS R> R> REL>ABS CALL wcFindWin32Constant VAL @ SWAP ; \ enum constants \ int wcEnumWin32Constants(char* addr, int len, CALLBACKPROC* proc) \ int callback(char* addr, int len, int value) 3 CALLBACK: .CONSTANT ( addr len value -- f ) DROP SWAP ABS>REL SWAP DUP ?CR TYPE SPACE KEY? 0= ; : WC ( <pattern> -- ) &.CONSTANT REL>ABS BL WORD COUNT SWAP REL>ABS CALL wcEnumWin32Constants DROP ; [ELSE] ( Andrew's own ) EMPTY DECIMAL LIBRARY WINCON.DLL 3 PROC wcFindWin32Constant ( addr len *val -- f ) 3 PROC wcEnumWin32Constants ( addr len function -- n ) VARIABLE VAL : FIND-CONSTANT ( addr len -- n f ) VAL CALL wcFindWin32Constant VAL @ SWAP ; \ enum constants \ int wcEnumWin32Constants(char* addr, int len, CALLBACKPROC* proc) \ int callback(char* addr, int len, int value) : (.CONSTANT) ( addr len value -- f ) DROP DUP ?CR TYPE SPACE KEY? 0= ; ' (.CONSTANT) 3 CALLBACK .CONSTANT : WC ( <pattern> -- ) BL WORD COUNT .CONSTANT CALL wcEnumWin32Constants DROP ; [THEN] : TEST ( <name> -- ) BL WORD COUNT FIND-CONSTANT IF ." = " . ELSE ." not found" DROP THEN ; --- NEW FILE: WINCON.DSP --- # Microsoft Developer Studio Project File - Name="wincon" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** NICHT BEARBEITEN ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=wincon - Win32 Release !MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE !MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl !MESSAGE !MESSAGE NMAKE /f "WINCON.MAK". !MESSAGE !MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben !MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: !MESSAGE !MESSAGE NMAKE /f "WINCON.MAK" CFG="wincon - Win32 Release" !MESSAGE !MESSAGE Für die Konfiguration stehen zur Auswahl: !MESSAGE !MESSAGE "wincon - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") !MESSAGE "wincon - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "wincon - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir ".\Release" # PROP BASE Intermediate_Dir ".\Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir ".\Release" # PROP Intermediate_Dir ".\Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c # ADD CPP /nologo /Zp4 /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\Wincon.dll" !ELSEIF "$(CFG)" == "wincon - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir ".\Debug" # PROP BASE Intermediate_Dir ".\Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir ".\Debug" # PROP Intermediate_Dir ".\Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c # ADD CPP /nologo /Zp4 /MT /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c # ADD BASE MTL /nologo /D "_DEBUG" /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\Wincon.dll" !ENDIF # Begin Target # Name "wincon - Win32 Release" # Name "wincon - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90" # Begin Source File SOURCE=.\wincon.c # End Source File # Begin Source File SOURCE=.\wincon.def # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" # Begin Source File SOURCE=.\wincon.rc # End Source File # End Group # Begin Source File SOURCE=.\wincon.i # End Source File # End Target # End Project --- NEW FILE: WINCON.DSW --- Microsoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "wincon"=.\WINCON.DSP - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### --- NEW FILE: wincon.i --- CONSTANT(WINVER) CONSTANT(STRICT) CONSTANT(MAX_PATH) CONSTANT(NULL) CONSTANT(FALSE) CONSTANT(TRUE) CONSTANT(ANYSIZE_ARRAY) CONSTANT(MEMORY_ALLOCATION_ALIGNMENT) CONSTANT(ADDRESS_TAG_BIT) CONSTANT(MAXUINT_PTR) CONSTANT(MAXINT_PTR) CONSTANT(MININT_PTR) CONSTANT(MAXULONG_PTR) CONSTANT(MAXLONG_PTR) CONSTANT(MINLONG_PTR) CONSTANT(MAXUHALF_PTR) CONSTANT(MAXHALF_PTR) CONSTANT(MINHALF_PTR) CONSTANT(APPLICATION_ERROR_MASK) [...15475 lines suppressed...] CONSTANT(TB_ADDSTRING) CONSTANT(TB_SETCOLORSCHEME) CONSTANT(TB_GETCOLORSCHEME) CONSTANT(TB_SETUNICODEFORMAT) CONSTANT(TB_GETUNICODEFORMAT) CONSTANT(SB_GETTEXT) CONSTANT(SB_SETTEXT) CONSTANT(SB_GETTEXTLENGTH) CONSTANT(SB_SETTIPTEXT) CONSTANT(SB_GETTIPTEXT) CONSTANT(SB_SETUNICODEFORMAT) CONSTANT(SB_GETUNICODEFORMAT) CONSTANT(SB_SETBKCOLOR) CONSTANT(TBM_SETUNICODEFORMAT) CONSTANT(TBM_GETUNICODEFORMAT) CONSTANT(UDM_SETUNICODEFORMAT) CONSTANT(UDM_GETUNICODEFORMAT) CONSTANT(LVM_SETUNICODEFORMAT) CONSTANT(LVM_GETUNICODEFORMAT) CONSTANT(LVITEM_V1_SIZE) --- NEW FILE: wincon.txt --- Wincon.dll is a Win32 DLL that provides access to almose 8000 Windows constants. These constants are needed to write Win32 programs, but adding them to the Forth dictionary as constants takes up considerable space and slows down the interpreter. Also, it would be very tedious to type in all 8000 of them. So what I did was create a DLL that has all of the Windows constants and a single exported function: BOOL FindConstant(char *addr, int len, int *value) FindConstant takes the address and length of a string with the name of the constant and searches its internal dictionary (hashed for speed). If the constant is found, the function returns TRUE (1) and the constant value is stored at the pointer passed as the third argument. If the constant is not found, the function returns FALSE (0). What Tom Zimmer did for Win32Forth was to vector number and replace it with a new function as follows: : newnumber ( string -- number flag ) <is this a valid number?> if <return number and true> else <find constant in windon.dll) if <return value and true> else <return false> then then ; This makes all of the constants available to the programmer and they are treated just like numbers. There is no dictionary overhead and the DLL is not needed for a turnkeyed program. ====================================================================== I created wincon.dll with Visual C++ 4.2 and the modified source for the C preprocessor supplied with the C compiler "lcc". When I run the C preprocessor on windows.h, it produces a list of all the numeric #defines it finds. I then compile this into a DLL. Building wincon.dll: 1. modify build.bat to point to your include directory 2. type "build" at the command prompt Files in this zip: BUILD.BAT batch file to build wincon.dll BUILD.C intput to preprocessor CPP.EXE modified preprocessor (from lcc) CPP.ZIP cpp source LCC.TXT lcc copyright notice README.TXT this file TEST.FTH test file WINCON.C source to wincon.dll WINCON.DEF definition of export functions WINCON.DLL the dll itself (release build) WINCON.LIB import library WINCON.MAK make file WINCON.MDP Visual C++ 4.2 project file ====================================================================== The source to cpp.exe was found in the source distribution for the c-compiler "lcc". The source was attributed to Dennis Ritchie, but I cannot find any credits in it. The lcc copyright notice is in the file lcc.txt. The small amount of code I have added to cpp and the source for wincon.dll is released to the public domain. Andrew McKewan, August 1996 ====================================================================== --- NEW FILE: wincon.aps --- (This appears to be a binary file; contents omitted.) --- NEW FILE: wincon.rc --- //Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // Deutsch (Deutschland) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) #ifdef _WIN32 LANGUAGE LANG_GERMAN, SUBLANG_GERMAN #pragma code_page(1252) #endif //_WIN32 #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 2,0,0,1 PRODUCTVERSION 2,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "000004e4" BEGIN VALUE "Comments", "\0" VALUE "CompanyName", "Win32Forth developer team\0" VALUE "FileDescription", "Win32Forth Windows constants support\0" VALUE "FileVersion", "2, 0, 0, 1\0" VALUE "InternalName", "WINCON\0" VALUE "LegalCopyright", "\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "WINCON.DLL\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "Win32Forth\0" VALUE "ProductVersion", "2, 0, 0, 1\0" VALUE "SpecialBuild", "\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0, 1252 END END #endif // !_MAC #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED #endif // Deutsch (Deutschland) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED --- NEW FILE: TestWinconVersion.f --- \ WinconVersion.f \ Test for wcDllGetVersion() in WinCon.dll \ Written by Dirk Busch \ ------------------------------------------------------------------------------ \ current Version off WinCon.dll \ ------------------------------------------------------------------------------ 1 constant WinconBuildNumber 0 constant WinconMinorVersion 2 constant WinconMajorVersion \ ------------------------------------------------------------------------------ \ get Wincon.dll Version \ ------------------------------------------------------------------------------ : ?WinconGetVersion ( -- f ) z" WINCON.DLL" rel>abs Call LoadLibrary ?dup if dup z" wcDllGetVersion" rel>abs swap Call GetProcAddress >r Call FreeLibrary drop r> 0<> else false then ; WinLibrary WINCON.DLL 1 proc wcDllGetVersion : WinconGetVersion { \ DllVersionInfo -- BuildNumber MinorVersion MajorVersion | f } ?WinconGetVersion if 5 cells LocalAlloc: DllVersionInfo 5 cells DllVersionInfo ! DllVersionInfo rel>abs Call wcDllGetVersion NOERROR = if DllVersionInfo dup 1 cells + @ >r dup 2 cells + @ >r 3 cells + @ r> r> else false then else false then ; \ ------------------------------------------------------------------------------ \ print Wincon.dll Version \ ------------------------------------------------------------------------------ : WinconCalcVersion ( BuildNumber MinorVersion MajorVersion -- version ) 10000 * swap 100 * + + ; : (.WinConVersion) ( BuildNumber MinorVersion MajorVersion -- ) base @ >r decimal ." Version: " WinconCalcVersion ((version)) type r> base ! ; : .WinconVersion ( -- ) ." WinCon.dll " WinconGetVersion ?dup if (.WinConVersion) else 0 0 1 (.WinConVersion) \ must be an old Version off Wincon.dll then ; \ ------------------------------------------------------------------------------ \ check Wincon.dll Version \ ------------------------------------------------------------------------------ : WinconCheckVersion ( BuildNumber MinorVersion MajorVersion -- f ) WinconGetVersion ?dup if WinconCalcVersion >r WinconCalcVersion r> >= else 3drop false then ; : ValidateWinconVersion ( BuildNumber MinorVersion MajorVersion -- ) WinconCheckVersion not if ." Error: needs WinCon.dll " WinconBuildNumber WinconMinorVersion WinconMajorVersion (.WinConVersion) ." or later" abort then ; \ ------------------------------------------------------------------------------ \ Test Wincon.dll Version \ ------------------------------------------------------------------------------ : .flag ( f -- ) if ." TRUE" else ." FALSE" then ; : TestWinconVersion ( -- ) cr cr .WinconVersion \ WinCon.dll Version: 2.00.01 cr 1 0 1 3dup (.WinConVersion) WinconCheckVersion .flag \ FALSE cr 1 0 2 3dup (.WinConVersion) WinconCheckVersion .flag \ TRUE cr 1 0 3 3dup (.WinConVersion) WinconCheckVersion .flag \ TRUE cr 1 0 2 3dup (.WinConVersion) ValidateWinconVersion \ ok cr 1 0 3 3dup (.WinConVersion) ValidateWinconVersion \ ok cr 1 0 1 3dup (.WinConVersion) ValidateWinconVersion \ error cr 1 0 2 3dup (.WinConVersion) ValidateWinconVersion \ ok ; TestWinconVersion --- NEW FILE: resource.h --- //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by wincon.rc // // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif --- NEW FILE: README.TXT --- ============================================================ wincon.dll readme The source to cpp.exe was found in the source distribution for the c-compiler "lcc". The source was attributed to Dennis Ritchie, but I cannot find any credits in it. The lcc copyright notice is in the file lcc.txt. The small amount of code I have added to cpp and the source for wincon.dll is released to the public domain. Andrew McKewan, August 1996 ============================================================ The dll has a single exported function: BOOL FindConstant(char *addr, int len, int *value) Pass it the address and length of a string specifying a Windows constant. If the constant is found, the function returns TRUE (1) and the value is store at the address *value, otherwise the function returns FALSE (0). Building wincon.dll: type "build" at the command prompt Files in this zip: BUILD.BAT batch file to build wincon.dll BUILD.C intput to preprocessor CPP.EXE modified preprocessor (from lcc) CPP.ZIP cpp source LCC.TXT lcc copyright notice README.TXT this file TEST.FTH test file WINCON.C source to wincon.dll WINCON.DEF definition of export functions WINCON.DLL the dll itself (release build) WINCON.LIB import library WINCON.MAK make file WINCON.MDP Visual C++ 4.2 project file --- NEW FILE: WINCON.C --- // wincon.c // Andrew McKewan, August 1996 #define WINVER 0x0501 #include <windows.h> #include <commctrl.h> #include <Shlwapi.h> #include <stdio.h> ////////////////////////////////////////////////////////////////////// // Each entry in the list has a link field, name and value. typedef struct _Entry { struct _Entry *link; char *name; int value; } Entry ; // Add entry to table #define CONSTANT(x) {0, #x, (int)x}, // Table of names from generated wincon.i file Entry entry[] = { #include "wincon.i" {NULL,0} }; ////////////////////////////////////////////////////////////////////// // Create a hash table of the names for quick lookup. #define HASHSIZE 2003 Entry *hashTable[HASHSIZE]; unsigned int hash(char *name) { unsigned int h = 0; char c; while (c = *name++) h += c; return h % HASHSIZE; } void BuildHash() { int i; for (i = 0; entry[i].name; i++) { Entry **bucket = &hashTable[hash(entry[i].name)]; entry[i].link = *bucket; *bucket = &entry[i]; } } void CountHash() // display results of hashing { int sizes[21]; int i, n, maxi=0; Entry *ep; for (i = 0; i < 21; i++) sizes[i] = 0; for (i = 0; i < HASHSIZE; i++) { n = 0; for (ep = hashTable[i]; ep; ep = ep->link) n += 1; if (n > 20) { if (n > maxi) maxi = n; n = 20; } sizes[n] += 1; } for (i = 0; i < 21; i++) printf("%2d: %4d\n", i, sizes[i]); printf("Max = %d\n", maxi); } // Find an entry in the hash table. Return NULL if not found. Entry *FindHash(char *name) { Entry *ep = hashTable[hash(name)]; while (ep && strcmp(name, ep->name)) ep = ep->link; return ep; } ////////////////////////////////////////////////////////////////////// // Exported function to find a constant. Return TRUE if found, // and store the value in *value BOOL APIENTRY wcFindWin32Constant(char *addr, int len, int *value) { char name[256]; Entry *ep; if (len <= 0 || len > 255) return FALSE; memcpy(name, addr, len); name[len] = 0; ep = FindHash(name); if (!ep) return FALSE; *value = ep->value; return TRUE; } BOOL APIENTRY FindWin32Constant(char *addr, int len, int *value) { return wcFindWin32Constant(addr, len, value); } ////////////////////////////////////////////////////////////////////// // Enumeration the constants. The function takes a string and a callback // procedure. If a constant is found containing the passed-in string, // call the callback with the full name and value. Return the number // of constants found typedef int (WINAPI *ENUMPROC)(char*, int, int); int APIENTRY wcEnumWin32Constants(char *addr, int len, ENUMPROC callback) { int i, n = 0; int all = 0; char pattern[256]; if (len < 0 || len > 255) return 0; if (len == 0) all = 1; // show all of then!! else { memcpy(pattern, addr, len); pattern[len] = 0; } for (i = 0; i < HASHSIZE; i++) { Entry *entry = hashTable[i]; while (entry) { if (all || strstr(entry->name, pattern)) { // exit if callback returnes zero if (!callback(entry->name, strlen(entry->name), entry->value)) return n; ++n; } entry = entry->link; } } return n; } int APIENTRY EnumWin32Constants(char *addr, int len, ENUMPROC callback) { return wcEnumWin32Constants(addr, len, callback); } ////////////////////////////////////////////////////////////////////// // DLL main entry point. Initializes the hash table. BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpReserved) { hModule=hModule; lpReserved=lpReserved; switch (reason) { case DLL_PROCESS_ATTACH: BuildHash(); // CountHash(); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } // Implemented by many of the Windows Shell DLLs to allow applications to // obtain DLL-specific version information. HRESULT APIENTRY wcDllGetVersion( DLLVERSIONINFO *pdvi ) { if( pdvi == NULL ) return E_POINTER; if( pdvi->cbSize != sizeof(DLLVERSIONINFO) ) return E_FAIL; pdvi->dwMajorVersion = 2; pdvi->dwMinorVersion = 0; pdvi->dwBuildNumber = 1; pdvi->dwPlatformID = DLLVER_PLATFORM_WINDOWS; return NOERROR; } |