From 66e4e4675286546a07e056b93af6ebc3fbfe0fa2 Mon Sep 17 00:00:00 2001 From: little-brother Date: Tue, 7 Mar 2023 04:09:33 +0300 Subject: [PATCH] Up to 1.0.4 * New option: exit-by-q * Ability to parse non-valid XML (unescaped > inside attribute values) --- main.c | 16 +++++++++++----- xml.c | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 5816321..8af8e42 100644 --- a/main.c +++ b/main.c @@ -67,7 +67,7 @@ #define MAX_LENGTH 4096 #define MAX_COLUMN_LENGTH 2000 #define APP_NAME TEXT("xmltab") -#define APP_VERSION TEXT("1.0.3") +#define APP_VERSION TEXT("1.0.4") #define LOADING TEXT("Loading...") #define WHITESPACE " \t\r\n" @@ -369,7 +369,7 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) { if (!xml) { free(data); return 0; - } + } INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(icex); @@ -1995,7 +1995,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F3 || wParam == VK_F5 || wParam == VK_F7 || (isCtrl && wParam == 0x46) || // Ctrl + F ((wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) || // 1 - 8 - (wParam == 0x4E || wParam == 0x50) && !getStoredValue(TEXT("disable-np-keys"), 0)) && // N, P + (wParam == 0x4E || wParam == 0x50) && !getStoredValue(TEXT("disable-np-keys"), 0) || // N, P + wParam == 0x51 && getStoredValue(TEXT("exit-by-q"), 0)) && // Q GetDlgCtrlID(GetFocus()) / 100 * 100 != IDC_HEADER_EDIT) { SetFocus(GetParent(hWnd)); keybd_event(wParam, wParam, KEYEVENTF_EXTENDEDKEY, 0); @@ -2009,11 +2010,16 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { case WMU_HOT_CHARS: { BOOL isCtrl = HIWORD(GetKeyState(VK_CONTROL)); + + unsigned char scancode = ((unsigned char*)&lParam)[2]; + UINT key = MapVirtualKey(scancode,MAPVK_VSC_TO_VK); + return !_istprint(wParam) && ( wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F1 || wParam == VK_F3 || wParam == VK_F5 || wParam == VK_F7) || wParam == VK_TAB || wParam == VK_RETURN || - isCtrl && (wParam == 0x46 || wParam == 0x20); + isCtrl && key == 0x46 || // Ctrl + F + getStoredValue(TEXT("exit-by-q"), 0) && key == 0x51 && GetDlgCtrlID(GetFocus()) / 100 * 100 != IDC_HEADER_EDIT; // Q } break; } @@ -2385,7 +2391,7 @@ char* formatXML(const char* data) { buf[bPos] = data[pos]; bPos++; - if (bLen - bPos < 100) { + if (bLen - bPos < 1000) { bLen += 32000; buf = realloc(buf, bLen); } diff --git a/xml.c b/xml.c index 5cf12a8..86db7f6 100644 --- a/xml.c +++ b/xml.c @@ -464,7 +464,20 @@ static const char *xml_parse_tag_body(struct xml_state *st, const char *d) { if (!st->cursor) { /* find first character of terminating pattern */ - m = strchr(d, st->tag->close[0]); + //m = strchr(d, st->tag->close[0]); + + // Fix special chars e.g > inside attributes + // https://forum.wincmd.ru/viewpost.php?p=135766 + int i = 0; + int q = 0; + while (d[i]) { + if (d[i] == st->tag->close[0] && !q) { + m = d + i; + break; + } + q = (q + (d[i] == '"')) % 2; + i++; + } } else { /* find next character of terminating pattern */ for (;;) {