MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libHPCS", "libHPCS.vcxproj", "{5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_tool", "..\test_tool\test_tool.vcxproj", "{3F415811-5359-48A6-9729-34BB4A3D7DDA}"
+ ProjectSection(ProjectDependencies) = postProject
+ {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6} = {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug with test_tool|Win32 = Debug with test_tool|Win32
Debug|Win32 = Debug|Win32
+ Release with test_tool|Win32 = Release with test_tool|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Debug with test_tool|Win32.ActiveCfg = Debug with test_tool|Win32
+ {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Debug with test_tool|Win32.Build.0 = Debug with test_tool|Win32
{5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Debug|Win32.ActiveCfg = Debug|Win32
{5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Debug|Win32.Build.0 = Debug|Win32
+ {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Release with test_tool|Win32.ActiveCfg = Release with test_tool|Win32
+ {5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Release with test_tool|Win32.Build.0 = Release with test_tool|Win32
{5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Release|Win32.ActiveCfg = Release|Win32
{5B9F8B15-85D5-4D5F-8F22-BB576E4CD4B6}.Release|Win32.Build.0 = Release|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Debug with test_tool|Win32.ActiveCfg = Debug with test_tool|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Debug with test_tool|Win32.Build.0 = Debug with test_tool|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Release with test_tool|Win32.ActiveCfg = Release with test_tool|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Release with test_tool|Win32.Build.0 = Release with test_tool|Win32
+ {3F415811-5359-48A6-9729-34BB4A3D7DDA}.Release|Win32.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug with test_tool|Win32">
+ <Configuration>Debug with test_tool</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="Release with test_tool|Win32">
+ <Configuration>Release with test_tool</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v120_xp</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug with test_tool|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release with test_tool|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v120_xp</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug with test_tool|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release with test_tool|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug with test_tool|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release with test_tool|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <Version>2.0</Version>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug with test_tool|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBHPCS_EXPORTS;_HPCS_LITTLE_ENDIAN;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <Version>2.0</Version>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <Version>2.0</Version>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release with test_tool|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBHPCS_EXPORTS;_HPCS_LITTLE_ENDIAN;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <Version>2.0</Version>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
#include "libhpcs_p.h"
#ifdef _WIN32
-/* Blank for now */
+#include <sdkddkver.h>
+#ifndef _WIN32_WINNT_WIN8
+#define _WIN32_WINNT_WIN8 0x0602
+#endif
+#if _WIN32_WINNT > _WIN32_WINNT_WIN8
+#include <Stringapiset.h>
+#else
+#include <WinNls.h>
+#endif
+#include <Shlwapi.h>
#else
#include <unicode/ustdio.h>
#endif
/** Platform-specific functions */
#ifdef _WIN32
-static enum HPCS_ParseCode __win32_next_native_line(HPCS_UFH fh, HPCS_NChar* line, int32_t length)
+static enum HPCS_ParseCode __win32_next_native_line(FILE* fh, WCHAR* line, int32_t length)
{
- /* Not implemented */
- return PARSE_E_CANT_READ;
+ if (fgetws(line, length, fh) == NULL)
+ return PARSE_E_CANT_READ;
+
+ return PARSE_OK;
}
-static HPCS_UFH __win32_open_data_file(const char* filename)
+static FILE* __win32_open_data_file(const char* filename)
{
- /* Not implemented */
- return NULL;
+ FILE* fh;
+ WCHAR* w_filename;
+ int w_size;
+
+ /* Get the required size */
+ w_size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, filename, -1, NULL, 0);
+ if (w_size == 0) {
+ PR_DEBUGF("Count MultiByteToWideChar() error: %x\n", GetLastError());
+ return NULL;
+ }
+ w_filename = calloc(w_size, sizeof(WCHAR));
+ if (w_filename == NULL)
+ return NULL;
+
+ if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, filename, -1, w_filename, w_size) == 0) {
+ PR_DEBUGF("Convert MultiByteToWideChar() error: %x\n", GetLastError());
+ free(w_filename);
+ return NULL;
+ }
+ fh = _wfopen(w_filename, L"r, ccs=UNICODE");
+
+ free(w_filename);
+ return fh;
+}
+
+static enum HPCS_ParseCode __win32_parse_native_method_info_line(char** name, char** value, WCHAR* line)
+{
+ WCHAR* w_name;
+ WCHAR* w_value;
+ WCHAR* w_newline;
+ enum HPCS_ParseCode ret;
+
+ w_name = wcstok(line, EQUALITY_SIGN);
+ if (w_name == NULL)
+ return PARSE_E_NOT_FOUND;
+ w_value = wcstok(NULL, EQUALITY_SIGN);
+ if (w_value == NULL)
+ return PARSE_E_NOT_FOUND;
+
+ /* Remove trailing \n from w_value, if any */
+ w_newline = StrStrW(w_value, CR_LF);
+ if (w_newline != NULL)
+ *w_newline = (WCHAR)0;
+
+ ret = __win32_wchar_to_utf8(name, w_name);
+ if (ret != PARSE_OK)
+ return ret;
+ ret = __win32_wchar_to_utf8(value, w_value);
+ if (ret != PARSE_OK)
+ return ret;
+
+ return PARSE_OK;
}
-static enum HPCS_ParseCode __win32_parse_native_method_info_line(char** name, char** value, UChar* line)
+static enum HPCS_ParseCode __win32_wchar_to_utf8(char** target, const WCHAR* s)
{
- /* Not implemented */
- return PARSE_E_CANT_READ;
+ int mb_size;
+
+ mb_size = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
+ if (mb_size == 0) {
+ PR_DEBUGF("Count WideCharToMultiByte() error: 0x%x\n", GetLastError());
+ return PARSE_E_INTERNAL;
+ }
+ *target = malloc(mb_size);
+ if (*target == NULL)
+ return PARSE_E_NO_MEM;
+
+ if (WideCharToMultiByte(CP_UTF8, 0, s, -1, *target, mb_size, NULL, NULL) == 0) {
+ free(*target);
+ PR_DEBUGF("Convert WideCharToMultiByte() error: 0x%x\n", GetLastError());
+ return PARSE_E_INTERNAL;
+ }
+
+ return PARSE_OK;
}
#else
static void __unix_hpcs_initialize()
#include <stdio.h>
#ifdef _WIN32
-#error "Not defined yet!"
+#include <Windows.h>
+#define HPCS_NChar WCHAR
+#define HPCS_UFH FILE*
#else
#include <unicode/ustdio.h>
#include <unicode/ustring.h>
PARSE_E_CANT_READ,
PARSE_E_NOT_FOUND,
PARSE_E_INV_PARAM,
+ PARSE_E_INTERNAL,
PARSE_W_NO_DATA
};
const char* HPCS_E__UNKNOWN_EC_STR = "Unknown error code.";
#ifdef _WIN32
-#error "Not implemented yet"
+WCHAR EQUALITY_SIGN[] = { 0x003D, 0x0000 };
+WCHAR CR_LF[] = { 0x000A, 0x0000 }; /* Windows hides the actual end-of-line which is {0x000D, 0x000A} from us */
#else
-/* ICU strings declarations */
UChar* EQUALITY_SIGN;
UChar* CR_LF;
#endif
/** Platform-specific functions */
#ifdef _WIN32
-static enum HPCS_ParseCode __win32_next_native_line(HPCS_UFH, HPCS_NChar* line, int32_t length);
+static enum HPCS_ParseCode __win32_next_native_line(FILE* fh, WCHAR* line, int32_t length);
static HPCS_UFH __win32_open_data_file(const char* filename);
-static enum HPCS_ParseCode __win32_parse_native_method_info_line(char** name, char** value, HPCS_NChar* line);
+static enum HPCS_ParseCode __win32_parse_native_method_info_line(char** name, char** value, WCHAR* line);
+static enum HPCS_ParseCode __win32_wchar_to_utf8(char** target, const WCHAR* s);
#else
static void __attribute((constructor)) __unix_hpcs_initialize();
static void __attribute((destructor)) __unix_hpcs_destroy();