source: trunk/dll/select.c@ 406

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

Use xfgets_bstripcr

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