Author: cfinck
Date: Sun Jun 22 15:58:56 2008
New Revision: 34050
URL:
http://svn.reactos.org/svn/reactos?rev=34050&view=rev
Log:
Add a library "host_wcsfuncs" with implementations for UTF-16 string functions
needed for some host tools
Instead of copying those functions into every host tool, which needs it (as we did
previously), we can now implement them all in this library and link the host tools to it.
If USE_HOST_WCSFUNCS is not defined, the "wcsfuncs.h" file will define them to
the CRT functions (so this library does not create overhead, when the code is built for
the target platform)
See issue #3285 for more details.
Added:
trunk/reactos/include/host/wcsfuncs.h (with props)
trunk/reactos/lib/host/
trunk/reactos/lib/host/directory.rbuild (with props)
trunk/reactos/lib/host/wcsfuncs/
trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c (with props)
trunk/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild (with props)
Modified:
trunk/reactos/lib/cmlib/cminit.c
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/lib/lib.rbuild
trunk/reactos/tools/mkhive/mkhive.h
trunk/reactos/tools/mkhive/mkhive.rbuild
trunk/reactos/tools/mkhive/registry.c
trunk/reactos/tools/mkhive/rtl.c
Added: trunk/reactos/include/host/wcsfuncs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/host/wcsfuncs.h?re…
==============================================================================
--- trunk/reactos/include/host/wcsfuncs.h (added)
+++ trunk/reactos/include/host/wcsfuncs.h [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -1,0 +1,24 @@
+/*
+ PROJECT: ReactOS
+ LICENSE: GPL v2 or any later version
+ FILE: include/host/wcsfuncs.h
+ PURPOSE: Header for the "host_wcsfuncs" static library
+ COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+*/
+
+#ifndef _HOST_WCSFUNCS_H
+#define _HOST_WCSFUNCS_H
+
+#ifdef USE_HOST_WCSFUNCS
+ /* Function prototypes */
+ SIZE_T utf16_wcslen(PCWSTR str);
+ PWSTR utf16_wcschr(PWSTR str, WCHAR c);
+ INT utf16_wcsncmp(PCWSTR string1, PCWSTR string2, size_t count);
+#else
+ /* Define the utf16_ functions to the CRT functions */
+ #define utf16_wcslen wcslen
+ #define utf16_wcschr wcschr
+ #define utf16_wcsncmp wcsncmp
+#endif
+
+#endif
Propchange: trunk/reactos/include/host/wcsfuncs.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/lib/cmlib/cminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cminit.c?rev=340…
==============================================================================
--- trunk/reactos/lib/cmlib/cminit.c [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cminit.c [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -19,7 +19,7 @@
SIZE_T NameSize;
/* Allocate the cell */
- NameSize = wcslen(Name) * sizeof(WCHAR);
+ NameSize = utf16_wcslen(Name) * sizeof(WCHAR);
RootCellIndex = HvAllocateCell(Hive,
FIELD_OFFSET(CM_KEY_NODE, Name) + NameSize,
Stable,
Modified: trunk/reactos/lib/cmlib/cmlib.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=3405…
==============================================================================
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -9,21 +9,25 @@
#define CMLIB_H
#ifdef CMLIB_HOST
-#include <host/typedefs.h>
-#include <stdio.h>
-#include <string.h>
-
-// Definitions copied from <ntstatus.h>
-// We only want to include host headers, so we define them manually
-#define STATUS_SUCCESS ((NTSTATUS)0x00000000)
-#define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002)
-#define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
-#define STATUS_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC000009A)
-#define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)
-#define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
-#define STATUS_REGISTRY_RECOVERED ((NTSTATUS)0x40000009)
-
-#endif
+ #include <host/typedefs.h>
+ #include <stdio.h>
+ #include <string.h>
+
+ // Definitions copied from <ntstatus.h>
+ // We only want to include host headers, so we define them manually
+ #define STATUS_SUCCESS ((NTSTATUS)0x00000000)
+ #define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002)
+ #define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
+ #define STATUS_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC000009A)
+ #define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)
+ #define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
+ #define STATUS_REGISTRY_RECOVERED ((NTSTATUS)0x40000009)
+
+ /* For <host/wcsfuncs.h> */
+ #define USE_HOST_WCSFUNCS
+#endif
+
+#include <host/wcsfuncs.h>
//
// Debug support switch
Added: trunk/reactos/lib/host/directory.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/host/directory.rbuild?…
==============================================================================
--- trunk/reactos/lib/host/directory.rbuild (added)
+++ trunk/reactos/lib/host/directory.rbuild [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -1,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE group SYSTEM "../../tools/rbuild/project.dtd">
+<group
xmlns:xi="http://www.w3.org/2001/XInclude">
+ <directory name="wcsfuncs">
+ <xi:include href="wcsfuncs/wcsfuncs.rbuild" />
+ </directory>
+</group>
Propchange: trunk/reactos/lib/host/directory.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/host/wcsfuncs/wcsfuncs…
==============================================================================
--- trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c (added)
+++ trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -1,0 +1,48 @@
+/*
+ PROJECT: ReactOS
+ LICENSE: GPL v2 or any later version
+ FILE: lib/host/wcsfuncs/wcsfuncs.c
+ PURPOSE: Reimplemented wide-character string functions for host tools (to be
independent of the host wchar_t size)
+ COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+*/
+
+#include <host/typedefs.h>
+
+/* Function implementations */
+SIZE_T utf16_wcslen(PCWSTR str)
+{
+ SIZE_T i;
+
+ for(i = 0; str[i]; i++);
+
+ return i;
+}
+
+PWSTR utf16_wcschr(PWSTR str, WCHAR c)
+{
+ SIZE_T i;
+
+ for(i = 0; str[i] && str[i] != c; i++);
+
+ if(str[i])
+ return &str[i];
+ else
+ return NULL;
+}
+
+INT utf16_wcsncmp(PCWSTR string1, PCWSTR string2, size_t count)
+{
+ while(count--)
+ {
+ if(*string1 != *string2)
+ return 1;
+
+ if(*string1 == 0)
+ return 0;
+
+ string1++;
+ string2++;
+ }
+
+ return 0;
+}
Propchange: trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/host/wcsfuncs/wcsfuncs…
==============================================================================
--- trunk/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild (added)
+++ trunk/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -1,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
+<module name="host_wcsfuncs" type="staticlibrary">
+ <include base="ReactOS">include</include>
+ <file>wcsfuncs.c</file>
+</module>
Propchange: trunk/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/lib/lib.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/lib.rbuild?rev=34050&a…
==============================================================================
--- trunk/reactos/lib/lib.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/lib.rbuild [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -21,6 +21,9 @@
</directory>
<directory name="fslib">
<xi:include href="fslib/directory.rbuild" />
+ </directory>
+ <directory name="host">
+ <xi:include href="host/directory.rbuild" />
</directory>
<directory name="inflib">
<xi:include href="inflib/inflib.rbuild" />
Modified: trunk/reactos/tools/mkhive/mkhive.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.h?rev=…
==============================================================================
--- trunk/reactos/tools/mkhive/mkhive.h [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.h [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -31,6 +31,9 @@
#include <stdlib.h>
#include <host/typedefs.h>
+
+#define USE_HOST_WCSFUNCS
+#include <host/wcsfuncs.h>
// Definitions copied from <ntstatus.h>
// We only want to include host headers, so we define them manually
@@ -96,13 +99,6 @@
#define GCC_PACKED __attribute__((packed))
#endif//_MSC_VER
-/* rtl.c */
-PWSTR
-xwcschr(
- PWSTR String,
- WCHAR Char
-);
-
#endif /* __MKHIVE_H__ */
/* EOF */
Modified: trunk/reactos/tools/mkhive/mkhive.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.rbuild…
==============================================================================
--- trunk/reactos/tools/mkhive/mkhive.rbuild [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.rbuild [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -11,6 +11,7 @@
<compilerflag>-fshort-wchar</compilerflag>
<library>inflibhost</library>
<library>cmlibhost</library>
+ <library>host_wcsfuncs</library>
<file>binhive.c</file>
<file>cmi.c</file>
<file>mkhive.c</file>
Modified: trunk/reactos/tools/mkhive/registry.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/registry.c?re…
==============================================================================
--- trunk/reactos/tools/mkhive/registry.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/registry.c [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -127,7 +127,7 @@
LocalKeyName = (PWSTR)KeyName;
for (;;)
{
- End = (PWSTR) xwcschr(LocalKeyName, '\\');
+ End = (PWSTR) utf16_wcschr(LocalKeyName, '\\');
if (End)
{
KeyString.Buffer = LocalKeyName;
@@ -138,9 +138,9 @@
RtlInitUnicodeString(&KeyString, LocalKeyName);
/* Redirect from 'CurrentControlSet' to 'ControlSet001' */
- if (!xwcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
- ParentKey->NameSize == 12 &&
- !memcmp(ParentKey->Name, L"SYSTEM", 12))
+ if (!utf16_wcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
+ ParentKey->NameSize == 12 &&
+ !memcmp(ParentKey->Name, L"SYSTEM", 12))
RtlInitUnicodeString(&KeyString, L"ControlSet001");
/* Check subkey in memory structure */
Modified: trunk/reactos/tools/mkhive/rtl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/rtl.c?rev=340…
==============================================================================
--- trunk/reactos/tools/mkhive/rtl.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/rtl.c [iso-8859-1] Sun Jun 22 15:58:56 2008
@@ -9,41 +9,6 @@
#include "mkhive.h"
#include <bitmap.c>
-
-SIZE_T xwcslen( PCWSTR String ) {
- SIZE_T i;
-
- for( i = 0; String[i]; i++ );
-
- return i;
-}
-
-PWSTR xwcschr( PWSTR String, WCHAR Char )
-{
- SIZE_T i;
-
- for( i = 0; String[i] && String[i] != Char; i++ );
-
- if( String[i] ) return &String[i];
- else return NULL;
-}
-
-int xwcsncmp(PCWSTR s1, PCWSTR s2, size_t n)
-{
- while(n--)
- {
- if(*s1 != *s2)
- return 1;
-
- if(*s1 == 0)
- return 0;
-
- s1++;
- s2++;
- }
-
- return 0;
-}
/*
* @implemented
@@ -88,7 +53,7 @@
if(SourceString)
{
- DestSize = xwcslen(SourceString) * sizeof(WCHAR);
+ DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
DestinationString->Length = (USHORT)DestSize;
DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
}