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