source: trunk/dll/grep2.c@ 1283

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

Fix seek and scan local HDs selection to always handle nonexistent drives correctly (Ticket 301)

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