source: trunk/dll/grep2.c@ 1036

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

Fixed early memory free; Added free_... functions to make fortify checking easier; Added fortify scopes; Delete now moves to trash can on systems with the xworkplace trash can installed.

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