Skip to content

Commit

Permalink
Up to 1.0.4
Browse files Browse the repository at this point in the history
* New option: exit-by-q
* Ability to parse non-valid XML (unescaped > inside attribute values)
  • Loading branch information
little-brother committed Mar 7, 2023
1 parent 35c8e23 commit 66e4e46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 11 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 14 additions & 1 deletion xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down

0 comments on commit 66e4e46

Please sign in to comment.