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