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