source: trunk/dll/grep2.c@ 1335

Last change on this file since 1335 was 1335, checked in by Steven Levine, 17 years ago

Ticket 26: Add exception handlers to all threads using xbeginthread

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