spiegel-keyman/developer/kmcompx/include/XX/kmx_debug.cpp
Sabine 3e58fa76b6 get keymans version
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
2022-07-12 10:43:20 +02:00

167 lines
3.5 KiB
C++

/*
Copyright: Copyright (C) 2003-2018 SIL International.
Authors: mcdurdin
*/
#include "kmx_processevent.h"
#include <stdarg.h>
#include <iostream>
using namespace km::kbp;
using namespace kmx;
#define TAB "\t"
#define NL "\n"
#include <chrono>
#ifdef _MSC_VER
#define _USE_WINDOWS
#endif
#ifdef _USE_WINDOWS
#define DECLSPEC_IMPORT __declspec(dllimport)
#define WINBASEAPI DECLSPEC_IMPORT
#define VOID void
#define WINAPI __stdcall
extern "C"
__declspec(dllimport)
void
__stdcall
OutputDebugStringA(
char *lpOutputString
);
#else
#include <syslog.h>
#endif
// simulation of Windows GetTickCount()
unsigned long
GetTickCount()
{
using namespace std::chrono;
return (unsigned long) duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
}
int km::kbp::kmx::Sab(int sa)
{
return 8;
}
int DebugLog_11(const char *file, int line, const char *function, const char *fmt, ...)
{
char fmtbuf[256];
va_list vars;
va_start(vars, fmt);
vsnprintf(fmtbuf, sizeof(fmtbuf) / sizeof(fmtbuf[0]), fmt, vars); // I2248 // I3547
fmtbuf[255] = 0;
va_end(vars);
if (!g_debug_KeymanLog)
return 0;
char windowinfo[1024];
sprintf(windowinfo,
"%ld" TAB //"TickCount" TAB
"%s:%d" TAB //"SourceFile" TAB
"%s" TAB //"Function"
"%s" NL, //"Message"
GetTickCount(), //"TickCount" TAB
file, line, //"SourceFile" TAB
function, //"Function" TAB
fmtbuf); //"Message"
if (g_debug_ToConsole) { // I3951
std::cout << windowinfo << std::endl; // OutputDebugStringA(windowinfo);
} else {
#ifdef _USE_WINDOWS
std::cout << windowinfo << std::endl; // OutputDebugStringA(windowinfo);
#else
syslog(LOG_DEBUG, "%s", windowinfo);
#endif
}
return 0;
}
const char *km::kbp::kmx::Debug_ModifierName(KMX_UINT modifiers) {
#ifdef _MSC_VER
__declspec(thread)
#endif
static char buf[256];
buf[0] = 0;
for(int i = 0; s_modifier_names[i].name; i++)
if (modifiers & s_modifier_names[i].modifier) {
strcat(buf, " ");
strcat(buf, s_modifier_names[i].name);
}
if (*buf) return buf + 1;
return "Unmodified";
}
const char *km::kbp::kmx::Debug_VirtualKey(KMX_WORD vk) {
#ifdef _MSC_VER
__declspec(thread)
#endif
static char buf[256];
if (!ShouldDebug()) {
return "";
}
if (vk < 256) {
sprintf(buf, "['%s' 0x%x]", s_key_names[vk], vk);
}
else {
sprintf(buf, "[0x%x]", vk);
}
return buf;
}
const char *km::kbp::kmx::Debug_UnicodeString(PKMX_WCHAR s, int x) {
if (!ShouldDebug()) {
return "";
}
#ifdef _MSC_VER
__declspec(thread)
#endif
static char bufout[2][128 * 7];
KMX_WCHAR *p;
char *q;
bufout[x][0] = 0;
for (p = s, q = bufout[x]; *p && (p - s < 128); p++)
{
sprintf(q, "U+%4.4X ", *p);
q = strchr(q, 0);
}
//WideCharToMultiByte(CP_ACP, 0, buf, -1, bufout, 128, NULL, NULL);
return bufout[x];
}
const char *km::kbp::kmx::Debug_UnicodeString(std::u16string s, int x) {
if (!ShouldDebug()) {
return "";
}
#ifdef _MSC_VER
__declspec(thread)
#endif
static char bufout[2][128 * 7];
auto p = s.begin();
char *q;
bufout[x][0] = 0;
for (q = bufout[x]; (intptr_t)(q-bufout[x]) < (128*7) && p != s.end(); p++)
{
sprintf(q, "U+%4.4X ", *p); q = strchr(q, 0);
}
return bufout[x];
}
void km::kbp::kmx::write_console(KMX_BOOL error, const wchar_t *fmt, ...) {
if (!g_silent || error) {
va_list vars;
va_start(vars, fmt);
vwprintf(fmt, vars);
va_end(vars);
}
}