source: trunk/dll/grep2.c@ 1047

Last change on this file since 1047 was 1047, checked in by Gregg Young, 17 years ago

Minor code cleanup

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