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