source: trunk/dll/select.c@ 787

Last change on this file since 787 was 787, checked in by Steven Levine, 18 years ago

Rework UM_FILLSETUPLIST IDM_SAVEDIRCNRSTATE and ..._setups() logic for ticket# 109 and #31
Add GetMSecTimer()
Use GetMSecTimer in DbgMsg
Tweak notebook.ipf scanning page
Move more #pragma alloc_text statements to end of files for OpenWatcom
Delete obsoletes
Revert ExpandAll() ShowTreeRec() DosSleeps to 0 - DosSleep(1) was slowing down inner loops
Drop afFilesToGet - use FilesToGet directly
Optimze ShowTreeRec() collapse logic - was really slow

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: select.c 787 2007-08-19 21:02:37Z stevenhl $
5
6 Container item selection support routines
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2007 Steven H. Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 25 May 05 SHL Rework for ULONGLONG
13 06 Jun 05 SHL Drop unused code
14 06 Jul 06 SHL Support compare content (IDM_SELECTSAMECONTENT)
15 13 Jul 06 SHL Use Runtime_Error
16 29 Jul 06 SHL Use xfgets_bstripcr
17 15 Aug 06 SHL Rework SetMask args and logic
18 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
19 19 Apr 07 SHL Sync with NumItemsToUnhilite mods
20 12 May 07 SHL Use dcd->ulItemsToUnHilite
21 14 Jun 07 SHL SelectAll: make odd expression go away
22 02 Aug 07 SHL Sync with CNRITEM mods
23 04 Aug 07 SHL Use Runtime_Error
24 05 Aug 07 SHL Rework SpecialSelect to use CNRITEM_EXISTS and
25 not use pszFileName since CNRITEM_EXISTS set implies
26 pszFileName not null
27 14 Aug 07 SHL Revert ExpandAll DosSleep to 0
28
29***********************************************************************/
30
31#define INCL_DOS
32#define INCL_WIN
33#define INCL_LONGLONG
34#include <os2.h>
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <share.h>
40#include <io.h>
41
42#include "fm3dll.h"
43#include "fm3str.h"
44
45#pragma alloc_text(SELECT,UnHilite,SelectAll,DeselectAll,MarkAll,SetMask)
46#pragma alloc_text(SELECT,SelectList)
47#pragma alloc_text(SELECT1,Deselect,HideAll,RemoveAll,ExpandAll,InvertAll)
48
49static PSZ pszSrcFile = __FILE__;
50
51VOID UnHilite(HWND hwndCnr, BOOL all, CHAR *** list, ULONG ulItemsToUnHilite)
52{
53 PCNRITEM pci;
54 INT numfiles = 0, numalloc = 0, x = 0;
55 INT attribute = CRA_CURSORED;
56
57 if (all && list && *list) {
58 FreeList(*list);
59 *list = NULL;
60 }
61 pci = (PCNRITEM) CurrentRecord(hwndCnr);
62 if (pci && (INT)pci != -1) {
63 if (pci->rc.flRecordAttr & CRA_SELECTED) {
64 attribute = CRA_SELECTED;
65 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
66 MPFROMSHORT(attribute));
67 }
68 while (pci && (INT)pci != -1) {
69 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
70 MPFROM2SHORT(FALSE, CRA_SELECTED));
71 if (!all)
72 break;
73 // Count is one extra to ensure non-zero elsewhere
74 // x is 0 based index
75 if (x + 2 == ulItemsToUnHilite)
76 break;
77 if (list)
78 AddToList(pci->pszFileName, list, &numfiles, &numalloc);
79 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
80 MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
81 x++;
82 }
83 }
84}
85
86VOID SelectList(HWND hwndCnr, BOOL partial, BOOL deselect, BOOL clearfirst,
87 PCNRITEM pciParent, PSZ filename, CHAR ** list)
88{
89
90 PCNRITEM pci;
91 register INT x;
92 BOOL foundone = FALSE;
93 ULONG errs = 0;
94
95 if (clearfirst && !deselect)
96 UnHilite(hwndCnr, TRUE, NULL, 0);
97 if (list && list[0]) {
98 for (x = 0; list[x]; x++) {
99 pci = FindCnrRecord(hwndCnr,
100 list[x], pciParent, partial, partial, TRUE);
101 if (pci) {
102 WinSendMsg(hwndCnr,
103 CM_SETRECORDEMPHASIS,
104 MPFROMP(pci),
105 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
106 CRA_SELECTED));
107 foundone = TRUE;
108 }
109 }
110 if (!foundone)
111 Runtime_Error(pszSrcFile, __LINE__, "select failed");
112 }
113 else if (filename && *filename) {
114
115 FILE *fp;
116 CHAR input[1024], *p;
117
118 fp = _fsopen(filename, "r", SH_DENYNO);
119 if (fp) {
120 while (!feof(fp)) {
121 if (!xfgets_bstripcr(input, sizeof(input), fp, pszSrcFile, __LINE__))
122 break;
123 if (*input == '\"') {
124 memmove(input, input + 1, strlen(input) + 1);
125 lstrip(input);
126 p = strchr(input, '\"');
127 if (p)
128 *p = 0;
129 rstrip(input);
130 }
131 else {
132 p = strchr(input, ' ');
133 if (p)
134 *p = 0;
135 }
136 /* input now contains name of file to select */
137 pci = FindCnrRecord(hwndCnr,
138 input, pciParent, partial, partial, TRUE);
139 if (pci) /* found it? */
140 WinSendMsg(hwndCnr,
141 CM_SETRECORDEMPHASIS,
142 MPFROMP(pci),
143 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
144 CRA_SELECTED));
145 else
146 errs++;
147 if (errs > 50) { /* prevent runaway on bad file */
148
149 APIRET ret;
150
151 ret = saymsg(MB_YESNO,
152 hwndCnr,
153 GetPString(IDS_POSSIBLEERRORTEXT),
154 GetPString(IDS_MAYNOTBELISTTEXT), filename);
155 if (ret == MBID_NO)
156 break;
157 errs = 0;
158 }
159 }
160 fclose(fp);
161 }
162 }
163}
164
165VOID SelectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
166 PSZ text, BOOL is_arc)
167{
168
169 PCNRITEM pci;
170 BOOL markit;
171 PSZ file;
172 PSZ pszToMatch;
173 MASK Mask;
174 INT x;
175 ULONG textlen = 0;
176
177 if (text)
178 textlen = strlen(text);
179 memset(&Mask, 0, sizeof(Mask));
180 if (maskstr)
181 SetMask(maskstr, &Mask);
182 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
183 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
184 while (pci && (INT)pci != -1) {
185
186 markit = FALSE;
187
188 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
189 if (!is_arc) {
190 if (files && ~pci->attrFile & FILE_DIRECTORY)
191 markit = TRUE;
192 if (dirs && pci->attrFile & FILE_DIRECTORY)
193 markit = TRUE;
194 }
195 else
196 markit = TRUE;
197 if (maskstr && *maskstr && markit) {
198 markit = FALSE;
199 // Point a filename part
200 file = strrchr(pci->pszFileName, '\\');
201 if (!file)
202 file = strrchr(pci->pszFileName, ':');
203 if (file)
204 file++;
205 else
206 file = pci->pszFileName;
207 for (x = 0; Mask.pszMasks[x]; x++) {
208 if (*Mask.pszMasks[x]) {
209 if ((strchr(Mask.pszMasks[x], '\\') ||
210 strchr(Mask.pszMasks[x], ':')))
211 pszToMatch = pci->pszFileName;
212 else
213 pszToMatch = file;
214 if (*Mask.pszMasks[x] != '/') {
215 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE)) {
216 markit = TRUE;
217 }
218 }
219 else {
220 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
221 markit = FALSE;
222 break;
223 }
224 }
225 }
226 } // for
227 }
228 }
229
230 if (markit && text && *text) {
231 if (~pci->attrFile & FILE_DIRECTORY) {
232 PSZ input;
233 markit = FALSE;
234 input = xmalloc(65537, pszSrcFile, __LINE__);
235 if (input) {
236 ULONG pos;
237 LONG len;
238 FILE *inputFile;
239
240 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
241 pos = ftell(inputFile);
242 while (!feof(inputFile)) {
243 if (pos)
244 fseek(inputFile, pos - 256, SEEK_SET);
245 len = fread(input, 1, 65536, inputFile);
246 if (len >= 0) {
247 if (findstring(text, textlen, input, len, FALSE)) {
248 markit = TRUE;
249 break;
250 }
251 }
252 else
253 break;
254 } // while
255 fclose(inputFile);
256 }
257 free(input);
258 DosSleep(1);
259 }
260 }
261 else
262 markit = FALSE;
263 }
264
265 if (markit)
266 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
267 MPFROM2SHORT(TRUE, CRA_SELECTED));
268 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
269 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
270 } // while
271}
272
273VOID DeselectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
274 PSZ text, BOOL is_arc)
275{
276 PCNRITEM pci;
277 BOOL unmarkit;
278 PSZ file;
279 PSZ pszToMatch;
280 MASK Mask;
281 register INT x;
282 ULONG textlen = 0;
283
284 if (text)
285 textlen = strlen(text);
286 memset(&Mask, 0, sizeof(Mask));
287 if (maskstr && *maskstr)
288 SetMask(maskstr, &Mask);
289 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
290 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
291 while (pci && (INT)pci != -1) {
292 unmarkit = FALSE;
293 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
294 if (!is_arc) {
295 if (files && ~pci->attrFile & FILE_DIRECTORY)
296 unmarkit = TRUE;
297 if (dirs && (pci->attrFile & FILE_DIRECTORY))
298 unmarkit = TRUE;
299 }
300 else
301 unmarkit = TRUE;
302 if (maskstr && *maskstr && unmarkit) {
303 unmarkit = FALSE;
304 file = strrchr(pci->pszFileName, '\\');
305 if (!file)
306 file = strrchr(pci->pszFileName, ':');
307 if (file)
308 file++;
309 else
310 file = pci->pszFileName;
311 for (x = 0; Mask.pszMasks[x]; x++) {
312 if (*Mask.pszMasks[x]) {
313 if (strchr(Mask.pszMasks[x], '\\') ||
314 strchr(Mask.pszMasks[x], ':'))
315 pszToMatch = pci->pszFileName;
316 else
317 pszToMatch = file;
318 if (*Mask.pszMasks[x] != '/') {
319 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE))
320 unmarkit = TRUE;
321 }
322 else {
323 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
324 unmarkit = FALSE;
325 break;
326 }
327 }
328 }
329 }
330 }
331 }
332
333 if (unmarkit && text && *text) {
334 if (~pci->attrFile & FILE_DIRECTORY) {
335 PSZ input;
336 unmarkit = FALSE;
337 input = xmalloc(65537, pszSrcFile, __LINE__);
338 if (input) {
339 ULONG pos;
340 LONG len;
341 FILE *inputFile;
342
343 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
344 pos = ftell(inputFile);
345 while (!feof(inputFile)) {
346 if (pos)
347 fseek(inputFile, pos - 256, SEEK_SET);
348 len = fread(input, 1, 65536, inputFile);
349 if (len >= 0) {
350 if (findstring(text, textlen, input, len, FALSE)) {
351 unmarkit = TRUE;
352 break;
353 }
354 }
355 else
356 break;
357 } // while
358 fclose(inputFile);
359 }
360 free(input);
361 DosSleep(1);
362 }
363 }
364 else
365 unmarkit = FALSE;
366 }
367
368 if (unmarkit)
369 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, pci,
370 MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED |
371 CRA_INUSE | CRA_SOURCE));
372 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
373 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
374 }
375}
376
377VOID Deselect(HWND hwndCnr)
378{
379 PCNRITEM pcil;
380
381 pcil = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
382 MPFROMLONG(CMA_FIRST),
383 MPFROMSHORT(CRA_SELECTED));
384 while (pcil && (INT)pcil != -1) {
385 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pcil),
386 MPFROM2SHORT(FALSE, CRA_SELECTED));
387 pcil = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pcil),
388 MPFROMSHORT(CRA_SELECTED));
389 }
390}
391
392//=== HideAll() Hide all selected records ===
393
394VOID HideAll(HWND hwndCnr)
395{
396 PCNRITEM pci, pciH;
397 INT attribute = CRA_CURSORED;
398 CNRINFO cnri;
399 BOOL didone = FALSE;
400
401 memset(&cnri, 0, sizeof(CNRINFO));
402 cnri.cb = sizeof(CNRINFO);
403 WinSendMsg(hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
404 MPFROMLONG(sizeof(CNRINFO)));
405 pci = (PCNRITEM) CurrentRecord(hwndCnr);
406 if (pci && (INT)pci != -1) {
407 if (pci->rc.flRecordAttr & CRA_SELECTED) {
408 attribute = CRA_SELECTED;
409 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
410 MPFROMSHORT(attribute));
411 }
412 }
413 while (pci && (INT)pci != -1) {
414 pciH = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
415 MPFROMSHORT(attribute));
416 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
417 MPFROM2SHORT(FALSE, CRA_CURSORED | CRA_SELECTED |
418 CRA_INUSE | CRA_SOURCE));
419 pci->rc.flRecordAttr |= CRA_FILTERED;
420 didone = TRUE;
421 if (fSyncUpdates) {
422 if (cnri.flWindowAttr & CV_DETAIL)
423 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
424 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
425 else
426 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci),
427 MPFROM2SHORT(1, CMA_REPOSITION | CMA_ERASE));
428 }
429 pci = pciH;
430 }
431 if (didone && !fSyncUpdates)
432 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
433 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
434}
435
436VOID MarkAll(HWND hwndCnr, BOOL quitit, BOOL target, BOOL source)
437{
438 PCNRITEM pci;
439 INT attribute = CRA_CURSORED;
440
441 if (quitit)
442 attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
443 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
444 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
445 if (pci && (INT)pci != -1) {
446 if (attribute == CRA_CURSORED) {
447 if (pci->rc.flRecordAttr & CRA_SELECTED) {
448 attribute = CRA_SELECTED;
449 pci =
450 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
451 MPFROMSHORT(attribute));
452 }
453 }
454 }
455 while (pci && (INT)pci != -1) {
456 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
457 MPFROM2SHORT(!quitit,
458 target ? CRA_TARGET : source ? CRA_SOURCE :
459 CRA_INUSE));
460 pci =
461 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
462 MPFROMSHORT(attribute));
463 }
464}
465
466VOID RemoveAll(HWND hwndCnr, ULONGLONG * pullTotalBytes,
467 ULONG * pulTotalFiles)
468{
469 PCNRITEM pci;
470 INT attribute = CRA_CURSORED;
471 BOOL didone = FALSE;
472
473 pci = (PCNRITEM) CurrentRecord(hwndCnr);
474 if (pci && (INT)pci != -1) {
475 if (pci->rc.flRecordAttr & CRA_SELECTED) {
476 attribute = CRA_SELECTED;
477 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
478 MPFROMSHORT(attribute));
479 }
480 }
481 while (pci && (INT)pci != -1) {
482 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
483 didone = TRUE;
484 if (pulTotalFiles)
485 *pulTotalFiles -= 1;
486 if (pullTotalBytes)
487 *pullTotalBytes -= (pci->cbFile + pci->easize);
488 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
489 MPFROM2SHORT(0, CRA_SELECTED));
490 if (fSyncUpdates)
491 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
492 else
493 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE);
494 if (attribute == CRA_CURSORED)
495 break;
496 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
497 MPFROMSHORT(attribute));
498 }
499 else
500 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
501 MPFROMSHORT(attribute));
502 }
503 if (didone && !fSyncUpdates)
504 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
505 MPFROM2SHORT(0, CMA_REPOSITION));
506}
507
508//== SetMask() Convert mask string to array of pointers to masks ==
509
510VOID SetMask(PSZ maskstr, MASK * mask)
511{
512 UINT x;
513 PSZ p;
514
515 if (maskstr)
516 strcpy(mask->szMask, maskstr); // Got new mask string
517 // Build array of pointers
518 p = mask->szMaskCopy;
519 strcpy(p, mask->szMask);
520 // Allow up to 25 masks - ignore extras
521 for (x = 0; *p && x < 25; x++) {
522 mask->pszMasks[x] = p;
523 while (*p && *p != ';')
524 p++; // Find separator
525 if (*p) {
526 *p = 0; // Replace ;
527 p++;
528 }
529 } // for
530 mask->pszMasks[x] = NULL; // Mark end
531}
532
533VOID ExpandAll(HWND hwndCnr, BOOL expand, PCNRITEM pciParent)
534{
535 PCNRITEM pci;
536
537 if (!pciParent)
538 pciParent = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
539 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
540 if (pciParent) {
541 if (expand && ~pciParent->rc.flRecordAttr & CRA_EXPANDED)
542 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciParent), MPVOID);
543 else if (!expand && (pciParent->rc.flRecordAttr & CRA_EXPANDED))
544 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciParent), MPVOID);
545 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
546 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
547 if (pci)
548 DosSleep(0);
549 while (pci && (INT)pci != -1) {
550 ExpandAll(hwndCnr, expand, pci);
551 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
552 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
553 }
554 }
555 DosSleep(0);
556}
557
558VOID InvertAll(HWND hwndCnr)
559{
560 PCNRITEM pci;
561
562 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
563 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
564 while (pci && (INT)pci != -1) {
565 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
566 if (~pci->rc.flRecordAttr & CRA_SELECTED)
567 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
568 MPFROM2SHORT(TRUE, CRA_SELECTED));
569 else
570 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
571 MPFROM2SHORT(FALSE, CRA_SELECTED));
572 }
573 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
574 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
575 }
576}
577
578#pragma alloc_text (SELECT3,SpecialSelect)
579#pragma alloc_text(SELECT4,FreeCnrs,SpecialSelect2,CompSSNames,CompSSNamesB)
580
581/**
582 * Do select actions for compare directories containers
583 *
584 */
585
586VOID SpecialSelect(HWND hwndCnrS, HWND hwndCnrD, INT action, BOOL reset)
587{
588 PCNRITEM pciS, pciD, *pciSa = NULL, *pciDa = NULL;
589 CNRINFO cnri;
590 BOOL slow = FALSE;
591 UINT x, numD, numS;
592
593 if (!hwndCnrS || !hwndCnrD) {
594 Runtime_Error(pszSrcFile, __LINE__, "hwndCnrS %p hwndCnrD %p", hwndCnrS, hwndCnrD);
595 return;
596 }
597
598 memset(&cnri, 0, sizeof(CNRINFO));
599 cnri.cb = sizeof(CNRINFO);
600 WinSendMsg(hwndCnrD, CM_QUERYCNRINFO, MPFROMP(&cnri),
601 MPFROMLONG(sizeof(CNRINFO)));
602 numD = cnri.cRecords;
603 memset(&cnri, 0, sizeof(CNRINFO));
604 cnri.cb = sizeof(CNRINFO);
605 WinSendMsg(hwndCnrS, CM_QUERYCNRINFO, MPFROMP(&cnri),
606 MPFROMLONG(sizeof(CNRINFO)));
607 numS = cnri.cRecords;
608 if (!numD || numS != numD) {
609 Runtime_Error(pszSrcFile, __LINE__, "numD %u != numS %u", numD, numS);
610 return;
611 }
612 pciDa = xmalloc(sizeof(PCNRITEM) * numD, pszSrcFile, __LINE__);
613 if (!pciDa)
614 return;
615
616 pciSa = xmalloc(sizeof(PCNRITEM) * numS, pszSrcFile, __LINE__);
617 if (!pciSa) {
618 free(pciDa);
619 return;
620 }
621
622Restart:
623
624 memset(pciDa, 0, sizeof(PCNRITEM) * numD);
625 memset(pciSa, 0, sizeof(PCNRITEM) * numS);
626
627 pciD = (PCNRITEM)WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
628 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
629 x = 0;
630 while (pciD && (INT)pciD != -1 && x < numD) {
631 if (reset)
632 pciD->flags = 0;
633 pciDa[x] = pciD;
634 x++;
635 if (!slow)
636 pciD = (PCNRITEM) pciD->rc.preccNextRecord;
637 else
638 pciD = (PCNRITEM) WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
639 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
640 if (!(x % 500))
641 DosSleep(1);
642 // else if (!(x % 50))
643 // DosSleep(0);
644 } // while
645
646 if (numD != x) {
647 if (!slow) {
648 slow = TRUE;
649 goto Restart;
650 }
651 free(pciDa);
652 free(pciSa);
653 Runtime_Error(pszSrcFile, __LINE__, "numD %u != x %lu", numD, x);
654 return;
655 }
656
657 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
658 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
659 x = 0;
660 while (pciS && (INT)pciS != -1 && x < numS) {
661 if (reset)
662 pciS->flags = 0;
663 pciSa[x] = pciS;
664 x++;
665 if (!slow)
666 pciS = (PCNRITEM) pciS->rc.preccNextRecord;
667 else
668 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pciS),
669 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
670 if (!(x % 500))
671 DosSleep(1);
672 // else if (!(x % 50))
673 // DosSleep(0);
674 } // while
675
676 if (numS != x) {
677 if (!slow) {
678 slow = TRUE;
679 goto Restart;
680 }
681 free(pciSa);
682 free(pciDa);
683 Runtime_Error(pszSrcFile, __LINE__, "numS (%lu) != x (%lu)", numS, x);
684 return;
685 }
686
687 // 05 Aug 07 SHL fixme to know what sets reset
688 if (reset) {
689 // Update flags for files that exist on both sides
690 for (x = 0; x < numS; x++) {
691
692 // 05 Aug 07 SHL fixme to know if should clear first
693 if (!*pciSa[x]->pszFileName || !*pciDa[x]->pszFileName)
694 continue;
695
696 pciSa[x]->flags |= CNRITEM_EXISTS; // File exists on both sides
697 pciDa[x]->flags |= CNRITEM_EXISTS;
698 if (pciSa[x]->cbFile + pciSa[x]->easize >
699 pciDa[x]->cbFile + pciDa[x]->easize) {
700 pciSa[x]->flags |= CNRITEM_LARGER;
701 pciDa[x]->flags |= CNRITEM_SMALLER;
702 }
703 else if (pciSa[x]->cbFile + pciSa[x]->easize <
704 pciDa[x]->cbFile + pciDa[x]->easize) {
705 pciSa[x]->flags |= CNRITEM_SMALLER;
706 pciDa[x]->flags |= CNRITEM_LARGER;
707 }
708 if ((pciSa[x]->date.year > pciDa[x]->date.year) ? TRUE :
709 (pciSa[x]->date.year < pciDa[x]->date.year) ? FALSE :
710 (pciSa[x]->date.month > pciDa[x]->date.month) ? TRUE :
711 (pciSa[x]->date.month < pciDa[x]->date.month) ? FALSE :
712 (pciSa[x]->date.day > pciDa[x]->date.day) ? TRUE :
713 (pciSa[x]->date.day < pciDa[x]->date.day) ? FALSE :
714 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? TRUE :
715 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? FALSE :
716 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? TRUE :
717 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? FALSE :
718 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? TRUE :
719 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? FALSE : FALSE) {
720 pciSa[x]->flags |= CNRITEM_NEWER;
721 pciDa[x]->flags |= CNRITEM_OLDER;
722 }
723 else if ((pciSa[x]->date.year < pciDa[x]->date.year) ? TRUE :
724 (pciSa[x]->date.year > pciDa[x]->date.year) ? FALSE :
725 (pciSa[x]->date.month < pciDa[x]->date.month) ? TRUE :
726 (pciSa[x]->date.month > pciDa[x]->date.month) ? FALSE :
727 (pciSa[x]->date.day < pciDa[x]->date.day) ? TRUE :
728 (pciSa[x]->date.day > pciDa[x]->date.day) ? FALSE :
729 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? TRUE :
730 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? FALSE :
731 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? TRUE :
732 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? FALSE :
733 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? TRUE :
734 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? FALSE :
735 FALSE) {
736 pciSa[x]->flags |= CNRITEM_OLDER;
737 pciDa[x]->flags |= CNRITEM_NEWER;
738 }
739 if (!(x % 500))
740 DosSleep(1);
741 // else if (!(x % 50))
742 // DosSleep(0);
743 } // for
744 } // if reset
745
746 switch (action) {
747 case IDM_SELECTIDENTICAL:
748 for (x = 0; x < numS; x++) {
749 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
750 pciSa[x]->flags & CNRITEM_EXISTS &&
751 ~pciSa[x]->flags & CNRITEM_SMALLER &&
752 ~pciSa[x]->flags & CNRITEM_LARGER &&
753 ~pciSa[x]->flags & CNRITEM_NEWER &&
754 ~pciSa[x]->flags & CNRITEM_OLDER) {
755 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
756 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
757 MPFROM2SHORT(TRUE, CRA_SELECTED));
758 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
759 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
760 MPFROM2SHORT(TRUE, CRA_SELECTED));
761 }
762 if (!(x % 500))
763 DosSleep(1);
764 // else if (!(x % 50))
765 // DosSleep(0);
766 } // for
767 break;
768
769 case IDM_SELECTSAME:
770 for (x = 0; x < numS; x++) {
771 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
772 pciSa[x]->flags & CNRITEM_EXISTS &&
773 ~pciSa[x]->flags & CNRITEM_SMALLER &&
774 ~pciSa[x]->flags & CNRITEM_LARGER) {
775 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
776 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
777 MPFROM2SHORT(TRUE, CRA_SELECTED));
778 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
779 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
780 MPFROM2SHORT(TRUE, CRA_SELECTED));
781 }
782 if (!(x % 500))
783 DosSleep(1);
784 // else if (!(x % 50))
785 // DosSleep(0);
786 }
787 break;
788
789 case IDM_SELECTSAMECONTENT:
790 for (x = 0; x < numS; x++) {
791 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
792 pciSa[x]->flags & CNRITEM_EXISTS)
793 {
794 FILE *fp1 = NULL;
795 FILE *fp2 = NULL;
796 BOOL gotMatch = FALSE;
797 UINT errLineNo = 0;
798 UINT compErrno = 0;
799 CHAR buf1[1024];
800 CHAR buf2[1024];
801 HAB hab = WinQueryAnchorBlock(hwndCnrS);
802
803 if (!*pciSa[x]->pszFileName ||
804 !*pciDa[x]->pszFileName) {
805 Runtime_Error(pszSrcFile, __LINE__,
806 "CNRITEM_EXISTS set with null file name for index %u", x);
807 break;
808 }
809
810 fp1 = _fsopen(pciSa[x]->pszFileName, "rb", SH_DENYNO);
811 if (!fp1) {
812 errLineNo = __LINE__;
813 compErrno = errno;
814 }
815 else {
816 fp2 = _fsopen(pciDa[x]->pszFileName, "rb", SH_DENYNO);
817 if (!fp2) {
818 errLineNo = __LINE__;
819 compErrno = errno;
820 }
821 else {
822 size_t len1 = filelength(fileno(fp1));
823 size_t len2 = filelength(fileno(fp2));
824
825 if (len1 == len2) {
826 setbuf(fp1, NULL);
827 setbuf(fp2, NULL);
828 while (WinIsWindow(hab, hwndCnrS)) {
829 size_t numread1 = fread(buf1, 1, 1024, fp1);
830 size_t numread2 = fread(buf2, 1, 1024, fp2);
831
832 if (!numread1 || !numread2 || numread1 != numread2) {
833 if (ferror(fp1) || ferror(fp2)) {
834 errLineNo = __LINE__;
835 compErrno = errno;
836 }
837 else if (feof(fp1) && feof(fp2))
838 gotMatch = TRUE;
839 break;
840 }
841 else if (memcmp(buf1, buf2, numread1))
842 break;
843 } // while
844 } // same len
845 }
846 }
847
848 if (fp1)
849 fclose(fp1);
850
851 if (fp2)
852 fclose(fp2);
853
854 if (errLineNo) {
855 Runtime_Error(pszSrcFile, errLineNo,
856 "error %d while comparing", compErrno);
857 }
858
859 if (gotMatch) {
860 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
861 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
862 MPFROM2SHORT(TRUE, CRA_SELECTED));
863 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
864 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
865 MPFROM2SHORT(TRUE, CRA_SELECTED));
866 }
867 }
868 if (!(x % 500))
869 DosSleep(1);
870 // else if (!(x % 50))
871 // DosSleep(0);
872 } // for
873 break;
874
875 case IDM_SELECTBOTH:
876 for (x = 0; x < numS; x++) {
877 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
878 pciSa[x]->flags & CNRITEM_EXISTS) {
879 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
880 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
881 MPFROM2SHORT(TRUE, CRA_SELECTED));
882 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
883 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
884 MPFROM2SHORT(TRUE, CRA_SELECTED));
885 }
886 if (!(x % 500))
887 DosSleep(1);
888 // else if (!(x % 50))
889 // DosSleep(0);
890 }
891 break;
892
893 case IDM_SELECTONE:
894 for (x = 0; x < numS; x++) {
895 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
896 ~pciSa[x]->flags & CNRITEM_EXISTS) {
897 if (*pciSa[x]->pszFileName) {
898 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
899 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
900 MPFROM2SHORT(TRUE, CRA_SELECTED));
901 }
902 }
903 else if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
904 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
905 MPFROM2SHORT(TRUE, CRA_SELECTED));
906 }
907 }
908 if (!(x % 500))
909 DosSleep(1);
910 // else if (!(x % 50))
911 // DosSleep(0);
912 }
913 break;
914
915 case IDM_SELECTBIGGER:
916 for (x = 0; x < numS; x++) {
917 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
918 if (pciSa[x]->flags & CNRITEM_LARGER) {
919 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
920 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
921 MPFROM2SHORT(TRUE, CRA_SELECTED));
922 }
923 else if (pciDa[x]->flags & CNRITEM_LARGER) {
924 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
925 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
926 MPFROM2SHORT(TRUE, CRA_SELECTED));
927 }
928 }
929 if (!(x % 500))
930 DosSleep(1);
931 // else if (!(x % 50))
932 // DosSleep(0);
933 }
934 break;
935
936 case IDM_SELECTSMALLER:
937 for (x = 0; x < numS; x++) {
938 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
939 if (pciSa[x]->flags & CNRITEM_SMALLER) {
940 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
941 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
942 MPFROM2SHORT(TRUE, CRA_SELECTED));
943 }
944 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
945 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
946 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
947 MPFROM2SHORT(TRUE, CRA_SELECTED));
948 }
949 }
950 if (!(x % 500))
951 DosSleep(1);
952 // else if (!(x % 50))
953 // DosSleep(0);
954 }
955 break;
956
957 case IDM_SELECTNEWER:
958 for (x = 0; x < numS; x++) {
959 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
960 if (pciSa[x]->flags & CNRITEM_NEWER) {
961 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
962 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
963 MPFROM2SHORT(TRUE, CRA_SELECTED));
964 }
965 else if (pciDa[x]->flags & CNRITEM_NEWER) {
966 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
967 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
968 MPFROM2SHORT(TRUE, CRA_SELECTED));
969 }
970 }
971 if (!(x % 500))
972 DosSleep(1);
973 // else if (!(x % 50))
974 // DosSleep(0);
975 }
976 break;
977
978 case IDM_SELECTOLDER:
979 for (x = 0; x < numS; x++) {
980 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
981 if (pciSa[x]->flags & CNRITEM_OLDER) {
982 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
983 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
984 MPFROM2SHORT(TRUE, CRA_SELECTED));
985 }
986 else if (pciDa[x]->flags & CNRITEM_OLDER) {
987 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
988 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
989 MPFROM2SHORT(TRUE, CRA_SELECTED));
990 }
991 }
992 if (!(x % 500))
993 DosSleep(1);
994 // else if (!(x % 50))
995 // DosSleep(0);
996 }
997 break;
998
999 case IDM_DESELECTBOTH:
1000 for (x = 0; x < numS; x++) {
1001 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1002 pciSa[x]->flags & CNRITEM_EXISTS) {
1003 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1004 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1005 MPFROM2SHORT(FALSE, CRA_SELECTED));
1006 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1007 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1008 MPFROM2SHORT(FALSE, CRA_SELECTED));
1009 }
1010 if (!(x % 500))
1011 DosSleep(1);
1012 // else if (!(x % 50))
1013 // DosSleep(0);
1014 }
1015 break;
1016
1017 case IDM_DESELECTONE:
1018 for (x = 0; x < numS; x++) {
1019 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1020 if (~pciSa[x]->flags & CNRITEM_EXISTS) {
1021 if (*pciSa[x]->pszFileName) {
1022 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1023 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1024 MPFROM2SHORT(FALSE, CRA_SELECTED));
1025 }
1026 else if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1027 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1028 MPFROM2SHORT(FALSE, CRA_SELECTED));
1029 }
1030 }
1031 if (!(x % 500))
1032 DosSleep(1);
1033 // else if (!(x % 50))
1034 // DosSleep(0);
1035 }
1036 break;
1037
1038 case IDM_DESELECTBIGGER:
1039 for (x = 0; x < numS; x++) {
1040 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1041 if (pciSa[x]->flags & CNRITEM_LARGER) {
1042 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1043 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1044 MPFROM2SHORT(FALSE, CRA_SELECTED));
1045 }
1046 else if (pciDa[x]->flags & CNRITEM_LARGER) {
1047 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1048 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1049 MPFROM2SHORT(FALSE, CRA_SELECTED));
1050 }
1051 }
1052 if (!(x % 500))
1053 DosSleep(1);
1054 // else if (!(x % 50))
1055 // DosSleep(0);
1056 }
1057 break;
1058
1059 case IDM_DESELECTSMALLER:
1060 for (x = 0; x < numS; x++) {
1061 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1062 if (pciSa[x]->flags & CNRITEM_SMALLER) {
1063 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1064 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1065 MPFROM2SHORT(FALSE, CRA_SELECTED));
1066 }
1067 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
1068 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1069 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1070 MPFROM2SHORT(FALSE, CRA_SELECTED));
1071 }
1072 }
1073 if (!(x % 500))
1074 DosSleep(1);
1075 // else if (!(x % 50))
1076 // DosSleep(0);
1077 }
1078 break;
1079
1080 case IDM_DESELECTNEWER:
1081 for (x = 0; x < numS; x++) {
1082 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1083 if (pciSa[x]->flags & CNRITEM_NEWER) {
1084 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1085 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1086 MPFROM2SHORT(FALSE, CRA_SELECTED));
1087 }
1088 else if (pciDa[x]->flags & CNRITEM_NEWER) {
1089 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1090 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1091 MPFROM2SHORT(FALSE, CRA_SELECTED));
1092 }
1093 }
1094 if (!(x % 500))
1095 DosSleep(1);
1096 // else if (!(x % 50))
1097 // DosSleep(0);
1098 }
1099 break;
1100
1101 case IDM_DESELECTOLDER:
1102 for (x = 0; x < numS; x++) {
1103 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1104 if (pciSa[x]->flags & CNRITEM_OLDER) {
1105 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1106 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1107 MPFROM2SHORT(FALSE, CRA_SELECTED));
1108 }
1109 else if (pciDa[x]->flags & CNRITEM_OLDER) {
1110 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1111 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1112 MPFROM2SHORT(FALSE, CRA_SELECTED));
1113 }
1114 }
1115 if (!(x % 500))
1116 DosSleep(1);
1117 // else if (!(x % 50))
1118 // DosSleep(0);
1119 }
1120 break;
1121
1122 default:
1123 break;
1124 }
1125
1126 if (reset) {
1127 while (numS) {
1128 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD,
1129 MPFROMP(pciSa), MPFROM2SHORT((min(numS, 65535)), 0));
1130 DosSleep(1);
1131 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD,
1132 MPFROMP(pciDa), MPFROM2SHORT((min(numD, 65535)), 0));
1133 numS -= min(numS, 65535);
1134 if (numS)
1135 DosSleep(1);
1136 }
1137 }
1138
1139 free(pciSa);
1140 free(pciDa);
1141 DosPostEventSem(CompactSem);
1142}
1143
1144struct SS
1145{
1146 PCNRITEM pci;
1147 BOOL unique, all, smallest, largest, newest, oldest;
1148};
1149
1150struct Cnr
1151{
1152 HWND hwndCnr;
1153 ULONG numfiles;
1154 struct SS *ss;
1155};
1156
1157static int CompSSNamesB(const void *s1, const void *s2)
1158{
1159 struct SS *ss2 = (struct SS *)s2;
1160
1161 return stricmp((PSZ)s1, ss2->pci->pszFileName);
1162}
1163
1164static int CompSSNames(const void *s1, const void *s2)
1165{
1166 struct SS *ss1 = (struct SS *)s1;
1167 struct SS *ss2 = (struct SS *)s2;
1168
1169 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
1170}
1171
1172VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
1173{
1174 register INT z;
1175
1176 for (z = 0; z < numw; z++) {
1177 if (Cnrs[z].ss)
1178 free(Cnrs[z].ss);
1179 }
1180 free(Cnrs);
1181 DosPostEventSem(CompactSem);
1182}
1183
1184/**
1185 * Do select actions for single container
1186 *
1187 */
1188
1189VOID SpecialSelect2(HWND hwndParent, INT action)
1190{
1191 PCNRITEM pci;
1192 HENUM henum;
1193 HWND hwnd;
1194 register INT numwindows = 0, w, x, z, cmp;
1195 struct Cnr *Cnrs = NULL;
1196 struct SS *bsres;
1197
1198 if (!hwndParent)
1199 return;
1200
1201 /* count directory containers, build array of hwnds */
1202 henum = WinBeginEnumWindows(hwndParent);
1203 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
1204 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
1205 Cnrs =
1206 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
1207 __LINE__);
1208 if (!Cnrs) {
1209 Notify(GetPString(IDS_OUTOFMEMORY));
1210 return;
1211 }
1212 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
1213 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
1214 FID_CLIENT),
1215 DIR_CNR);
1216 numwindows++;
1217 }
1218 }
1219 WinEndEnumWindows(henum);
1220 if (numwindows < 2) {
1221 FreeCnrs(Cnrs, numwindows);
1222 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
1223 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
1224 return;
1225 }
1226 if (numwindows > 4) {
1227 WinSendMsg(Cnrs[0].
1228 hwndCnr,
1229 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
1230 DosSleep(1);
1231 }
1232
1233 /* count records, build array of pointers to records */
1234 for (z = 0; z < numwindows; z++) {
1235 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1236 CM_QUERYRECORD,
1237 MPVOID,
1238 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1239 x = 0;
1240 while (pci && (INT)pci != -1) {
1241 if (~pci->rc.flRecordAttr & CRA_FILTERED &&
1242 ~pci->attrFile & FILE_DIRECTORY) {
1243 Cnrs[z].ss =
1244 xrealloc(Cnrs[z].ss, (x + 1) * sizeof(struct SS), pszSrcFile,
1245 __LINE__);
1246 if (!Cnrs[z].ss) {
1247 FreeCnrs(Cnrs, numwindows);
1248 Notify(GetPString(IDS_OUTOFMEMORY));
1249 return;
1250 }
1251 memset(&Cnrs[z].ss[x], 0, sizeof(struct SS));
1252 Cnrs[z].ss[x].pci = pci;
1253 x++;
1254 }
1255 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1256 CM_QUERYRECORD,
1257 MPFROMP(pci),
1258 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1259 }
1260 DosSleep(1);
1261 Cnrs[z].numfiles = x;
1262 if (Cnrs[z].numfiles)
1263 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
1264 }
1265
1266 for (z = 0; z < numwindows; z++) {
1267 for (x = 0; x < Cnrs[z].numfiles; x++) {
1268 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
1269 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].smallest =
1270 Cnrs[z].ss[x].largest = TRUE;
1271 for (w = 0; w < numwindows; w++) {
1272 if (w != z && Cnrs[w].numfiles) {
1273 bsres = (struct SS *)bsearch(Cnrs[z].ss[x].pci->pszFileName,
1274 Cnrs[w].ss, Cnrs[w].numfiles,
1275 sizeof(struct SS), CompSSNamesB);
1276 if (bsres) {
1277 Cnrs[z].ss[x].unique = FALSE;
1278 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize >
1279 bsres->pci->cbFile + bsres->pci->easize)
1280 Cnrs[z].ss[x].smallest = FALSE;
1281 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize <
1282 bsres->pci->cbFile + bsres->pci->easize)
1283 Cnrs[z].ss[x].largest = FALSE;
1284 cmp =
1285 (Cnrs[z].ss[x].pci->date.year >
1286 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year <
1287 bsres->pci->date.
1288 year) ? FALSE : (Cnrs[z].
1289 ss[x].pci->
1290 date.month >
1291 bsres->pci->
1292 date.
1293 month) ? TRUE
1294 : (Cnrs[z].ss[x].pci->date.month <
1295 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1296 day >
1297 bsres->pci->date.
1298 day) ? TRUE : (Cnrs[z].
1299 ss[x].pci->
1300 date.day <
1301 bsres->
1302 pci->date.
1303 day) ?
1304 FALSE : (Cnrs[z].ss[x].pci->time.hours >
1305 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1306 time.hours <
1307 bsres->pci->time.
1308 hours) ? FALSE
1309 : (Cnrs[z].ss[x].pci->time.minutes >
1310 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1311 minutes <
1312 bsres->pci->time.
1313 minutes) ? FALSE
1314 : (Cnrs[z].ss[x].pci->time.seconds >
1315 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1316 seconds <
1317 bsres->pci->time.
1318 seconds) ? FALSE : FALSE;
1319 if (!cmp)
1320 Cnrs[z].ss[x].newest = FALSE;
1321 cmp =
1322 (Cnrs[z].ss[x].pci->date.year <
1323 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year >
1324 bsres->pci->date.
1325 year) ? FALSE : (Cnrs[z].
1326 ss[x].pci->
1327 date.month <
1328 bsres->pci->
1329 date.
1330 month) ? TRUE
1331 : (Cnrs[z].ss[x].pci->date.month >
1332 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1333 day <
1334 bsres->pci->date.
1335 day) ? TRUE : (Cnrs[z].
1336 ss[x].pci->
1337 date.day >
1338 bsres->
1339 pci->date.
1340 day) ?
1341 FALSE : (Cnrs[z].ss[x].pci->time.hours <
1342 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1343 time.hours >
1344 bsres->pci->time.
1345 hours) ? FALSE
1346 : (Cnrs[z].ss[x].pci->time.minutes <
1347 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1348 minutes >
1349 bsres->pci->time.
1350 minutes) ? FALSE
1351 : (Cnrs[z].ss[x].pci->time.seconds <
1352 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1353 seconds >
1354 bsres->pci->time.
1355 seconds) ? FALSE : FALSE;
1356 if (!cmp)
1357 Cnrs[z].ss[x].oldest = FALSE;
1358 cmp = 0;
1359 break;
1360 }
1361 else
1362 Cnrs[z].ss[x].all = FALSE;
1363 }
1364 }
1365 if (Cnrs[z].ss[x].unique)
1366 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].newest = Cnrs[z].ss[x].all =
1367 Cnrs[z].ss[x].largest = Cnrs[z].ss[x].smallest = FALSE;
1368 DosSleep(1);
1369 }
1370 DosSleep(1);
1371 }
1372
1373 switch (action) {
1374 case IDM_SELECTBOTH:
1375 for (z = 0; z < numwindows; z++) {
1376 for (x = 0; x < Cnrs[z].numfiles; x++) {
1377 if (Cnrs[z].ss[x].all)
1378 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1379 MPFROMP(Cnrs[z].ss[x].pci),
1380 MPFROM2SHORT(TRUE, CRA_SELECTED));
1381 }
1382 DosSleep(1);
1383 }
1384 break;
1385 case IDM_SELECTMORE:
1386 for (z = 0; z < numwindows; z++) {
1387 for (x = 0; x < Cnrs[z].numfiles; x++) {
1388 if (!Cnrs[z].ss[x].unique)
1389 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1390 MPFROMP(Cnrs[z].ss[x].pci),
1391 MPFROM2SHORT(TRUE, CRA_SELECTED));
1392 }
1393 DosSleep(1);
1394 }
1395 break;
1396 case IDM_SELECTONE:
1397 for (z = 0; z < numwindows; z++) {
1398 for (x = 0; x < Cnrs[z].numfiles; x++) {
1399 if (Cnrs[z].ss[x].unique)
1400 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1401 MPFROMP(Cnrs[z].ss[x].pci),
1402 MPFROM2SHORT(TRUE, CRA_SELECTED));
1403 }
1404 DosSleep(1);
1405 }
1406 break;
1407 case IDM_SELECTNEWER:
1408 for (z = 0; z < numwindows; z++) {
1409 for (x = 0; x < Cnrs[z].numfiles; x++) {
1410 if (Cnrs[z].ss[x].newest)
1411 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1412 MPFROMP(Cnrs[z].ss[x].pci),
1413 MPFROM2SHORT(TRUE, CRA_SELECTED));
1414 }
1415 DosSleep(1);
1416 }
1417 break;
1418 case IDM_SELECTOLDER:
1419 for (z = 0; z < numwindows; z++) {
1420 for (x = 0; x < Cnrs[z].numfiles; x++) {
1421 if (Cnrs[z].ss[x].oldest)
1422 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1423 MPFROMP(Cnrs[z].ss[x].pci),
1424 MPFROM2SHORT(TRUE, CRA_SELECTED));
1425 }
1426 DosSleep(1);
1427 }
1428 break;
1429 case IDM_SELECTBIGGER:
1430 for (z = 0; z < numwindows; z++) {
1431 for (x = 0; x < Cnrs[z].numfiles; x++) {
1432 if (Cnrs[z].ss[x].largest)
1433 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1434 MPFROMP(Cnrs[z].ss[x].pci),
1435 MPFROM2SHORT(TRUE, CRA_SELECTED));
1436 }
1437 DosSleep(1);
1438 }
1439 break;
1440 case IDM_SELECTSMALLER:
1441 for (z = 0; z < numwindows; z++) {
1442 for (x = 0; x < Cnrs[z].numfiles; x++) {
1443 if (Cnrs[z].ss[x].smallest)
1444 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1445 MPFROMP(Cnrs[z].ss[x].pci),
1446 MPFROM2SHORT(TRUE, CRA_SELECTED));
1447 }
1448 DosSleep(1);
1449 }
1450 break;
1451
1452 case IDM_DESELECTBOTH:
1453 for (z = 0; z < numwindows; z++) {
1454 for (x = 0; x < Cnrs[z].numfiles; x++) {
1455 if (Cnrs[z].ss[x].all)
1456 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1457 MPFROMP(Cnrs[z].ss[x].pci),
1458 MPFROM2SHORT(FALSE, CRA_SELECTED));
1459 }
1460 DosSleep(1);
1461 }
1462 break;
1463 case IDM_DESELECTMORE:
1464 for (z = 0; z < numwindows; z++) {
1465 for (x = 0; x < Cnrs[z].numfiles; x++) {
1466 if (!Cnrs[z].ss[x].unique)
1467 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1468 MPFROMP(Cnrs[z].ss[x].pci),
1469 MPFROM2SHORT(FALSE, CRA_SELECTED));
1470 }
1471 DosSleep(1);
1472 }
1473 break;
1474 case IDM_DESELECTONE:
1475 for (z = 0; z < numwindows; z++) {
1476 for (x = 0; x < Cnrs[z].numfiles; x++) {
1477 if (Cnrs[z].ss[x].unique)
1478 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1479 MPFROMP(Cnrs[z].ss[x].pci),
1480 MPFROM2SHORT(FALSE, CRA_SELECTED));
1481 }
1482 DosSleep(1);
1483 }
1484 break;
1485 case IDM_DESELECTNEWER:
1486 for (z = 0; z < numwindows; z++) {
1487 for (x = 0; x < Cnrs[z].numfiles; x++) {
1488 if (Cnrs[z].ss[x].newest)
1489 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1490 MPFROMP(Cnrs[z].ss[x].pci),
1491 MPFROM2SHORT(FALSE, CRA_SELECTED));
1492 }
1493 DosSleep(1);
1494 }
1495 break;
1496 case IDM_DESELECTOLDER:
1497 for (z = 0; z < numwindows; z++) {
1498 for (x = 0; x < Cnrs[z].numfiles; x++) {
1499 if (Cnrs[z].ss[x].oldest)
1500 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1501 MPFROMP(Cnrs[z].ss[x].pci),
1502 MPFROM2SHORT(FALSE, CRA_SELECTED));
1503 }
1504 DosSleep(1);
1505 }
1506 break;
1507 case IDM_DESELECTBIGGER:
1508 for (z = 0; z < numwindows; z++) {
1509 for (x = 0; x < Cnrs[z].numfiles; x++) {
1510 if (Cnrs[z].ss[x].largest)
1511 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1512 MPFROMP(Cnrs[z].ss[x].pci),
1513 MPFROM2SHORT(FALSE, CRA_SELECTED));
1514 }
1515 DosSleep(1);
1516 }
1517 break;
1518 case IDM_DESELECTSMALLER:
1519 for (z = 0; z < numwindows; z++) {
1520 for (x = 0; x < Cnrs[z].numfiles; x++) {
1521 if (Cnrs[z].ss[x].smallest)
1522 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1523 MPFROMP(Cnrs[z].ss[x].pci),
1524 MPFROM2SHORT(FALSE, CRA_SELECTED));
1525 }
1526 DosSleep(1);
1527 }
1528 break;
1529 }
1530
1531 FreeCnrs(Cnrs, numwindows);
1532}
Note: See TracBrowser for help on using the repository browser.