source: trunk/dll/grep2.c@ 123

Last change on this file since 123 was 123, checked in by root, 21 years ago

Rework lstrip/rstrip usage

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