source: trunk/dll/select.c@ 606

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

Drag drop work around for number of files limitation in PM

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