mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Improve PICT compatibility, add batch mode to gpr2gpa
This commit is contained in:
154
WindowsUnicodeToolShim/WindowsUnicodeToolShim.cpp
Normal file
154
WindowsUnicodeToolShim/WindowsUnicodeToolShim.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
#include <string>
|
||||
|
||||
#include "UTF8.h"
|
||||
#include "UTF16.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
|
||||
// This library provides front-ends and shims to make tools a bit more portable by handling all path strings as UTF-8,
|
||||
// and providing a "main" entry point that is also UTF-8.
|
||||
|
||||
static std::string ConvertWStringToUTF8(const wchar_t *str)
|
||||
{
|
||||
size_t strLength = wcslen(str);
|
||||
|
||||
std::string result;
|
||||
|
||||
for (size_t i = 0; i < strLength; )
|
||||
{
|
||||
size_t charsDigested = 0;
|
||||
uint32_t codePoint = 0;
|
||||
uint8_t asUTF8[4];
|
||||
if (!PortabilityLayer::UTF16Processor::DecodeCodePoint(reinterpret_cast<const uint16_t*>(str) + i, strLength - i, charsDigested, codePoint))
|
||||
return "";
|
||||
|
||||
i += charsDigested;
|
||||
|
||||
size_t bytesEmitted = 0;
|
||||
PortabilityLayer::UTF8Processor::EncodeCodePoint(asUTF8, bytesEmitted, codePoint);
|
||||
|
||||
result.append(reinterpret_cast<const char*>(asUTF8), bytesEmitted);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::wstring ConvertUTF8ToWString(const char *str)
|
||||
{
|
||||
size_t strLength = strlen(str);
|
||||
|
||||
std::wstring result;
|
||||
|
||||
for (size_t i = 0; i < strLength; )
|
||||
{
|
||||
size_t charsDigested = 0;
|
||||
uint32_t codePoint = 0;
|
||||
uint16_t asUTF16[4];
|
||||
if (!PortabilityLayer::UTF8Processor::DecodeCodePoint(reinterpret_cast<const uint8_t*>(str) + i, strLength - i, charsDigested, codePoint))
|
||||
return L"";
|
||||
|
||||
i += charsDigested;
|
||||
|
||||
size_t codePointsEmitted = 0;
|
||||
PortabilityLayer::UTF16Processor::EncodeCodePoint(asUTF16, codePointsEmitted, codePoint);
|
||||
|
||||
result.append(reinterpret_cast<const wchar_t*>(asUTF16), codePointsEmitted);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FILE *fopen_utf8(const char *path, const char *options)
|
||||
{
|
||||
std::wstring pathUTF16 = ConvertUTF8ToWString(path);
|
||||
std::wstring optionsUTF16 = ConvertUTF8ToWString(options);
|
||||
|
||||
return _wfopen(pathUTF16.c_str(), optionsUTF16.c_str());
|
||||
}
|
||||
|
||||
int fputs_utf8(const char *str, FILE *f)
|
||||
{
|
||||
return fputs(str, f);
|
||||
}
|
||||
|
||||
|
||||
int mkdir_utf8(const char *path)
|
||||
{
|
||||
std::wstring pathUTF16 = ConvertUTF8ToWString(path);
|
||||
return _wmkdir(pathUTF16.c_str());
|
||||
}
|
||||
|
||||
void TerminateDirectoryPath(std::string &path)
|
||||
{
|
||||
const size_t length = path.length();
|
||||
|
||||
if (length == 0)
|
||||
path.append("\\");
|
||||
else
|
||||
{
|
||||
const char lastChar = path[path.length() - 1];
|
||||
if (lastChar != '\\' && lastChar != '/')
|
||||
path.append("\\");
|
||||
}
|
||||
}
|
||||
|
||||
void ScanDirectoryForExtension(std::vector<std::string> &outPaths, const char *path, const char *ending, bool recursive)
|
||||
{
|
||||
std::wstring dirFilter = std::wstring(L"\\\\?\\") + ConvertUTF8ToWString(path) + L"\\*";
|
||||
size_t endingLen = strlen(ending);
|
||||
|
||||
WIN32_FIND_DATAW findDataW;
|
||||
HANDLE h = FindFirstFileW(dirFilter.c_str(), &findDataW);
|
||||
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string utf8Name = ConvertWStringToUTF8(findDataW.cFileName);
|
||||
if (utf8Name != "." && utf8Name != "..")
|
||||
{
|
||||
if (recursive && findDataW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
ScanDirectoryForExtension(outPaths, (std::string(path) + "\\" + utf8Name).c_str(), ending, true);
|
||||
else if (utf8Name.length() >= endingLen && utf8Name.substr(utf8Name.length() - endingLen) == ending)
|
||||
outPaths.push_back(std::string(path) + "\\" + utf8Name);
|
||||
}
|
||||
|
||||
if (!FindNextFileW(h, &findDataW))
|
||||
break;
|
||||
}
|
||||
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
|
||||
int toolMain(int argc, const char **argv);
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
||||
LPWSTR *szArglist;
|
||||
int nArgs;
|
||||
|
||||
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
||||
|
||||
std::vector<std::string> utf8ArgStrings;
|
||||
std::vector<const char *> utf8Args;
|
||||
|
||||
utf8ArgStrings.resize(nArgs);
|
||||
utf8Args.resize(nArgs);
|
||||
|
||||
for (int i = 0; i < nArgs; i++)
|
||||
{
|
||||
utf8ArgStrings[i] = ConvertWStringToUTF8(szArglist[i]);
|
||||
utf8Args[i] = utf8ArgStrings[i].c_str();
|
||||
}
|
||||
|
||||
const char **args = nullptr;
|
||||
if (nArgs)
|
||||
args = &utf8Args[0];
|
||||
|
||||
return toolMain(nArgs, args);
|
||||
}
|
9
WindowsUnicodeToolShim/WindowsUnicodeToolShim.h
Normal file
9
WindowsUnicodeToolShim/WindowsUnicodeToolShim.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *fopen_utf8(const char *path, const char *options);
|
||||
int fputs_utf8(const char *str, FILE *f);
|
||||
int mkdir_utf8(const char *path);
|
||||
void TerminateDirectoryPath(std::string &path);
|
||||
void ScanDirectoryForExtension(std::vector<std::string>& outPaths, const char *path, const char *ending, bool recursive);
|
135
WindowsUnicodeToolShim/WindowsUnicodeToolShim.vcxproj
Normal file
135
WindowsUnicodeToolShim/WindowsUnicodeToolShim.vcxproj
Normal file
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{15009625-1120-405E-8BBA-69A16CD6713D}</ProjectGuid>
|
||||
<RootNamespace>WindowsUnicodeToolShim</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</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" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\PortabilityLayer.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</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" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\PortabilityLayer.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\PortabilityLayer.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\PortabilityLayer.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="WindowsUnicodeToolShim.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="WindowsUnicodeToolShim.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user