Author: ekohl Date: Sat May 1 12:43:39 2010 New Revision: 47071
URL: http://svn.reactos.org/svn/reactos?rev=47071&view=rev Log: [NEWINFLIB] - Change Unicode string functions from wcs* to str*W because glibc (Linux build) provides the wcs* functions but they use a wchar_t size of 32 bits instead of the required 16 bits. - Add a str*W to wcs* wrapper (infrosrtl.c) in order to use the wcs* function for the WIN32 build. - Add required str*W functions to the host library.
ATTENTION: This might break the build bot although it has been tested on Windows and Linux!!!
Added: trunk/reactos/lib/newinflib/infrosrtl.c (with props) Modified: trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c trunk/reactos/lib/newinflib/builddep.h trunk/reactos/lib/newinflib/infcore.c trunk/reactos/lib/newinflib/infget.c trunk/reactos/lib/newinflib/infhost.h trunk/reactos/lib/newinflib/infhostrtl.c trunk/reactos/lib/newinflib/inflib.rbuild trunk/reactos/lib/newinflib/infput.c trunk/reactos/lib/newinflib/infrosput.c
Modified: 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 [iso-8859-1] (original) +++ trunk/reactos/lib/host/wcsfuncs/wcsfuncs.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -18,7 +18,30 @@ return i; }
+ +SIZE_T strlenW(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; +} + +PWSTR strchrW(PWSTR str, WCHAR c) { SIZE_T i;
@@ -46,3 +69,20 @@
return 0; } + +INT strncmpW(PCWSTR string1, PCWSTR string2, size_t count) +{ + while(count--) + { + if(*string1 != *string2) + return 1; + + if(*string1 == 0) + return 0; + + string1++; + string2++; + } + + return 0; +}
Modified: trunk/reactos/lib/newinflib/builddep.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/builddep.h?re... ============================================================================== --- trunk/reactos/lib/newinflib/builddep.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/builddep.h [iso-8859-1] Sat May 1 12:43:39 2010 @@ -28,20 +28,13 @@ #define INF_STATUS_BUFFER_OVERFLOW E2BIG #define INF_SUCCESS(x) (0 == (x))
-typedef char TCHAR, *PTCHAR, *PTSTR; -typedef const TCHAR *PCTSTR; - -#define _T(x) x -#define _tcsicmp strcasecmp -#define _tcslen strlen -#define _tcscpy strcpy -#define _tcstoul strtoul -#define _tcstol strtol #define STRFMT "%s"
-#ifdef _MSC_VER -#define strcasecmp _stricmp -#endif +NTSTATUS NTAPI RtlMultiByteToUnicodeN(IN PWCHAR UnicodeString, + IN ULONG UnicodeSize, IN PULONG ResultSize, IN PCSTR MbString, IN ULONG MbSize); + +BOOLEAN NTAPI RtlIsTextUnicode( PVOID buf, INT len, INT *pf ); +
#define IS_TEXT_UNICODE_ASCII16 1 #define IS_TEXT_UNICODE_REVERSE_ASCII16 16 @@ -69,9 +62,17 @@ #include <windows.h> #define NTOS_MODE_USER #include <ndk/ntndk.h> -#include <tchar.h>
extern PVOID InfpHeap; + +INT isspaceW(WCHAR c); +INT strlenW(PCWSTR s); +PWSTR strcpyW(PWSTR d, PCWSTR s); +PWSTR strncpyW(PWSTR d, PCWSTR s, SIZE_T c); +INT strcmpiW(PCWSTR s1, PCWSTR s2); +LONG strtolW(PCWSTR s, PWSTR *e, INT r); +ULONG strtoulW(PCWSTR s, PWSTR *e, INT r); +
#define FREE(Area) RtlFreeHeap(InfpHeap, 0, (Area)) #define MALLOC(Size) RtlAllocateHeap(InfpHeap, 0, (Size))
Modified: trunk/reactos/lib/newinflib/infcore.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infcore.c?rev... ============================================================================== --- trunk/reactos/lib/newinflib/infcore.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infcore.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -154,7 +154,7 @@ Section = Cache->FirstSection; while (Section != NULL) { - if (_wcsicmp (Section->Name, Name) == 0) + if (strcmpiW(Section->Name, Name) == 0) { return Section; } @@ -182,7 +182,7 @@
/* Allocate and initialize the new section */ Size = (ULONG)FIELD_OFFSET(INFCACHESECTION, - Name[wcslen (Name) + 1]); + Name[strlenW(Name) + 1]); Section = (PINFCACHESECTION)MALLOC(Size); if (Section == NULL) { @@ -193,7 +193,7 @@ Size);
/* Copy section name */ - wcscpy (Section->Name, Name); + strcpyW(Section->Name, Name);
/* Append section */ if (Cache->FirstSection == NULL) @@ -266,14 +266,14 @@ return NULL; }
- Line->Key = (PWCHAR)MALLOC((wcslen(Key) + 1) * sizeof(WCHAR)); + Line->Key = (PWCHAR)MALLOC((strlenW(Key) + 1) * sizeof(WCHAR)); if (Line->Key == NULL) { DPRINT1("MALLOC() failed\n"); return NULL; }
- wcscpy(Line->Key, Key); + strcpyW(Line->Key, Key);
return (PVOID)Line->Key; } @@ -287,7 +287,7 @@ ULONG Size;
Size = (ULONG)FIELD_OFFSET(INFCACHEFIELD, - Data[wcslen(Data) + 1]); + Data[strlenW(Data) + 1]); Field = (PINFCACHEFIELD)MALLOC(Size); if (Field == NULL) { @@ -296,7 +296,7 @@ } ZEROMEMORY (Field, Size); - wcscpy (Field->Data, Data); + strcpyW(Field->Data, Data);
/* Append key */ if (Line->FirstField == NULL) @@ -325,7 +325,7 @@ Line = Section->FirstLine; while (Line != NULL) { - if (Line->Key != NULL && _wcsicmp (Line->Key, Key) == 0) + if (Line->Key != NULL && strcmpiW(Line->Key, Key) == 0) { return Line; } @@ -522,7 +522,7 @@ return p + 1;
default: - if (!iswspace(*p)) + if (!isspaceW(*p)) { parser->start = p; set_state( parser, KEY_NAME ); @@ -595,7 +595,7 @@ set_state( parser, EOL_BACKSLASH ); return p; default: - if (!iswspace(*p)) token_end = p + 1; + if (!isspaceW(*p)) token_end = p + 1; else { push_token( parser, p ); @@ -647,7 +647,7 @@ set_state( parser, EOL_BACKSLASH ); return p; default: - if (!isspace(*p)) token_end = p + 1; + if (!isspaceW(*p)) token_end = p + 1; else { push_token( parser, p ); @@ -692,7 +692,7 @@ return p + 1;
default: - if (iswspace(*p)) + if (isspaceW(*p)) continue; push_token( parser, p ); pop_state( parser ); @@ -749,7 +749,7 @@ set_state( parser, EOL_BACKSLASH ); return p; } - if (!iswspace(*p)) + if (!isspaceW(*p)) break; } parser->start = p; @@ -770,7 +770,7 @@ set_state( parser, EOL_BACKSLASH ); return p; } - if (!iswspace(*p)) + if (!isspaceW(*p)) break; } pop_state( parser );
Modified: trunk/reactos/lib/newinflib/infget.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infget.c?rev=... ============================================================================== --- trunk/reactos/lib/newinflib/infget.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infget.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -41,7 +41,7 @@ return &percent; }
- wcsncpy(ValueName, str, *len); + strncpyW(ValueName, str, *len); ValueName[*len] = 0;
DPRINT("Value name: %S\n", ValueName); @@ -94,7 +94,7 @@
if (Status == STATUS_SUCCESS) { - *len = wcslen(Data); + *len = strlenW(Data); DPRINT("Substitute: %S Length: %ul\n", Data, *len); return Data; } @@ -253,7 +253,7 @@ CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine; while (CacheLine != NULL) { - if (CacheLine->Key != NULL && _wcsicmp (CacheLine->Key, Key) == 0) + if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0) {
if (ContextIn != ContextOut) @@ -289,7 +289,7 @@ CacheLine = (PINFCACHELINE)ContextIn->Line; while (CacheLine != NULL) { - if (CacheLine->Key != NULL && _wcsicmp (CacheLine->Key, Key) == 0) + if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0) {
if (ContextIn != ContextOut) @@ -329,7 +329,7 @@ while (CacheSection != NULL) { /* Are the section names the same? */ - if (_wcsicmp(CacheSection->Name, Section) == 0) + if (strcmpiW(CacheSection->Name, Section) == 0) { return CacheSection->LineCount; } @@ -402,7 +402,7 @@ Ptr = ReturnBuffer; while (CacheField != NULL) { - *Ptr = (UCHAR)wcstoul(CacheField->Data, NULL, 16); + *Ptr = (UCHAR)strtoulW(CacheField->Data, NULL, 16);
Ptr++; CacheField = CacheField->Next; @@ -450,7 +450,7 @@ Ptr = CacheField->Data; }
- *IntegerValue = (LONG)wcstol(Ptr, NULL, 0); + *IntegerValue = (LONG)strtolW(Ptr, NULL, 0);
return INF_STATUS_SUCCESS; } @@ -493,7 +493,7 @@ Size = 0; while (FieldPtr != NULL) { - Size += ((ULONG)wcslen (FieldPtr->Data) + 1); + Size += ((ULONG)strlenW(FieldPtr->Data) + 1); FieldPtr = FieldPtr->Next; } Size++; @@ -511,9 +511,9 @@ FieldPtr = CacheField; while (FieldPtr != NULL) { - Size = (ULONG)wcslen (FieldPtr->Data) + 1; - - wcscpy (Ptr, FieldPtr->Data); + Size = (ULONG)strlenW(FieldPtr->Data) + 1; + + strcpyW(Ptr, FieldPtr->Data);
Ptr = Ptr + Size; FieldPtr = FieldPtr->Next; @@ -565,7 +565,7 @@ Ptr = CacheField->Data; }
-// Size = (ULONG)wcslen (Ptr) + 1; +// Size = (ULONG)strlenW(Ptr) + 1; Size = InfpSubstituteString(Context->Inf, Ptr, NULL, @@ -579,7 +579,7 @@ if (ReturnBufferSize <= Size) return INF_STATUS_BUFFER_OVERFLOW;
-// wcscpy (ReturnBuffer, Ptr); +// strcpyW(ReturnBuffer, Ptr); InfpSubstituteString(Context->Inf, Ptr, ReturnBuffer,
Modified: trunk/reactos/lib/newinflib/infhost.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infhost.h?rev... ============================================================================== --- trunk/reactos/lib/newinflib/infhost.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infhost.h [iso-8859-1] Sat May 1 12:43:39 2010 @@ -13,12 +13,6 @@ #endif /* __cplusplus */
#include "infcommon.h" - -extern NTSTATUS NTAPI RtlMultiByteToUnicodeN(IN PWCHAR UnicodeString, - IN ULONG UnicodeSize, IN PULONG ResultSize, IN PCSTR MbString, IN ULONG MbSize); - -extern BOOLEAN NTAPI RtlIsTextUnicode( PVOID buf, INT len, INT *pf ); -
extern int InfHostOpenBufferedFile(PHINF InfHandle, void *Buffer,
Modified: trunk/reactos/lib/newinflib/infhostrtl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infhostrtl.c?... ============================================================================== --- trunk/reactos/lib/newinflib/infhostrtl.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infhostrtl.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -115,7 +115,7 @@ { for (i = 0; i < len; i++) { - if (wcschr(std_control_chars, s[i])) + if (strchrW(std_control_chars, s[i])) { out_flags |= IS_TEXT_UNICODE_CONTROLS; break; @@ -127,7 +127,7 @@ { for (i = 0; i < len; i++) { - if (wcschr(byterev_control_chars, s[i])) + if (strchrW(byterev_control_chars, s[i])) { out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS; break;
Modified: trunk/reactos/lib/newinflib/inflib.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/inflib.rbuild... ============================================================================== --- trunk/reactos/lib/newinflib/inflib.rbuild [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/inflib.rbuild [iso-8859-1] Sat May 1 12:43:39 2010 @@ -9,6 +9,7 @@ <file>infrosgen.c</file> <file>infrosget.c</file> <file>infrosput.c</file> + <file>infrosrtl.c</file> </module> <module name="newinflibhost" type="hoststaticlibrary" allowwarnings="true"> <include base="newinflibhost">.</include>
Modified: trunk/reactos/lib/newinflib/infput.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infput.c?rev=... ============================================================================== --- trunk/reactos/lib/newinflib/infput.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infput.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -37,7 +37,7 @@ }
/* Doesn't fit? */ - Length = (ULONG)wcslen(Text) * sizeof(WCHAR); + Length = (ULONG)strlenW(Text) * sizeof(WCHAR); if (OutBuf->FreeSize < Length + 1 && INF_SUCCESS(OutBuf->Status)) { DPRINT("Out of free space. TotalSize %u FreeSize %u Length %u\n",
Modified: trunk/reactos/lib/newinflib/infrosput.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infrosput.c?r... ============================================================================== --- trunk/reactos/lib/newinflib/infrosput.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infrosput.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -64,13 +64,13 @@ HeaderBuffer = MALLOC(HeaderBufferSize); if (NULL != HeaderBuffer) { - wcscpy(HeaderBuffer, L"; "); + strcpyW(HeaderBuffer, L"; "); for (Index = 0; Index < HeaderComment->Length / sizeof(WCHAR); Index++) { HeaderBuffer[2 + Index] = HeaderComment->Buffer[Index]; } - wcscpy(HeaderBuffer + (2 + HeaderComment->Length / sizeof(WCHAR)), - L"\r\n\r\n"); + strcpyW(HeaderBuffer + (2 + HeaderComment->Length / sizeof(WCHAR)), + L"\r\n\r\n"); NtWriteFile(FileHandle, NULL, NULL,
Added: trunk/reactos/lib/newinflib/infrosrtl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infrosrtl.c?r... ============================================================================== --- trunk/reactos/lib/newinflib/infrosrtl.c (added) +++ trunk/reactos/lib/newinflib/infrosrtl.c [iso-8859-1] Sat May 1 12:43:39 2010 @@ -1,0 +1,51 @@ +/* + * PROJECT: .inf file parser + * LICENSE: GPL - See COPYING in the top level directory + * PROGRAMMER: Eric Kohl + */ + +/* INCLUDES *****************************************************************/ + +#include "inflib.h" +#include "infhost.h" + +#define NDEBUG +#include <debug.h> + + +/* FUNCTIONS ****************************************************************/ + +INT isspaceW(WCHAR c) +{ + return iswspace(c); +} + +INT strlenW(PCWSTR s) +{ + return wcslen(s); +} + +PWSTR strcpyW(PWSTR d, PCWSTR s) +{ + return wcscpy(d, s); +} + +PWSTR strncpyW(PWSTR d, PCWSTR s, SIZE_T c) +{ + return wcsncpy(d, s, c); +} + +INT strcmpiW(PCWSTR s1, PCWSTR s2) +{ + return wcsicmp(s1, s2); +} + +LONG strtolW(PCWSTR s, PWSTR *e, INT r) +{ + return wcstol(s, e, r); +} + +ULONG strtoulW(PCWSTR s, PWSTR *e, INT r) +{ + return wcstoul(s, e, r); +}
Propchange: trunk/reactos/lib/newinflib/infrosrtl.c ------------------------------------------------------------------------------ svn:eol-style = native
Propchange: trunk/reactos/lib/newinflib/infrosrtl.c ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision