source: trunk/dll/grep2.c@ 1118

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

Clean up of fix for trap caused by FM/2 being on a full disk. It now preserves the data files. (Ticket 152, 271)

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