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