source: trunk/dll/grep2.c@ 1161

Last change on this file since 1161 was 1161, checked in by John Small, 17 years ago

Ticket 187: Draft 1: Functions only

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