source: trunk/dll/grep2.c@ 1082

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

Changes so FM2 will use TMP/TEMP directory for all temp files; Replaced save_dir2 with global variable so BldFullPathName could easily replace code that performed the same function; Added #ifdef FORTIFY to free_ function that are only used when fortified.

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