mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-22 07:37:40 +00:00
chore(developer): Win-functions in FileNameConsistency
This commit is contained in:
parent
1ec6f8a6d1
commit
2c6726974a
3 changed files with 37 additions and 34 deletions
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
extern char CompileDir[MAX_PATH];
|
||||
/*
|
||||
BOOL FileExists(char const * filename) {
|
||||
bool FileExists(char const * filename) {
|
||||
_finddata_t fi;
|
||||
intptr_t n;
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ BOOL FileExists(char const * filename) {
|
|||
return FALSE;
|
||||
}
|
||||
*/
|
||||
BOOL IsRelativePath(KMX_CHAR const * p) {
|
||||
bool IsRelativePath(KMX_CHAR const * p) {
|
||||
// Relative path (returns TRUE):
|
||||
// ..\...\BITMAP.BMP
|
||||
// PATH\BITMAP.BMP
|
||||
|
|
@ -34,7 +34,7 @@ BOOL IsRelativePath(KMX_CHAR const * p) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL IsRelativePath(KMX_WCHART const * p) {
|
||||
bool IsRelativePath(KMX_WCHART const * p) {
|
||||
// Relative path (returns TRUE):
|
||||
// ..\...\BITMAP.BMP
|
||||
// PATH\BITMAP.BMP
|
||||
|
|
@ -49,21 +49,19 @@ BOOL IsRelativePath(KMX_WCHART const * p) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
KMX_DWORD CheckFilenameConsistency(char const * Filename, BOOL ReportMissingFile) {
|
||||
KMX_DWORD CheckFilenameConsistency(char const * Filename, bool ReportMissingFile) {
|
||||
PKMX_WCHAR WFilename = strtowstr((char *)Filename);
|
||||
|
||||
KMX_DWORD const result = CheckFilenameConsistency(u16fmt(WFilename).c_str(), ReportMissingFile); // _S2KMX_DWORD const result = CheckFilenameConsistency(WFilename, ReportMissingFile);
|
||||
KMX_DWORD const result = CheckFilenameConsistency(u16fmt(WFilename).c_str(), ReportMissingFile); // _S2 KMX_DWORD const result = CheckFilenameConsistency(WFilename, ReportMissingFile);
|
||||
delete WFilename;
|
||||
return result;
|
||||
}
|
||||
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_WCHART const * Filename, BOOL ReportMissingFile) {
|
||||
KMX_CHAR ErrExtra[256]; // _S2
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_WCHART const * Filename, bool ReportMissingFile) {
|
||||
KMX_WCHAR ErrExtra[256]; // _S2
|
||||
KMX_WCHART Name[_MAX_PATH], FName[_MAX_FNAME], Ext[_MAX_EXT];
|
||||
_wfinddata_t fi;
|
||||
intptr_t n;
|
||||
|
||||
|
||||
if (IsRelativePath(Filename)) {
|
||||
PKMX_WCHAR WCompileDir = strtowstr(CompileDir);
|
||||
wcscpy_s(Name, _countof(Name), u16fmt(WCompileDir).c_str()); // I3481 // _S2 wcscpy_s(Name, _countof(Name), WCompileDir); // I3481
|
||||
|
|
@ -72,21 +70,31 @@ KMX_DWORD CheckFilenameConsistency(KMX_WCHART const * Filename, BOOL ReportMissi
|
|||
else {
|
||||
wcscpy_s(Name, _countof(Name), Filename); // I3481
|
||||
}
|
||||
|
||||
if ((n = _wfindfirst(Name, &fi)) == -1) {
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
_wfinddata_t fi;
|
||||
n = _wfindfirst(Name, &fi);
|
||||
#else
|
||||
n= access(Name,F_OK);
|
||||
#endif
|
||||
|
||||
if (n == -1){
|
||||
if (ReportMissingFile) {
|
||||
sprintf(ErrExtra, "referenced file '%ls'", Filename); //_S2 wsprintf(ErrExtra, "referenced file '%ls'", Filename);
|
||||
|
||||
u16sprintf(ErrExtra,_countof(ErrExtra),L"referenced file %ls",Filename); //_S2 wsprintf(ErrExtra, "referenced file '%ls'", Filename); // right spfrintf fun?
|
||||
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) {
|
||||
sprintf(ErrExtra, "reference '%ls' does not match actual filename '%ls'", Name, fi.name); // _S2 wsprintf(ErrExtra, "reference '%ls' does not match actual filename '%ls'", Name, fi.name);
|
||||
|
||||
const wchar_t* cptr1 = wcsrchr(Name, '\\');
|
||||
cptr1++;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (wcscmp(cptr1, fi.name) != 0) { // _S2 if (wcscmp(Name, fi.name) != 0) {
|
||||
u16sprintf(ErrExtra,_countof(ErrExtra),L"reference '%ls' does not match actual filename '%ls'", *cptr1, &fi.name); // _S2 wsprintf(ErrExtra, "reference '%ls' does not match actual filename '%ls'", Name, fi.name);
|
||||
AddWarning(CHINT_FilenameHasDifferingCase);
|
||||
}
|
||||
#endif
|
||||
return CERR_None;
|
||||
}
|
||||
|
||||
|
|
@ -96,13 +104,14 @@ KMX_DWORD CheckFilenameConsistencyForCalls(PFILE_KEYBOARD fk) {
|
|||
// file called function.call_js. This is ripe for rewrite!
|
||||
// But let's check what we have anyway
|
||||
PFILE_STORE sp;
|
||||
DWORD i, msg;
|
||||
|
||||
DWORD i, msg;
|
||||
for (i = 0, sp = fk->dpStoreArray; i < fk->cxStoreArray; i++, sp++) {
|
||||
if (!sp->fIsCall) continue;
|
||||
|
||||
const std::wstring callsite(u16fmt(sp->dpString).c_str());
|
||||
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) {
|
||||
|
|
@ -110,4 +119,4 @@ KMX_DWORD CheckFilenameConsistencyForCalls(PFILE_KEYBOARD fk) {
|
|||
}
|
||||
}
|
||||
return CERR_None;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
#include <Compfile.h>
|
||||
|
||||
KMX_DWORD CheckFilenameConsistencyForCalls(PFILE_KEYBOARD fk);
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_CHAR const * Filename, BOOL ReportMissingFile);
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_WCHART const * Filename, BOOL ReportMissingFile);
|
||||
//BOOL FileExists(char const * filename);
|
||||
BOOL IsRelativePath(KMX_CHAR const * p);
|
||||
BOOL IsRelativePath(KMX_WCHART const * p);
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_CHAR const * Filename, bool ReportMissingFile);
|
||||
KMX_DWORD CheckFilenameConsistency(KMX_WCHART const * Filename, bool ReportMissingFile);
|
||||
//bool FileExists(char const * filename); //_S2 never used
|
||||
bool IsRelativePath(KMX_CHAR const * p);
|
||||
bool IsRelativePath(KMX_WCHART const * p);
|
||||
|
|
|
|||
|
|
@ -19,12 +19,8 @@ std::wstring wstring_from_string(std::string const str) {
|
|||
}
|
||||
|
||||
std::u16string u16string_from_string(std::string const str) {
|
||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
std::u16string ret =
|
||||
converter.
|
||||
from_bytes(str);
|
||||
return ret;
|
||||
//return converter.from_bytes(str);
|
||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
|
||||
std::string string_from_u16string(std::u16string const str) {
|
||||
|
|
@ -41,8 +37,6 @@ long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// _S2 use with c_str() e.g. u16fmt( DEBUGSTORE_MATCH).c_str()
|
||||
std::wstring u16fmt(const km_kbp_cp* str) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> convert_wstring;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue