source: trunk/dll/grep2.c@ 402

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

Avoid 0 length malloc, optimize option checks
Use xfgets

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