source: trunk/dll/select.c@ 793

Last change on this file since 793 was 793, checked in by Gregg Young, 18 years ago

Move #pragma alloc_text to end for OpenWatcom compat

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