source: trunk/dll/grep2.c@ 1398

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

Move embeded strings to PCSZ variables or string table; Eliminate Error2 functions Runtime_Error with NULL format string returns "No data" error. Change declares from PSZ to PCSZ in functions where the variable isn't changed. Added btm as an executable file type in several additional places. Use fProtectOnly to prevent attempt to execute Dos and Win programs on "Protect only" installs in several additional places.

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