source: trunk/dll/select.c@ 793

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

Move #pragma alloc_text to end for OpenWatcom compat

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