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