| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: grep2.c 907 2008-01-06 07:26:17Z stevenhl $ | 
|---|
| 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 |  | 
|---|
| 23 | fixme for more excess locals to be gone | 
|---|
| 24 |  | 
|---|
| 25 | ***********************************************************************/ | 
|---|
| 26 |  | 
|---|
| 27 | #include <stdlib.h> | 
|---|
| 28 | #include <string.h> | 
|---|
| 29 | #include <ctype.h> | 
|---|
| 30 | #include <share.h> | 
|---|
| 31 | #include <process.h>                    // _beginthread | 
|---|
| 32 |  | 
|---|
| 33 | #define INCL_DOS | 
|---|
| 34 | #define INCL_WIN | 
|---|
| 35 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| 36 | #define INCL_WINSTDCNR                  // makelist.h | 
|---|
| 37 |  | 
|---|
| 38 | #include "fm3dlg.h" | 
|---|
| 39 | #include "fm3str.h" | 
|---|
| 40 | #include "mle.h" | 
|---|
| 41 | #include "grep.h" | 
|---|
| 42 | #include "errutil.h"                    // Dos_Error... | 
|---|
| 43 | #include "strutil.h"                    // GetPString | 
|---|
| 44 | #include "fm3dll.h" | 
|---|
| 45 |  | 
|---|
| 46 | #pragma data_seg(DATA1) | 
|---|
| 47 |  | 
|---|
| 48 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 49 |  | 
|---|
| 50 | MRESULT EXPENTRY EnvDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 51 | { | 
|---|
| 52 | SHORT sSelect; | 
|---|
| 53 | CHAR *p; | 
|---|
| 54 | CHAR s[CCHMAXPATH]; | 
|---|
| 55 | CHAR szPath[CCHMAXPATH]; | 
|---|
| 56 |  | 
|---|
| 57 | static CHAR lastenv[CCHMAXPATH] = "DPATH"; | 
|---|
| 58 |  | 
|---|
| 59 | switch (msg) { | 
|---|
| 60 | case WM_INITDLG: | 
|---|
| 61 | if (mp2) { | 
|---|
| 62 | WinSetWindowPtr(hwnd, QWL_USER, mp2); | 
|---|
| 63 | *(CHAR *) mp2 = 0; | 
|---|
| 64 | { | 
|---|
| 65 | CHAR *p; | 
|---|
| 66 | CHAR *pp; | 
|---|
| 67 |  | 
|---|
| 68 | p = GetPString(IDS_ENVVARNAMES); | 
|---|
| 69 | while (*p == ' ') | 
|---|
| 70 | p++; | 
|---|
| 71 | while (*p) { | 
|---|
| 72 | *szPath = 0; | 
|---|
| 73 | pp = szPath; | 
|---|
| 74 | while (*p && *p != ' ') | 
|---|
| 75 | *pp++ = *p++; | 
|---|
| 76 | *pp = 0; | 
|---|
| 77 | while (*p == ' ') | 
|---|
| 78 | p++; | 
|---|
| 79 | if (*szPath) | 
|---|
| 80 | WinSendDlgItemMsg(hwnd, | 
|---|
| 81 | ENV_LISTBOX, | 
|---|
| 82 | LM_INSERTITEM, | 
|---|
| 83 | MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath)); | 
|---|
| 84 | } | 
|---|
| 85 | } | 
|---|
| 86 | WinSendDlgItemMsg(hwnd, | 
|---|
| 87 | ENV_NAME, | 
|---|
| 88 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID); | 
|---|
| 89 | WinSetDlgItemText(hwnd, ENV_NAME, lastenv); | 
|---|
| 90 | WinSendDlgItemMsg(hwnd, | 
|---|
| 91 | ENV_NAME, | 
|---|
| 92 | EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID); | 
|---|
| 93 | } | 
|---|
| 94 | else | 
|---|
| 95 | WinDismissDlg(hwnd, 0); | 
|---|
| 96 | break; | 
|---|
| 97 |  | 
|---|
| 98 | case WM_CONTROL: | 
|---|
| 99 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 100 | case ENV_LISTBOX: | 
|---|
| 101 | switch (SHORT2FROMMP(mp1)) { | 
|---|
| 102 | case LN_SELECT: | 
|---|
| 103 | { | 
|---|
| 104 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 105 | ENV_LISTBOX, | 
|---|
| 106 | LM_QUERYSELECTION, | 
|---|
| 107 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
| 108 | if (sSelect >= 0) { | 
|---|
| 109 | *s = 0; | 
|---|
| 110 | WinSendDlgItemMsg(hwnd, | 
|---|
| 111 | ENV_LISTBOX, | 
|---|
| 112 | LM_QUERYITEMTEXT, | 
|---|
| 113 | MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s)); | 
|---|
| 114 | bstrip(s); | 
|---|
| 115 | if (*s) | 
|---|
| 116 | WinSetDlgItemText(hwnd, ENV_NAME, s); | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 | break; | 
|---|
| 120 | case LN_ENTER: | 
|---|
| 121 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID); | 
|---|
| 122 | break; | 
|---|
| 123 | } | 
|---|
| 124 | } | 
|---|
| 125 | return 0; | 
|---|
| 126 |  | 
|---|
| 127 | case WM_COMMAND: | 
|---|
| 128 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 129 | case DID_CANCEL: | 
|---|
| 130 | WinDismissDlg(hwnd, 0); | 
|---|
| 131 | break; | 
|---|
| 132 | case DID_OK: | 
|---|
| 133 | p = WinQueryWindowPtr(hwnd, QWL_USER); | 
|---|
| 134 | if (p) { | 
|---|
| 135 | WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p); | 
|---|
| 136 | bstrip(p); | 
|---|
| 137 | if (!*p) { | 
|---|
| 138 | DosBeep(50, 100); | 
|---|
| 139 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME)); | 
|---|
| 140 | } | 
|---|
| 141 | else { | 
|---|
| 142 | strcpy(lastenv, p); | 
|---|
| 143 | WinDismissDlg(hwnd, 1); | 
|---|
| 144 | } | 
|---|
| 145 | } | 
|---|
| 146 | break; | 
|---|
| 147 | case IDM_HELP: | 
|---|
| 148 | if (hwndHelp) | 
|---|
| 149 | WinSendMsg(hwndHelp, | 
|---|
| 150 | HM_DISPLAY_HELP, | 
|---|
| 151 | MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID)); | 
|---|
| 152 | break; | 
|---|
| 153 | } | 
|---|
| 154 | return 0; | 
|---|
| 155 | } | 
|---|
| 156 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | MRESULT EXPENTRY GrepDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 160 | { | 
|---|
| 161 | HWND hwndCollect; | 
|---|
| 162 | HWND hwndMLE = WinWindowFromID(hwnd, GREP_SEARCH); | 
|---|
| 163 | FILE *fp; | 
|---|
| 164 | ULONG ul; | 
|---|
| 165 | LONG lLen; | 
|---|
| 166 | SHORT sSelect; | 
|---|
| 167 | CHAR *p; | 
|---|
| 168 | CHAR s[8192 + 14]; | 
|---|
| 169 | CHAR simple[8192]; | 
|---|
| 170 | CHAR path[CCHMAXPATH]; | 
|---|
| 171 |  | 
|---|
| 172 | static CHAR lastmask[8192] = "*"; | 
|---|
| 173 | static CHAR lasttext[4096] = ""; | 
|---|
| 174 | static BOOL recurse = TRUE; | 
|---|
| 175 | static BOOL sensitive = FALSE; | 
|---|
| 176 | static BOOL absolute = FALSE; | 
|---|
| 177 | static BOOL sayfiles = TRUE; | 
|---|
| 178 | static BOOL searchEAs = TRUE; | 
|---|
| 179 | static BOOL searchFiles = TRUE; | 
|---|
| 180 | static BOOL changed = FALSE; | 
|---|
| 181 | static BOOL findifany = TRUE; | 
|---|
| 182 | static BOOL gRemember = FALSE; | 
|---|
| 183 | ULONG size = sizeof(BOOL); | 
|---|
| 184 | static UINT newer = 0; | 
|---|
| 185 | static UINT older = 0; | 
|---|
| 186 | static ULONG greater = 0; | 
|---|
| 187 | static ULONG lesser = 0; | 
|---|
| 188 |  | 
|---|
| 189 | switch (msg) { | 
|---|
| 190 | case WM_INITDLG: | 
|---|
| 191 | if (!mp2) { | 
|---|
| 192 | WinDismissDlg(hwnd, 0); | 
|---|
| 193 | break; | 
|---|
| 194 | } | 
|---|
| 195 | WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2); | 
|---|
| 196 | WinSendDlgItemMsg(hwnd, | 
|---|
| 197 | GREP_MASK, | 
|---|
| 198 | EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID); | 
|---|
| 199 | MLEsetlimit(hwndMLE, 4096); | 
|---|
| 200 | MLEsetformat(hwndMLE, MLFIE_NOTRANS); | 
|---|
| 201 | WinSendDlgItemMsg(hwnd, | 
|---|
| 202 | GREP_NEWER, | 
|---|
| 203 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 204 | WinSendDlgItemMsg(hwnd, | 
|---|
| 205 | GREP_OLDER, | 
|---|
| 206 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 207 | WinSendDlgItemMsg(hwnd, | 
|---|
| 208 | GREP_GREATER, | 
|---|
| 209 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 210 | WinSendDlgItemMsg(hwnd, | 
|---|
| 211 | GREP_LESSER, | 
|---|
| 212 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 213 | WinSetDlgItemText(hwnd, GREP_MASK, lastmask); | 
|---|
| 214 | WinSendDlgItemMsg(hwnd, | 
|---|
| 215 | GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID); | 
|---|
| 216 | PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep", | 
|---|
| 217 | (PVOID) & gRemember, &size); | 
|---|
| 218 | WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember); | 
|---|
| 219 | if (gRemember) { | 
|---|
| 220 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse", | 
|---|
| 221 | (PVOID) & recurse, &size); | 
|---|
| 222 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute", | 
|---|
| 223 | (PVOID) & absolute, &size); | 
|---|
| 224 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Case", | 
|---|
| 225 | (PVOID) & sensitive, &size); | 
|---|
| 226 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles", | 
|---|
| 227 | (PVOID) & sayfiles, &size); | 
|---|
| 228 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles", | 
|---|
| 229 | (PVOID) & searchFiles, &size); | 
|---|
| 230 | PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs", | 
|---|
| 231 | (PVOID) & searchEAs, &size); | 
|---|
| 232 | } | 
|---|
| 233 | if (!gRemember) { | 
|---|
| 234 | recurse = TRUE; | 
|---|
| 235 | sensitive = FALSE; | 
|---|
| 236 | absolute = FALSE; | 
|---|
| 237 | sayfiles = TRUE; | 
|---|
| 238 | searchEAs = TRUE; | 
|---|
| 239 | searchFiles = TRUE; | 
|---|
| 240 | } | 
|---|
| 241 | WinSetWindowText(hwndMLE, lasttext); | 
|---|
| 242 | if (*lasttext) { | 
|---|
| 243 | MLEsetcurpos(hwndMLE, 0); | 
|---|
| 244 | MLEsetcurposa(hwndMLE, 4096); | 
|---|
| 245 | if (!searchEAs) | 
|---|
| 246 | searchFiles = TRUE; | 
|---|
| 247 | } | 
|---|
| 248 | WinCheckButton(hwnd, GREP_RECURSE, recurse); | 
|---|
| 249 | WinCheckButton(hwnd, GREP_ABSOLUTE, absolute); | 
|---|
| 250 | WinCheckButton(hwnd, GREP_CASE, sensitive); | 
|---|
| 251 | WinCheckButton(hwnd, GREP_SAYFILES, sayfiles); | 
|---|
| 252 | WinCheckButton(hwnd, GREP_SEARCHEAS, searchEAs); | 
|---|
| 253 | WinCheckButton(hwnd, GREP_SEARCHFILES, searchFiles); | 
|---|
| 254 | WinCheckButton(hwnd, GREP_FINDIFANY, findifany); | 
|---|
| 255 |  | 
|---|
| 256 | sprintf(s, "%lu", greater); | 
|---|
| 257 | WinSetDlgItemText(hwnd, GREP_GREATER, s); | 
|---|
| 258 | sprintf(s, "%lu", lesser); | 
|---|
| 259 | WinSetDlgItemText(hwnd, GREP_LESSER, s); | 
|---|
| 260 | sprintf(s, "%u", newer); | 
|---|
| 261 | WinSetDlgItemText(hwnd, GREP_NEWER, s); | 
|---|
| 262 | sprintf(s, "%u", older); | 
|---|
| 263 | WinSetDlgItemText(hwnd, GREP_OLDER, s); | 
|---|
| 264 |  | 
|---|
| 265 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), FALSE); | 
|---|
| 266 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), FALSE); | 
|---|
| 267 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), FALSE); | 
|---|
| 268 |  | 
|---|
| 269 | save_dir2(s); | 
|---|
| 270 | if (s[strlen(s) - 1] != '\\') | 
|---|
| 271 | strcat(s, "\\"); | 
|---|
| 272 | strcat(s, "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 | static GREP g;          // Passed to thread | 
|---|
| 781 |  | 
|---|
| 782 | p = xmalloc(8192 + 512, pszSrcFile, __LINE__); | 
|---|
| 783 | if (!p) | 
|---|
| 784 | break; | 
|---|
| 785 | memset(&g, 0, sizeof(GREP)); | 
|---|
| 786 | g.size = sizeof(GREP); | 
|---|
| 787 | recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0; | 
|---|
| 788 | absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0; | 
|---|
| 789 | sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0; | 
|---|
| 790 | sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0; | 
|---|
| 791 | searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0; | 
|---|
| 792 | searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0; | 
|---|
| 793 | findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0; | 
|---|
| 794 | gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS); | 
|---|
| 795 | if (gRemember) { | 
|---|
| 796 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse", | 
|---|
| 797 | (PVOID) & recurse, sizeof(BOOL)); | 
|---|
| 798 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute", | 
|---|
| 799 | (PVOID) & absolute, sizeof(BOOL)); | 
|---|
| 800 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Case", | 
|---|
| 801 | (PVOID) & sensitive, sizeof(BOOL)); | 
|---|
| 802 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles", | 
|---|
| 803 | (PVOID) & sayfiles, sizeof(BOOL)); | 
|---|
| 804 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles", | 
|---|
| 805 | (PVOID) & searchFiles, sizeof(BOOL)); | 
|---|
| 806 | PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs", | 
|---|
| 807 | (PVOID) & searchEAs, sizeof(BOOL)); | 
|---|
| 808 | } | 
|---|
| 809 | g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0; | 
|---|
| 810 | if (g.finddupes) { | 
|---|
| 811 | g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0; | 
|---|
| 812 | g.nosizedupes = | 
|---|
| 813 | WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0; | 
|---|
| 814 | g.ignoreextdupes = | 
|---|
| 815 | WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0; | 
|---|
| 816 | } | 
|---|
| 817 | // Parse file masks | 
|---|
| 818 | *p = 0; | 
|---|
| 819 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p); | 
|---|
| 820 | bstrip(p); | 
|---|
| 821 | if (!*p) { | 
|---|
| 822 | DosBeep(50, 100); | 
|---|
| 823 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK)); | 
|---|
| 824 | free(p); | 
|---|
| 825 | break; | 
|---|
| 826 | } | 
|---|
| 827 | strcpy(g.tosearch, p); | 
|---|
| 828 | strcpy(lastmask, p); | 
|---|
| 829 | // Parse search strings | 
|---|
| 830 | *p = 0; | 
|---|
| 831 | WinQueryWindowText(hwndMLE, 4096, p); | 
|---|
| 832 | strcpy(lasttext, p); | 
|---|
| 833 | { | 
|---|
| 834 | CHAR *pszFrom; | 
|---|
| 835 | CHAR *pszTo; | 
|---|
| 836 | ULONG matched = 0; | 
|---|
| 837 |  | 
|---|
| 838 | pszTo = g.searchPattern; | 
|---|
| 839 | pszFrom = p; | 
|---|
| 840 | while (*pszFrom) { | 
|---|
| 841 | if (*pszFrom == '\r') { | 
|---|
| 842 | pszFrom++; | 
|---|
| 843 | continue; | 
|---|
| 844 | } | 
|---|
| 845 | if (*pszFrom == '\n') { | 
|---|
| 846 | if (*(pszFrom + 1)) | 
|---|
| 847 | matched++; | 
|---|
| 848 | *pszTo = 0; | 
|---|
| 849 | } | 
|---|
| 850 | else | 
|---|
| 851 | *pszTo = *pszFrom; | 
|---|
| 852 | pszTo++; | 
|---|
| 853 | pszFrom++; | 
|---|
| 854 | } | 
|---|
| 855 | if (*g.searchPattern) | 
|---|
| 856 | matched++; | 
|---|
| 857 | *pszTo++ = 0; | 
|---|
| 858 | *pszTo = 0; | 
|---|
| 859 | g.numlines = matched; | 
|---|
| 860 | if (matched) { | 
|---|
| 861 | g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__); | 
|---|
| 862 | if (!g.matched) | 
|---|
| 863 | g.numlines = 0; | 
|---|
| 864 | } | 
|---|
| 865 | } | 
|---|
| 866 | *p = 0; | 
|---|
| 867 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p); | 
|---|
| 868 | greater = atol(p); | 
|---|
| 869 | *p = 0; | 
|---|
| 870 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p); | 
|---|
| 871 | lesser = atol(p); | 
|---|
| 872 | *p = 0; | 
|---|
| 873 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p); | 
|---|
| 874 | newer = atoi(p); | 
|---|
| 875 | *p = 0; | 
|---|
| 876 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p); | 
|---|
| 877 | older = atoi(p); | 
|---|
| 878 | if (older || newer) { | 
|---|
| 879 | FDATE fdate; | 
|---|
| 880 | FTIME ftime; | 
|---|
| 881 | struct tm tm; | 
|---|
| 882 | time_t t; | 
|---|
| 883 |  | 
|---|
| 884 | t = time(NULL); | 
|---|
| 885 | tm = *localtime(&t); | 
|---|
| 886 | fdate.day = tm.tm_mday; | 
|---|
| 887 | fdate.month = tm.tm_mon + 1; | 
|---|
| 888 | fdate.year = tm.tm_year - 80; | 
|---|
| 889 | ftime.hours = tm.tm_hour; | 
|---|
| 890 | ftime.minutes = tm.tm_min; | 
|---|
| 891 | ftime.twosecs = tm.tm_sec / 2; | 
|---|
| 892 | if (older) { | 
|---|
| 893 | g.olderthan = SecsSince1980(&fdate, &ftime); | 
|---|
| 894 | g.olderthan -= (older * (24L * 60L * 60L)); | 
|---|
| 895 | } | 
|---|
| 896 | if (newer) { | 
|---|
| 897 | g.newerthan = SecsSince1980(&fdate, &ftime); | 
|---|
| 898 | g.newerthan -= (newer * (24L * 60L * 60L)); | 
|---|
| 899 | } | 
|---|
| 900 | } | 
|---|
| 901 | if (!newer) | 
|---|
| 902 | g.newerthan = 0; | 
|---|
| 903 | if (!older) | 
|---|
| 904 | g.olderthan = 0; | 
|---|
| 905 | g.greaterthan = greater; | 
|---|
| 906 | g.lessthan = lesser; | 
|---|
| 907 | g.absFlag = absolute; | 
|---|
| 908 | g.caseFlag = sensitive; | 
|---|
| 909 | g.dirFlag = recurse; | 
|---|
| 910 | g.sayfiles = sayfiles; | 
|---|
| 911 | g.searchEAs = searchEAs; | 
|---|
| 912 | g.searchFiles = searchFiles; | 
|---|
| 913 | g.findifany = findifany; | 
|---|
| 914 | g.hwndFiles = hwndCollect; | 
|---|
| 915 | g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT); | 
|---|
| 916 | g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED); | 
|---|
| 917 | g.attrFile = ((DIRCNRDATA *) INSTDATA(hwndCollect))->mask.attrFile; | 
|---|
| 918 | g.antiattr = ((DIRCNRDATA *) INSTDATA(hwndCollect))->mask.antiattr; | 
|---|
| 919 | g.stopflag = &((DIRCNRDATA *) INSTDATA(hwndCollect))->stopflag; | 
|---|
| 920 | if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) { | 
|---|
| 921 | Runtime_Error(pszSrcFile, __LINE__, | 
|---|
| 922 | GetPString(IDS_COULDNTSTARTTHREADTEXT)); | 
|---|
| 923 | free(p); | 
|---|
| 924 | WinDismissDlg(hwnd, 0); | 
|---|
| 925 | break; | 
|---|
| 926 | } | 
|---|
| 927 | else | 
|---|
| 928 | DosSleep(100); //05 Aug 07 GKY 128 | 
|---|
| 929 | free(p); | 
|---|
| 930 | } | 
|---|
| 931 | if (changed) { | 
|---|
| 932 | SHORT x; | 
|---|
| 933 |  | 
|---|
| 934 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 935 | GREP_LISTBOX, | 
|---|
| 936 | LM_QUERYITEMCOUNT, | 
|---|
| 937 | MPVOID, MPVOID); | 
|---|
| 938 | if (sSelect > 0) { | 
|---|
| 939 | save_dir2(s); | 
|---|
| 940 | if (s[strlen(s) - 1] != '\\') | 
|---|
| 941 | strcat(s, "\\"); | 
|---|
| 942 | strcat(s, "GREPMASK.DAT"); | 
|---|
| 943 | fp = xfopen(s, "w", pszSrcFile, __LINE__); | 
|---|
| 944 | if (fp) { | 
|---|
| 945 | fputs(GetPString(IDS_GREPFILETEXT), fp); | 
|---|
| 946 | for (x = 0; x < sSelect; x++) { | 
|---|
| 947 | *s = 0; | 
|---|
| 948 | WinSendDlgItemMsg(hwnd, | 
|---|
| 949 | GREP_LISTBOX, | 
|---|
| 950 | LM_QUERYITEMTEXT, | 
|---|
| 951 | MPFROM2SHORT(x, 8192), MPFROMP(s)); | 
|---|
| 952 | bstrip(s); | 
|---|
| 953 | if (*s) | 
|---|
| 954 | fprintf(fp, "%s\n", s); | 
|---|
| 955 | } | 
|---|
| 956 | fclose(fp); | 
|---|
| 957 | } | 
|---|
| 958 | } | 
|---|
| 959 | } | 
|---|
| 960 | WinDismissDlg(hwnd, 1); | 
|---|
| 961 | break; | 
|---|
| 962 | } | 
|---|
| 963 | return 0; | 
|---|
| 964 | } | 
|---|
| 965 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 966 | } | 
|---|
| 967 |  | 
|---|
| 968 | #pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc) | 
|---|