source: trunk/dll/select.c@ 690

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

Commit more OpenWatcom compatibility updates

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