Kaydet (Commit) d8edf07e authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Bin use of UTF-16 expat variant in the Windows shell extension

Thus we can drop that variant completely.

Change-Id: I11a8e40436921219bd6dd4afad4c7907ccb6b84c
üst 42782fdd
......@@ -287,7 +287,6 @@ else # !SYSTEM_EXPAT
$(eval $(call gb_Helper_register_static_libraries,PLAINLIBS, \
expat \
expat_utf16 \
expat_x64 \
))
......@@ -299,11 +298,6 @@ $(call gb_LinkTarget_set_include,$(1),\
$$(INCLUDE) \
)
$(if $(filter expat_utf16,$(2)),\
$(call gb_LinkTarget_add_defs,$(1),\
-DXML_UNICODE \
))
$(call gb_LinkTarget_use_static_libraries,$(1),\
$(2) \
)
......@@ -312,18 +306,12 @@ endef
endif # SYSTEM_EXPAT
# now define 2 wrappers that select which internal static library to use...
define gb_LinkTarget__use_expat_utf8
$(call gb_LinkTarget__use_expat,$(1),expat)
endef
define gb_LinkTarget__use_expat_utf16
$(call gb_LinkTarget__use_expat,$(1),expat_utf16)
endef
define gb_LinkTarget__use_expat_utf16_x64
define gb_LinkTarget__use_expat_utf8_x64
$(call gb_LinkTarget__use_expat,$(1),expat_x64)
endef
......
......@@ -15,7 +15,6 @@ $(eval $(call gb_Module_add_targets,expat,\
ExternalPackage_expat \
UnpackedTarball_expat \
StaticLibrary_expat \
StaticLibrary_expat_utf16 \
))
# Actually it wasn't that clear if we should
......@@ -32,9 +31,6 @@ $(eval $(call gb_Module_add_targets,expat,\
endif
# ---------------- X64 stuff special ---------------------
# use UNICODE only because shell/shlxthandler
# doesn't link against ascii_expat_xmlparse
#---------------------------------------------------------
ifeq ($(BUILD_X64),TRUE)
$(eval $(call gb_Module_add_targets,expat,\
StaticLibrary_expat_x64 \
......
Simple SAX parser library with added UTF-16 support.
When we build expat internally ("bundled"), we build two variants: One
that has an "ASCII" (actually UTF-8) API, another that has a "Unicode"
(meaning UTF-16) API. Additionally, expat is split into two parts,
expat_xmlparse and expat_xmltok. It's the former which has the two
variants, ascii_expat_xmlparse (UTF-8) and expat_xmlparse (UTF-16).
Code that uses expat then declares in its .mk file which one it wants
to use. See the magic in ../RepositoryExternal.mk, where in the
expat_utf16 case -DXML_UNICODE is passed when compiling source code
that wants to use the UTF-16 variant.
Now, this sounds fairly clear so far.
But wait. LO can also be conigured to use a *system* expat
library. The System expat library is only available as one variant,
the "ASCII" one. (But the library is still called just "libexpat", no
"ascii" in the name, that is just LO/OO's convention.) So how does
this work then, how can the code that wants to use the UTF-16 expat
API then actually use the "ASCII" (UTF-8) expat API? Well, in the
SYSTEM_EXPAT case no -DXML_UNICODE is used, so the code needs to check
that and adapt. So in the system libexpat case, mentioning expat_utf16
in a .mk file doesn't mean any UTF-16-using libexpat would actually be
used.
Yeah, this is silly, confusing, etc.
Furthermore, at least Debian actually *does* have also a "Unicode"
expat library, called libexpatw. Debian's LO does not use that,
though. (Using it would require modifications to the LO build
machinery.)
Now, if LO manages just fine with just the UTF-8 (or, "ASCII") system
libexpat in builds where that is used, why is a separate Unicode one
needed when an internal expat is used? Good question. Next
question. Patches welcome.
From:
[http://expat.sourceforge.net/]
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_StaticLibrary_StaticLibrary,expat_utf16))
$(eval $(call gb_StaticLibrary_set_warnings_not_errors,expat_utf16))
$(eval $(call gb_StaticLibrary_use_unpacked,expat_utf16,expat))
# no configure step on windows, no dependency
ifneq ($(OS)$(COM),WNTMSC)
$(eval $(call gb_StaticLibrary_use_external_project,expat_utf16,expat))
endif
$(eval $(call gb_StaticLibrary_add_defs,expat_utf16,\
-DXML_UNICODE \
))
$(eval $(call gb_StaticLibrary_set_include,expat_utf16,\
-I$(call gb_UnpackedTarball_get_dir,expat) \
$$(INCLUDE) \
))
ifeq ($(OS),MACOSX)
ifneq ($(strip $(SYSBASE)),)
$(eval $(call gb_StaticLibrary_add_defs,expat_utf16,\
-DHAVE_MEMMOVE \
-DHAVE_BCOPY \
))
endif
endif
ifeq ($(OS),WNT)
$(eval $(call gb_StaticLibrary_add_defs,expat_utf16,\
-DCOMPILED_FROM_DSP \
))
else
$(eval $(call gb_StaticLibrary_add_defs,expat_utf16,\
-DHAVE_EXPAT_CONFIG_H \
))
endif
$(eval $(call gb_StaticLibrary_add_generated_cobjects,expat_utf16,\
UnpackedTarball/expat/lib/unicode_xmlparse \
UnpackedTarball/expat/lib/unicode_xmlrole \
UnpackedTarball/expat/lib/unicode_xmltok \
))
# vim: set noet sw=4 ts=4:
......@@ -21,7 +21,6 @@ $(eval $(call gb_StaticLibrary_set_include,expat_x64,\
))
$(eval $(call gb_StaticLibrary_add_defs,expat_x64,\
-DXML_UNICODE \
-DCOMPILED_FROM_DSP \
))
......
......@@ -15,18 +15,15 @@ $(eval $(call gb_UnpackedTarball_add_patches,expat,\
expat/expat-2.1.0.patch \
))
# This is a bit hackish
# we need to compile it twice:
# with -DXML_UNICODE and without.
# This is a bit hackish.
# When building for Windows (as 32-bit) we need to build it twice: as
# 32- and 64-bit code, to be able to produce a 64-bit Explorer
# ("shell") extension that is used when the 32-bit LibreOffice is
# installed on a 64-bit OS.
# This is a bit hackish too ;-)
# on windows 64 bit platform we need to link it twice:
# with $(LINK_X64_BINARY) and with $(gb_LINK).
$(eval $(call gb_UnpackedTarball_set_post_action,expat,\
cp lib/xmltok.c lib/unicode_xmltok.c && \
cp lib/xmlrole.c lib/unicode_xmlrole.c && \
cp lib/xmlparse.c lib/unicode_xmlparse.c \
$(if $(filter $(BUILD_X64),TRUE), && \
$(if $(filter $(BUILD_X64),TRUE), \
cp lib/xmlparse.c lib/xmlparse_x64.c && \
cp lib/xmltok.c lib/xmltok_x64.c && \
cp lib/xmlrole.c lib/xmlrole_x64.c) \
......
......@@ -48,7 +48,7 @@ $(eval $(call gb_Library_add_defs,ooofilt,\
))
$(eval $(call gb_Library_use_externals,ooofilt,\
expat_utf16 \
expat_utf8 \
zlib \
))
......
......@@ -54,7 +54,7 @@ $(eval $(call gb_Library_add_defs,ooofilt_x64,\
))
$(eval $(call gb_Library_use_externals,ooofilt_x64,\
expat_utf16_x64 \
expat_utf8_x64 \
zlib_x64 \
))
......
......@@ -48,7 +48,7 @@ $(eval $(call gb_Library_add_defs,propertyhdl,\
))
$(eval $(call gb_Library_use_externals,propertyhdl,\
expat_utf16 \
expat_utf8 \
zlib \
))
......
......@@ -54,7 +54,7 @@ $(eval $(call gb_Library_add_defs,propertyhdl_x64,\
))
$(eval $(call gb_Library_use_externals,propertyhdl_x64,\
expat_utf16_x64 \
expat_utf8_x64 \
zlib_x64 \
))
......
......@@ -32,18 +32,10 @@ $(eval $(call gb_Library_set_include,recentfile,\
$$(INCLUDE) \
))
ifeq ($(GUI),WNT)
$(eval $(call gb_Library_use_externals,recentfile,\
expat_utf16 \
))
else
$(eval $(call gb_Library_use_externals,recentfile,\
expat_utf8 \
))
endif
$(eval $(call gb_Library_use_libraries,recentfile,\
sal \
$(gb_UWINAPI) \
......
......@@ -48,7 +48,7 @@ $(eval $(call gb_Library_add_defs,shlxthdl,\
))
$(eval $(call gb_Library_use_externals,shlxthdl,\
expat_utf16 \
expat_utf8 \
zlib \
))
......
......@@ -54,7 +54,7 @@ $(eval $(call gb_Library_add_defs,shlxthdl_x64,\
))
$(eval $(call gb_Library_use_externals,shlxthdl_x64,\
expat_utf16_x64 \
expat_utf8_x64 \
zlib_x64 \
))
......
......@@ -47,7 +47,7 @@ $(eval $(call gb_StaticLibrary_add_defs,shlxthandler_common,\
))
$(eval $(call gb_StaticLibrary_use_externals,shlxthandler_common,\
expat_utf16 \
expat_utf8 \
zlib \
))
......
......@@ -53,7 +53,7 @@ $(eval $(call gb_StaticLibrary_add_defs,shlxthandler_common_x64,\
))
$(eval $(call gb_StaticLibrary_use_externals,shlxthandler_common_x64,\
expat_utf16_x64 \
expat_utf8_x64 \
zlib_x64 \
))
......
......@@ -32,18 +32,10 @@ $(eval $(call gb_StaticLibrary_set_include,shell_xmlparser,\
$$(INCLUDE) \
))
ifeq ($(GUI),WNT)
$(eval $(call gb_StaticLibrary_use_externals,shell_xmlparser,\
expat_utf16 \
))
else
$(eval $(call gb_StaticLibrary_use_externals,shell_xmlparser,\
expat_utf8 \
))
endif
$(eval $(call gb_StaticLibrary_add_exception_objects,shell_xmlparser,\
shell/source/all/xml_parser \
))
......
......@@ -35,7 +35,7 @@ $(eval $(call gb_StaticLibrary_set_include,shell_xmlparser_x64,\
))
$(eval $(call gb_StaticLibrary_use_externals,shell_xmlparser_x64,\
expat_utf16_x64 \
expat_utf8_x64 \
))
$(eval $(call gb_StaticLibrary_add_x64_generated_exception_objects,shell_xmlparser_x64,\
......
......@@ -23,7 +23,7 @@
#include <string>
#include <map>
#if defined(XML_UNICODE) || defined(XML_UNICODE_WCHAR_T)
#ifdef _WIN32
typedef std::wstring string_t;
typedef wchar_t char_t;
#else
......
......@@ -72,6 +72,12 @@ std::wstring StringToWString(const std::string& String);
*/
std::string WStringToString(const std::wstring& String);
//---------------------------------
/** Convert a string to a wstring
using CP_UTF8
*/
std::wstring UTF8ToWString(const std::string& String);
//---------------------------------
/** Retrieve a string from the
resources of this module
......
......@@ -21,6 +21,12 @@
#include "internal/xml_parser.hxx"
#include "internal/i_xml_parser_event_handler.hxx"
#ifdef _WIN32
#include "internal/utilities.hxx"
#else
#define UTF8ToWString(s) s
#endif
#include <assert.h>
namespace /* private */
......@@ -96,12 +102,12 @@ static void xml_start_element_handler(void* UserData, const XML_Char* name, cons
while(atts[i])
{
attributes[reinterpret_cast<const char_t*>(get_local_name(atts[i]))] = reinterpret_cast<const char_t*>(atts[i+1]);
attributes[UTF8ToWString(reinterpret_cast<const char*>(get_local_name(atts[i])))] = UTF8ToWString(reinterpret_cast<const char*>(atts[i+1]));
i += 2; // skip to next pair
}
pDocHdl->start_element(
reinterpret_cast<const char_t*>(name), reinterpret_cast<const char_t*>(get_local_name(name)), attributes);
UTF8ToWString(reinterpret_cast<const char*>(name)), UTF8ToWString(reinterpret_cast<const char*>(get_local_name(name))), attributes);
}
}
......@@ -112,11 +118,13 @@ static void xml_end_element_handler(void* UserData, const XML_Char* name)
xml_parser* pImpl = get_parser_instance(UserData);
i_xml_parser_event_handler* pDocHdl = pImpl->get_document_handler();
if (pDocHdl)
pDocHdl->end_element(reinterpret_cast<const char_t*>(name), reinterpret_cast<const char_t*>(get_local_name(name)));
pDocHdl->end_element(UTF8ToWString(reinterpret_cast<const char*>(name)), UTF8ToWString(reinterpret_cast<const char*>(get_local_name(name))));
}
static void xml_character_data_handler(void* UserData, const XML_Char* s, int len)
{
static int count = 0;
assert(UserData);
xml_parser* pImpl = get_parser_instance(UserData);
......@@ -124,10 +132,30 @@ static void xml_character_data_handler(void* UserData, const XML_Char* s, int le
if (pDocHdl)
{
if (has_only_whitespaces(s,len))
pDocHdl->ignore_whitespace(string_t(reinterpret_cast<const char_t*>(s), len));
pDocHdl->ignore_whitespace(UTF8ToWString(std::string(reinterpret_cast<const char*>(s), len)));
else
pDocHdl->characters(string_t(reinterpret_cast<const char_t*>(s), len));
pDocHdl->characters(UTF8ToWString(std::string(reinterpret_cast<const char*>(s), len)));
}
#if 0
if (count < 5) {
char buf[1000];
sprintf(buf,
"%s: len=%d\n"
"s=%.10s\n"
"pDocHdl=%p has_only_whitespaces()=%d\n"
"string=%S",
"xml_character_data_handler",
len,
s,
pDocHdl,
has_only_whitespaces(s,len),
UTF8ToWString(std::string(reinterpret_cast<const char*>(s), len)).c_str()
);
MessageBoxA(NULL, buf, "xml_character_data_handler", MB_OK);
count++;
}
#endif
}
static void xml_comment_handler(void* UserData, const XML_Char* Data)
......@@ -137,7 +165,7 @@ static void xml_comment_handler(void* UserData, const XML_Char* Data)
xml_parser* pImpl = get_parser_instance(UserData);
i_xml_parser_event_handler* pDocHdl = pImpl->get_document_handler();
if (pDocHdl)
pDocHdl->comment(reinterpret_cast<const char_t*>(Data));
pDocHdl->comment(UTF8ToWString(reinterpret_cast<const char*>(Data)));
}
} // extern "C"
......
......@@ -32,40 +32,58 @@
const size_t MAX_RES_STRING = 1024;
const wchar_t SPACE_CHAR = _T(' ');
//---------------------------------
/**
*/
std::wstring StringToWString(const std::string& String)
static std::wstring StringToWString(const std::string& String, int codepage)
{
int len = MultiByteToWideChar(
CP_ACP, 0, String.c_str(), -1, 0, 0);
codepage, 0, String.c_str(), -1, 0, 0);
wchar_t* buff = reinterpret_cast<wchar_t*>(
_alloca(len * sizeof(wchar_t)));
MultiByteToWideChar(
CP_ACP, 0, String.c_str(), -1, buff, len);
codepage, 0, String.c_str(), -1, buff, len);
return std::wstring(buff);
}
//---------------------------------
/**
*/
std::string WStringToString(const std::wstring& String)
static std::string WStringToString(const std::wstring& String, int codepage)
{
int len = WideCharToMultiByte(
CP_ACP, 0, String.c_str(), -1, 0, 0, 0, 0);
codepage, 0, String.c_str(), -1, 0, 0, 0, 0);
char* buff = reinterpret_cast<char*>(
_alloca(len * sizeof(char)));
WideCharToMultiByte(
CP_ACP, 0, String.c_str(), -1, buff, len, 0, 0);
codepage, 0, String.c_str(), -1, buff, len, 0, 0);
return std::string(buff);
}
//---------------------------------
/**
*/
std::wstring StringToWString(const std::string& String)
{
return StringToWString(String, CP_ACP);
}
//---------------------------------
/**
*/
std::string WStringToString(const std::wstring& String)
{
return WStringToString(String, CP_ACP);
}
//---------------------------------
/**
*/
std::wstring UTF8ToWString(const std::string& String)
{
return StringToWString(String, CP_UTF8);
}
//---------------------------------
/**
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment