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