source: trunk/dll/grep2.c@ 1505

Last change on this file since 1505 was 1505, checked in by Gregg Young, 15 years ago

Remove unnecessary type casts; minor formating cleanup.

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