source: trunk/dll/grep2.c@ 771

Last change on this file since 771 was 771, checked in by Gregg Young, 18 years ago

Increase subject to 1024 reduce DosSleep times

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: grep2.c 771 2007-08-06 03:05:35Z 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
[123]20
[202]21 fixme for more excess locals to be gone
22
[123]23***********************************************************************/
24
[2]25#define INCL_DOS
26#define INCL_WIN
27#define INCL_GPI
28#define INCL_DOSERRORS
[202]29#include <os2.h>
[2]30
31#include <stdarg.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <ctype.h>
36#include <time.h>
37#include <share.h>
38#include <limits.h>
[689]39#include <process.h> // _beginthread
[202]40
[2]41#include "fm3dll.h"
42#include "fm3dlg.h"
43#include "fm3str.h"
44#include "mle.h"
45#include "grep.h"
46
47#pragma data_seg(DATA1)
[336]48
49static PSZ pszSrcFile = __FILE__;
50
[2]51#pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc)
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);
[551]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
272 save_dir2(s);
273 if (s[strlen(s) - 1] != '\\')
274 strcat(s, "\\");
275 strcat(s, "GREPMASK.DAT");
276 fp = _fsopen(s, "r", SH_DENYWR);
[551]277 if (fp) {
[402]278 while (!feof(fp)) {
[551]279 if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
[202]280 break;
[402]281 if (*s && *s != ';') {
[202]282 WinSendDlgItemMsg(hwnd,
283 GREP_LISTBOX,
284 LM_INSERTITEM,
[551]285 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
[402]286 }
[2]287 }
[202]288 fclose(fp);
[190]289 }
[202]290
[190]291 FillPathListBox(hwnd,
292 WinWindowFromID(hwnd, GREP_DRIVELIST),
[551]293 (HWND) 0, NULL, FALSE);
[190]294 break;
295
296 case WM_ADJUSTWINDOWPOS:
[551]297 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
[190]298 break;
299
300 case UM_SETDIR:
301 PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
[551]302 (HPS) 0, FALSE, TRUE);
[190]303 return 0;
304
305 case UM_FOCUSME:
306 /* set focus to window hwnd in mp1 */
307 if (mp1)
[551]308 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
[190]309 return 0;
310
311 case WM_CONTROL:
[551]312 switch (SHORT1FROMMP(mp1)) {
313 case GREP_REMEMBERFLAGS:
314 {
315 BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
[549]316
[551]317 PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
318 (PVOID) & gRemember, sizeof(BOOL));
319 }
320 break;
[549]321
[190]322 case GREP_DRIVELIST:
[551]323 switch (SHORT2FROMMP(mp1)) {
[190]324 case LN_KILLFOCUS:
325 WinSetDlgItemText(hwnd,
[551]326 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]327 break;
328 case LN_SETFOCUS:
329 WinSetDlgItemText(hwnd,
[551]330 GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
[190]331 break;
332 case LN_ENTER:
[551]333 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[202]334 bstrip(s);
335 p = strrchr(s, '\\');
336 if (p)
337 strcpy(simple, p);
[551]338 else if (*s) {
[202]339 strcpy(simple, "\\");
340 strcat(simple, s);
341 *s = 0;
342 }
343 else
344 strcpy(simple, "\\*");
345 if (simple[strlen(simple) - 1] == ';')
346 simple[strlen(simple) - 1] = 0;
347 lLen = strlen(simple) + 1;
[551]348 if (strlen(s) > 8192 - lLen) {
349 Runtime_Error(pszSrcFile, __LINE__, "too big");
350 WinSetDlgItemText(hwnd, GREP_MASK, s);
[202]351 break;
352 }
[2]353
[551]354 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
355 GREP_DRIVELIST,
356 LM_QUERYSELECTION,
357 MPFROMSHORT(LIT_FIRST), MPVOID);
358 if (sSelect >= 0) {
[202]359 if (*s && s[strlen(s) - 1] != ';')
360 strcat(s, ";");
361 WinSendDlgItemMsg(hwnd,
362 GREP_DRIVELIST,
363 LM_QUERYITEMTEXT,
364 MPFROM2SHORT(sSelect,
365 (8192 - strlen(s)) - lLen),
366 MPFROMP(&s[strlen(s)]));
367 rstrip(s);
[551]368 if (*s) {
[202]369 strcat(s, simple);
[551]370 WinSetDlgItemText(hwnd, GREP_MASK, s);
[190]371 WinSendDlgItemMsg(hwnd,
[202]372 GREP_MASK,
373 EM_SETSEL,
374 MPFROM2SHORT(strlen(s) - (lLen + 1),
[551]375 strlen(s)), MPVOID);
[202]376 PostMsg(hwnd,
377 UM_FOCUSME,
[551]378 MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
[190]379 }
380 }
[551]381 break; // LN_ENTER
382 } // switch
[190]383 break;
[202]384
[190]385 case GREP_LISTBOX:
[551]386 switch (SHORT2FROMMP(mp1)) {
[190]387 case LN_KILLFOCUS:
388 WinSetDlgItemText(hwnd,
[551]389 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]390 break;
391 case LN_SETFOCUS:
[551]392 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
[190]393 break;
394 case LN_ENTER:
395 case LN_SELECT:
396 if ((SHORT2FROMMP(mp1) == LN_ENTER &&
397 !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) ||
398 (SHORT2FROMMP(mp1) == LN_SELECT &&
399 WinQueryButtonCheckstate(hwnd, GREP_APPEND)))
400 break;
401 {
[551]402 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
403 GREP_LISTBOX,
404 LM_QUERYSELECTION,
405 MPFROMSHORT(LIT_FIRST), MPVOID);
406 if (sSelect >= 0) {
[202]407 *s = 0;
[551]408 if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
409 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[190]410 bstrip(s);
411 if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
412 strcat(s, ";");
413 }
414 WinSendDlgItemMsg(hwnd,
415 GREP_LISTBOX,
416 LM_QUERYITEMTEXT,
417 MPFROM2SHORT(sSelect, 8192 - strlen(s)),
418 MPFROMP(s + strlen(s)));
419 bstrip(s);
420 if (*s)
[551]421 WinSetDlgItemText(hwnd, GREP_MASK, s);
[190]422 }
423 }
424 break;
[2]425 }
426 break;
[202]427
[190]428 case GREP_MASK:
429 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
430 WinSetDlgItemText(hwnd,
[551]431 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]432 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[551]433 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
[2]434 break;
[190]435 case GREP_SEARCH:
436 if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
437 WinSetDlgItemText(hwnd,
[551]438 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]439 if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
[551]440 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
[190]441 break;
442 case GREP_GREATER:
443 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
444 WinSetDlgItemText(hwnd,
[551]445 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]446 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[551]447 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
[190]448 break;
449 case GREP_LESSER:
450 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
451 WinSetDlgItemText(hwnd,
[551]452 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]453 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[551]454 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
[190]455 break;
456 case GREP_NEWER:
457 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
458 WinSetDlgItemText(hwnd,
[551]459 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]460 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[551]461 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
[190]462 break;
463 case GREP_OLDER:
464 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
465 WinSetDlgItemText(hwnd,
[551]466 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
[190]467 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[551]468 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
[190]469 break;
470 case GREP_FINDDUPES:
471 {
472 BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
[2]473
[190]474 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes);
475 WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes);
476 WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes);
477 WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes);
478 WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes);
[551]479 WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
480 finddupes);
[190]481 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes);
482 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes);
483 WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes);
484 WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes);
485 WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes);
486 WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes);
487 WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes);
488 WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes);
489 WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes);
490 WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes);
491 WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes);
492 if (finddupes)
493 WinCheckButton(hwnd, GREP_RECURSE, TRUE);
494 }
495 }
496 return 0;
[2]497
[190]498 case WM_COMMAND:
[551]499 switch (SHORT1FROMMP(mp1)) {
[190]500 case GREP_ENV:
501 {
502 CHAR *t;
[202]503 CHAR env[8192];
[2]504
[190]505 *path = 0;
506 if (!WinDlgBox(HWND_DESKTOP,
[551]507 hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
[190]508 break;
509 }
510 bstrip(path);
511 if (!*path)
512 break;
513 if (!stricmp(path, "LIBPATH"))
514 LoadLibPath(env, 8192);
[551]515 else {
[190]516 p = getenv(path);
517 if (!p)
518 break;
519 strcpy(env, p);
520 }
521 bstrip(env);
522 if (!*env)
523 break;
[551]524 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[190]525 bstrip(s);
[551]526 if (strlen(s) > 8192 - 5) {
527 Runtime_Error(pszSrcFile, __LINE__, "too big");
[190]528 break;
529 }
530 p = strrchr(s, '\\');
531 if (p)
532 strcpy(simple, p + 1);
533 else if (*s)
534 strcpy(simple, s);
535 else
536 strcpy(simple, "*");
537 if (!p)
538 *s = 0;
539 if (simple[strlen(simple) - 1] == ';')
540 simple[strlen(simple) - 1] = 0;
[202]541 lLen = strlen(simple) + 1;
[190]542 p = env;
[551]543 while (p && *p) {
[190]544 strncpy(path, p, CCHMAXPATH - 1);
545 path[CCHMAXPATH - 1] = 0;
546 t = strchr(path, ';');
547 if (t)
548 *t = 0;
549 bstrip(path);
[551]550 if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
551 if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
552 WinSetDlgItemText(hwnd, GREP_MASK, s);
[190]553 break;
554 }
[551]555 if (!*s || (*s && s[strlen(s) - 1] != ';')) {
[190]556 if (*s)
557 strcat(s, ";");
558 strcat(s, path);
[202]559 lLen += strlen(path);
[551]560 if (s[strlen(s) - 1] != '\\') {
[202]561 lLen++;
[190]562 strcat(s, "\\");
563 }
564 rstrip(s);
[551]565 if (*s) {
[190]566 strcat(s, simple);
[551]567 WinSetDlgItemText(hwnd, GREP_MASK, s);
[190]568 WinSendDlgItemMsg(hwnd,
569 GREP_MASK,
570 EM_SETSEL,
[202]571 MPFROM2SHORT(strlen(s) - (lLen - 1),
[551]572 strlen(s)), MPVOID);
[190]573 }
574 }
575 }
576 p = strchr(p, ';');
577 if (p)
578 p++;
579 }
580 }
581 break;
[2]582
[190]583 case GREP_WALK:
[551]584 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[202]585 bstrip(s);
[551]586 if (strlen(s) > 8192 - 5) {
587 Runtime_Error(pszSrcFile, __LINE__, "too big");
[202]588 break;
589 }
590 *path = 0;
591 if (WinDlgBox(HWND_DESKTOP,
592 hwnd,
593 WalkAllDlgProc,
[551]594 FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
[202]595 p = strrchr(s, '\\');
596 if (p)
597 strcpy(simple, p + 1);
598 else if (*s)
599 strcpy(simple, s);
600 else
601 strcpy(simple, "*");
602 if (!p)
603 *s = 0;
604 if (simple[strlen(simple) - 1] == ';')
605 simple[strlen(simple) - 1] = 0;
606 lLen = strlen(simple) + 1;
[551]607 if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
608 Runtime_Error(pszSrcFile, __LINE__, "too big");
609 WinSetDlgItemText(hwnd, GREP_MASK, s);
[190]610 break;
611 }
[551]612 if (!*s || (*s && s[strlen(s) - 1] != ';')) {
[202]613 if (*s)
614 strcat(s, ";");
615 strcat(s, path);
616 lLen += strlen(path);
[551]617 if (s[strlen(s) - 1] != '\\') {
[202]618 lLen++;
619 strcat(s, "\\");
620 }
621 rstrip(s);
[551]622 if (*s) {
[202]623 strcat(s, simple);
[551]624 WinSetDlgItemText(hwnd, GREP_MASK, s);
[202]625 WinSendDlgItemMsg(hwnd,
626 GREP_MASK,
627 EM_SETSEL,
628 MPFROM2SHORT(strlen(s) - (lLen - 1),
[551]629 strlen(s)), MPVOID);
[190]630 }
631 }
[2]632 }
[190]633 break;
[2]634
[190]635 case GREP_ADD:
[202]636 *s = 0;
[551]637 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[202]638 bstrip(s);
[551]639 if (*s) {
[190]640 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
641 GREP_LISTBOX,
[202]642 LM_SEARCHSTRING,
643 MPFROM2SHORT(0, LIT_FIRST),
644 MPFROMP(s));
[551]645 if (sSelect < 0) {
[190]646 WinSendDlgItemMsg(hwnd,
647 GREP_LISTBOX,
[202]648 LM_INSERTITEM,
[551]649 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
[190]650 changed = TRUE;
651 }
652 }
653 break;
[2]654
[202]655 case GREP_DELETE:
656 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
657 GREP_LISTBOX,
658 LM_QUERYSELECTION,
[551]659 MPFROMSHORT(LIT_FIRST), MPVOID);
660 if (sSelect >= 0) {
[202]661 WinSendDlgItemMsg(hwnd,
662 GREP_LISTBOX,
[551]663 LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
[202]664 changed = TRUE;
665 }
666 break;
[2]667
[202]668 case GREP_OM:
669 *s = 0;
[551]670 WinQueryDlgItemText(hwnd, GREP_OLDER, 34, s);
[202]671 ul = atoi(s) * 30L;
672 sprintf(s, "%lu", ul);
[551]673 WinSetDlgItemText(hwnd, GREP_OLDER, s);
[190]674 break;
[2]675
[190]676 case GREP_NM:
[202]677 *s = 0;
[551]678 WinQueryDlgItemText(hwnd, GREP_NEWER, 34, s);
[202]679 ul = atoi(s) * 30L;
680 sprintf(s, "%lu", ul);
[551]681 WinSetDlgItemText(hwnd, GREP_NEWER, s);
[190]682 break;
[2]683
[190]684 case GREP_GK:
[202]685 *s = 0;
[551]686 WinQueryDlgItemText(hwnd, GREP_GREATER, 34, s);
[202]687 ul = atol(s) * 1024L;
688 sprintf(s, "%lu", ul);
689 WinSetDlgItemText(hwnd, GREP_GREATER, s);
[190]690 break;
[2]691
[190]692 case GREP_LK:
[202]693 *s = 0;
[551]694 WinQueryDlgItemText(hwnd, GREP_LESSER, 34, s);
[202]695 ul = atol(s) * 1024L;
696 sprintf(s, "%lu", ul);
[551]697 WinSetDlgItemText(hwnd, GREP_LESSER, s);
[190]698 break;
[2]699
[190]700 case DID_CANCEL:
701 WinDismissDlg(hwnd, 0);
702 break;
[2]703
[190]704 case IDM_HELP:
705 if (hwndHelp)
706 WinSendMsg(hwndHelp,
707 HM_DISPLAY_HELP,
[551]708 MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
[190]709 break;
[2]710
[190]711 case GREP_LOCALHDS:
712 case GREP_REMOTEHDS:
713 case GREP_ALLHDS:
714 {
[202]715 CHAR szDrive[] = " :\\";
[190]716 ULONG ulDriveNum;
717 ULONG ulDriveMap;
718 INT x;
719 BOOL incl;
[2]720
[202]721 CHAR new[8192];
[2]722
[202]723 *s = 0;
[551]724 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
[202]725 s[8192 - 1] = 0;
726 p = strchr(s, ';');
[190]727 if (p)
728 *p = 0;
[202]729 p = strrchr(s, '\\');
[190]730 if (!p)
[202]731 p = strrchr(s, '/');
[190]732 if (!p)
[202]733 p = strrchr(s, ':');
[190]734 if (p)
[202]735 strcpy(s, p + 1);
736 if (!*s)
737 strcpy(s, "*");
[190]738 DosError(FERR_DISABLEHARDERR);
[551]739 DosQCurDisk(&ulDriveNum, &ulDriveMap);
[202]740 *new = 0;
[551]741 for (x = 2; x < 26; x++) {
742 if (ulDriveMap & (1L << x)) {
[190]743 incl = FALSE;
[551]744 switch (SHORT1FROMMP(mp1)) {
[190]745 case GREP_ALLHDS:
746 if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE)))
747 incl = TRUE;
748 break;
749 case GREP_LOCALHDS:
750 if (!(driveflags[x] &
[551]751 (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
752 DRIVE_VIRTUAL)))
[190]753 incl = TRUE;
754 break;
755 case GREP_REMOTEHDS:
756 if (!(driveflags[x] &
757 (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
758 (driveflags[x] & DRIVE_REMOTE))
759 incl = TRUE;
760 break;
761 }
762 }
[551]763 if (incl) {
764 if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
[190]765 if (*new)
766 strcat(new, ";");
767 *szDrive = x + 'A';
768 strcat(new, szDrive);
[202]769 strcat(new, s);
[190]770 }
771 }
772 }
773 if (*new)
[551]774 WinSetDlgItemText(hwnd, GREP_MASK, new);
[190]775 }
776 break;
[2]777
[190]778 case DID_OK:
779 hwndCollect = WinQueryWindowULong(hwnd, QWL_USER);
780 if (!hwndCollect)
[551]781 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
[402]782 else {
[202]783 static GREP g; // Passed to thread
[2]784
[551]785 p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
[202]786 if (!p)
[190]787 break;
788 memset(&g, 0, sizeof(GREP));
789 g.size = sizeof(GREP);
[402]790 recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
791 absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
792 sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
793 sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
794 searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
795 searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
796 findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
[551]797 gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
798 if (gRemember) {
799 PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse",
800 (PVOID) & recurse, sizeof(BOOL));
801 PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute",
802 (PVOID) & absolute, sizeof(BOOL));
803 PrfWriteProfileData(fmprof, FM3Str, "Grep_Case",
804 (PVOID) & sensitive, sizeof(BOOL));
805 PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles",
806 (PVOID) & sayfiles, sizeof(BOOL));
807 PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles",
808 (PVOID) & searchFiles, sizeof(BOOL));
809 PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
810 (PVOID) & searchEAs, sizeof(BOOL));
811 }
812 g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
[402]813 if (g.finddupes) {
814 g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
[551]815 g.nosizedupes =
816 WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
817 g.ignoreextdupes =
818 WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
[190]819 }
[402]820 // Parse file masks
[202]821 *p = 0;
[551]822 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
[202]823 bstrip(p);
[551]824 if (!*p) {
[190]825 DosBeep(50, 100);
[551]826 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
[202]827 free(p);
[190]828 break;
829 }
[202]830 strcpy(g.tosearch, p);
831 strcpy(lastmask, p);
[402]832 // Parse search strings
[202]833 *p = 0;
[551]834 WinQueryWindowText(hwndMLE, 4096, p);
[202]835 strcpy(lasttext, p);
[190]836 {
[202]837 CHAR *pszFrom;
838 CHAR *pszTo;
[190]839 ULONG matched = 0;
[2]840
[202]841 pszTo = g.searchPattern;
842 pszFrom = p;
[551]843 while (*pszFrom) {
844 if (*pszFrom == '\r') {
[202]845 pszFrom++;
[190]846 continue;
847 }
[551]848 if (*pszFrom == '\n') {
[202]849 if (*(pszFrom + 1))
[190]850 matched++;
[202]851 *pszTo = 0;
[190]852 }
853 else
[202]854 *pszTo = *pszFrom;
855 pszTo++;
856 pszFrom++;
[190]857 }
858 if (*g.searchPattern)
859 matched++;
[202]860 *pszTo++ = 0;
861 *pszTo = 0;
[190]862 g.numlines = matched;
[402]863 if (matched) {
[551]864 g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
[402]865 if (!g.matched)
866 g.numlines = 0;
867 }
[190]868 }
[202]869 *p = 0;
[551]870 WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
[202]871 greater = atol(p);
872 *p = 0;
[551]873 WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
[202]874 lesser = atol(p);
875 *p = 0;
[551]876 WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
[202]877 newer = atoi(p);
878 *p = 0;
[551]879 WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
[202]880 older = atoi(p);
[402]881 if (older || newer) {
[190]882 FDATE fdate;
883 FTIME ftime;
884 struct tm tm;
885 time_t t;
[2]886
[190]887 t = time(NULL);
888 tm = *localtime(&t);
889 fdate.day = tm.tm_mday;
890 fdate.month = tm.tm_mon + 1;
891 fdate.year = tm.tm_year - 80;
892 ftime.hours = tm.tm_hour;
893 ftime.minutes = tm.tm_min;
894 ftime.twosecs = tm.tm_sec / 2;
[402]895 if (older) {
[190]896 g.olderthan = SecsSince1980(&fdate, &ftime);
897 g.olderthan -= (older * (24L * 60L * 60L));
898 }
[402]899 if (newer) {
[190]900 g.newerthan = SecsSince1980(&fdate, &ftime);
901 g.newerthan -= (newer * (24L * 60L * 60L));
902 }
903 }
904 if (!newer)
905 g.newerthan = 0;
906 if (!older)
907 g.olderthan = 0;
908 g.greaterthan = greater;
909 g.lessthan = lesser;
910 g.absFlag = absolute;
911 g.caseFlag = sensitive;
912 g.dirFlag = recurse;
913 g.sayfiles = sayfiles;
914 g.searchEAs = searchEAs;
915 g.searchFiles = searchFiles;
916 g.findifany = findifany;
917 g.hwndFiles = hwndCollect;
918 g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT);
919 g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED);
[551]920 g.attrFile = ((DIRCNRDATA *) INSTDATA(hwndCollect))->mask.attrFile;
921 g.antiattr = ((DIRCNRDATA *) INSTDATA(hwndCollect))->mask.antiattr;
922 g.stopflag = &((DIRCNRDATA *) INSTDATA(hwndCollect))->stopflag;
923 if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) {
924 Runtime_Error(pszSrcFile, __LINE__,
925 GetPString(IDS_COULDNTSTARTTHREADTEXT));
[202]926 free(p);
[190]927 WinDismissDlg(hwnd, 0);
928 break;
929 }
930 else
[771]931 DosSleep(100); //05 Aug 07 GKY 128
[202]932 free(p);
[190]933 }
[402]934 if (changed) {
[190]935 SHORT x;
[551]936
[190]937 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
938 GREP_LISTBOX,
939 LM_QUERYITEMCOUNT,
[551]940 MPVOID, MPVOID);
[402]941 if (sSelect > 0) {
[190]942 save_dir2(s);
943 if (s[strlen(s) - 1] != '\\')
944 strcat(s, "\\");
945 strcat(s, "GREPMASK.DAT");
[551]946 fp = xfopen(s, "w", pszSrcFile, __LINE__);
[402]947 if (fp) {
[190]948 fputs(GetPString(IDS_GREPFILETEXT), fp);
[402]949 for (x = 0; x < sSelect; x++) {
[190]950 *s = 0;
951 WinSendDlgItemMsg(hwnd,
952 GREP_LISTBOX,
953 LM_QUERYITEMTEXT,
[551]954 MPFROM2SHORT(x, 8192), MPFROMP(s));
[190]955 bstrip(s);
956 if (*s)
957 fprintf(fp, "%s\n", s);
958 }
959 fclose(fp);
960 }
961 }
[2]962 }
[190]963 WinDismissDlg(hwnd, 1);
964 break;
965 }
966 return 0;
[2]967 }
[190]968 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]969}
Note: See TracBrowser for help on using the repository browser.