source: trunk/dll/select.c@ 689

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

Commit OpenWatcom compatibility updates

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