source: trunk/dll/grep2.c@ 130

Last change on this file since 130 was 130, checked in by root, 20 years ago

Use QWL_USER

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: grep2.c 130 2005-05-23 19:04:06Z root $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2005 Steven H.Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 23 May 05 SHL Use QWL_USER
11
12***********************************************************************/
13
14#define INCL_DOS
15#define INCL_WIN
16#define INCL_GPI
17#define INCL_DOSERRORS
18
19#include <os2.h>
20#include <stdarg.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <ctype.h>
25#include <time.h>
26#include <share.h>
27#include <limits.h>
28#include "fm3dll.h"
29#include "fm3dlg.h"
30#include "fm3str.h"
31#include "mle.h"
32#include "grep.h"
33
34#pragma data_seg(DATA1)
35#pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc)
36
37
38MRESULT EXPENTRY EnvDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {
39
40 static CHAR lastenv[CCHMAXPATH] = "DPATH";
41
42 switch(msg) {
43 case WM_INITDLG:
44 if(mp2) {
45 WinSetWindowPtr(hwnd,QWL_USER,mp2);
46 *(CHAR *)mp2 = 0;
47 {
48 char *p,*pp,temp[CCHMAXPATH];
49
50 p = GetPString(IDS_ENVVARNAMES);
51 while(*p == ' ')
52 p++;
53 while(*p) {
54 *temp = 0;
55 pp = temp;
56 while(*p && *p != ' ')
57 *pp++ = *p++;
58 *pp = 0;
59 while(*p == ' ')
60 p++;
61 if(*temp)
62 WinSendDlgItemMsg(hwnd,
63 ENV_LISTBOX,
64 LM_INSERTITEM,
65 MPFROM2SHORT(LIT_END,0),
66 MPFROMP(temp));
67 }
68 }
69 WinSendDlgItemMsg(hwnd,
70 ENV_NAME,
71 EM_SETTEXTLIMIT,
72 MPFROM2SHORT(CCHMAXPATH,0),
73 MPVOID);
74 WinSetDlgItemText(hwnd,
75 ENV_NAME,
76 lastenv);
77 WinSendDlgItemMsg(hwnd,
78 ENV_NAME,
79 EM_SETSEL,
80 MPFROM2SHORT(0,CCHMAXPATH),
81 MPVOID);
82 }
83 else
84 WinDismissDlg(hwnd,0);
85 break;
86
87 case WM_CONTROL:
88 switch(SHORT1FROMMP(mp1)) {
89 case ENV_LISTBOX:
90 switch(SHORT2FROMMP(mp1)) {
91 case LN_SELECT:
92 {
93 SHORT sSelect;
94 CHAR s[CCHMAXPATH];
95
96 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
97 ENV_LISTBOX,
98 LM_QUERYSELECTION,
99 MPFROMSHORT(LIT_FIRST),
100 MPVOID);
101 if(sSelect >= 0) {
102 *s = 0;
103 WinSendDlgItemMsg(hwnd,
104 ENV_LISTBOX,
105 LM_QUERYITEMTEXT,
106 MPFROM2SHORT(sSelect,CCHMAXPATH),
107 MPFROMP(s));
108 bstrip(s);
109 if(*s)
110 WinSetDlgItemText(hwnd,
111 ENV_NAME,
112 s);
113 }
114 }
115 break;
116 case LN_ENTER:
117 PostMsg(hwnd,
118 WM_COMMAND,
119 MPFROM2SHORT(DID_OK,0),
120 MPVOID);
121 break;
122 }
123 }
124 return 0;
125
126 case WM_COMMAND:
127 switch(SHORT1FROMMP(mp1)) {
128 case DID_CANCEL:
129 WinDismissDlg(hwnd,0);
130 break;
131 case DID_OK:
132 {
133 CHAR *p = WinQueryWindowPtr(hwnd,QWL_USER);
134
135 if(p) {
136 WinQueryDlgItemText(hwnd,
137 ENV_NAME,
138 CCHMAXPATH,
139 p);
140 bstrip(p);
141 if(*p) {
142 strcpy(lastenv,p);
143 WinDismissDlg(hwnd,1);
144 }
145 else {
146 DosBeep(250,100);
147 WinSetFocus(HWND_DESKTOP,
148 WinWindowFromID(hwnd,ENV_NAME));
149 }
150 }
151 }
152 break;
153 case IDM_HELP:
154 if(hwndHelp)
155 WinSendMsg(hwndHelp,
156 HM_DISPLAY_HELP,
157 MPFROM2SHORT(HELP_ENV,0),
158 MPFROMSHORT(HM_RESOURCEID));
159 break;
160 }
161 return 0;
162 }
163 return WinDefDlgProc(hwnd,msg,mp1,mp2);
164}
165
166
167MRESULT EXPENTRY GrepDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {
168
169 static CHAR lastmask[8192] = "*",lasttext[4096] = "";
170 static BOOL recurse = TRUE,sensitive = FALSE,absolute = FALSE,
171 sayfiles = FALSE,searchEAs = TRUE,searchFiles = TRUE,
172 changed = FALSE,findifany = TRUE;
173 static UINT newer = 0L,older = 0L;
174 static ULONG greater = 0L,lesser = 0L;
175 HWND hwndCollect,hwndMLE = WinWindowFromID(hwnd,GREP_SEARCH);
176
177 switch(msg) {
178 case WM_INITDLG:
179 if(!mp2) {
180 WinDismissDlg(hwnd,0);
181 break;
182 }
183 WinSetWindowULong(hwnd,QWL_USER,*(HWND *)mp2);
184 WinSendDlgItemMsg(hwnd,
185 GREP_MASK,
186 EM_SETTEXTLIMIT,
187 MPFROM2SHORT(8192,0),
188 MPVOID);
189 MLEsetlimit(hwndMLE,4096);
190 MLEsetformat(hwndMLE,MLFIE_NOTRANS);
191 WinSendDlgItemMsg(hwnd,
192 GREP_NEWER,
193 EM_SETTEXTLIMIT,
194 MPFROM2SHORT(34,0),
195 MPVOID);
196 WinSendDlgItemMsg(hwnd,
197 GREP_OLDER,
198 EM_SETTEXTLIMIT,
199 MPFROM2SHORT(34,0),
200 MPVOID);
201 WinSendDlgItemMsg(hwnd,
202 GREP_GREATER,
203 EM_SETTEXTLIMIT,
204 MPFROM2SHORT(34,0),
205 MPVOID);
206 WinSendDlgItemMsg(hwnd,
207 GREP_LESSER,
208 EM_SETTEXTLIMIT,
209 MPFROM2SHORT(34,0),
210 MPVOID);
211 WinSetDlgItemText(hwnd,
212 GREP_MASK,
213 lastmask);
214 WinSendDlgItemMsg(hwnd,
215 GREP_MASK,
216 EM_SETSEL,
217 MPFROM2SHORT(0,8192),
218 MPVOID);
219 WinSetWindowText(hwndMLE,lasttext);
220 if(*lasttext) {
221 MLEsetcurpos(hwndMLE,0);
222 MLEsetcurposa(hwndMLE,4096);
223 if(!searchEAs)
224 searchFiles = TRUE;
225 }
226 WinCheckButton(hwnd,GREP_RECURSE,recurse);
227 WinCheckButton(hwnd,GREP_ABSOLUTE,absolute);
228 WinCheckButton(hwnd,GREP_CASE,sensitive);
229 WinCheckButton(hwnd,GREP_SAYFILES,sayfiles);
230 WinCheckButton(hwnd,GREP_SEARCHEAS,searchEAs);
231 WinCheckButton(hwnd,GREP_SEARCHFILES,searchFiles);
232 WinCheckButton(hwnd,GREP_FINDIFANY,findifany);
233 {
234 CHAR s[35];
235
236 sprintf(s,"%lu",greater);
237 WinSetDlgItemText(hwnd,GREP_GREATER,s);
238 sprintf(s,"%lu",lesser);
239 WinSetDlgItemText(hwnd,GREP_LESSER,s);
240 sprintf(s,"%u",newer);
241 WinSetDlgItemText(hwnd,GREP_NEWER,s);
242 sprintf(s,"%u",older);
243 WinSetDlgItemText(hwnd,GREP_OLDER,s);
244 }
245 WinEnableWindow(WinWindowFromID(hwnd,GREP_IGNOREEXTDUPES),FALSE);
246 WinEnableWindow(WinWindowFromID(hwnd,GREP_CRCDUPES),FALSE);
247 WinEnableWindow(WinWindowFromID(hwnd,GREP_NOSIZEDUPES),FALSE);
248 {
249 FILE *fp;
250 static CHAR s[8192 + 14];
251
252 save_dir2(s);
253 if(s[strlen(s) - 1] != '\\')
254 strcat(s,"\\");
255 strcat(s,"GREPMASK.DAT");
256 fp = _fsopen(s,"r",SH_DENYWR);
257 if(fp) {
258 while(!feof(fp)) {
259 if(!fgets(s,8192 + 4,fp))
260 break;
261 bstripcr(s);
262 if(*s && *s != ';')
263 WinSendDlgItemMsg(hwnd,
264 GREP_LISTBOX,
265 LM_INSERTITEM,
266 MPFROM2SHORT(LIT_SORTASCENDING,0),
267 MPFROMP(s));
268 }
269 fclose(fp);
270 }
271 }
272 FillPathListBox(hwnd,
273 WinWindowFromID(hwnd,GREP_DRIVELIST),
274 (HWND)0,
275 NULL,
276 FALSE);
277 break;
278
279 case WM_ADJUSTWINDOWPOS:
280 PostMsg(hwnd,
281 UM_SETDIR,
282 MPVOID,
283 MPVOID);
284 break;
285
286 case UM_SETDIR:
287 PaintRecessedWindow(WinWindowFromID(hwnd,GREP_HELP),
288 (HPS)0,
289 FALSE,
290 TRUE);
291 return 0;
292
293 case UM_FOCUSME:
294 /* set focus to window hwnd in mp1 */
295 if(mp1)
296 WinSetFocus(HWND_DESKTOP,(HWND)mp1);
297 return 0;
298
299 case WM_CONTROL:
300 switch(SHORT1FROMMP(mp1)) {
301 case GREP_DRIVELIST:
302 switch(SHORT2FROMMP(mp1)) {
303 case LN_KILLFOCUS:
304 WinSetDlgItemText(hwnd,
305 GREP_HELP,
306 GetPString(IDS_ARCDEFAULTHELPTEXT));
307 break;
308 case LN_SETFOCUS:
309 WinSetDlgItemText(hwnd,
310 GREP_HELP,
311 GetPString(IDS_2CLICKADDDRVMASKTEXT));
312 break;
313 case LN_ENTER:
314 {
315 SHORT sSelect;
316 static CHAR s[8192],simple[8192],*p;
317 LONG len;
318
319 WinQueryDlgItemText(hwnd,
320 GREP_MASK,
321 8192,
322 s);
323 bstrip(s);
324 p = strrchr(s,'\\');
325 if(p)
326 strcpy(simple,p);
327 else if(*s) {
328 strcpy(simple,"\\");
329 strcat(simple,s);
330 *s = 0;
331 }
332 else
333 strcpy(simple,"\\*");
334 if(simple[strlen(simple) - 1] == ';')
335 simple[strlen(simple) - 1] = 0;
336 len = strlen(simple) + 1;
337 if(strlen(s) > 8192 - len) {
338 DosBeep(250,100);
339 WinSetDlgItemText(hwnd,
340 GREP_MASK,
341 s);
342 break;
343 }
344
345 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
346 GREP_DRIVELIST,
347 LM_QUERYSELECTION,
348 MPFROMSHORT(LIT_FIRST),
349 MPVOID);
350 if(sSelect >= 0) {
351 if(*s && s[strlen(s) - 1] != ';')
352 strcat(s,";");
353 WinSendDlgItemMsg(hwnd,
354 GREP_DRIVELIST,
355 LM_QUERYITEMTEXT,
356 MPFROM2SHORT(sSelect,
357 (8192 - strlen(s)) - len),
358 MPFROMP(&s[strlen(s)]));
359 rstrip(s);
360 if(*s) {
361 strcat(s,simple);
362 WinSetDlgItemText(hwnd,
363 GREP_MASK,
364 s);
365 WinSendDlgItemMsg(hwnd,
366 GREP_MASK,
367 EM_SETSEL,
368 MPFROM2SHORT(strlen(s) - (len + 1),
369 strlen(s)),
370 MPVOID);
371 PostMsg(hwnd,
372 UM_FOCUSME,
373 MPFROMLONG(WinWindowFromID(hwnd,GREP_MASK)),
374 MPVOID);
375 }
376 }
377 }
378 break;
379 }
380 break;
381 case GREP_LISTBOX:
382 switch(SHORT2FROMMP(mp1)) {
383 case LN_KILLFOCUS:
384 WinSetDlgItemText(hwnd,
385 GREP_HELP,
386 GetPString(IDS_ARCDEFAULTHELPTEXT));
387 break;
388 case LN_SETFOCUS:
389 WinSetDlgItemText(hwnd,
390 GREP_HELP,
391 GetPString(IDS_ADDSELDELMASKTEXT));
392 break;
393 case LN_ENTER:
394 case LN_SELECT:
395 if((SHORT2FROMMP(mp1) == LN_ENTER &&
396 !WinQueryButtonCheckstate(hwnd,GREP_APPEND)) ||
397 (SHORT2FROMMP(mp1) == LN_SELECT &&
398 WinQueryButtonCheckstate(hwnd,GREP_APPEND)))
399 break;
400 {
401 SHORT sSelect;
402 static CHAR s[8192];
403
404 *s = 0;
405 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
406 GREP_LISTBOX,
407 LM_QUERYSELECTION,
408 MPFROMSHORT(LIT_FIRST),
409 MPVOID);
410 if(sSelect >= 0) {
411 if(WinQueryButtonCheckstate(hwnd,GREP_APPEND)) {
412 WinQueryDlgItemText(hwnd,
413 GREP_MASK,
414 8192,
415 s);
416 bstrip(s);
417 if(*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
418 strcat(s,";");
419 }
420 WinSendDlgItemMsg(hwnd,
421 GREP_LISTBOX,
422 LM_QUERYITEMTEXT,
423 MPFROM2SHORT(sSelect,8192 - strlen(s)),
424 MPFROMP(s + strlen(s)));
425 bstrip(s);
426 if(*s)
427 WinSetDlgItemText(hwnd,
428 GREP_MASK,
429 s);
430 }
431 }
432 break;
433 }
434 break;
435 case GREP_MASK:
436 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)
437 WinSetDlgItemText(hwnd,
438 GREP_HELP,
439 GetPString(IDS_ARCDEFAULTHELPTEXT));
440 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)
441 WinSetDlgItemText(hwnd,
442 GREP_HELP,
443 GetPString(IDS_MASKSFINDTEXT));
444 break;
445 case GREP_SEARCH:
446 if(SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
447 WinSetDlgItemText(hwnd,
448 GREP_HELP,
449 GetPString(IDS_ARCDEFAULTHELPTEXT));
450 if(SHORT2FROMMP(mp1) == MLN_SETFOCUS)
451 WinSetDlgItemText(hwnd,
452 GREP_HELP,
453 GetPString(IDS_TEXTFINDTEXT));
454 break;
455 case GREP_GREATER:
456 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)
457 WinSetDlgItemText(hwnd,
458 GREP_HELP,
459 GetPString(IDS_ARCDEFAULTHELPTEXT));
460 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)
461 WinSetDlgItemText(hwnd,
462 GREP_HELP,
463 GetPString(IDS_MINSIZEFINDTEXT));
464 break;
465 case GREP_LESSER:
466 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)
467 WinSetDlgItemText(hwnd,
468 GREP_HELP,
469 GetPString(IDS_ARCDEFAULTHELPTEXT));
470 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)
471 WinSetDlgItemText(hwnd,
472 GREP_HELP,
473 GetPString(IDS_MAXSIZEFINDTEXT));
474 break;
475 case GREP_NEWER:
476 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)
477 WinSetDlgItemText(hwnd,
478 GREP_HELP,
479 GetPString(IDS_ARCDEFAULTHELPTEXT));
480 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)
481 WinSetDlgItemText(hwnd,
482 GREP_HELP,
483 GetPString(IDS_MAXAGEFINDTEXT));
484 break;
485 case GREP_OLDER:
486 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)
487 WinSetDlgItemText(hwnd,
488 GREP_HELP,
489 GetPString(IDS_ARCDEFAULTHELPTEXT));
490 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)
491 WinSetDlgItemText(hwnd,
492 GREP_HELP,
493 GetPString(IDS_MINAGEFINDTEXT));
494 break;
495 case GREP_FINDDUPES:
496 {
497 BOOL finddupes = WinQueryButtonCheckstate(hwnd,GREP_FINDDUPES);
498
499 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCH),!finddupes);
500 WinEnableWindow(WinWindowFromID(hwnd,GREP_ABSOLUTE),!finddupes);
501 WinEnableWindow(WinWindowFromID(hwnd,GREP_CASE),!finddupes);
502 WinEnableWindow(WinWindowFromID(hwnd,GREP_CRCDUPES),finddupes);
503 WinEnableWindow(WinWindowFromID(hwnd,GREP_NOSIZEDUPES),finddupes);
504 WinEnableWindow(WinWindowFromID(hwnd,GREP_IGNOREEXTDUPES),finddupes);
505 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCHFILES),!finddupes);
506 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCHEAS),!finddupes);
507 WinEnableWindow(WinWindowFromID(hwnd,GREP_GREATER),!finddupes);
508 WinEnableWindow(WinWindowFromID(hwnd,GREP_LESSER),!finddupes);
509 WinEnableWindow(WinWindowFromID(hwnd,GREP_NEWER),!finddupes);
510 WinEnableWindow(WinWindowFromID(hwnd,GREP_OLDER),!finddupes);
511 WinEnableWindow(WinWindowFromID(hwnd,GREP_FINDIFANY),!finddupes);
512 WinEnableWindow(WinWindowFromID(hwnd,GREP_GK),!finddupes);
513 WinEnableWindow(WinWindowFromID(hwnd,GREP_LK),!finddupes);
514 WinEnableWindow(WinWindowFromID(hwnd,GREP_NM),!finddupes);
515 WinEnableWindow(WinWindowFromID(hwnd,GREP_OM),!finddupes);
516 if(finddupes)
517 WinCheckButton(hwnd,GREP_RECURSE,TRUE);
518 }
519 }
520 return 0;
521
522 case WM_COMMAND:
523 switch(SHORT1FROMMP(mp1)) {
524 case GREP_ENV:
525 {
526 CHAR path[CCHMAXPATH];
527 CHAR *p,*t;
528 static CHAR s[8192],simple[8192],env[8192];
529 LONG len;
530
531 *path = 0;
532 if (!WinDlgBox(HWND_DESKTOP,
533 hwnd,
534 EnvDlgProc,
535 FM3ModHandle,
536 ENV_FRAME,
537 path)) {
538 break;
539 }
540 bstrip(path);
541 if (!*path)
542 break;
543 if(!stricmp(path,"LIBPATH"))
544 LoadLibPath(env,8192);
545 else {
546 p = getenv(path);
547 if(!p)
548 break;
549 strcpy(env,p);
550 }
551 bstrip(env);
552 if(!*env)
553 break;
554 WinQueryDlgItemText(hwnd,
555 GREP_MASK,
556 8192,
557 s);
558 bstrip(s);
559 if(strlen(s) > 8192 - 5) {
560 DosBeep(50,100);
561 break;
562 }
563 p = strrchr(s,'\\');
564 if(p)
565 strcpy(simple,p + 1);
566 else if(*s)
567 strcpy(simple,s);
568 else
569 strcpy(simple,"*");
570 if(!p)
571 *s = 0;
572 if(simple[strlen(simple) - 1] == ';')
573 simple[strlen(simple) - 1] = 0;
574 len = strlen(simple) + 1;
575 p = env;
576 while(p && *p) {
577 strncpy(path,p,CCHMAXPATH - 1);
578 path[CCHMAXPATH - 1] = 0;
579 t = strchr(path,';');
580 if(t)
581 *t = 0;
582 bstrip(path);
583 if(isalpha(*path) && path[1] == ':' && path[2] == '\\') {
584 if(strlen(s) > (8192 - len) - (strlen(path) + 1)) {
585 WinSetDlgItemText(hwnd,
586 GREP_MASK,
587 s);
588 break;
589 }
590 if(!*s || (*s && s[strlen(s) - 1] != ';')) {
591 if(*s)
592 strcat(s,";");
593 strcat(s,path);
594 len += strlen(path);
595 if(s[strlen(s) - 1] != '\\') {
596 len++;
597 strcat(s,"\\");
598 }
599 rstrip(s);
600 if(*s) {
601 strcat(s,simple);
602 WinSetDlgItemText(hwnd,
603 GREP_MASK,
604 s);
605 WinSendDlgItemMsg(hwnd,
606 GREP_MASK,
607 EM_SETSEL,
608 MPFROM2SHORT(strlen(s) - (len - 1),
609 strlen(s)),
610 MPVOID);
611 }
612 }
613 }
614 p = strchr(p,';');
615 if(p)
616 p++;
617 }
618 }
619 break;
620
621 case GREP_WALK:
622 {
623 CHAR path[CCHMAXPATH],*p;
624 static CHAR s[8192],simple[8192];
625 LONG len;
626
627 WinQueryDlgItemText(hwnd,
628 GREP_MASK,
629 8192,
630 s);
631 bstrip(s);
632 if(strlen(s) > 8192 - 5) {
633 DosBeep(50,100);
634 break;
635 }
636 *path = 0;
637 if(WinDlgBox(HWND_DESKTOP,
638 hwnd,
639 WalkAllDlgProc,
640 FM3ModHandle,
641 WALK_FRAME,
642 MPFROMP(path)) &&
643 *path) {
644 p = strrchr(s,'\\');
645 if(p)
646 strcpy(simple,p + 1);
647 else if(*s)
648 strcpy(simple,s);
649 else
650 strcpy(simple,"*");
651 if(!p)
652 *s = 0;
653 if(simple[strlen(simple) - 1] == ';')
654 simple[strlen(simple) - 1] = 0;
655 len = strlen(simple) + 1;
656 if(strlen(s) > (8192 - len) - (strlen(path) + 1)) {
657 DosBeep(250,100);
658 WinSetDlgItemText(hwnd,
659 GREP_MASK,
660 s);
661 break;
662 }
663 if(!*s || (*s && s[strlen(s) - 1] != ';')) {
664 if(*s)
665 strcat(s,";");
666 strcat(s,path);
667 len += strlen(path);
668 if(s[strlen(s) - 1] != '\\') {
669 len++;
670 strcat(s,"\\");
671 }
672 rstrip(s);
673 if(*s) {
674 strcat(s,simple);
675 WinSetDlgItemText(hwnd,
676 GREP_MASK,
677 s);
678 WinSendDlgItemMsg(hwnd,
679 GREP_MASK,
680 EM_SETSEL,
681 MPFROM2SHORT(strlen(s) - (len - 1),
682 strlen(s)),
683 MPVOID);
684 }
685 }
686 }
687 }
688 break;
689
690 case GREP_ADD:
691 {
692 static CHAR s[8192];
693 SHORT sSelect;
694
695 *s = 0;
696 WinQueryDlgItemText(hwnd,
697 GREP_MASK,
698 8192,
699 s);
700 bstrip(s);
701 if(*s) {
702 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
703 GREP_LISTBOX,
704 LM_SEARCHSTRING,
705 MPFROM2SHORT(0,LIT_FIRST),
706 MPFROMP(s));
707 if(sSelect < 0) {
708 WinSendDlgItemMsg(hwnd,
709 GREP_LISTBOX,
710 LM_INSERTITEM,
711 MPFROM2SHORT(LIT_SORTASCENDING,0),
712 MPFROMP(s));
713 changed = TRUE;
714 }
715 }
716 }
717 break;
718
719 case GREP_DELETE:
720 {
721 SHORT sSelect;
722
723 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
724 GREP_LISTBOX,
725 LM_QUERYSELECTION,
726 MPFROMSHORT(LIT_FIRST),
727 MPVOID);
728 if(sSelect >= 0) {
729 WinSendDlgItemMsg(hwnd,
730 GREP_LISTBOX,
731 LM_DELETEITEM,
732 MPFROM2SHORT(sSelect,0),
733 MPVOID);
734 changed = TRUE;
735 }
736 }
737 break;
738
739 case GREP_OM:
740 {
741 CHAR str[81];
742 UINT temp;
743
744 *str = 0;
745 WinQueryDlgItemText(hwnd,
746 GREP_OLDER,
747 34,
748 str);
749 temp = atoi(str) * 30L;
750 sprintf(str,"%u",temp);
751 WinSetDlgItemText(hwnd,
752 GREP_OLDER,
753 str);
754 }
755 break;
756
757 case GREP_NM:
758 {
759 CHAR str[81];
760 UINT temp;
761
762 *str = 0;
763 WinQueryDlgItemText(hwnd,
764 GREP_NEWER,
765 34,
766 str);
767 temp = atoi(str) * 30L;
768 sprintf(str,"%u",temp);
769 WinSetDlgItemText(hwnd,
770 GREP_NEWER,
771 str);
772 }
773 break;
774
775 case GREP_GK:
776 {
777 CHAR str[81];
778 ULONG temp;
779
780 *str = 0;
781 WinQueryDlgItemText(hwnd,
782 GREP_GREATER,
783 34,
784 str);
785 temp = atol(str) * 1024L;
786 sprintf(str,"%lu",temp);
787 WinSetDlgItemText(hwnd,GREP_GREATER,str);
788 }
789 break;
790
791 case GREP_LK:
792 {
793 CHAR str[81];
794 ULONG temp;
795
796 *str = 0;
797 WinQueryDlgItemText(hwnd,
798 GREP_LESSER,
799 34,
800 str);
801 temp = atol(str) * 1024L;
802 sprintf(str,"%lu",temp);
803 WinSetDlgItemText(hwnd,
804 GREP_LESSER,
805 str);
806 }
807 break;
808
809 case DID_CANCEL:
810 WinDismissDlg(hwnd,0);
811 break;
812
813 case IDM_HELP:
814 if(hwndHelp)
815 WinSendMsg(hwndHelp,
816 HM_DISPLAY_HELP,
817 MPFROM2SHORT(HELP_GREP,0),
818 MPFROMSHORT(HM_RESOURCEID));
819 break;
820
821 case GREP_LOCALHDS:
822 case GREP_REMOTEHDS:
823 case GREP_ALLHDS:
824 {
825 static CHAR str[8192],new[8192];
826 CHAR *p,*szDrive = " :\\";
827 ULONG ulDriveNum,ulDriveMap;
828 INT x;
829 BOOL incl;
830
831 *str = *new = 0;
832 WinQueryDlgItemText(hwnd,
833 GREP_MASK,
834 8192,
835 str);
836 str[8192 - 1] = 0;
837 p = strchr(str,';');
838 if(p)
839 *p = 0;
840 p = strrchr(str,'\\');
841 if(!p)
842 p = strrchr(str,'/');
843 if(!p)
844 p = strrchr(str,':');
845 if(p)
846 strcpy(str,p + 1);
847 if(!*str)
848 strcpy(str,"*");
849 *new = 0;
850 DosError(FERR_DISABLEHARDERR);
851 DosQCurDisk(&ulDriveNum,
852 &ulDriveMap);
853 for(x = 2;x < 26;x++) {
854 if(ulDriveMap & (1L << x)) {
855 incl = FALSE;
856 switch(SHORT1FROMMP(mp1)) {
857 case GREP_ALLHDS:
858 if(!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE)))
859 incl = TRUE;
860 break;
861 case GREP_LOCALHDS:
862 if(!(driveflags[x] &
863 (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE)))
864 incl = TRUE;
865 break;
866 case GREP_REMOTEHDS:
867 if(!(driveflags[x] &
868 (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
869 (driveflags[x] & DRIVE_REMOTE))
870 incl = TRUE;
871 break;
872 }
873 }
874 if(incl) {
875 if(strlen(new) + strlen(str) + 5 < 8192 - 1) {
876 if(*new)
877 strcat(new,";");
878 *szDrive = x + 'A';
879 strcat(new,szDrive);
880 strcat(new,str);
881 }
882 }
883 }
884 if(*new)
885 WinSetDlgItemText(hwnd,
886 GREP_MASK,
887 new);
888 }
889 break;
890
891 case DID_OK:
892 hwndCollect = WinQueryWindowULong(hwnd,QWL_USER);
893 if(!hwndCollect)
894 DosBeep(50,100);
895 else {
896
897 static GREP g;
898 CHAR *str;
899
900 str = malloc(8192 + 512);
901 if(!str) {
902 DosBeep(50,100);
903 break;
904 }
905 memset(&g,0,sizeof(GREP));
906 *str = 0;
907 g.size = sizeof(GREP);
908 if(WinQueryButtonCheckstate(hwnd,GREP_RECURSE))
909 recurse = TRUE;
910 else
911 recurse = FALSE;
912 if(WinQueryButtonCheckstate(hwnd,GREP_ABSOLUTE))
913 absolute = TRUE;
914 else
915 absolute = FALSE;
916 if(WinQueryButtonCheckstate(hwnd,GREP_CASE))
917 sensitive = TRUE;
918 else
919 sensitive = FALSE;
920 if(WinQueryButtonCheckstate(hwnd,GREP_SAYFILES))
921 sayfiles = TRUE;
922 else
923 sayfiles = FALSE;
924 if(WinQueryButtonCheckstate(hwnd,GREP_SEARCHEAS))
925 searchEAs = TRUE;
926 else
927 searchEAs = FALSE;
928 if(WinQueryButtonCheckstate(hwnd,GREP_SEARCHFILES))
929 searchFiles = TRUE;
930 else
931 searchFiles = FALSE;
932 if(WinQueryButtonCheckstate(hwnd,GREP_FINDIFANY))
933 findifany = TRUE;
934 else
935 findifany = FALSE;
936 if(WinQueryButtonCheckstate(hwnd,GREP_FINDDUPES))
937 g.finddupes = TRUE;
938 else
939 g.finddupes = FALSE;
940 if(g.finddupes) {
941 if(WinQueryButtonCheckstate(hwnd,GREP_CRCDUPES))
942 g.CRCdupes = TRUE;
943 else
944 g.CRCdupes = FALSE;
945 if(WinQueryButtonCheckstate(hwnd,GREP_NOSIZEDUPES))
946 g.nosizedupes = TRUE;
947 else
948 g.nosizedupes = FALSE;
949 if(WinQueryButtonCheckstate(hwnd,GREP_IGNOREEXTDUPES))
950 g.ignoreextdupes = TRUE;
951 else
952 g.ignoreextdupes = FALSE;
953 }
954 *str = 0;
955 WinQueryDlgItemText(hwnd,
956 GREP_MASK,
957 8192,
958 str);
959 bstrip(str);
960 if(!*str) {
961 DosBeep(50,100);
962 WinSetFocus(HWND_DESKTOP,
963 WinWindowFromID(hwnd,GREP_MASK));
964 free(str);
965 break;
966 }
967 strcpy(g.tosearch,str);
968 strcpy(lastmask,str);
969 *str = 0;
970 WinQueryWindowText(hwndMLE,
971 4096,
972 str);
973 strcpy(lasttext,str);
974 {
975 CHAR *p,*pp;
976 ULONG matched = 0;
977
978 pp = g.searchPattern;
979 p = str;
980 while(*p) {
981 if(*p == '\r') {
982 p++;
983 continue;
984 }
985 if(*p == '\n') {
986 if(*(p + 1))
987 matched++;
988 *pp = 0;
989 }
990 else
991 *pp = *p;
992 pp++;
993 p++;
994 }
995 if(*g.searchPattern)
996 matched++;
997 *pp = 0;
998 pp++;
999 *pp = 0;
1000 g.numlines = matched;
1001 g.matched = malloc(g.numlines);
1002 if(!g.matched)
1003 g.numlines = 0;
1004 }
1005 *str = 0;
1006 WinQueryDlgItemText(hwnd,
1007 GREP_GREATER,
1008 34,
1009 str);
1010 greater = atol(str);
1011 *str = 0;
1012 WinQueryDlgItemText(hwnd,
1013 GREP_LESSER,
1014 34,
1015 str);
1016 lesser = atol(str);
1017 *str = 0;
1018 WinQueryDlgItemText(hwnd,
1019 GREP_NEWER,
1020 34,
1021 str);
1022 newer = atoi(str);
1023 *str = 0;
1024 WinQueryDlgItemText(hwnd,
1025 GREP_OLDER,
1026 34,
1027 str);
1028 older = atoi(str);
1029 if(older || newer) {
1030
1031 FDATE fdate;
1032 FTIME ftime;
1033 struct tm tm;
1034 time_t t;
1035
1036 t = time(NULL);
1037 tm = *localtime(&t);
1038 fdate.day = tm.tm_mday;
1039 fdate.month = tm.tm_mon + 1;
1040 fdate.year = tm.tm_year - 80;
1041 ftime.hours = tm.tm_hour;
1042 ftime.minutes = tm.tm_min;
1043 ftime.twosecs = tm.tm_sec / 2;
1044 if(older) {
1045 g.olderthan = SecsSince1980(&fdate,&ftime);
1046 g.olderthan -= (older * (24L * 60L * 60L));
1047 }
1048 if(newer) {
1049 g.newerthan = SecsSince1980(&fdate,&ftime);
1050 g.newerthan -= (newer * (24L * 60L * 60L));
1051 }
1052 }
1053 if(!newer)
1054 g.newerthan = 0;
1055 if(!older)
1056 g.olderthan = 0;
1057 g.greaterthan = greater;
1058 g.lessthan = lesser;
1059 g.absFlag = absolute;
1060 g.caseFlag = sensitive;
1061 g.dirFlag = recurse;
1062 g.sayfiles = sayfiles;
1063 g.searchEAs = searchEAs;
1064 g.searchFiles = searchFiles;
1065 g.findifany = findifany;
1066 g.hwndFiles = hwndCollect;
1067 g.hwnd = WinQueryWindow(hwndCollect,QW_PARENT);
1068 g.hwndCurFile = WinWindowFromID(g.hwnd,DIR_SELECTED);
1069 g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
1070 g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
1071 g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
1072 if(_beginthread(dogrep,NULL,524280,(PVOID)&g) == -1) {
1073 free(str);
1074 DosBeep(50,100);
1075 WinDismissDlg(hwnd,0);
1076 break;
1077 }
1078 else
1079 DosSleep(128L);
1080 free(str);
1081 }
1082 if(changed) {
1083
1084 FILE *fp;
1085 static CHAR s[8192 + 14];
1086 SHORT sSelect,x;
1087
1088 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,
1089 GREP_LISTBOX,
1090 LM_QUERYITEMCOUNT,
1091 MPVOID,
1092 MPVOID);
1093 if(sSelect > 0) {
1094 save_dir2(s);
1095 if(s[strlen(s) - 1] != '\\')
1096 strcat(s,"\\");
1097 strcat(s,"GREPMASK.DAT");
1098 fp = fopen(s,"w");
1099 if(fp) {
1100 fputs(GetPString(IDS_GREPFILETEXT),fp);
1101 for(x = 0;x < sSelect;x++) {
1102 *s = 0;
1103 WinSendDlgItemMsg(hwnd,
1104 GREP_LISTBOX,
1105 LM_QUERYITEMTEXT,
1106 MPFROM2SHORT(x,8192),
1107 MPFROMP(s));
1108 bstrip(s);
1109 if(*s)
1110 fprintf(fp,"%s\n",s);
1111 }
1112 fclose(fp);
1113 }
1114 }
1115 }
1116 WinDismissDlg(hwnd,1);
1117 break;
1118 }
1119 return 0;
1120 }
1121 return WinDefDlgProc(hwnd,msg,mp1,mp2);
1122}
1123
Note: See TracBrowser for help on using the repository browser.