source: trunk/dll/grep2.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

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