source: trunk/dll/select.c@ 603

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

Work around for PM drag/drop limit; more drag/drop error checking

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