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