source: trunk/dll/select.c@ 442

Last change on this file since 442 was 442, checked in by root, 19 years ago

Rework SetMask args and logic

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