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