source: trunk/dll/select.c@ 551

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

Indentation cleanup

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