source: trunk/dll/select.c@ 787

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

Rework UM_FILLSETUPLIST IDM_SAVEDIRCNRSTATE and ..._setups() logic for ticket# 109 and #31
Add GetMSecTimer()
Use GetMSecTimer in DbgMsg
Tweak notebook.ipf scanning page
Move more #pragma alloc_text statements to end of files for OpenWatcom
Delete obsoletes
Revert ExpandAll() ShowTreeRec() DosSleeps to 0 - DosSleep(1) was slowing down inner loops
Drop afFilesToGet - use FilesToGet directly
Optimze ShowTreeRec() collapse logic - was really slow

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