source: trunk/dll/grep2.c@ 1375

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

Updated history; comments minor code cleanup for recent changes

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