Skip to content

Commit

Permalink
Up to 0.9.6
Browse files Browse the repository at this point in the history
* Fix 1-8, N/P keys in x32 version
* Trim values in tree
* Add default ini-file
  • Loading branch information
little-brother committed Dec 18, 2021
1 parent 8aa9dd0 commit 4859e6f
Showing 1 changed file with 75 additions and 58 deletions.
133 changes: 75 additions & 58 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
#define MAX_LENGTH 4096
#define MAX_COLUMN_LENGTH 2000
#define APP_NAME TEXT("xmltab")
#define APP_VERSION TEXT("0.9.5")
#define APP_VERSION TEXT("0.9.6")
#define LOADING TEXT("Loading...")
#define WHITESPACE " \t\r\n"

#define XML_TEXT "#TEXT"
#define XML_COMMENT "#COMMENT"
Expand Down Expand Up @@ -144,9 +145,10 @@ int __stdcall ListSearchTextW(HWND hWnd, TCHAR* searchString, int searchParamete
if (TabCtrl_GetCurSel(hTabWnd) == 1) {
HWND hTextWnd = GetDlgItem(hTabWnd, IDC_TEXT);
DWORD len = _tcslen(searchString);
int spos = SendMessage(hTextWnd, EM_GETSEL, 0, 0);
DWORD spos = 0;
SendMessage(hTextWnd, EM_GETSEL, 0, (LPARAM)&spos);
int mode = 0;
FINDTEXTEXW ft = {{HIWORD(spos), -1}, searchString, {0, 0}};
FINDTEXTEXW ft = {{spos, -1}, searchString, {0, 0}};
if (searchParameter & LCS_MATCHCASE)
mode |= FR_MATCHCASE;
if (searchParameter & LCS_WHOLEWORDS)
Expand Down Expand Up @@ -922,10 +924,11 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (kd->wVKey == 0x43) { // C
BOOL isCtrl = HIWORD(GetKeyState(VK_CONTROL));
BOOL isShift = HIWORD(GetKeyState(VK_SHIFT));
BOOL isCopyColumn = getStoredValue(TEXT("copy-column"), 0) && ListView_GetSelectedCount(pHdr->hwndFrom) > 1;
if (!isCtrl && !isShift)
return FALSE;

int action = !isShift ? IDM_COPY_CELL : isCtrl ? IDM_COPY_COLUMN : IDM_COPY_ROWS;
int action = !isShift && !isCopyColumn ? IDM_COPY_CELL : isCtrl || isCopyColumn ? IDM_COPY_COLUMN : IDM_COPY_ROWS;
SendMessage(hWnd, WM_COMMAND, action, 0);
return TRUE;
}
Expand Down Expand Up @@ -1782,12 +1785,7 @@ LRESULT CALLBACK cbNewText(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
return 0;
}

if (msg == WM_KEYDOWN && wParam == VK_F1) {
SendMessage(getMainWindow(hWnd), WM_KEYDOWN, wParam, lParam);
return TRUE;
}

if (msg == WM_KEYDOWN && (wParam == VK_TAB || wParam == VK_ESCAPE)) {
if (msg == WM_KEYDOWN) {
return CallWindowProc(cbHotKey, hWnd, msg, wParam, lParam);
}

Expand All @@ -1802,7 +1800,12 @@ LRESULT CALLBACK cbHotKey(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
(wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) || // 1 - 8
(wParam == 0x4E || wParam == 0x50) && !getStoredValue(TEXT("disable-np-keys"), 0))) { // N, P
HWND hMainWnd = getMainWindow(hWnd);
SendMessage(wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F1 ? hMainWnd : GetParent(hMainWnd), WM_KEYDOWN, wParam, lParam);
if (wParam == VK_TAB || wParam == VK_F1) {
SendMessage(hMainWnd, WM_KEYDOWN, wParam, lParam);
} else {
SetFocus(GetParent(hMainWnd));
keybd_event(wParam, wParam, KEYEVENTF_EXTENDEDKEY, 0);
}
return 0;
}

Expand All @@ -1827,7 +1830,17 @@ HTREEITEM addNode(HWND hTreeWnd, HTREEITEM hParentItem, xml_element* node) {
} else if (node->key && strncmp(node->key, "!--", 3) == 0) {
sprintf(buf8, XML_COMMENT);
} else if (!isEmpty(value)) {
sprintf(buf8, "%s = %s", node->key, value);
// trim value
int l = 0, r = 0;
int len = strlen(value);
for (int i = 0; strchr(WHITESPACE, value[i]) && i < len; i++)
l++;
for (int i = len - 1; strchr(WHITESPACE, value[i]) && i > 0; i--)
r++;
len -= l + r;
sprintf(buf8, "%s = %.*s", node->key, len, value + l);
} else if (isEmpty(value) && node->child_count == 0 && getStoredValue(TEXT("show-empty"), 0)) {
sprintf(buf8, "%s = %s", node->key, "<none>");
} else {
sprintf(buf8, "%s", node->key);
}
Expand Down Expand Up @@ -1947,7 +1960,7 @@ char* formatXML(const char* data) {

BOOL isSave = FALSE;
BOOL isSpace = FALSE;
BOOL isNun = strchr(" \t\r\n", c) != 0;
BOOL isNun = strchr(WHITESPACE, c) != 0;
BOOL isCDataStart = FALSE;

if (1000 == 1000 && isCData) {
Expand Down Expand Up @@ -1993,7 +2006,7 @@ char* formatXML(const char* data) {
} else if (!inTag && isValue && !isNun) {
isSave = TRUE;
} else if (!inTag && isValue && isNun) {
int n = strspn(data + pos, " \t\r\n");
int n = strspn(data + pos, WHITESPACE);
BOOL isEmptyTail = data[pos + n] == '<';
if (isEmptyTail) {
isValue = FALSE;
Expand Down Expand Up @@ -2172,7 +2185,7 @@ BOOL isNumber(const TCHAR* val) {
BOOL isEmpty (const char* s) {
BOOL res = TRUE;
for (int i = 0; s && res && i < strlen(s); i++)
res = strchr(" \t\n\r", s[i]) != NULL;
res = strchr(WHITESPACE, s[i]) != NULL;

return res;
}
Expand Down Expand Up @@ -2217,52 +2230,56 @@ BOOL isUtf8(const char * string) {
}

void mergeSortJoiner(int indexes[], void* data, int l, int m, int r, BOOL isBackward, BOOL isNums) {
int n1 = m - l + 1;
int n2 = r - m;

int L[n1], R[n2];

for (int i = 0; i < n1; i++)
L[i] = indexes[l + i];
for (int j = 0; j < n2; j++)
R[j] = indexes[m + 1 + j];

int i = 0, j = 0, k = l;
while (i < n1 && j < n2) {
int cmp = isNums ? ((double*)data)[L[i]] <= ((double*)data)[R[j]] : _tcscmp(((TCHAR**)data)[L[i]], ((TCHAR**)data)[R[j]]) <= 0;
if (isBackward)
cmp = !cmp;

if (cmp) {
indexes[k] = L[i];
i++;
} else {
indexes[k] = R[j];
j++;
}
k++;
}

while (i < n1) {
indexes[k] = L[i];
i++;
k++;
}

while (j < n2) {
indexes[k] = R[j];
j++;
k++;
}
int n1 = m - l + 1;
int n2 = r - m;

int* L = calloc(n1, sizeof(int));
int* R = calloc(n2, sizeof(int));

for (int i = 0; i < n1; i++)
L[i] = indexes[l + i];
for (int j = 0; j < n2; j++)
R[j] = indexes[m + 1 + j];

int i = 0, j = 0, k = l;
while (i < n1 && j < n2) {
int cmp = isNums ? ((double*)data)[L[i]] <= ((double*)data)[R[j]] : _tcscmp(((TCHAR**)data)[L[i]], ((TCHAR**)data)[R[j]]) <= 0;
if (isBackward)
cmp = !cmp;

if (cmp) {
indexes[k] = L[i];
i++;
} else {
indexes[k] = R[j];
j++;
}
k++;
}

while (i < n1) {
indexes[k] = L[i];
i++;
k++;
}

while (j < n2) {
indexes[k] = R[j];
j++;
k++;
}

free(L);
free(R);
}

void mergeSort(int indexes[], void* data, int l, int r, BOOL isBackward, BOOL isNums) {
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(indexes, data, l, m, isBackward, isNums);
mergeSort(indexes, data, m + 1, r, isBackward, isNums);
mergeSortJoiner(indexes, data, l, m, r, isBackward, isNums);
}
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(indexes, data, l, m, isBackward, isNums);
mergeSort(indexes, data, m + 1, r, isBackward, isNums);
mergeSortJoiner(indexes, data, l, m, r, isBackward, isNums);
}
}

HTREEITEM TreeView_AddItem (HWND hTreeWnd, TCHAR* caption, HTREEITEM parent, LPARAM lParam) {
Expand Down

0 comments on commit 4859e6f

Please sign in to comment.