source: trunk/dll/select.c@ 606

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

Drag drop work around for number of files limitation in PM

  • 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 606 2007-04-13 21:30:27Z 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 == fExceedPMDrgLimit - 1){
65 fExceedPMDrgLimit = 0;
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
573 if (!hwndCnrS || !hwndCnrD)
574 return;
575
576 memset(&cnri, 0, sizeof(CNRINFO));
577 cnri.cb = sizeof(CNRINFO);
578 WinSendMsg(hwndCnrD, CM_QUERYCNRINFO, MPFROMP(&cnri),
579 MPFROMLONG(sizeof(CNRINFO)));
580 numD = (INT) cnri.cRecords;
581 memset(&cnri, 0, sizeof(CNRINFO));
582 cnri.cb = sizeof(CNRINFO);
583 WinSendMsg(hwndCnrS, CM_QUERYCNRINFO, MPFROMP(&cnri),
584 MPFROMLONG(sizeof(CNRINFO)));
585 numS = (INT) cnri.cRecords;
586 if (!numD || numS != numD) {
587 saymsg(MB_ENTER,
588 HWND_DESKTOP,
589 DEBUG_STRING, "numD (%lu) != numS (%lu)", numD, numS);
590 return;
591 }
592 pciDa = xmalloc(sizeof(PCNRITEM) * numD, pszSrcFile, __LINE__);
593 if (!pciDa)
594 return;
595
596 pciSa = xmalloc(sizeof(PCNRITEM) * numS, pszSrcFile, __LINE__);
597 if (!pciSa) {
598 free(pciDa);
599 return;
600 }
601
602Restart:
603
604 memset(pciDa, 0, sizeof(PCNRITEM) * numD);
605 memset(pciSa, 0, sizeof(PCNRITEM) * numS);
606
607 pciD = (PCNRITEM) WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
608 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
609 x = 0;
610 while (pciD && (INT) pciD != -1 && x < numD) {
611 if (reset)
612 pciD->flags = 0;
613 pciDa[x] = pciD;
614 x++;
615 if (!slow)
616 pciD = (PCNRITEM) pciD->rc.preccNextRecord;
617 else
618 pciD = (PCNRITEM) WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
619 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
620 if (!(x % 500))
621 DosSleep(1L);
622 else if (!(x % 50))
623 DosSleep(0L);
624 }
625 if (numD != x) {
626 if (!slow) {
627 slow = TRUE;
628 goto Restart;
629 }
630 free(pciDa);
631 free(pciSa);
632 saymsg(MB_ENTER,
633 HWND_DESKTOP, DEBUG_STRING, "numD (%lu) != x (%lu)", numD, x);
634 return;
635 }
636
637 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
638 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
639 x = 0;
640 while (pciS && (INT) pciS != -1 && x < numS) {
641 if (reset)
642 pciS->flags = 0;
643 pciSa[x] = pciS;
644 x++;
645 if (!slow)
646 pciS = (PCNRITEM) pciS->rc.preccNextRecord;
647 else
648 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pciS),
649 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
650 if (!(x % 500))
651 DosSleep(1L);
652 else if (!(x % 50))
653 DosSleep(0L);
654 }
655 if (numS != x) {
656 if (!slow) {
657 slow = TRUE;
658 goto Restart;
659 }
660 free(pciSa);
661 free(pciDa);
662 Runtime_Error(pszSrcFile, __LINE__, "numS (%lu) != x (%lu)", numS, x);
663 return;
664 }
665
666 if (reset) {
667 for (x = 0; x < numS; x++) {
668 if (!*pciSa[x]->szFileName || !*pciDa[x]->szFileName)
669 continue;
670 pciSa[x]->flags |= CNRITEM_EXISTS;
671 pciDa[x]->flags |= CNRITEM_EXISTS;
672 if (pciSa[x]->cbFile + pciSa[x]->easize >
673 pciDa[x]->cbFile + pciDa[x]->easize) {
674 pciSa[x]->flags |= CNRITEM_LARGER;
675 pciDa[x]->flags |= CNRITEM_SMALLER;
676 }
677 else if (pciSa[x]->cbFile + pciSa[x]->easize <
678 pciDa[x]->cbFile + pciDa[x]->easize) {
679 pciSa[x]->flags |= CNRITEM_SMALLER;
680 pciDa[x]->flags |= CNRITEM_LARGER;
681 }
682 if ((pciSa[x]->date.year > pciDa[x]->date.year) ? TRUE :
683 (pciSa[x]->date.year < pciDa[x]->date.year) ? FALSE :
684 (pciSa[x]->date.month > pciDa[x]->date.month) ? TRUE :
685 (pciSa[x]->date.month < pciDa[x]->date.month) ? FALSE :
686 (pciSa[x]->date.day > pciDa[x]->date.day) ? TRUE :
687 (pciSa[x]->date.day < pciDa[x]->date.day) ? FALSE :
688 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? TRUE :
689 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? FALSE :
690 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? TRUE :
691 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? FALSE :
692 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? TRUE :
693 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? FALSE : FALSE) {
694 pciSa[x]->flags |= CNRITEM_NEWER;
695 pciDa[x]->flags |= CNRITEM_OLDER;
696 }
697 else if ((pciSa[x]->date.year < pciDa[x]->date.year) ? TRUE :
698 (pciSa[x]->date.year > pciDa[x]->date.year) ? FALSE :
699 (pciSa[x]->date.month < pciDa[x]->date.month) ? TRUE :
700 (pciSa[x]->date.month > pciDa[x]->date.month) ? FALSE :
701 (pciSa[x]->date.day < pciDa[x]->date.day) ? TRUE :
702 (pciSa[x]->date.day > pciDa[x]->date.day) ? FALSE :
703 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? TRUE :
704 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? FALSE :
705 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? TRUE :
706 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? FALSE :
707 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? TRUE :
708 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? FALSE :
709 FALSE) {
710 pciSa[x]->flags |= CNRITEM_OLDER;
711 pciDa[x]->flags |= CNRITEM_NEWER;
712 }
713 if (!(x % 500))
714 DosSleep(1L);
715 else if (!(x % 50))
716 DosSleep(0L);
717 }
718 }
719
720 switch (action) {
721 case IDM_SELECTIDENTICAL:
722 for (x = 0; x < numS; x++) {
723 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED)) {
724 if (*pciSa[x]->szFileName &&
725 (pciSa[x]->flags & CNRITEM_EXISTS) &&
726 !(pciSa[x]->flags & CNRITEM_SMALLER) &&
727 !(pciSa[x]->flags & CNRITEM_LARGER) &&
728 !(pciSa[x]->flags & CNRITEM_NEWER) &&
729 !(pciSa[x]->flags & CNRITEM_OLDER)) {
730 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
731 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
732 MPFROM2SHORT(TRUE, CRA_SELECTED));
733 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
734 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
735 MPFROM2SHORT(TRUE, CRA_SELECTED));
736 }
737 if (!(x % 500))
738 DosSleep(1L);
739 else if (!(x % 50))
740 DosSleep(0L);
741 }
742 }
743 break;
744
745 case IDM_SELECTSAME:
746 for (x = 0; x < numS; x++) {
747 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
748 *pciSa[x]->szFileName &&
749 (pciSa[x]->flags & CNRITEM_EXISTS) &&
750 !(pciSa[x]->flags & CNRITEM_SMALLER) &&
751 !(pciSa[x]->flags & CNRITEM_LARGER)) {
752 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
753 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
754 MPFROM2SHORT(TRUE, CRA_SELECTED));
755 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
756 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
757 MPFROM2SHORT(TRUE, CRA_SELECTED));
758 }
759 if (!(x % 500))
760 DosSleep(1L);
761 else if (!(x % 50))
762 DosSleep(0L);
763 }
764 break;
765
766 case IDM_SELECTSAMECONTENT:
767 // fixme
768 for (x = 0; x < numS; x++) {
769 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
770 *pciSa[x]->szFileName &&
771 *pciDa[x]->szFileName &&
772 pciSa[x]->flags & CNRITEM_EXISTS &&
773 pciDa[x]->flags & CNRITEM_EXISTS) {
774
775 FILE *fp1 = NULL;
776 FILE *fp2 = NULL;
777 BOOL gotMatch = FALSE;
778 UINT errLineNo = 0;
779 UINT compErrno = 0;
780 CHAR buf1[1024];
781 CHAR buf2[1024];
782 HAB hab = WinQueryAnchorBlock(hwndCnrS);
783
784 fp1 = _fsopen(pciSa[x]->szFileName, "rb", SH_DENYNO);
785 if (!fp1) {
786 errLineNo = __LINE__;
787 compErrno = errno;
788 }
789 else {
790 fp2 = _fsopen(pciDa[x]->szFileName, "rb", SH_DENYNO);
791 if (!fp2) {
792 errLineNo = __LINE__;
793 compErrno = errno;
794 }
795 else {
796 size_t len1 = filelength(fileno(fp1));
797 size_t len2 = filelength(fileno(fp2));
798
799 if (len1 == len2) {
800 setbuf(fp1, NULL);
801 setbuf(fp2, NULL);
802 while (WinIsWindow(hab, hwndCnrS)) {
803 size_t numread1 = fread(buf1, 1, 1024, fp1);
804 size_t numread2 = fread(buf2, 1, 1024, fp2);
805
806 if (!numread1 || !numread2 || numread1 != numread2) {
807 if (ferror(fp1) || ferror(fp2)) {
808 errLineNo = __LINE__;
809 compErrno = errno;
810 }
811 else if (feof(fp1) && feof(fp2))
812 gotMatch = TRUE;
813 break;
814 }
815 else if (memcmp(buf1, buf2, numread1))
816 break;
817 } // while
818 } // same len
819 }
820 }
821
822 if (fp1)
823 fclose(fp1);
824
825 if (fp2)
826 fclose(fp2);
827
828 if (errLineNo) {
829 Runtime_Error(pszSrcFile, errLineNo,
830 "error %d while comparing", compErrno);
831 }
832 if (gotMatch) {
833 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
834 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
835 MPFROM2SHORT(TRUE, CRA_SELECTED));
836 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
837 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
838 MPFROM2SHORT(TRUE, CRA_SELECTED));
839 }
840 }
841 if (!(x % 500))
842 DosSleep(1L);
843 else if (!(x % 50))
844 DosSleep(0L);
845 } // for records
846 break;
847
848 case IDM_SELECTBOTH:
849 for (x = 0; x < numS; x++) {
850 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
851 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_EXISTS)) {
852 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
853 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
854 MPFROM2SHORT(TRUE, CRA_SELECTED));
855 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
856 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
857 MPFROM2SHORT(TRUE, CRA_SELECTED));
858 }
859 if (!(x % 500))
860 DosSleep(1L);
861 else if (!(x % 50))
862 DosSleep(0L);
863 }
864 break;
865
866 case IDM_SELECTONE:
867 for (x = 0; x < numS; x++) {
868 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
869 *pciSa[x]->szFileName && !(pciSa[x]->flags & CNRITEM_EXISTS)) {
870 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
871 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
872 MPFROM2SHORT(TRUE, CRA_SELECTED));
873 }
874 else if (*pciDa[x]->szFileName && !(pciDa[x]->flags & CNRITEM_EXISTS)) {
875 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
876 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
877 MPFROM2SHORT(TRUE, CRA_SELECTED));
878 }
879 if (!(x % 500))
880 DosSleep(1L);
881 else if (!(x % 50))
882 DosSleep(0L);
883 }
884 break;
885
886 case IDM_SELECTBIGGER:
887 for (x = 0; x < numS; x++) {
888 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
889 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_LARGER)) {
890 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
891 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
892 MPFROM2SHORT(TRUE, CRA_SELECTED));
893 }
894 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
895 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_LARGER)) {
896 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
897 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
898 MPFROM2SHORT(TRUE, CRA_SELECTED));
899 }
900 if (!(x % 500))
901 DosSleep(1L);
902 else if (!(x % 50))
903 DosSleep(0L);
904 }
905 break;
906
907 case IDM_SELECTSMALLER:
908 for (x = 0; x < numS; x++) {
909 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
910 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_SMALLER)) {
911 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
912 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
913 MPFROM2SHORT(TRUE, CRA_SELECTED));
914 }
915 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
916 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_SMALLER)) {
917 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
918 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
919 MPFROM2SHORT(TRUE, CRA_SELECTED));
920 }
921 if (!(x % 500))
922 DosSleep(1L);
923 else if (!(x % 50))
924 DosSleep(0L);
925 }
926 break;
927
928 case IDM_SELECTNEWER:
929 for (x = 0; x < numS; x++) {
930 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
931 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_NEWER)) {
932 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
933 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
934 MPFROM2SHORT(TRUE, CRA_SELECTED));
935 }
936 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
937 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_NEWER)) {
938 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
939 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
940 MPFROM2SHORT(TRUE, CRA_SELECTED));
941 }
942 if (!(x % 500))
943 DosSleep(1L);
944 else if (!(x % 50))
945 DosSleep(0L);
946 }
947 break;
948
949 case IDM_SELECTOLDER:
950 for (x = 0; x < numS; x++) {
951 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
952 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_OLDER)) {
953 if (!(pciSa[x]->rc.flRecordAttr & CRA_SELECTED))
954 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
955 MPFROM2SHORT(TRUE, CRA_SELECTED));
956 }
957 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
958 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_OLDER)) {
959 if (!(pciDa[x]->rc.flRecordAttr & CRA_SELECTED))
960 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
961 MPFROM2SHORT(TRUE, CRA_SELECTED));
962 }
963 if (!(x % 500))
964 DosSleep(1L);
965 else if (!(x % 50))
966 DosSleep(0L);
967 }
968 break;
969
970 case IDM_DESELECTBOTH:
971 for (x = 0; x < numS; x++) {
972 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
973 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_EXISTS)) {
974 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
975 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
976 MPFROM2SHORT(FALSE, CRA_SELECTED));
977 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
978 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
979 MPFROM2SHORT(FALSE, CRA_SELECTED));
980 }
981 if (!(x % 500))
982 DosSleep(1L);
983 else if (!(x % 50))
984 DosSleep(0L);
985 }
986 break;
987
988 case IDM_DESELECTONE:
989 for (x = 0; x < numS; x++) {
990 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
991 *pciSa[x]->szFileName && !(pciSa[x]->flags & CNRITEM_EXISTS)) {
992 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
993 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
994 MPFROM2SHORT(FALSE, CRA_SELECTED));
995 }
996 else if (*pciDa[x]->szFileName && !(pciDa[x]->flags & CNRITEM_EXISTS)) {
997 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
998 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
999 MPFROM2SHORT(FALSE, CRA_SELECTED));
1000 }
1001 if (!(x % 500))
1002 DosSleep(1L);
1003 else if (!(x % 50))
1004 DosSleep(0L);
1005 }
1006 break;
1007
1008 case IDM_DESELECTBIGGER:
1009 for (x = 0; x < numS; x++) {
1010 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1011 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_LARGER)) {
1012 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1013 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1014 MPFROM2SHORT(FALSE, CRA_SELECTED));
1015 }
1016 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1017 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_LARGER)) {
1018 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1019 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1020 MPFROM2SHORT(FALSE, CRA_SELECTED));
1021 }
1022 if (!(x % 500))
1023 DosSleep(1L);
1024 else if (!(x % 50))
1025 DosSleep(0L);
1026 }
1027 break;
1028
1029 case IDM_DESELECTSMALLER:
1030 for (x = 0; x < numS; x++) {
1031 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1032 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_SMALLER)) {
1033 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1034 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1035 MPFROM2SHORT(FALSE, CRA_SELECTED));
1036 }
1037 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1038 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_SMALLER)) {
1039 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1040 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1041 MPFROM2SHORT(FALSE, CRA_SELECTED));
1042 }
1043 if (!(x % 500))
1044 DosSleep(1L);
1045 else if (!(x % 50))
1046 DosSleep(0L);
1047 }
1048 break;
1049
1050 case IDM_DESELECTNEWER:
1051 for (x = 0; x < numS; x++) {
1052 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1053 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_NEWER)) {
1054 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1055 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1056 MPFROM2SHORT(FALSE, CRA_SELECTED));
1057 }
1058 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1059 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_NEWER)) {
1060 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1061 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1062 MPFROM2SHORT(FALSE, CRA_SELECTED));
1063 }
1064 if (!(x % 500))
1065 DosSleep(1L);
1066 else if (!(x % 50))
1067 DosSleep(0L);
1068 }
1069 break;
1070
1071 case IDM_DESELECTOLDER:
1072 for (x = 0; x < numS; x++) {
1073 if (!(pciSa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1074 *pciSa[x]->szFileName && (pciSa[x]->flags & CNRITEM_OLDER)) {
1075 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1076 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1077 MPFROM2SHORT(FALSE, CRA_SELECTED));
1078 }
1079 else if (!(pciDa[x]->rc.flRecordAttr & CRA_FILTERED) &&
1080 *pciDa[x]->szFileName && (pciDa[x]->flags & CNRITEM_OLDER)) {
1081 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1082 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1083 MPFROM2SHORT(FALSE, CRA_SELECTED));
1084 }
1085 if (!(x % 500))
1086 DosSleep(1L);
1087 else if (!(x % 50))
1088 DosSleep(0L);
1089 }
1090 break;
1091
1092 default:
1093 break;
1094 }
1095
1096 if (reset) {
1097 while (numS) {
1098 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD,
1099 MPFROMP(pciSa), MPFROM2SHORT((min(numS, 65535)), 0));
1100 DosSleep(0L);
1101 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD,
1102 MPFROMP(pciDa), MPFROM2SHORT((min(numD, 65535)), 0));
1103 numS -= min(numS, 65535);
1104 if (numS)
1105 DosSleep(0L);
1106 }
1107 }
1108
1109 free(pciSa);
1110 free(pciDa);
1111 DosPostEventSem(CompactSem);
1112}
1113
1114struct SS
1115{
1116 PCNRITEM pci;
1117 BOOL unique, all, smallest, largest, newest, oldest;
1118};
1119
1120struct Cnr
1121{
1122 HWND hwndCnr;
1123 ULONG numfiles;
1124 struct SS *ss;
1125};
1126
1127static int CompSSNamesB(const void *s1, const void *s2)
1128{
1129 struct SS *ss2 = (struct SS *)s2;
1130
1131 return stricmp((CHAR *) s1, ss2->pci->pszFileName);
1132}
1133
1134static int CompSSNames(const void *s1, const void *s2)
1135{
1136 struct SS *ss1 = (struct SS *)s1;
1137 struct SS *ss2 = (struct SS *)s2;
1138
1139 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
1140}
1141
1142VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
1143{
1144 register INT z;
1145
1146 for (z = 0; z < numw; z++) {
1147 if (Cnrs[z].ss)
1148 free(Cnrs[z].ss);
1149 }
1150 free(Cnrs);
1151 DosPostEventSem(CompactSem);
1152}
1153
1154VOID SpecialSelect2(HWND hwndParent, INT action)
1155{
1156 PCNRITEM pci;
1157 HENUM henum;
1158 HWND hwnd;
1159 register INT numwindows = 0, w, x, z, cmp;
1160 struct Cnr *Cnrs = NULL;
1161 struct SS *bsres;
1162
1163 if (!hwndParent)
1164 return;
1165
1166 /* count directory containers, build array of hwnds */
1167 henum = WinBeginEnumWindows(hwndParent);
1168 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
1169 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
1170 Cnrs =
1171 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
1172 __LINE__);
1173 if (!Cnrs) {
1174 Notify(GetPString(IDS_OUTOFMEMORY));
1175 return;
1176 }
1177 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
1178 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
1179 FID_CLIENT),
1180 DIR_CNR);
1181 numwindows++;
1182 }
1183 }
1184 WinEndEnumWindows(henum);
1185 if (numwindows < 2) {
1186 FreeCnrs(Cnrs, numwindows);
1187 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
1188 // fixme DosBeep(250,100);
1189 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
1190 return;
1191 }
1192 if (numwindows > 4) {
1193 WinSendMsg(Cnrs[0].
1194 hwndCnr,
1195 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
1196 DosSleep(0L);
1197 }
1198
1199 /* count records, build array of pointers to records */
1200 for (z = 0; z < numwindows; z++) {
1201 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1202 CM_QUERYRECORD,
1203 MPVOID,
1204 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1205 x = 0;
1206 while (pci && (INT) pci != -1) {
1207 if (!(pci->rc.flRecordAttr & CRA_FILTERED) &&
1208 !(pci->attrFile & FILE_DIRECTORY)) {
1209 Cnrs[z].ss =
1210 xrealloc(Cnrs[z].ss, (x + 1) * sizeof(struct SS), pszSrcFile,
1211 __LINE__);
1212 if (!Cnrs[z].ss) {
1213 FreeCnrs(Cnrs, numwindows);
1214 Notify(GetPString(IDS_OUTOFMEMORY));
1215 return;
1216 }
1217 memset(&Cnrs[z].ss[x], 0, sizeof(struct SS));
1218 Cnrs[z].ss[x].pci = pci;
1219 x++;
1220 }
1221 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1222 CM_QUERYRECORD,
1223 MPFROMP(pci),
1224 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1225 }
1226 DosSleep(0L);
1227 Cnrs[z].numfiles = x;
1228 if (Cnrs[z].numfiles)
1229 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
1230 }
1231
1232 for (z = 0; z < numwindows; z++) {
1233 for (x = 0; x < Cnrs[z].numfiles; x++) {
1234 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
1235 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].smallest =
1236 Cnrs[z].ss[x].largest = TRUE;
1237 for (w = 0; w < numwindows; w++) {
1238 if (w != z && Cnrs[w].numfiles) {
1239 bsres = (struct SS *)bsearch(Cnrs[z].ss[x].pci->pszFileName,
1240 Cnrs[w].ss, Cnrs[w].numfiles,
1241 sizeof(struct SS), CompSSNamesB);
1242 if (bsres) {
1243 Cnrs[z].ss[x].unique = FALSE;
1244 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize >
1245 bsres->pci->cbFile + bsres->pci->easize)
1246 Cnrs[z].ss[x].smallest = FALSE;
1247 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize <
1248 bsres->pci->cbFile + bsres->pci->easize)
1249 Cnrs[z].ss[x].largest = FALSE;
1250 cmp =
1251 (Cnrs[z].ss[x].pci->date.year >
1252 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year <
1253 bsres->pci->date.
1254 year) ? FALSE : (Cnrs[z].
1255 ss[x].pci->
1256 date.month >
1257 bsres->pci->
1258 date.
1259 month) ? TRUE
1260 : (Cnrs[z].ss[x].pci->date.month <
1261 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1262 day >
1263 bsres->pci->date.
1264 day) ? TRUE : (Cnrs[z].
1265 ss[x].pci->
1266 date.day <
1267 bsres->
1268 pci->date.
1269 day) ?
1270 FALSE : (Cnrs[z].ss[x].pci->time.hours >
1271 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1272 time.hours <
1273 bsres->pci->time.
1274 hours) ? FALSE
1275 : (Cnrs[z].ss[x].pci->time.minutes >
1276 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1277 minutes <
1278 bsres->pci->time.
1279 minutes) ? FALSE
1280 : (Cnrs[z].ss[x].pci->time.seconds >
1281 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1282 seconds <
1283 bsres->pci->time.
1284 seconds) ? FALSE : FALSE;
1285 if (!cmp)
1286 Cnrs[z].ss[x].newest = FALSE;
1287 cmp =
1288 (Cnrs[z].ss[x].pci->date.year <
1289 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year >
1290 bsres->pci->date.
1291 year) ? FALSE : (Cnrs[z].
1292 ss[x].pci->
1293 date.month <
1294 bsres->pci->
1295 date.
1296 month) ? TRUE
1297 : (Cnrs[z].ss[x].pci->date.month >
1298 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1299 day <
1300 bsres->pci->date.
1301 day) ? TRUE : (Cnrs[z].
1302 ss[x].pci->
1303 date.day >
1304 bsres->
1305 pci->date.
1306 day) ?
1307 FALSE : (Cnrs[z].ss[x].pci->time.hours <
1308 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1309 time.hours >
1310 bsres->pci->time.
1311 hours) ? FALSE
1312 : (Cnrs[z].ss[x].pci->time.minutes <
1313 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1314 minutes >
1315 bsres->pci->time.
1316 minutes) ? FALSE
1317 : (Cnrs[z].ss[x].pci->time.seconds <
1318 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1319 seconds >
1320 bsres->pci->time.
1321 seconds) ? FALSE : FALSE;
1322 if (!cmp)
1323 Cnrs[z].ss[x].oldest = FALSE;
1324 cmp = 0;
1325 break;
1326 }
1327 else
1328 Cnrs[z].ss[x].all = FALSE;
1329 }
1330 }
1331 if (Cnrs[z].ss[x].unique)
1332 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].newest = Cnrs[z].ss[x].all =
1333 Cnrs[z].ss[x].largest = Cnrs[z].ss[x].smallest = FALSE;
1334 DosSleep(0L);
1335 }
1336 DosSleep(1L);
1337 }
1338
1339 switch (action) {
1340 case IDM_SELECTBOTH:
1341 for (z = 0; z < numwindows; z++) {
1342 for (x = 0; x < Cnrs[z].numfiles; x++) {
1343 if (Cnrs[z].ss[x].all)
1344 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1345 MPFROMP(Cnrs[z].ss[x].pci),
1346 MPFROM2SHORT(TRUE, CRA_SELECTED));
1347 }
1348 DosSleep(0L);
1349 }
1350 break;
1351 case IDM_SELECTMORE:
1352 for (z = 0; z < numwindows; z++) {
1353 for (x = 0; x < Cnrs[z].numfiles; x++) {
1354 if (!Cnrs[z].ss[x].unique)
1355 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1356 MPFROMP(Cnrs[z].ss[x].pci),
1357 MPFROM2SHORT(TRUE, CRA_SELECTED));
1358 }
1359 DosSleep(0L);
1360 }
1361 break;
1362 case IDM_SELECTONE:
1363 for (z = 0; z < numwindows; z++) {
1364 for (x = 0; x < Cnrs[z].numfiles; x++) {
1365 if (Cnrs[z].ss[x].unique)
1366 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1367 MPFROMP(Cnrs[z].ss[x].pci),
1368 MPFROM2SHORT(TRUE, CRA_SELECTED));
1369 }
1370 DosSleep(0L);
1371 }
1372 break;
1373 case IDM_SELECTNEWER:
1374 for (z = 0; z < numwindows; z++) {
1375 for (x = 0; x < Cnrs[z].numfiles; x++) {
1376 if (Cnrs[z].ss[x].newest)
1377 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1378 MPFROMP(Cnrs[z].ss[x].pci),
1379 MPFROM2SHORT(TRUE, CRA_SELECTED));
1380 }
1381 DosSleep(0L);
1382 }
1383 break;
1384 case IDM_SELECTOLDER:
1385 for (z = 0; z < numwindows; z++) {
1386 for (x = 0; x < Cnrs[z].numfiles; x++) {
1387 if (Cnrs[z].ss[x].oldest)
1388 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1389 MPFROMP(Cnrs[z].ss[x].pci),
1390 MPFROM2SHORT(TRUE, CRA_SELECTED));
1391 }
1392 DosSleep(0L);
1393 }
1394 break;
1395 case IDM_SELECTBIGGER:
1396 for (z = 0; z < numwindows; z++) {
1397 for (x = 0; x < Cnrs[z].numfiles; x++) {
1398 if (Cnrs[z].ss[x].largest)
1399 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1400 MPFROMP(Cnrs[z].ss[x].pci),
1401 MPFROM2SHORT(TRUE, CRA_SELECTED));
1402 }
1403 DosSleep(0L);
1404 }
1405 break;
1406 case IDM_SELECTSMALLER:
1407 for (z = 0; z < numwindows; z++) {
1408 for (x = 0; x < Cnrs[z].numfiles; x++) {
1409 if (Cnrs[z].ss[x].smallest)
1410 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1411 MPFROMP(Cnrs[z].ss[x].pci),
1412 MPFROM2SHORT(TRUE, CRA_SELECTED));
1413 }
1414 DosSleep(0L);
1415 }
1416 break;
1417
1418 case IDM_DESELECTBOTH:
1419 for (z = 0; z < numwindows; z++) {
1420 for (x = 0; x < Cnrs[z].numfiles; x++) {
1421 if (Cnrs[z].ss[x].all)
1422 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1423 MPFROMP(Cnrs[z].ss[x].pci),
1424 MPFROM2SHORT(FALSE, CRA_SELECTED));
1425 }
1426 DosSleep(0L);
1427 }
1428 break;
1429 case IDM_DESELECTMORE:
1430 for (z = 0; z < numwindows; z++) {
1431 for (x = 0; x < Cnrs[z].numfiles; x++) {
1432 if (!Cnrs[z].ss[x].unique)
1433 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1434 MPFROMP(Cnrs[z].ss[x].pci),
1435 MPFROM2SHORT(FALSE, CRA_SELECTED));
1436 }
1437 DosSleep(0L);
1438 }
1439 break;
1440 case IDM_DESELECTONE:
1441 for (z = 0; z < numwindows; z++) {
1442 for (x = 0; x < Cnrs[z].numfiles; x++) {
1443 if (Cnrs[z].ss[x].unique)
1444 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1445 MPFROMP(Cnrs[z].ss[x].pci),
1446 MPFROM2SHORT(FALSE, CRA_SELECTED));
1447 }
1448 DosSleep(0L);
1449 }
1450 break;
1451 case IDM_DESELECTNEWER:
1452 for (z = 0; z < numwindows; z++) {
1453 for (x = 0; x < Cnrs[z].numfiles; x++) {
1454 if (Cnrs[z].ss[x].newest)
1455 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1456 MPFROMP(Cnrs[z].ss[x].pci),
1457 MPFROM2SHORT(FALSE, CRA_SELECTED));
1458 }
1459 DosSleep(0L);
1460 }
1461 break;
1462 case IDM_DESELECTOLDER:
1463 for (z = 0; z < numwindows; z++) {
1464 for (x = 0; x < Cnrs[z].numfiles; x++) {
1465 if (Cnrs[z].ss[x].oldest)
1466 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1467 MPFROMP(Cnrs[z].ss[x].pci),
1468 MPFROM2SHORT(FALSE, CRA_SELECTED));
1469 }
1470 DosSleep(0L);
1471 }
1472 break;
1473 case IDM_DESELECTBIGGER:
1474 for (z = 0; z < numwindows; z++) {
1475 for (x = 0; x < Cnrs[z].numfiles; x++) {
1476 if (Cnrs[z].ss[x].largest)
1477 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1478 MPFROMP(Cnrs[z].ss[x].pci),
1479 MPFROM2SHORT(FALSE, CRA_SELECTED));
1480 }
1481 DosSleep(0L);
1482 }
1483 break;
1484 case IDM_DESELECTSMALLER:
1485 for (z = 0; z < numwindows; z++) {
1486 for (x = 0; x < Cnrs[z].numfiles; x++) {
1487 if (Cnrs[z].ss[x].smallest)
1488 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1489 MPFROMP(Cnrs[z].ss[x].pci),
1490 MPFROM2SHORT(FALSE, CRA_SELECTED));
1491 }
1492 DosSleep(0L);
1493 }
1494 break;
1495 }
1496
1497 FreeCnrs(Cnrs, numwindows);
1498}
Note: See TracBrowser for help on using the repository browser.