| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: grep2.c 1104 2008-08-02 20:33:03Z gyoung $
|
|---|
| 5 |
|
|---|
| 6 | Grep dialog for collector
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2004, 2006 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
|---|
| 12 | 23 May 05 SHL Use QWL_USER
|
|---|
| 13 | 06 Jun 05 SHL Indent -i2
|
|---|
| 14 | 06 Jun 05 SHL Rework for VAC3.65 compat, lose excess statics
|
|---|
| 15 | 17 Jul 06 SHL Use Runtime_Error
|
|---|
| 16 | 28 Jul 06 SHL Avoid 0 length malloc, optimize option checks
|
|---|
| 17 | 29 Jul 06 SHL Use xfgets
|
|---|
| 18 | 22 Oct 06 GKY Switch say files on as default so you can tell that seek and scan files is doing something
|
|---|
| 19 | 07 Jan 07 GKY Add remember search flags to seek and scan
|
|---|
| 20 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
|---|
| 21 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 22 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
|
|---|
| 23 |
|
|---|
| 24 | fixme for more excess locals to be gone
|
|---|
| 25 |
|
|---|
| 26 | ***********************************************************************/
|
|---|
| 27 |
|
|---|
| 28 | #include <stdlib.h>
|
|---|
| 29 | #include <string.h>
|
|---|
| 30 | #include <ctype.h>
|
|---|
| 31 | #include <share.h>
|
|---|
| 32 | #include <process.h> // _beginthread
|
|---|
| 33 |
|
|---|
| 34 | #define INCL_DOS
|
|---|
| 35 | #define INCL_WIN
|
|---|
| 36 | #define INCL_LONGLONG // dircnrs.h
|
|---|
| 37 | #define INCL_WINSTDCNR // makelist.h
|
|---|
| 38 |
|
|---|
| 39 | #include "fm3dlg.h"
|
|---|
| 40 | #include "fm3str.h"
|
|---|
| 41 | #include "mle.h"
|
|---|
| 42 | #include "grep.h"
|
|---|
| 43 | #include "errutil.h" // Dos_Error...
|
|---|
| 44 | #include "strutil.h" // GetPString
|
|---|
| 45 | #include "pathutil.h" // BldFullPathName
|
|---|
| 46 | #include "fm3dll.h"
|
|---|
| 47 | #include "fortify.h"
|
|---|
| 48 |
|
|---|
| 49 | #pragma data_seg(DATA1)
|
|---|
| 50 |
|
|---|
| 51 | static PSZ pszSrcFile = __FILE__;
|
|---|
| 52 |
|
|---|
| 53 | MRESULT EXPENTRY EnvDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 54 | {
|
|---|
| 55 | SHORT sSelect;
|
|---|
| 56 | CHAR *p;
|
|---|
| 57 | CHAR s[CCHMAXPATH];
|
|---|
| 58 | CHAR szPath[CCHMAXPATH];
|
|---|
| 59 |
|
|---|
| 60 | static CHAR lastenv[CCHMAXPATH] = "DPATH";
|
|---|
| 61 |
|
|---|
| 62 | switch (msg) {
|
|---|
| 63 | case WM_INITDLG:
|
|---|
| 64 | if (mp2) {
|
|---|
| 65 | WinSetWindowPtr(hwnd, QWL_USER, mp2);
|
|---|
| 66 | *(CHAR *)mp2 = 0;
|
|---|
| 67 | {
|
|---|
| 68 | CHAR *p;
|
|---|
| 69 | CHAR *pp;
|
|---|
| 70 |
|
|---|
| 71 | p = GetPString(IDS_ENVVARNAMES);
|
|---|
| 72 | while (*p == ' ')
|
|---|
| 73 | p++;
|
|---|
| 74 | while (*p) {
|
|---|
| 75 | *szPath = 0;
|
|---|
| 76 | pp = szPath;
|
|---|
| 77 | while (*p && *p != ' ')
|
|---|
| 78 | *pp++ = *p++;
|
|---|
| 79 | *pp = 0;
|
|---|
| 80 | while (*p == ' ')
|
|---|
| 81 | p++;
|
|---|
| 82 | if (*szPath)
|
|---|
| 83 | WinSendDlgItemMsg(hwnd,
|
|---|
| 84 | ENV_LISTBOX,
|
|---|
| 85 | LM_INSERTITEM,
|
|---|
| 86 | MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath));
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | WinSendDlgItemMsg(hwnd,
|
|---|
| 90 | ENV_NAME,
|
|---|
| 91 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
|---|
| 92 | WinSetDlgItemText(hwnd, ENV_NAME, lastenv);
|
|---|
| 93 | WinSendDlgItemMsg(hwnd,
|
|---|
| 94 | ENV_NAME,
|
|---|
| 95 | EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
|
|---|
| 96 | }
|
|---|
| 97 | else
|
|---|
| 98 | WinDismissDlg(hwnd, 0);
|
|---|
| 99 | break;
|
|---|
| 100 |
|
|---|
| 101 | case WM_CONTROL:
|
|---|
| 102 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 103 | case ENV_LISTBOX:
|
|---|
| 104 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 105 | case LN_SELECT:
|
|---|
| 106 | {
|
|---|
| 107 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 108 | ENV_LISTBOX,
|
|---|
| 109 | LM_QUERYSELECTION,
|
|---|
| 110 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 111 | if (sSelect >= 0) {
|
|---|
| 112 | *s = 0;
|
|---|
| 113 | WinSendDlgItemMsg(hwnd,
|
|---|
| 114 | ENV_LISTBOX,
|
|---|
| 115 | LM_QUERYITEMTEXT,
|
|---|
| 116 | MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
|
|---|
| 117 | bstrip(s);
|
|---|
| 118 | if (*s)
|
|---|
| 119 | WinSetDlgItemText(hwnd, ENV_NAME, s);
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | break;
|
|---|
| 123 | case LN_ENTER:
|
|---|
| 124 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 125 | break;
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 | return 0;
|
|---|
| 129 |
|
|---|
| 130 | case WM_COMMAND:
|
|---|
| 131 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 132 | case DID_CANCEL:
|
|---|
| 133 | WinDismissDlg(hwnd, 0);
|
|---|
| 134 | break;
|
|---|
| 135 | case DID_OK:
|
|---|
| 136 | p = WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 137 | if (p) {
|
|---|
| 138 | WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
|
|---|
| 139 | bstrip(p);
|
|---|
| 140 | if (!*p) {
|
|---|
| 141 | DosBeep(50, 100);
|
|---|
| 142 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
|
|---|
| 143 | }
|
|---|
| 144 | else {
|
|---|
| 145 | strcpy(lastenv, p);
|
|---|
| 146 | WinDismissDlg(hwnd, 1);
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 | break;
|
|---|
| 150 | case IDM_HELP:
|
|---|
| 151 | if (hwndHelp)
|
|---|
| 152 | WinSendMsg(hwndHelp,
|
|---|
| 153 | HM_DISPLAY_HELP,
|
|---|
| 154 | MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 155 | break;
|
|---|
| 156 | }
|
|---|
| 157 | return 0;
|
|---|
| 158 | }
|
|---|
| 159 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | MRESULT EXPENTRY GrepDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 163 | {
|
|---|
| 164 | HWND hwndCollect;
|
|---|
| 165 | HWND hwndMLE = WinWindowFromID(hwnd, GREP_SEARCH);
|
|---|
| 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];
|
|---|
| 174 |
|
|---|
| 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;
|
|---|
| 180 | static BOOL sayfiles = TRUE;
|
|---|
| 181 | static BOOL searchEAs = TRUE;
|
|---|
| 182 | static BOOL searchFiles = TRUE;
|
|---|
| 183 | static BOOL changed = FALSE;
|
|---|
| 184 | static BOOL findifany = TRUE;
|
|---|
| 185 | static BOOL gRemember = FALSE;
|
|---|
| 186 | ULONG size = sizeof(BOOL);
|
|---|
| 187 | static UINT newer = 0;
|
|---|
| 188 | static UINT older = 0;
|
|---|
| 189 | static ULONG greater = 0;
|
|---|
| 190 | static ULONG lesser = 0;
|
|---|
| 191 |
|
|---|
| 192 | switch (msg) {
|
|---|
| 193 | case WM_INITDLG:
|
|---|
| 194 | if (!mp2) {
|
|---|
| 195 | WinDismissDlg(hwnd, 0);
|
|---|
| 196 | break;
|
|---|
| 197 | }
|
|---|
| 198 | WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2);
|
|---|
| 199 | WinSendDlgItemMsg(hwnd,
|
|---|
| 200 | GREP_MASK,
|
|---|
| 201 | EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
|
|---|
| 202 | MLEsetlimit(hwndMLE, 4096);
|
|---|
| 203 | MLEsetformat(hwndMLE, MLFIE_NOTRANS);
|
|---|
| 204 | WinSendDlgItemMsg(hwnd,
|
|---|
| 205 | GREP_NEWER,
|
|---|
| 206 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
|---|
| 207 | WinSendDlgItemMsg(hwnd,
|
|---|
| 208 | GREP_OLDER,
|
|---|
| 209 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
|---|
| 210 | WinSendDlgItemMsg(hwnd,
|
|---|
| 211 | GREP_GREATER,
|
|---|
| 212 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
|---|
| 213 | WinSendDlgItemMsg(hwnd,
|
|---|
| 214 | GREP_LESSER,
|
|---|
| 215 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
|---|
| 216 | WinSetDlgItemText(hwnd, GREP_MASK, lastmask);
|
|---|
| 217 | WinSendDlgItemMsg(hwnd,
|
|---|
| 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 | }
|
|---|
| 244 | WinSetWindowText(hwndMLE, lasttext);
|
|---|
| 245 | if (*lasttext) {
|
|---|
| 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);
|
|---|
| 258 |
|
|---|
| 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 |
|
|---|
| 268 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), FALSE);
|
|---|
| 269 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), FALSE);
|
|---|
| 270 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), FALSE);
|
|---|
| 271 |
|
|---|
| 272 | BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT");
|
|---|
| 273 | fp = _fsopen(s, "r", SH_DENYWR);
|
|---|
| 274 | if (fp) {
|
|---|
| 275 | while (!feof(fp)) {
|
|---|
| 276 | if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
|
|---|
| 277 | break;
|
|---|
| 278 | if (*s && *s != ';') {
|
|---|
| 279 | WinSendDlgItemMsg(hwnd,
|
|---|
| 280 | GREP_LISTBOX,
|
|---|
| 281 | LM_INSERTITEM,
|
|---|
| 282 | MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
|
|---|
| 283 | }
|
|---|
| 284 | }
|
|---|
| 285 | fclose(fp);
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | FillPathListBox(hwnd,
|
|---|
| 289 | WinWindowFromID(hwnd, GREP_DRIVELIST),
|
|---|
| 290 | (HWND) 0, NULL, FALSE);
|
|---|
| 291 | break;
|
|---|
| 292 |
|
|---|
| 293 | case WM_ADJUSTWINDOWPOS:
|
|---|
| 294 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
|---|
| 295 | break;
|
|---|
| 296 |
|
|---|
| 297 | case UM_SETDIR:
|
|---|
| 298 | PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
|
|---|
| 299 | (HPS) 0, FALSE, TRUE);
|
|---|
| 300 | return 0;
|
|---|
| 301 |
|
|---|
| 302 | case UM_FOCUSME:
|
|---|
| 303 | /* set focus to window hwnd in mp1 */
|
|---|
| 304 | if (mp1)
|
|---|
| 305 | WinSetFocus(HWND_DESKTOP, (HWND) mp1);
|
|---|
| 306 | return 0;
|
|---|
| 307 |
|
|---|
| 308 | case WM_CONTROL:
|
|---|
| 309 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 310 | case GREP_REMEMBERFLAGS:
|
|---|
| 311 | {
|
|---|
| 312 | BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
|
|---|
| 313 |
|
|---|
| 314 | PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
|
|---|
| 315 | (PVOID) & gRemember, sizeof(BOOL));
|
|---|
| 316 | }
|
|---|
| 317 | break;
|
|---|
| 318 |
|
|---|
| 319 | case GREP_DRIVELIST:
|
|---|
| 320 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 321 | case LN_KILLFOCUS:
|
|---|
| 322 | WinSetDlgItemText(hwnd,
|
|---|
| 323 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 324 | break;
|
|---|
| 325 | case LN_SETFOCUS:
|
|---|
| 326 | WinSetDlgItemText(hwnd,
|
|---|
| 327 | GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
|
|---|
| 328 | break;
|
|---|
| 329 | case LN_ENTER:
|
|---|
| 330 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 331 | bstrip(s);
|
|---|
| 332 | p = strrchr(s, '\\');
|
|---|
| 333 | if (p)
|
|---|
| 334 | strcpy(simple, p);
|
|---|
| 335 | else if (*s) {
|
|---|
| 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;
|
|---|
| 345 | if (strlen(s) > 8192 - lLen) {
|
|---|
| 346 | Runtime_Error(pszSrcFile, __LINE__, "too big");
|
|---|
| 347 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 348 | break;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 352 | GREP_DRIVELIST,
|
|---|
| 353 | LM_QUERYSELECTION,
|
|---|
| 354 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 355 | if (sSelect >= 0) {
|
|---|
| 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);
|
|---|
| 365 | if (*s) {
|
|---|
| 366 | strcat(s, simple);
|
|---|
| 367 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 368 | WinSendDlgItemMsg(hwnd,
|
|---|
| 369 | GREP_MASK,
|
|---|
| 370 | EM_SETSEL,
|
|---|
| 371 | MPFROM2SHORT(strlen(s) - (lLen + 1),
|
|---|
| 372 | strlen(s)), MPVOID);
|
|---|
| 373 | PostMsg(hwnd,
|
|---|
| 374 | UM_FOCUSME,
|
|---|
| 375 | MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
|
|---|
| 376 | }
|
|---|
| 377 | }
|
|---|
| 378 | break; // LN_ENTER
|
|---|
| 379 | } // switch
|
|---|
| 380 | break;
|
|---|
| 381 |
|
|---|
| 382 | case GREP_LISTBOX:
|
|---|
| 383 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 384 | case LN_KILLFOCUS:
|
|---|
| 385 | WinSetDlgItemText(hwnd,
|
|---|
| 386 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 387 | break;
|
|---|
| 388 | case LN_SETFOCUS:
|
|---|
| 389 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
|
|---|
| 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 | {
|
|---|
| 399 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 400 | GREP_LISTBOX,
|
|---|
| 401 | LM_QUERYSELECTION,
|
|---|
| 402 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 403 | if (sSelect >= 0) {
|
|---|
| 404 | *s = 0;
|
|---|
| 405 | if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
|
|---|
| 406 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 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)
|
|---|
| 418 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 419 | }
|
|---|
| 420 | }
|
|---|
| 421 | break;
|
|---|
| 422 | }
|
|---|
| 423 | break;
|
|---|
| 424 |
|
|---|
| 425 | case GREP_MASK:
|
|---|
| 426 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 427 | WinSetDlgItemText(hwnd,
|
|---|
| 428 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 429 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 430 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
|
|---|
| 431 | break;
|
|---|
| 432 | case GREP_SEARCH:
|
|---|
| 433 | if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
|
|---|
| 434 | WinSetDlgItemText(hwnd,
|
|---|
| 435 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 436 | if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
|
|---|
| 437 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
|
|---|
| 438 | break;
|
|---|
| 439 | case GREP_GREATER:
|
|---|
| 440 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 441 | WinSetDlgItemText(hwnd,
|
|---|
| 442 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 443 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 444 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
|
|---|
| 445 | break;
|
|---|
| 446 | case GREP_LESSER:
|
|---|
| 447 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 448 | WinSetDlgItemText(hwnd,
|
|---|
| 449 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 450 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 451 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
|
|---|
| 452 | break;
|
|---|
| 453 | case GREP_NEWER:
|
|---|
| 454 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 455 | WinSetDlgItemText(hwnd,
|
|---|
| 456 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 457 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 458 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
|
|---|
| 459 | break;
|
|---|
| 460 | case GREP_OLDER:
|
|---|
| 461 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
|---|
| 462 | WinSetDlgItemText(hwnd,
|
|---|
| 463 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
|---|
| 464 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
|---|
| 465 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
|
|---|
| 466 | break;
|
|---|
| 467 | case GREP_FINDDUPES:
|
|---|
| 468 | {
|
|---|
| 469 | BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
|
|---|
| 470 |
|
|---|
| 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);
|
|---|
| 476 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
|
|---|
| 477 | finddupes);
|
|---|
| 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;
|
|---|
| 494 |
|
|---|
| 495 | case WM_COMMAND:
|
|---|
| 496 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 497 | case GREP_ENV:
|
|---|
| 498 | {
|
|---|
| 499 | CHAR *t;
|
|---|
| 500 | CHAR env[8192];
|
|---|
| 501 |
|
|---|
| 502 | *path = 0;
|
|---|
| 503 | if (!WinDlgBox(HWND_DESKTOP,
|
|---|
| 504 | hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
|
|---|
| 505 | break;
|
|---|
| 506 | }
|
|---|
| 507 | bstrip(path);
|
|---|
| 508 | if (!*path)
|
|---|
| 509 | break;
|
|---|
| 510 | if (!stricmp(path, "LIBPATH"))
|
|---|
| 511 | LoadLibPath(env, 8192);
|
|---|
| 512 | else {
|
|---|
| 513 | p = getenv(path);
|
|---|
| 514 | if (!p)
|
|---|
| 515 | break;
|
|---|
| 516 | strcpy(env, p);
|
|---|
| 517 | }
|
|---|
| 518 | bstrip(env);
|
|---|
| 519 | if (!*env)
|
|---|
| 520 | break;
|
|---|
| 521 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 522 | bstrip(s);
|
|---|
| 523 | if (strlen(s) > 8192 - 5) {
|
|---|
| 524 | Runtime_Error(pszSrcFile, __LINE__, "too big");
|
|---|
| 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;
|
|---|
| 538 | lLen = strlen(simple) + 1;
|
|---|
| 539 | p = env;
|
|---|
| 540 | while (p && *p) {
|
|---|
| 541 | strncpy(path, p, CCHMAXPATH - 1);
|
|---|
| 542 | path[CCHMAXPATH - 1] = 0;
|
|---|
| 543 | t = strchr(path, ';');
|
|---|
| 544 | if (t)
|
|---|
| 545 | *t = 0;
|
|---|
| 546 | bstrip(path);
|
|---|
| 547 | if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
|
|---|
| 548 | if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
|
|---|
| 549 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 550 | break;
|
|---|
| 551 | }
|
|---|
| 552 | if (!*s || (*s && s[strlen(s) - 1] != ';')) {
|
|---|
| 553 | if (*s)
|
|---|
| 554 | strcat(s, ";");
|
|---|
| 555 | strcat(s, path);
|
|---|
| 556 | lLen += strlen(path);
|
|---|
| 557 | if (s[strlen(s) - 1] != '\\') {
|
|---|
| 558 | lLen++;
|
|---|
| 559 | strcat(s, "\\");
|
|---|
| 560 | }
|
|---|
| 561 | rstrip(s);
|
|---|
| 562 | if (*s) {
|
|---|
| 563 | strcat(s, simple);
|
|---|
| 564 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 565 | WinSendDlgItemMsg(hwnd,
|
|---|
| 566 | GREP_MASK,
|
|---|
| 567 | EM_SETSEL,
|
|---|
| 568 | MPFROM2SHORT(strlen(s) - (lLen - 1),
|
|---|
| 569 | strlen(s)), MPVOID);
|
|---|
| 570 | }
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 | p = strchr(p, ';');
|
|---|
| 574 | if (p)
|
|---|
| 575 | p++;
|
|---|
| 576 | }
|
|---|
| 577 | }
|
|---|
| 578 | break;
|
|---|
| 579 |
|
|---|
| 580 | case GREP_WALK:
|
|---|
| 581 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 582 | bstrip(s);
|
|---|
| 583 | if (strlen(s) > 8192 - 5) {
|
|---|
| 584 | Runtime_Error(pszSrcFile, __LINE__, "too big");
|
|---|
| 585 | break;
|
|---|
| 586 | }
|
|---|
| 587 | *path = 0;
|
|---|
| 588 | if (WinDlgBox(HWND_DESKTOP,
|
|---|
| 589 | hwnd,
|
|---|
| 590 | WalkAllDlgProc,
|
|---|
| 591 | FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
|
|---|
| 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;
|
|---|
| 604 | if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
|
|---|
| 605 | Runtime_Error(pszSrcFile, __LINE__, "too big");
|
|---|
| 606 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 607 | break;
|
|---|
| 608 | }
|
|---|
| 609 | if (!*s || (*s && s[strlen(s) - 1] != ';')) {
|
|---|
| 610 | if (*s)
|
|---|
| 611 | strcat(s, ";");
|
|---|
| 612 | strcat(s, path);
|
|---|
| 613 | lLen += strlen(path);
|
|---|
| 614 | if (s[strlen(s) - 1] != '\\') {
|
|---|
| 615 | lLen++;
|
|---|
| 616 | strcat(s, "\\");
|
|---|
| 617 | }
|
|---|
| 618 | rstrip(s);
|
|---|
| 619 | if (*s) {
|
|---|
| 620 | strcat(s, simple);
|
|---|
| 621 | WinSetDlgItemText(hwnd, GREP_MASK, s);
|
|---|
| 622 | WinSendDlgItemMsg(hwnd,
|
|---|
| 623 | GREP_MASK,
|
|---|
| 624 | EM_SETSEL,
|
|---|
| 625 | MPFROM2SHORT(strlen(s) - (lLen - 1),
|
|---|
| 626 | strlen(s)), MPVOID);
|
|---|
| 627 | }
|
|---|
| 628 | }
|
|---|
| 629 | }
|
|---|
| 630 | break;
|
|---|
| 631 |
|
|---|
| 632 | case GREP_ADD:
|
|---|
| 633 | *s = 0;
|
|---|
| 634 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 635 | bstrip(s);
|
|---|
| 636 | if (*s) {
|
|---|
| 637 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 638 | GREP_LISTBOX,
|
|---|
| 639 | LM_SEARCHSTRING,
|
|---|
| 640 | MPFROM2SHORT(0, LIT_FIRST),
|
|---|
| 641 | MPFROMP(s));
|
|---|
| 642 | if (sSelect < 0) {
|
|---|
| 643 | WinSendDlgItemMsg(hwnd,
|
|---|
| 644 | GREP_LISTBOX,
|
|---|
| 645 | LM_INSERTITEM,
|
|---|
| 646 | MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
|
|---|
| 647 | changed = TRUE;
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 | break;
|
|---|
| 651 |
|
|---|
| 652 | case GREP_DELETE:
|
|---|
| 653 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 654 | GREP_LISTBOX,
|
|---|
| 655 | LM_QUERYSELECTION,
|
|---|
| 656 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 657 | if (sSelect >= 0) {
|
|---|
| 658 | WinSendDlgItemMsg(hwnd,
|
|---|
| 659 | GREP_LISTBOX,
|
|---|
| 660 | LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
|
|---|
| 661 | changed = TRUE;
|
|---|
| 662 | }
|
|---|
| 663 | break;
|
|---|
| 664 |
|
|---|
| 665 | case GREP_OM:
|
|---|
| 666 | *s = 0;
|
|---|
| 667 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, s);
|
|---|
| 668 | ul = atoi(s) * 30L;
|
|---|
| 669 | sprintf(s, "%lu", ul);
|
|---|
| 670 | WinSetDlgItemText(hwnd, GREP_OLDER, s);
|
|---|
| 671 | break;
|
|---|
| 672 |
|
|---|
| 673 | case GREP_NM:
|
|---|
| 674 | *s = 0;
|
|---|
| 675 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, s);
|
|---|
| 676 | ul = atoi(s) * 30L;
|
|---|
| 677 | sprintf(s, "%lu", ul);
|
|---|
| 678 | WinSetDlgItemText(hwnd, GREP_NEWER, s);
|
|---|
| 679 | break;
|
|---|
| 680 |
|
|---|
| 681 | case GREP_GK:
|
|---|
| 682 | *s = 0;
|
|---|
| 683 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, s);
|
|---|
| 684 | ul = atol(s) * 1024L;
|
|---|
| 685 | sprintf(s, "%lu", ul);
|
|---|
| 686 | WinSetDlgItemText(hwnd, GREP_GREATER, s);
|
|---|
| 687 | break;
|
|---|
| 688 |
|
|---|
| 689 | case GREP_LK:
|
|---|
| 690 | *s = 0;
|
|---|
| 691 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, s);
|
|---|
| 692 | ul = atol(s) * 1024L;
|
|---|
| 693 | sprintf(s, "%lu", ul);
|
|---|
| 694 | WinSetDlgItemText(hwnd, GREP_LESSER, s);
|
|---|
| 695 | break;
|
|---|
| 696 |
|
|---|
| 697 | case DID_CANCEL:
|
|---|
| 698 | WinDismissDlg(hwnd, 0);
|
|---|
| 699 | break;
|
|---|
| 700 |
|
|---|
| 701 | case IDM_HELP:
|
|---|
| 702 | if (hwndHelp)
|
|---|
| 703 | WinSendMsg(hwndHelp,
|
|---|
| 704 | HM_DISPLAY_HELP,
|
|---|
| 705 | MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 706 | break;
|
|---|
| 707 |
|
|---|
| 708 | case GREP_LOCALHDS:
|
|---|
| 709 | case GREP_REMOTEHDS:
|
|---|
| 710 | case GREP_ALLHDS:
|
|---|
| 711 | {
|
|---|
| 712 | CHAR szDrive[] = " :\\";
|
|---|
| 713 | ULONG ulDriveNum;
|
|---|
| 714 | ULONG ulDriveMap;
|
|---|
| 715 | INT x;
|
|---|
| 716 | BOOL incl;
|
|---|
| 717 |
|
|---|
| 718 | CHAR new[8192];
|
|---|
| 719 |
|
|---|
| 720 | *s = 0;
|
|---|
| 721 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
|---|
| 722 | s[8192 - 1] = 0;
|
|---|
| 723 | p = strchr(s, ';');
|
|---|
| 724 | if (p)
|
|---|
| 725 | *p = 0;
|
|---|
| 726 | p = strrchr(s, '\\');
|
|---|
| 727 | if (!p)
|
|---|
| 728 | p = strrchr(s, '/');
|
|---|
| 729 | if (!p)
|
|---|
| 730 | p = strrchr(s, ':');
|
|---|
| 731 | if (p)
|
|---|
| 732 | strcpy(s, p + 1);
|
|---|
| 733 | if (!*s)
|
|---|
| 734 | strcpy(s, "*");
|
|---|
| 735 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 736 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
|---|
| 737 | *new = 0;
|
|---|
| 738 | for (x = 2; x < 26; x++) {
|
|---|
| 739 | if (ulDriveMap & (1L << x)) {
|
|---|
| 740 | incl = FALSE;
|
|---|
| 741 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 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] &
|
|---|
| 748 | (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
|
|---|
| 749 | DRIVE_VIRTUAL)))
|
|---|
| 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 | }
|
|---|
| 760 | if (incl) {
|
|---|
| 761 | if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
|
|---|
| 762 | if (*new)
|
|---|
| 763 | strcat(new, ";");
|
|---|
| 764 | *szDrive = x + 'A';
|
|---|
| 765 | strcat(new, szDrive);
|
|---|
| 766 | strcat(new, s);
|
|---|
| 767 | }
|
|---|
| 768 | }
|
|---|
| 769 | }
|
|---|
| 770 | if (*new)
|
|---|
| 771 | WinSetDlgItemText(hwnd, GREP_MASK, new);
|
|---|
| 772 | }
|
|---|
| 773 | break;
|
|---|
| 774 |
|
|---|
| 775 | case DID_OK:
|
|---|
| 776 | hwndCollect = WinQueryWindowULong(hwnd, QWL_USER);
|
|---|
| 777 | if (!hwndCollect)
|
|---|
| 778 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
|---|
| 779 | else {
|
|---|
| 780 | // 07 Feb 08 SHL - fixme to malloc and free in thread
|
|---|
| 781 | static GREP g; // Passed to thread
|
|---|
| 782 |
|
|---|
| 783 | p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
|
|---|
| 784 | if (!p)
|
|---|
| 785 | break;
|
|---|
| 786 | memset(&g, 0, sizeof(GREP));
|
|---|
| 787 | g.size = sizeof(GREP);
|
|---|
| 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;
|
|---|
| 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;
|
|---|
| 811 | if (g.finddupes) {
|
|---|
| 812 | g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
|
|---|
| 813 | g.nosizedupes =
|
|---|
| 814 | WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
|
|---|
| 815 | g.ignoreextdupes =
|
|---|
| 816 | WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
|
|---|
| 817 | }
|
|---|
| 818 | // Parse file masks
|
|---|
| 819 | *p = 0;
|
|---|
| 820 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
|
|---|
| 821 | bstrip(p);
|
|---|
| 822 | if (!*p) {
|
|---|
| 823 | DosBeep(50, 100);
|
|---|
| 824 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
|
|---|
| 825 | free(p);
|
|---|
| 826 | # ifdef FORTIFY
|
|---|
| 827 | Fortify_LeaveScope();
|
|---|
| 828 | # endif
|
|---|
| 829 | break;
|
|---|
| 830 | }
|
|---|
| 831 | strcpy(g.tosearch, p);
|
|---|
| 832 | strcpy(lastmask, p);
|
|---|
| 833 | // Parse search strings
|
|---|
| 834 | *p = 0;
|
|---|
| 835 | WinQueryWindowText(hwndMLE, 4096, p);
|
|---|
| 836 | strcpy(lasttext, p);
|
|---|
| 837 | {
|
|---|
| 838 | CHAR *pszFrom;
|
|---|
| 839 | CHAR *pszTo;
|
|---|
| 840 | ULONG matched = 0;
|
|---|
| 841 |
|
|---|
| 842 | pszTo = g.searchPattern;
|
|---|
| 843 | pszFrom = p;
|
|---|
| 844 | while (*pszFrom) {
|
|---|
| 845 | if (*pszFrom == '\r') {
|
|---|
| 846 | pszFrom++;
|
|---|
| 847 | continue;
|
|---|
| 848 | }
|
|---|
| 849 | if (*pszFrom == '\n') {
|
|---|
| 850 | if (*(pszFrom + 1))
|
|---|
| 851 | matched++;
|
|---|
| 852 | *pszTo = 0;
|
|---|
| 853 | }
|
|---|
| 854 | else
|
|---|
| 855 | *pszTo = *pszFrom;
|
|---|
| 856 | pszTo++;
|
|---|
| 857 | pszFrom++;
|
|---|
| 858 | }
|
|---|
| 859 | if (*g.searchPattern)
|
|---|
| 860 | matched++;
|
|---|
| 861 | *pszTo++ = 0;
|
|---|
| 862 | *pszTo = 0;
|
|---|
| 863 | g.numlines = matched;
|
|---|
| 864 | if (matched) {
|
|---|
| 865 | g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
|
|---|
| 866 | if (!g.matched)
|
|---|
| 867 | g.numlines = 0;
|
|---|
| 868 | }
|
|---|
| 869 | }
|
|---|
| 870 | *p = 0;
|
|---|
| 871 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
|
|---|
| 872 | greater = atol(p);
|
|---|
| 873 | *p = 0;
|
|---|
| 874 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
|
|---|
| 875 | lesser = atol(p);
|
|---|
| 876 | *p = 0;
|
|---|
| 877 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
|
|---|
| 878 | newer = atoi(p);
|
|---|
| 879 | *p = 0;
|
|---|
| 880 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
|
|---|
| 881 | older = atoi(p);
|
|---|
| 882 | if (older || newer) {
|
|---|
| 883 | FDATE fdate;
|
|---|
| 884 | FTIME ftime;
|
|---|
| 885 | struct tm tm;
|
|---|
| 886 | time_t t;
|
|---|
| 887 |
|
|---|
| 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;
|
|---|
| 896 | if (older) {
|
|---|
| 897 | g.olderthan = SecsSince1980(&fdate, &ftime);
|
|---|
| 898 | g.olderthan -= (older * (24L * 60L * 60L));
|
|---|
| 899 | }
|
|---|
| 900 | if (newer) {
|
|---|
| 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);
|
|---|
| 921 | g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
|
|---|
| 922 | g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
|
|---|
| 923 | g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
|
|---|
| 924 | if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) {
|
|---|
| 925 | Runtime_Error(pszSrcFile, __LINE__,
|
|---|
| 926 | GetPString(IDS_COULDNTSTARTTHREADTEXT));
|
|---|
| 927 | free(p);
|
|---|
| 928 | # ifdef FORTIFY
|
|---|
| 929 | Fortify_LeaveScope();
|
|---|
| 930 | # endif
|
|---|
| 931 | WinDismissDlg(hwnd, 0);
|
|---|
| 932 | break;
|
|---|
| 933 | }
|
|---|
| 934 | DosSleep(100); //05 Aug 07 GKY 128
|
|---|
| 935 | free(p);
|
|---|
| 936 | # ifdef FORTIFY
|
|---|
| 937 | Fortify_LeaveScope();
|
|---|
| 938 | # endif
|
|---|
| 939 | }
|
|---|
| 940 | if (changed) {
|
|---|
| 941 | // Grep mask list changed
|
|---|
| 942 | SHORT x;
|
|---|
| 943 |
|
|---|
| 944 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 945 | GREP_LISTBOX,
|
|---|
| 946 | LM_QUERYITEMCOUNT,
|
|---|
| 947 | MPVOID, MPVOID);
|
|---|
| 948 | if (sSelect > 0) {
|
|---|
| 949 | BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT");
|
|---|
| 950 | fp = xfopen(s, "w", pszSrcFile, __LINE__);
|
|---|
| 951 | if (fp) {
|
|---|
| 952 | fputs(GetPString(IDS_GREPFILETEXT), fp);
|
|---|
| 953 | for (x = 0; x < sSelect; x++) {
|
|---|
| 954 | *s = 0;
|
|---|
| 955 | WinSendDlgItemMsg(hwnd,
|
|---|
| 956 | GREP_LISTBOX,
|
|---|
| 957 | LM_QUERYITEMTEXT,
|
|---|
| 958 | MPFROM2SHORT(x, 8192), MPFROMP(s));
|
|---|
| 959 | bstrip(s);
|
|---|
| 960 | if (*s)
|
|---|
| 961 | fprintf(fp, "%s\n", s);
|
|---|
| 962 | }
|
|---|
| 963 | fclose(fp);
|
|---|
| 964 | }
|
|---|
| 965 | }
|
|---|
| 966 | }
|
|---|
| 967 | WinDismissDlg(hwnd, 1);
|
|---|
| 968 | break;
|
|---|
| 969 | }
|
|---|
| 970 | return 0;
|
|---|
| 971 | }
|
|---|
| 972 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | #pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc)
|
|---|