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