[123] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: grep2.c 1471 2009-10-13 23:43:04Z stevenhl $
|
---|
| 5 |
|
---|
[1335] | 6 | grep dialog for collector
|
---|
[402] | 7 |
|
---|
[123] | 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[1394] | 9 | Copyright (c) 2004, 2009 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
|
---|
[1335] | 24 | 10 Dec 08 SHL Integrate exception handler support
|
---|
[1375] | 25 | 01 Jan 09 GKY Add Seek and Scan to drives & directory context menus pass drive/dir as search root
|
---|
[1395] | 26 | 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
|
---|
[1400] | 27 | 08 Mar 09 GKY Additional strings move to PCSZs in init.c
|
---|
[1471] | 28 | 07 Oct 09 SHL Remember last search mask across runs
|
---|
[123] | 29 |
|
---|
[202] | 30 | fixme for more excess locals to be gone
|
---|
| 31 |
|
---|
[123] | 32 | ***********************************************************************/
|
---|
| 33 |
|
---|
[2] | 34 | #include <stdlib.h>
|
---|
| 35 | #include <string.h>
|
---|
| 36 | #include <ctype.h>
|
---|
| 37 | #include <share.h>
|
---|
[1223] | 38 | #include <time.h>
|
---|
[202] | 39 |
|
---|
[907] | 40 | #define INCL_DOS
|
---|
| 41 | #define INCL_WIN
|
---|
[1471] | 42 | #define INCL_LONGLONG // dircnrs.h
|
---|
| 43 | #define INCL_WINSTDCNR // makelist.h
|
---|
[907] | 44 |
|
---|
[1185] | 45 | #include "fm3dll.h"
|
---|
[1223] | 46 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
[1208] | 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)
|
---|
[2] | 52 | #include "fm3dlg.h"
|
---|
| 53 | #include "fm3str.h"
|
---|
| 54 | #include "mle.h"
|
---|
| 55 | #include "grep.h"
|
---|
[1471] | 56 | #include "errutil.h" // Dos_Error...
|
---|
| 57 | #include "strutil.h" // GetPString
|
---|
| 58 | #include "pathutil.h" // BldFullPathName
|
---|
| 59 | #include "walkem.h" // FillPathListBox
|
---|
[1161] | 60 | #include "grep2.h"
|
---|
[1185] | 61 | #include "wrappers.h" // xfgets
|
---|
[1471] | 62 | #include "misc.h" // LoadLibPath
|
---|
[1185] | 63 | #include "strips.h" // bstrip
|
---|
| 64 | #include "dirs.h" // save_dir2
|
---|
[1029] | 65 | #include "fortify.h"
|
---|
[1335] | 66 | #include "excputil.h" // xbeginthread
|
---|
[1471] | 67 | #include "valid.h" // IsFile
|
---|
[2] | 68 |
|
---|
| 69 | #pragma data_seg(DATA1)
|
---|
[336] | 70 |
|
---|
| 71 | static PSZ pszSrcFile = __FILE__;
|
---|
| 72 |
|
---|
[1471] | 73 | static PCSZ PSCZ_GREP_LASTMASK_SELECT = "Grep_LastMaskSelect";
|
---|
| 74 |
|
---|
[190] | 75 | MRESULT EXPENTRY EnvDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
| 76 | {
|
---|
[202] | 77 | SHORT sSelect;
|
---|
| 78 | CHAR *p;
|
---|
| 79 | CHAR s[CCHMAXPATH];
|
---|
| 80 | CHAR szPath[CCHMAXPATH];
|
---|
| 81 |
|
---|
[2] | 82 | static CHAR lastenv[CCHMAXPATH] = "DPATH";
|
---|
| 83 |
|
---|
[551] | 84 | switch (msg) {
|
---|
[190] | 85 | case WM_INITDLG:
|
---|
[551] | 86 | if (mp2) {
|
---|
[190] | 87 | WinSetWindowPtr(hwnd, QWL_USER, mp2);
|
---|
[1009] | 88 | *(CHAR *)mp2 = 0;
|
---|
[190] | 89 | {
|
---|
[1394] | 90 | PCSZ p;
|
---|
| 91 | PSZ pp;
|
---|
[2] | 92 |
|
---|
[1335] | 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 | }
|
---|
[2] | 110 | }
|
---|
[190] | 111 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 112 | ENV_NAME,
|
---|
| 113 | EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
---|
[551] | 114 | WinSetDlgItemText(hwnd, ENV_NAME, lastenv);
|
---|
[190] | 115 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 116 | ENV_NAME,
|
---|
| 117 | EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
|
---|
[190] | 118 | }
|
---|
| 119 | else
|
---|
| 120 | WinDismissDlg(hwnd, 0);
|
---|
| 121 | break;
|
---|
[2] | 122 |
|
---|
[190] | 123 | case WM_CONTROL:
|
---|
[551] | 124 | switch (SHORT1FROMMP(mp1)) {
|
---|
[190] | 125 | case ENV_LISTBOX:
|
---|
[551] | 126 | switch (SHORT2FROMMP(mp1)) {
|
---|
[190] | 127 | case LN_SELECT:
|
---|
[1335] | 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;
|
---|
[190] | 145 | case LN_ENTER:
|
---|
[1335] | 146 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
---|
| 147 | break;
|
---|
[2] | 148 | }
|
---|
[190] | 149 | }
|
---|
| 150 | return 0;
|
---|
[2] | 151 |
|
---|
[190] | 152 | case WM_COMMAND:
|
---|
[551] | 153 | switch (SHORT1FROMMP(mp1)) {
|
---|
[190] | 154 | case DID_CANCEL:
|
---|
| 155 | WinDismissDlg(hwnd, 0);
|
---|
| 156 | break;
|
---|
| 157 | case DID_OK:
|
---|
[202] | 158 | p = WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
[551] | 159 | if (p) {
|
---|
[1335] | 160 | WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
|
---|
| 161 | bstrip(p);
|
---|
| 162 | if (!*p) {
|
---|
[1471] | 163 | if (!fAlertBeepOff)
|
---|
[1395] | 164 | DosBeep(50, 100);
|
---|
[1335] | 165 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
|
---|
| 166 | }
|
---|
| 167 | else {
|
---|
| 168 | strcpy(lastenv, p);
|
---|
| 169 | WinDismissDlg(hwnd, 1);
|
---|
| 170 | }
|
---|
[2] | 171 | }
|
---|
[190] | 172 | break;
|
---|
| 173 | case IDM_HELP:
|
---|
| 174 | if (hwndHelp)
|
---|
[1335] | 175 | WinSendMsg(hwndHelp,
|
---|
| 176 | HM_DISPLAY_HELP,
|
---|
| 177 | MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
[190] | 178 | break;
|
---|
| 179 | }
|
---|
| 180 | return 0;
|
---|
[2] | 181 | }
|
---|
[190] | 182 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 183 | }
|
---|
| 184 |
|
---|
[190] | 185 | MRESULT EXPENTRY GrepDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
| 186 | {
|
---|
| 187 | HWND hwndCollect;
|
---|
| 188 | HWND hwndMLE = WinWindowFromID(hwnd, GREP_SEARCH);
|
---|
[202] | 189 | FILE *fp;
|
---|
| 190 | ULONG ul;
|
---|
| 191 | LONG lLen;
|
---|
| 192 | SHORT sSelect;
|
---|
| 193 | CHAR *p;
|
---|
[1471] | 194 | GREPINFO *GrepInfo;
|
---|
| 195 | ULONG size;
|
---|
[202] | 196 | CHAR simple[8192];
|
---|
| 197 | CHAR path[CCHMAXPATH];
|
---|
[1471] | 198 | CHAR s[8192 + 14];
|
---|
[2] | 199 |
|
---|
[1471] | 200 | // 07 Oct 09 SHL fixme to not be static and save to profile?
|
---|
| 201 | static CHAR lastmask[8192];
|
---|
| 202 | static CHAR lasttext[4096];
|
---|
[190] | 203 | static BOOL recurse = TRUE;
|
---|
[1471] | 204 | static BOOL sensitive;
|
---|
| 205 | static BOOL absolute;
|
---|
| 206 | static BOOL sayfiles;
|
---|
[190] | 207 | static BOOL searchEAs = TRUE;
|
---|
| 208 | static BOOL searchFiles = TRUE;
|
---|
[1471] | 209 | static BOOL changed;
|
---|
| 210 | static BOOL fInitDone; // First time init done
|
---|
[190] | 211 | static BOOL findifany = TRUE;
|
---|
[1471] | 212 | static BOOL gRemember;
|
---|
[190] | 213 | static UINT newer = 0;
|
---|
| 214 | static UINT older = 0;
|
---|
| 215 | static ULONG greater = 0;
|
---|
| 216 | static ULONG lesser = 0;
|
---|
[1471] | 217 | static SHORT sLastMaskSelect = LIT_NONE;
|
---|
[2] | 218 |
|
---|
[551] | 219 | switch (msg) {
|
---|
[190] | 220 | case WM_INITDLG:
|
---|
[551] | 221 | if (!mp2) {
|
---|
[190] | 222 | WinDismissDlg(hwnd, 0);
|
---|
| 223 | break;
|
---|
| 224 | }
|
---|
[1366] | 225 | GrepInfo = mp2;
|
---|
[1367] | 226 | if (GrepInfo->szGrepPath && IsFile(GrepInfo->szGrepPath) == 0) {
|
---|
[1471] | 227 | BldFullPathName(lastmask, GrepInfo->szGrepPath, "*"); // Directory passed
|
---|
| 228 | sLastMaskSelect = LIT_NONE;
|
---|
| 229 | fInitDone = TRUE;
|
---|
[1367] | 230 | }
|
---|
[1471] | 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 |
|
---|
[1366] | 242 | WinSetWindowULong(hwnd, QWL_USER, *(HWND *) GrepInfo->hwnd);
|
---|
[190] | 243 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 244 | GREP_MASK,
|
---|
| 245 | EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
|
---|
[190] | 246 | MLEsetlimit(hwndMLE, 4096);
|
---|
| 247 | MLEsetformat(hwndMLE, MLFIE_NOTRANS);
|
---|
| 248 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 249 | GREP_NEWER,
|
---|
| 250 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
---|
[190] | 251 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 252 | GREP_OLDER,
|
---|
| 253 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
---|
[190] | 254 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 255 | GREP_GREATER,
|
---|
| 256 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
---|
[190] | 257 | WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 258 | GREP_LESSER,
|
---|
| 259 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
|
---|
[551] | 260 | WinSetDlgItemText(hwnd, GREP_MASK, lastmask);
|
---|
[190] | 261 | WinSendDlgItemMsg(hwnd,
|
---|
[1394] | 262 | GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID);
|
---|
[1366] | 263 | size = sizeof(BOOL);
|
---|
[551] | 264 | PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep",
|
---|
[1335] | 265 | (PVOID) & gRemember, &size);
|
---|
[551] | 266 | WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember);
|
---|
| 267 | if (gRemember) {
|
---|
[1366] | 268 | size = sizeof(BOOL);
|
---|
[551] | 269 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse",
|
---|
[1394] | 270 | (PVOID) & recurse, &size);
|
---|
[1366] | 271 | size = sizeof(BOOL);
|
---|
[551] | 272 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute",
|
---|
[1394] | 273 | (PVOID) & absolute, &size);
|
---|
[1366] | 274 | size = sizeof(BOOL);
|
---|
[551] | 275 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Case",
|
---|
[1394] | 276 | (PVOID) & sensitive, &size);
|
---|
[1366] | 277 | size = sizeof(BOOL);
|
---|
[551] | 278 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles",
|
---|
[1394] | 279 | (PVOID) & sayfiles, &size);
|
---|
[1366] | 280 | size = sizeof(BOOL);
|
---|
[551] | 281 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles",
|
---|
[1394] | 282 | (PVOID) & searchFiles, &size);
|
---|
[1366] | 283 | size = sizeof(BOOL);
|
---|
[551] | 284 | PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
|
---|
[1335] | 285 | (PVOID) & searchEAs, &size);
|
---|
[551] | 286 | }
|
---|
| 287 | if (!gRemember) {
|
---|
| 288 | recurse = TRUE;
|
---|
| 289 | sensitive = FALSE;
|
---|
| 290 | absolute = FALSE;
|
---|
| 291 | sayfiles = TRUE;
|
---|
| 292 | searchEAs = TRUE;
|
---|
| 293 | searchFiles = TRUE;
|
---|
| 294 | }
|
---|
[190] | 295 | WinSetWindowText(hwndMLE, lasttext);
|
---|
[551] | 296 | if (*lasttext) {
|
---|
[190] | 297 | MLEsetcurpos(hwndMLE, 0);
|
---|
| 298 | MLEsetcurposa(hwndMLE, 4096);
|
---|
| 299 | if (!searchEAs)
|
---|
[1335] | 300 | searchFiles = TRUE;
|
---|
[190] | 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);
|
---|
[2] | 309 |
|
---|
[202] | 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 |
|
---|
[190] | 319 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), FALSE);
|
---|
| 320 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), FALSE);
|
---|
| 321 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), FALSE);
|
---|
[202] | 322 |
|
---|
[1471] | 323 | // Fill mask listbox
|
---|
[1398] | 324 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_GREPMASKDAT);
|
---|
[202] | 325 | fp = _fsopen(s, "r", SH_DENYWR);
|
---|
[551] | 326 | if (fp) {
|
---|
[402] | 327 | while (!feof(fp)) {
|
---|
[1335] | 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 | }
|
---|
[2] | 336 | }
|
---|
[202] | 337 | fclose(fp);
|
---|
[190] | 338 | }
|
---|
[1471] | 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));
|
---|
[202] | 343 |
|
---|
[190] | 344 | FillPathListBox(hwnd,
|
---|
[1335] | 345 | WinWindowFromID(hwnd, GREP_DRIVELIST),
|
---|
| 346 | (HWND) 0, NULL, FALSE);
|
---|
[1471] | 347 | // 25 Sep 09 SHL fixme select drive matching current container?
|
---|
[190] | 348 | break;
|
---|
| 349 |
|
---|
| 350 | case WM_ADJUSTWINDOWPOS:
|
---|
[551] | 351 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
|
---|
[190] | 352 | break;
|
---|
| 353 |
|
---|
| 354 | case UM_SETDIR:
|
---|
| 355 | PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
|
---|
[1335] | 356 | (HPS) 0, FALSE, TRUE);
|
---|
[190] | 357 | return 0;
|
---|
| 358 |
|
---|
| 359 | case UM_FOCUSME:
|
---|
[1471] | 360 | // set focus to window hwnd in mp1
|
---|
[190] | 361 | if (mp1)
|
---|
[551] | 362 | WinSetFocus(HWND_DESKTOP, (HWND) mp1);
|
---|
[190] | 363 | return 0;
|
---|
| 364 |
|
---|
| 365 | case WM_CONTROL:
|
---|
[551] | 366 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 367 | case GREP_REMEMBERFLAGS:
|
---|
| 368 | {
|
---|
[1335] | 369 | BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
|
---|
[549] | 370 |
|
---|
[1335] | 371 | PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
|
---|
| 372 | (PVOID) & gRemember, sizeof(BOOL));
|
---|
[551] | 373 | }
|
---|
| 374 | break;
|
---|
[549] | 375 |
|
---|
[190] | 376 | case GREP_DRIVELIST:
|
---|
[551] | 377 | switch (SHORT2FROMMP(mp1)) {
|
---|
[190] | 378 | case LN_KILLFOCUS:
|
---|
[1335] | 379 | WinSetDlgItemText(hwnd,
|
---|
| 380 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
| 381 | break;
|
---|
[190] | 382 | case LN_SETFOCUS:
|
---|
[1335] | 383 | WinSetDlgItemText(hwnd,
|
---|
| 384 | GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
|
---|
| 385 | break;
|
---|
[190] | 386 | case LN_ENTER:
|
---|
[1335] | 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) {
|
---|
[1438] | 393 | strcpy(simple, PCSZ_BACKSLASH);
|
---|
[1335] | 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 | }
|
---|
[2] | 407 |
|
---|
[1335] | 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 | }
|
---|
[1471] | 435 | break; // LN_ENTER
|
---|
| 436 | } // switch
|
---|
[190] | 437 | break;
|
---|
[202] | 438 |
|
---|
[190] | 439 | case GREP_LISTBOX:
|
---|
[551] | 440 | switch (SHORT2FROMMP(mp1)) {
|
---|
[190] | 441 | case LN_KILLFOCUS:
|
---|
[1335] | 442 | WinSetDlgItemText(hwnd,
|
---|
| 443 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
| 444 | break;
|
---|
[190] | 445 | case LN_SETFOCUS:
|
---|
[1335] | 446 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
|
---|
| 447 | break;
|
---|
[190] | 448 | case LN_ENTER:
|
---|
| 449 | case LN_SELECT:
|
---|
[1335] | 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) {
|
---|
[1471] | 461 | sLastMaskSelect = sSelect;
|
---|
[1335] | 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;
|
---|
[2] | 480 | }
|
---|
| 481 | break;
|
---|
[202] | 482 |
|
---|
[190] | 483 | case GREP_MASK:
|
---|
| 484 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
---|
[1335] | 485 | WinSetDlgItemText(hwnd,
|
---|
| 486 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 487 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
---|
[1335] | 488 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
|
---|
[2] | 489 | break;
|
---|
[190] | 490 | case GREP_SEARCH:
|
---|
| 491 | if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
|
---|
[1335] | 492 | WinSetDlgItemText(hwnd,
|
---|
| 493 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 494 | if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
|
---|
[1335] | 495 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
|
---|
[190] | 496 | break;
|
---|
| 497 | case GREP_GREATER:
|
---|
| 498 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
---|
[1335] | 499 | WinSetDlgItemText(hwnd,
|
---|
| 500 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 501 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
---|
[1335] | 502 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
|
---|
[190] | 503 | break;
|
---|
| 504 | case GREP_LESSER:
|
---|
| 505 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
---|
[1335] | 506 | WinSetDlgItemText(hwnd,
|
---|
| 507 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 508 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
---|
[1335] | 509 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
|
---|
[190] | 510 | break;
|
---|
| 511 | case GREP_NEWER:
|
---|
| 512 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
---|
[1335] | 513 | WinSetDlgItemText(hwnd,
|
---|
| 514 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 515 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
---|
[1335] | 516 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
|
---|
[190] | 517 | break;
|
---|
| 518 | case GREP_OLDER:
|
---|
| 519 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
|
---|
[1335] | 520 | WinSetDlgItemText(hwnd,
|
---|
| 521 | GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
|
---|
[190] | 522 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
|
---|
[1335] | 523 | WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
|
---|
[190] | 524 | break;
|
---|
| 525 | case GREP_FINDDUPES:
|
---|
| 526 | {
|
---|
[1335] | 527 | BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
|
---|
[2] | 528 |
|
---|
[1335] | 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);
|
---|
[190] | 549 | }
|
---|
| 550 | }
|
---|
| 551 | return 0;
|
---|
[2] | 552 |
|
---|
[190] | 553 | case WM_COMMAND:
|
---|
[551] | 554 | switch (SHORT1FROMMP(mp1)) {
|
---|
[190] | 555 | case GREP_ENV:
|
---|
| 556 | {
|
---|
[1335] | 557 | CHAR *t;
|
---|
| 558 | CHAR env[8192];
|
---|
[2] | 559 |
|
---|
[1335] | 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;
|
---|
[1400] | 568 | if (!stricmp(path, PCSZ_LIBPATH))
|
---|
[1335] | 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++;
|
---|
[1438] | 617 | strcat(s, PCSZ_BACKSLASH);
|
---|
[1335] | 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 | }
|
---|
[190] | 635 | }
|
---|
| 636 | break;
|
---|
[2] | 637 |
|
---|
[190] | 638 | case GREP_WALK:
|
---|
[551] | 639 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
---|
[202] | 640 | bstrip(s);
|
---|
[551] | 641 | if (strlen(s) > 8192 - 5) {
|
---|
[1335] | 642 | Runtime_Error(pszSrcFile, __LINE__, "too big");
|
---|
| 643 | break;
|
---|
[202] | 644 | }
|
---|
| 645 | *path = 0;
|
---|
| 646 | if (WinDlgBox(HWND_DESKTOP,
|
---|
[1335] | 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++;
|
---|
[1438] | 674 | strcat(s, PCSZ_BACKSLASH);
|
---|
[1335] | 675 | }
|
---|
| 676 | rstrip(s);
|
---|
[1471] | 677 | // 25 Sep 09 SHL fixme to honor append
|
---|
[1335] | 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 | }
|
---|
[2] | 688 | }
|
---|
[190] | 689 | break;
|
---|
[2] | 690 |
|
---|
[190] | 691 | case GREP_ADD:
|
---|
[202] | 692 | *s = 0;
|
---|
[551] | 693 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
|
---|
[202] | 694 | bstrip(s);
|
---|
[551] | 695 | if (*s) {
|
---|
[1335] | 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 | }
|
---|
[190] | 708 | }
|
---|
| 709 | break;
|
---|
[2] | 710 |
|
---|
[202] | 711 | case GREP_DELETE:
|
---|
| 712 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 713 | GREP_LISTBOX,
|
---|
| 714 | LM_QUERYSELECTION,
|
---|
| 715 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
[551] | 716 | if (sSelect >= 0) {
|
---|
[1335] | 717 | WinSendDlgItemMsg(hwnd,
|
---|
| 718 | GREP_LISTBOX,
|
---|
| 719 | LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
|
---|
[1471] | 720 | if (sSelect >= sLastMaskSelect)
|
---|
| 721 | sLastMaskSelect--;
|
---|
[1335] | 722 | changed = TRUE;
|
---|
[202] | 723 | }
|
---|
| 724 | break;
|
---|
[2] | 725 |
|
---|
[202] | 726 | case GREP_OM:
|
---|
| 727 | *s = 0;
|
---|
[551] | 728 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, s);
|
---|
[202] | 729 | ul = atoi(s) * 30L;
|
---|
| 730 | sprintf(s, "%lu", ul);
|
---|
[551] | 731 | WinSetDlgItemText(hwnd, GREP_OLDER, s);
|
---|
[190] | 732 | break;
|
---|
[2] | 733 |
|
---|
[190] | 734 | case GREP_NM:
|
---|
[202] | 735 | *s = 0;
|
---|
[551] | 736 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, s);
|
---|
[202] | 737 | ul = atoi(s) * 30L;
|
---|
| 738 | sprintf(s, "%lu", ul);
|
---|
[551] | 739 | WinSetDlgItemText(hwnd, GREP_NEWER, s);
|
---|
[190] | 740 | break;
|
---|
[2] | 741 |
|
---|
[190] | 742 | case GREP_GK:
|
---|
[202] | 743 | *s = 0;
|
---|
[551] | 744 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, s);
|
---|
[202] | 745 | ul = atol(s) * 1024L;
|
---|
| 746 | sprintf(s, "%lu", ul);
|
---|
| 747 | WinSetDlgItemText(hwnd, GREP_GREATER, s);
|
---|
[190] | 748 | break;
|
---|
[2] | 749 |
|
---|
[190] | 750 | case GREP_LK:
|
---|
[202] | 751 | *s = 0;
|
---|
[551] | 752 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, s);
|
---|
[202] | 753 | ul = atol(s) * 1024L;
|
---|
| 754 | sprintf(s, "%lu", ul);
|
---|
[551] | 755 | WinSetDlgItemText(hwnd, GREP_LESSER, s);
|
---|
[190] | 756 | break;
|
---|
[2] | 757 |
|
---|
[190] | 758 | case DID_CANCEL:
|
---|
| 759 | WinDismissDlg(hwnd, 0);
|
---|
| 760 | break;
|
---|
[2] | 761 |
|
---|
[190] | 762 | case IDM_HELP:
|
---|
| 763 | if (hwndHelp)
|
---|
[1335] | 764 | WinSendMsg(hwndHelp,
|
---|
| 765 | HM_DISPLAY_HELP,
|
---|
| 766 | MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
[190] | 767 | break;
|
---|
[2] | 768 |
|
---|
[190] | 769 | case GREP_LOCALHDS:
|
---|
| 770 | case GREP_REMOTEHDS:
|
---|
| 771 | case GREP_ALLHDS:
|
---|
| 772 | {
|
---|
[1335] | 773 | CHAR szDrive[] = " :\\";
|
---|
| 774 | ULONG ulDriveNum;
|
---|
| 775 | ULONG ulDriveMap;
|
---|
| 776 | INT x;
|
---|
| 777 | BOOL incl;
|
---|
[2] | 778 |
|
---|
[1335] | 779 | CHAR new[8192];
|
---|
[2] | 780 |
|
---|
[1335] | 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);
|
---|
[190] | 833 | }
|
---|
| 834 | break;
|
---|
[2] | 835 |
|
---|
[190] | 836 | case DID_OK:
|
---|
| 837 | hwndCollect = WinQueryWindowULong(hwnd, QWL_USER);
|
---|
| 838 | if (!hwndCollect)
|
---|
[1398] | 839 | Runtime_Error(pszSrcFile, __LINE__, NULL);
|
---|
[402] | 840 | else {
|
---|
[1335] | 841 | // 07 Feb 08 SHL - fixme to malloc and free in thread
|
---|
[1471] | 842 | static GREP g; // Passed to thread
|
---|
[1335] | 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 | }
|
---|
[1471] | 870 | PrfWriteProfileData(fmprof, appname,
|
---|
| 871 | PSCZ_GREP_LASTMASK_SELECT, &sLastMaskSelect, sizeof(sLastMaskSelect));
|
---|
[1335] | 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) {
|
---|
[1471] | 885 | if (!fAlertBeepOff)
|
---|
[1395] | 886 | DosBeep(50, 100);
|
---|
[1335] | 887 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
|
---|
| 888 | free(p);
|
---|
[1063] | 889 | # ifdef FORTIFY
|
---|
[1335] | 890 | Fortify_LeaveScope();
|
---|
[1063] | 891 | # endif
|
---|
[1335] | 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;
|
---|
[2] | 904 |
|
---|
[1335] | 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;
|
---|
[2] | 950 |
|
---|
[1335] | 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);
|
---|
[1063] | 994 | # ifdef FORTIFY
|
---|
[1335] | 995 | Fortify_LeaveScope();
|
---|
[1063] | 996 | # endif
|
---|
[1335] | 997 | WinDismissDlg(hwnd, 0);
|
---|
| 998 | break;
|
---|
| 999 | }
|
---|
| 1000 | DosSleep(100); //05 Aug 07 GKY 128
|
---|
| 1001 | free(p);
|
---|
[1063] | 1002 | # ifdef FORTIFY
|
---|
[1335] | 1003 | Fortify_LeaveScope();
|
---|
[1063] | 1004 | # endif
|
---|
[190] | 1005 | }
|
---|
[402] | 1006 | if (changed) {
|
---|
[1471] | 1007 | // Save modified mask list
|
---|
[1335] | 1008 | SHORT x;
|
---|
[551] | 1009 |
|
---|
[1335] | 1010 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
| 1011 | GREP_LISTBOX,
|
---|
| 1012 | LM_QUERYITEMCOUNT,
|
---|
| 1013 | MPVOID, MPVOID);
|
---|
[1471] | 1014 | // 07 Oct 09 SHL Rewrite if list empty
|
---|
| 1015 | if (sSelect >= 0) {
|
---|
[1398] | 1016 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_GREPMASKDAT);
|
---|
[1335] | 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 | }
|
---|
[2] | 1035 | }
|
---|
[190] | 1036 | WinDismissDlg(hwnd, 1);
|
---|
| 1037 | break;
|
---|
| 1038 | }
|
---|
| 1039 | return 0;
|
---|
[2] | 1040 | }
|
---|
[190] | 1041 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 1042 | }
|
---|
[793] | 1043 |
|
---|
| 1044 | #pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc)
|
---|