source: trunk/dll/grep2.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

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