source: trunk/dll/select.c@ 603

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

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

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