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