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