mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 17:36:00 +00:00
Merge branch 'master' of https://github.com/keymanapp/keyman into refactor/developer/6026-kmcompx-compiler-cross-platform-part-2-NEW_VERSION # Conflicts: # common/core/desktop/src/kmx/kmx_context.h # common/core/desktop/src/kmx/kmx_processor.cpp # common/windows/cpp/include/keymanversion.h # common/windows/cpp/include/kkmnkbd/Compfile.h # common/windows/cpp/include/kmtip_guids.h # common/windows/cpp/src/kmtip_guids.cpp # core/src/kmx/kmx_conversion.cpp # core/src/kmx/kmx_conversion.h # core/src/kmx/kmx_file.cpp # core/src/kmx/kmx_processevent.cpp # core/src/kmx/kmx_processor.hpp # core/src/kmx/kmx_xstring.cpp # developer/js/.gitignore # developer/js/package-lock.json # developer/js/tests/tsconfig.json # developer/src/kmcmpdll/CasedKeys.cpp # developer/src/kmcmpdll/CheckFilenameConsistency.cpp # developer/src/kmcmpdll/CheckFilenameConsistency.h # developer/src/kmcmpdll/CheckForDuplicates.cpp # developer/src/kmcmpdll/CheckForDuplicates.h # developer/src/kmcmpdll/CheckNCapsConsistency.cpp # developer/src/kmcmpdll/CheckNCapsConsistency.h # developer/src/kmcmpdll/Compiler.cpp # developer/src/kmcmpdll/DeprecationChecks.cpp # developer/src/kmcmpdll/NamedCodeConstants.cpp # developer/src/kmcmpdll/UnreachableRules.cpp # developer/src/kmcmpdll/UnreachableRules.h # developer/src/kmcmpdll/compfile.h # developer/src/kmcmpdll/kcframe/kcframe.cpp # developer/src/kmcmpdll/kcframe/kcframe.vcxproj # developer/src/kmcmpdll/kcframe/kcframe.vcxproj.filters # developer/src/kmcmpdll/kmcmpdll.vcxproj # developer/src/kmcmpdll/kmcmpdll.vcxproj.filters # developer/src/kmcmpdll/version.rc # developer/src/kmcmpdll/versioning.cpp # developer/src/kmlmc/bundle.sh # developer/src/kmlmc/tests/test-join-word-breaker.ts # developer/src/kmlmc/tests/test-override-script-defaults.ts # developer/src/server/tsconfig.json # windows/src/developer/kmcmpdll/Makefile # windows/src/developer/kmcmpdll/vkeys.h # windows/src/engine/keyman32/keymanengine.h # windows/src/global/inc/Vkeys.h # windows/src/global/inc/rc4.h # windows/src/global/vc/rc4.cpp
189 lines
5.5 KiB
C++
189 lines
5.5 KiB
C++
#include "../../../../developer/kmcompx/include/pch.h" // _S2 #include "pch"
|
|
#include "../../../../developer/kmcompx/include/Compfile.h" // _S2 #include <Compfile.h>
|
|
#include "../../../../developer/kmcompx/include/compiler.h" // _S2 #include <compiler.h>
|
|
#include "../../../../developer/kmcompx/include/comperr.h" // _S2 #include <comperr.h>
|
|
#include "../../../../developer/kmcompx/include/kmcmpdll.h" // _S2 #include <kmcmpdll.h>
|
|
/*
|
|
#include "pch.h"
|
|
#include <compfile.h>
|
|
#include <compiler.h>
|
|
#include <comperr.h>
|
|
#include <kmcmpdll.h>
|
|
*/
|
|
#include <io.h>
|
|
#include <string>
|
|
#include "CheckFilenameConsistency.h"
|
|
|
|
extern char CompileDir[MAX_PATH];
|
|
|
|
bool FileExists(char const * filename) {
|
|
_finddata_t fi;
|
|
intptr_t n;
|
|
|
|
if ((n = _findfirst(filename, &fi)) != -1) {
|
|
_findclose(n);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool IsRelativePath(KMX_CHAR const * p) {
|
|
// Relative path (returns TRUE):
|
|
// ..\...\BITMAP.BMP
|
|
// PATH\BITMAP.BMP
|
|
// BITMAP.BMP
|
|
|
|
// Semi-absolute path (returns FALSE):
|
|
// \...\BITMAP.BMP
|
|
|
|
// Absolute path (returns FALSE):
|
|
// C:\...\BITMAP.BMP
|
|
// \\SERVER\SHARE\...\BITMAP.BMP
|
|
|
|
if (*p == '\\') return FALSE;
|
|
if (*p && *(p + 1) == ':') return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool IsRelativePath(KMX_WCHART const * p) {
|
|
// Relative path (returns TRUE):
|
|
// ..\...\BITMAP.BMP
|
|
// PATH\BITMAP.BMP
|
|
// BITMAP.BMP
|
|
|
|
// Semi-absolute path (returns FALSE):
|
|
// \...\BITMAP.BMP
|
|
|
|
// Absolute path (returns FALSE):
|
|
// C:\...\BITMAP.BMP
|
|
// \\SERVER\SHARE\...\BITMAP.BMP
|
|
|
|
if (*p == L'\\') return FALSE;
|
|
if (*p && *(p + 1) == L':') return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool IsRelativePath(KMX_WCHAR const * p) {
|
|
// Relative path (returns TRUE):
|
|
// ..\...\BITMAP.BMP
|
|
// PATH\BITMAP.BMP
|
|
// BITMAP.BMP
|
|
|
|
// Semi-absolute path (returns FALSE):
|
|
// \...\BITMAP.BMP
|
|
|
|
// Absolute path (returns FALSE):
|
|
// C:\...\BITMAP.BMP
|
|
// \\SERVER\SHARE\...\BITMAP.BMP
|
|
|
|
if (*p == u'\\') return FALSE;
|
|
if (*p && *(p + 1) == u':') return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
KMX_DWORD CheckFilenameConsistency(KMX_CHAR const * Filename, BOOL ReportMissingFile) {
|
|
|
|
PKMX_WCHAR WFilename = strtowstr((KMX_CHAR *)Filename); // _S2 PWCHAR WFilename = strtowstr((char *)Filename);
|
|
KMX_DWORD const result = CheckFilenameConsistency(WFilename, ReportMissingFile);
|
|
delete WFilename;
|
|
return result;
|
|
}
|
|
/* _S2 we need to use char16_t so this is not needed
|
|
KMX_DWORD CheckFilenameConsistency(wchar_t const * Filename, BOOL ReportMissingFile) {
|
|
WCHAR Name[_MAX_PATH], FName[_MAX_FNAME], Ext[_MAX_EXT];
|
|
_wfinddata_t fi;
|
|
intptr_t n;
|
|
|
|
if (IsRelativePath(Filename)) {
|
|
PKMX_WCHAR WCompileDir = strtowstr(CompileDir);
|
|
u16ncpy(Name, WCompileDir, _countof(Name)); // I3481 // _S2 wcscpy_s(Name, _countof(Name), WCompileDir); // I3481
|
|
u16ncat(Name, Filename, _countof(Name)); // I3481 // _S2 wcscat_s(Name, _countof(Name), Filename); // I3481
|
|
}
|
|
else {
|
|
wcscpy_s(Name, _countof(Name), Filename); // I3481
|
|
}
|
|
|
|
if ((n = _wfindfirst(Name, &fi)) == -1) {
|
|
if (ReportMissingFile) {
|
|
wsprintf(ErrExtra, "referenced file '%ls'", Filename);
|
|
AddWarning(CWARN_MissingFile);
|
|
}
|
|
return CERR_None;
|
|
}
|
|
|
|
_wsplitpath_s(Filename, nullptr, 0, nullptr, 0, FName, _MAX_FNAME, Ext, _MAX_EXT);
|
|
_wmakepath_s(Name, _MAX_PATH, nullptr, nullptr, FName, Ext);
|
|
if (wcscmp(Name, fi.name) != 0) {
|
|
wsprintf(ErrExtra, "reference '%ls' does not match actual filename '%ls'", Name, fi.name);
|
|
AddWarning(CHINT_FilenameHasDifferingCase);
|
|
}
|
|
return CERR_None;
|
|
}
|
|
*/
|
|
KMX_DWORD CheckFilenameConsistency(KMX_WCHAR const * Filename, bool ReportMissingFile) {
|
|
KMX_WCHAR Name[_MAX_PATH], FName[_MAX_FNAME], Ext[_MAX_EXT];
|
|
_wfinddata_t fi;
|
|
intptr_t n;
|
|
|
|
if (IsRelativePath(Filename)) {
|
|
PKMX_WCHAR WCompileDir = strtowstr(CompileDir);
|
|
u16ncpy(Name, WCompileDir, _countof(Name)); // I3481 // _S2 wcscpy_s(Name, _countof(Name), WCompileDir); // I3481
|
|
u16ncat(Name, Filename, _countof(Name)); // I3481 // _S2 wcscat_s(Name, _countof(Name), Filename); // I3481
|
|
}
|
|
else {
|
|
u16ncpy(Name, Filename, _countof(Name)); // I3481 // _S2 wcscpy_s(Name, _countof(Name), Filename); // I3481
|
|
}
|
|
/* _S2 needs to be included
|
|
if ((n = _wfindfirst(Name, &fi)) == -1) {
|
|
if (ReportMissingFile) {
|
|
wsprintf(ErrExtra, "referenced file '%ls'", Filename);
|
|
AddWarning(CWARN_MissingFile);
|
|
}
|
|
return CERR_None;
|
|
}
|
|
|
|
_wsplitpath_s(Filename, nullptr, 0, nullptr, 0, FName, _MAX_FNAME, Ext, _MAX_EXT);
|
|
_wmakepath_s(Name, _MAX_PATH, nullptr, nullptr, FName, Ext);
|
|
if (wcscmp(Name, fi.name) != 0) {
|
|
wsprintf(ErrExtra, "reference '%ls' does not match actual filename '%ls'", Name, fi.name);
|
|
AddWarning(CHINT_FilenameHasDifferingCase);
|
|
}
|
|
*/
|
|
|
|
|
|
return CERR_None;
|
|
}
|
|
|
|
|
|
|
|
|
|
KMX_DWORD CheckFilenameConsistencyForCalls(PFILE_KEYBOARD fk) {
|
|
// call() statements depend on a fairly ugly hack for js,
|
|
// where store(DllFunction) "my.dll:func" will look for a
|
|
// file called function.call_js. This is ripe for rewrite!
|
|
// But let's check what we have anyway
|
|
|
|
/* _S2 needs to be included
|
|
PFILE_STORE sp;
|
|
KMX_DWORD i, msg;
|
|
|
|
for (i = 0, sp = fk->dpStoreArray; i < fk->cxStoreArray; i++, sp++) {
|
|
if (!sp->fIsCall) continue;
|
|
|
|
const std::wstring callsite(sp->dpString);
|
|
const auto colon = callsite.find(':');
|
|
if (colon == std::wstring::npos) continue;
|
|
|
|
auto func = callsite.substr(colon + 1);
|
|
func.append(L".call_js");
|
|
if ((msg = CheckFilenameConsistency(func.c_str(), FALSE)) != CERR_None) {
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
*/
|
|
return CERR_None;
|
|
}
|