source: trunk/dll/grep2.c@ 1119

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

Comments for CS 1118 (Tickets 154 (not 152), 270)

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