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