source: trunk/dll/grep2.c@ 1196

Last change on this file since 1196 was 1185, checked in by John Small, 17 years ago

Ticket 187: Draft 2: Move remaining function declarations

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