source: trunk/dll/select.c@ 690

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

Commit more OpenWatcom compatibility updates

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