source: trunk/dll/grep2.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 18 years ago

Indentation cleanup

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