source: trunk/dll/grep2.c@ 1395

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

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

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