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