| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: grep2.c 1544 2010-09-30 13:00:59Z 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 | CHAR *moder = "r"; | 
|---|
| 201 |  | 
|---|
| 202 | // 07 Oct 09 SHL fixme to not be static and save to profile? | 
|---|
| 203 | static CHAR lastmask[8192]; | 
|---|
| 204 | static CHAR lasttext[4096]; | 
|---|
| 205 | static BOOL recurse = TRUE; | 
|---|
| 206 | static BOOL sensitive; | 
|---|
| 207 | static BOOL absolute; | 
|---|
| 208 | static BOOL sayfiles; | 
|---|
| 209 | static BOOL searchEAs = TRUE; | 
|---|
| 210 | static BOOL searchFiles = TRUE; | 
|---|
| 211 | static BOOL changed; | 
|---|
| 212 | static BOOL fInitDone;                // First time init done | 
|---|
| 213 | static BOOL findifany = TRUE; | 
|---|
| 214 | static BOOL gRemember; | 
|---|
| 215 | static UINT newer = 0; | 
|---|
| 216 | static UINT older = 0; | 
|---|
| 217 | static ULONG greater = 0; | 
|---|
| 218 | static ULONG lesser = 0; | 
|---|
| 219 | static SHORT sLastMaskSelect = LIT_NONE; | 
|---|
| 220 |  | 
|---|
| 221 | switch (msg) { | 
|---|
| 222 | case WM_INITDLG: | 
|---|
| 223 | if (!mp2) { | 
|---|
| 224 | WinDismissDlg(hwnd, 0); | 
|---|
| 225 | break; | 
|---|
| 226 | } | 
|---|
| 227 | GrepInfo = mp2; | 
|---|
| 228 | if (GrepInfo->szGrepPath && IsFile(GrepInfo->szGrepPath) == 0) { | 
|---|
| 229 | BldFullPathName(lastmask, GrepInfo->szGrepPath, "*");     // Directory passed | 
|---|
| 230 | sLastMaskSelect = LIT_NONE; | 
|---|
| 231 | fInitDone = TRUE; | 
|---|
| 232 | } | 
|---|
| 233 | else {//if (sLastMaskSelect == LIT_NONE) { | 
|---|
| 234 | size = sizeof(sLastMaskSelect); | 
|---|
| 235 | PrfQueryProfileData(fmprof, appname, (CHAR *) PSCZ_GREP_LASTMASK_SELECT, &sLastMaskSelect, &size); | 
|---|
| 236 | if (sLastMaskSelect >= 0) | 
|---|
| 237 | fInitDone = TRUE; | 
|---|
| 238 | } | 
|---|
| 239 | if (!fInitDone) { | 
|---|
| 240 | lastmask[0] = '*'; | 
|---|
| 241 | lastmask[1] = 0; | 
|---|
| 242 | } | 
|---|
| 243 |  | 
|---|
| 244 | WinSetWindowULong(hwnd, QWL_USER, *(HWND *) GrepInfo->hwnd); | 
|---|
| 245 | WinSendDlgItemMsg(hwnd, | 
|---|
| 246 | GREP_MASK, | 
|---|
| 247 | EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID); | 
|---|
| 248 | MLEsetlimit(hwndMLE, 4096); | 
|---|
| 249 | MLEsetformat(hwndMLE, MLFIE_NOTRANS); | 
|---|
| 250 | WinSendDlgItemMsg(hwnd, | 
|---|
| 251 | GREP_NEWER, | 
|---|
| 252 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 253 | WinSendDlgItemMsg(hwnd, | 
|---|
| 254 | GREP_OLDER, | 
|---|
| 255 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 256 | WinSendDlgItemMsg(hwnd, | 
|---|
| 257 | GREP_GREATER, | 
|---|
| 258 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 259 | WinSendDlgItemMsg(hwnd, | 
|---|
| 260 | GREP_LESSER, | 
|---|
| 261 | EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); | 
|---|
| 262 | WinSetDlgItemText(hwnd, GREP_MASK, lastmask); | 
|---|
| 263 | WinSendDlgItemMsg(hwnd, | 
|---|
| 264 | GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID); | 
|---|
| 265 | size = sizeof(BOOL); | 
|---|
| 266 | PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep", | 
|---|
| 267 | (PVOID) & gRemember, &size); | 
|---|
| 268 | WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember); | 
|---|
| 269 | if (gRemember) { | 
|---|
| 270 | size = sizeof(BOOL); | 
|---|
| 271 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse", | 
|---|
| 272 | (PVOID) & recurse, &size); | 
|---|
| 273 | size = sizeof(BOOL); | 
|---|
| 274 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute", | 
|---|
| 275 | (PVOID) & absolute, &size); | 
|---|
| 276 | size = sizeof(BOOL); | 
|---|
| 277 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Case", | 
|---|
| 278 | (PVOID) & sensitive, &size); | 
|---|
| 279 | size = sizeof(BOOL); | 
|---|
| 280 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles", | 
|---|
| 281 | (PVOID) & sayfiles, &size); | 
|---|
| 282 | size = sizeof(BOOL); | 
|---|
| 283 | PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles", | 
|---|
| 284 | (PVOID) & searchFiles, &size); | 
|---|
| 285 | size = sizeof(BOOL); | 
|---|
| 286 | PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs", | 
|---|
| 287 | (PVOID) & searchEAs, &size); | 
|---|
| 288 | } | 
|---|
| 289 | if (!gRemember) { | 
|---|
| 290 | recurse = TRUE; | 
|---|
| 291 | sensitive = FALSE; | 
|---|
| 292 | absolute = FALSE; | 
|---|
| 293 | sayfiles = TRUE; | 
|---|
| 294 | searchEAs = TRUE; | 
|---|
| 295 | searchFiles = TRUE; | 
|---|
| 296 | } | 
|---|
| 297 | WinSetWindowText(hwndMLE, lasttext); | 
|---|
| 298 | if (*lasttext) { | 
|---|
| 299 | MLEsetcurpos(hwndMLE, 0); | 
|---|
| 300 | MLEsetcurposa(hwndMLE, 4096); | 
|---|
| 301 | if (!searchEAs) | 
|---|
| 302 | searchFiles = TRUE; | 
|---|
| 303 | } | 
|---|
| 304 | WinCheckButton(hwnd, GREP_RECURSE, recurse); | 
|---|
| 305 | WinCheckButton(hwnd, GREP_ABSOLUTE, absolute); | 
|---|
| 306 | WinCheckButton(hwnd, GREP_CASE, sensitive); | 
|---|
| 307 | WinCheckButton(hwnd, GREP_SAYFILES, sayfiles); | 
|---|
| 308 | WinCheckButton(hwnd, GREP_SEARCHEAS, searchEAs); | 
|---|
| 309 | WinCheckButton(hwnd, GREP_SEARCHFILES, searchFiles); | 
|---|
| 310 | WinCheckButton(hwnd, GREP_FINDIFANY, findifany); | 
|---|
| 311 |  | 
|---|
| 312 | sprintf(s, "%lu", greater); | 
|---|
| 313 | WinSetDlgItemText(hwnd, GREP_GREATER, s); | 
|---|
| 314 | sprintf(s, "%lu", lesser); | 
|---|
| 315 | WinSetDlgItemText(hwnd, GREP_LESSER, s); | 
|---|
| 316 | sprintf(s, "%u", newer); | 
|---|
| 317 | WinSetDlgItemText(hwnd, GREP_NEWER, s); | 
|---|
| 318 | sprintf(s, "%u", older); | 
|---|
| 319 | WinSetDlgItemText(hwnd, GREP_OLDER, s); | 
|---|
| 320 |  | 
|---|
| 321 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), FALSE); | 
|---|
| 322 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), FALSE); | 
|---|
| 323 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), FALSE); | 
|---|
| 324 |  | 
|---|
| 325 | // Fill mask listbox | 
|---|
| 326 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_GREPMASKDAT); | 
|---|
| 327 | fp = xfsopen(s, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE); | 
|---|
| 328 | if (fp) { | 
|---|
| 329 | while (!feof(fp)) { | 
|---|
| 330 | if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__)) | 
|---|
| 331 | break; | 
|---|
| 332 | if (*s && *s != ';') { | 
|---|
| 333 | WinSendDlgItemMsg(hwnd, | 
|---|
| 334 | GREP_LISTBOX, | 
|---|
| 335 | LM_INSERTITEM, | 
|---|
| 336 | MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s)); | 
|---|
| 337 | } | 
|---|
| 338 | } | 
|---|
| 339 | fclose(fp); | 
|---|
| 340 | } | 
|---|
| 341 | // 25 Sep 09 SHL Reselect last last used item | 
|---|
| 342 | //if (sLastMaskSelect >= 0) | 
|---|
| 343 | //  WinSendDlgItemMsg(hwnd, GREP_LISTBOX, LM_SELECTITEM, | 
|---|
| 344 | //                  MPFROMSHORT(sLastMaskSelect), MPFROMSHORT(TRUE)); | 
|---|
| 345 |  | 
|---|
| 346 | FillPathListBox(hwnd, | 
|---|
| 347 | WinWindowFromID(hwnd, GREP_DRIVELIST), | 
|---|
| 348 | (HWND) 0, NULL, FALSE); | 
|---|
| 349 | // 25 Sep 09 SHL fixme select drive matching current container? | 
|---|
| 350 | break; | 
|---|
| 351 |  | 
|---|
| 352 | case WM_ADJUSTWINDOWPOS: | 
|---|
| 353 | PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID); | 
|---|
| 354 | break; | 
|---|
| 355 |  | 
|---|
| 356 | case UM_SETDIR: | 
|---|
| 357 | PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP), | 
|---|
| 358 | (HPS) 0, FALSE, TRUE); | 
|---|
| 359 | return 0; | 
|---|
| 360 |  | 
|---|
| 361 | case UM_FOCUSME: | 
|---|
| 362 | // set focus to window hwnd in mp1 | 
|---|
| 363 | if (mp1) | 
|---|
| 364 | WinSetFocus(HWND_DESKTOP, (HWND) mp1); | 
|---|
| 365 | return 0; | 
|---|
| 366 |  | 
|---|
| 367 | case WM_CONTROL: | 
|---|
| 368 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 369 | case GREP_REMEMBERFLAGS: | 
|---|
| 370 | { | 
|---|
| 371 | BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS); | 
|---|
| 372 |  | 
|---|
| 373 | PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep", | 
|---|
| 374 | (PVOID) & gRemember, sizeof(BOOL)); | 
|---|
| 375 | } | 
|---|
| 376 | break; | 
|---|
| 377 |  | 
|---|
| 378 | case GREP_DRIVELIST: | 
|---|
| 379 | switch (SHORT2FROMMP(mp1)) { | 
|---|
| 380 | case LN_KILLFOCUS: | 
|---|
| 381 | WinSetDlgItemText(hwnd, | 
|---|
| 382 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 383 | break; | 
|---|
| 384 | case LN_SETFOCUS: | 
|---|
| 385 | WinSetDlgItemText(hwnd, | 
|---|
| 386 | GREP_HELP, (CHAR *) GetPString(IDS_2CLICKADDDRVMASKTEXT)); | 
|---|
| 387 | break; | 
|---|
| 388 | case LN_ENTER: | 
|---|
| 389 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 390 | bstrip(s); | 
|---|
| 391 | p = strrchr(s, '\\'); | 
|---|
| 392 | if (p) | 
|---|
| 393 | strcpy(simple, p); | 
|---|
| 394 | else if (*s) { | 
|---|
| 395 | strcpy(simple, PCSZ_BACKSLASH); | 
|---|
| 396 | strcat(simple, s); | 
|---|
| 397 | *s = 0; | 
|---|
| 398 | } | 
|---|
| 399 | else | 
|---|
| 400 | strcpy(simple, "\\*"); | 
|---|
| 401 | if (simple[strlen(simple) - 1] == ';') | 
|---|
| 402 | simple[strlen(simple) - 1] = 0; | 
|---|
| 403 | lLen = strlen(simple) + 1; | 
|---|
| 404 | if (strlen(s) > 8192 - lLen) { | 
|---|
| 405 | Runtime_Error(pszSrcFile, __LINE__, "too big"); | 
|---|
| 406 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 407 | break; | 
|---|
| 408 | } | 
|---|
| 409 |  | 
|---|
| 410 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 411 | GREP_DRIVELIST, | 
|---|
| 412 | LM_QUERYSELECTION, | 
|---|
| 413 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
| 414 | if (sSelect >= 0) { | 
|---|
| 415 | if (*s && s[strlen(s) - 1] != ';') | 
|---|
| 416 | strcat(s, ";"); | 
|---|
| 417 | WinSendDlgItemMsg(hwnd, | 
|---|
| 418 | GREP_DRIVELIST, | 
|---|
| 419 | LM_QUERYITEMTEXT, | 
|---|
| 420 | MPFROM2SHORT(sSelect, | 
|---|
| 421 | (8192 - strlen(s)) - lLen), | 
|---|
| 422 | MPFROMP(&s[strlen(s)])); | 
|---|
| 423 | rstrip(s); | 
|---|
| 424 | if (*s) { | 
|---|
| 425 | strcat(s, simple); | 
|---|
| 426 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 427 | WinSendDlgItemMsg(hwnd, | 
|---|
| 428 | GREP_MASK, | 
|---|
| 429 | EM_SETSEL, | 
|---|
| 430 | MPFROM2SHORT(strlen(s) - (lLen + 1), | 
|---|
| 431 | strlen(s)), MPVOID); | 
|---|
| 432 | PostMsg(hwnd, | 
|---|
| 433 | UM_FOCUSME, | 
|---|
| 434 | MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID); | 
|---|
| 435 | } | 
|---|
| 436 | } | 
|---|
| 437 | break; // LN_ENTER | 
|---|
| 438 | } // switch | 
|---|
| 439 | break; | 
|---|
| 440 |  | 
|---|
| 441 | case GREP_LISTBOX: | 
|---|
| 442 | switch (SHORT2FROMMP(mp1)) { | 
|---|
| 443 | case LN_KILLFOCUS: | 
|---|
| 444 | WinSetDlgItemText(hwnd, | 
|---|
| 445 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 446 | break; | 
|---|
| 447 | case LN_SETFOCUS: | 
|---|
| 448 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_ADDSELDELMASKTEXT)); | 
|---|
| 449 | break; | 
|---|
| 450 | case LN_ENTER: | 
|---|
| 451 | case LN_SELECT: | 
|---|
| 452 | if ((SHORT2FROMMP(mp1) == LN_ENTER && | 
|---|
| 453 | !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) || | 
|---|
| 454 | (SHORT2FROMMP(mp1) == LN_SELECT && | 
|---|
| 455 | WinQueryButtonCheckstate(hwnd, GREP_APPEND))) | 
|---|
| 456 | break; | 
|---|
| 457 | { | 
|---|
| 458 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 459 | GREP_LISTBOX, | 
|---|
| 460 | LM_QUERYSELECTION, | 
|---|
| 461 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
| 462 | if (sSelect >= 0) { | 
|---|
| 463 | sLastMaskSelect = sSelect; | 
|---|
| 464 | *s = 0; | 
|---|
| 465 | if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) { | 
|---|
| 466 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 467 | bstrip(s); | 
|---|
| 468 | if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';') | 
|---|
| 469 | strcat(s, ";"); | 
|---|
| 470 | } | 
|---|
| 471 | WinSendDlgItemMsg(hwnd, | 
|---|
| 472 | GREP_LISTBOX, | 
|---|
| 473 | LM_QUERYITEMTEXT, | 
|---|
| 474 | MPFROM2SHORT(sSelect, 8192 - strlen(s)), | 
|---|
| 475 | MPFROMP(s + strlen(s))); | 
|---|
| 476 | bstrip(s); | 
|---|
| 477 | if (*s) | 
|---|
| 478 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 479 | } | 
|---|
| 480 | } | 
|---|
| 481 | break; | 
|---|
| 482 | } | 
|---|
| 483 | break; | 
|---|
| 484 |  | 
|---|
| 485 | case GREP_MASK: | 
|---|
| 486 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) | 
|---|
| 487 | WinSetDlgItemText(hwnd, | 
|---|
| 488 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 489 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS) | 
|---|
| 490 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_MASKSFINDTEXT)); | 
|---|
| 491 | break; | 
|---|
| 492 | case GREP_SEARCH: | 
|---|
| 493 | if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS) | 
|---|
| 494 | WinSetDlgItemText(hwnd, | 
|---|
| 495 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 496 | if (SHORT2FROMMP(mp1) == MLN_SETFOCUS) | 
|---|
| 497 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_TEXTFINDTEXT)); | 
|---|
| 498 | break; | 
|---|
| 499 | case GREP_GREATER: | 
|---|
| 500 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) | 
|---|
| 501 | WinSetDlgItemText(hwnd, | 
|---|
| 502 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 503 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS) | 
|---|
| 504 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_MINSIZEFINDTEXT)); | 
|---|
| 505 | break; | 
|---|
| 506 | case GREP_LESSER: | 
|---|
| 507 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) | 
|---|
| 508 | WinSetDlgItemText(hwnd, | 
|---|
| 509 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 510 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS) | 
|---|
| 511 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_MAXSIZEFINDTEXT)); | 
|---|
| 512 | break; | 
|---|
| 513 | case GREP_NEWER: | 
|---|
| 514 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) | 
|---|
| 515 | WinSetDlgItemText(hwnd, | 
|---|
| 516 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 517 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS) | 
|---|
| 518 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_MAXAGEFINDTEXT)); | 
|---|
| 519 | break; | 
|---|
| 520 | case GREP_OLDER: | 
|---|
| 521 | if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) | 
|---|
| 522 | WinSetDlgItemText(hwnd, | 
|---|
| 523 | GREP_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT)); | 
|---|
| 524 | if (SHORT2FROMMP(mp1) == EN_SETFOCUS) | 
|---|
| 525 | WinSetDlgItemText(hwnd, GREP_HELP, (CHAR *) GetPString(IDS_MINAGEFINDTEXT)); | 
|---|
| 526 | break; | 
|---|
| 527 | case GREP_FINDDUPES: | 
|---|
| 528 | { | 
|---|
| 529 | BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES); | 
|---|
| 530 |  | 
|---|
| 531 | WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes); | 
|---|
| 532 | WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes); | 
|---|
| 533 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes); | 
|---|
| 534 | WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes); | 
|---|
| 535 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes); | 
|---|
| 536 | WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), | 
|---|
| 537 | finddupes); | 
|---|
| 538 | WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes); | 
|---|
| 539 | WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes); | 
|---|
| 540 | WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes); | 
|---|
| 541 | WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes); | 
|---|
| 542 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes); | 
|---|
| 543 | WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes); | 
|---|
| 544 | WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes); | 
|---|
| 545 | WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes); | 
|---|
| 546 | WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes); | 
|---|
| 547 | WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes); | 
|---|
| 548 | WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes); | 
|---|
| 549 | if (finddupes) | 
|---|
| 550 | WinCheckButton(hwnd, GREP_RECURSE, TRUE); | 
|---|
| 551 | } | 
|---|
| 552 | } | 
|---|
| 553 | return 0; | 
|---|
| 554 |  | 
|---|
| 555 | case WM_COMMAND: | 
|---|
| 556 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 557 | case GREP_ENV: | 
|---|
| 558 | { | 
|---|
| 559 | CHAR *t; | 
|---|
| 560 | CHAR env[8192]; | 
|---|
| 561 |  | 
|---|
| 562 | *path = 0; | 
|---|
| 563 | if (!WinDlgBox(HWND_DESKTOP, | 
|---|
| 564 | hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) { | 
|---|
| 565 | break; | 
|---|
| 566 | } | 
|---|
| 567 | bstrip(path); | 
|---|
| 568 | if (!*path) | 
|---|
| 569 | break; | 
|---|
| 570 | if (!stricmp(path, PCSZ_LIBPATH)) | 
|---|
| 571 | LoadLibPath(env, 8192); | 
|---|
| 572 | else { | 
|---|
| 573 | p = getenv(path); | 
|---|
| 574 | if (!p) | 
|---|
| 575 | break; | 
|---|
| 576 | strcpy(env, p); | 
|---|
| 577 | } | 
|---|
| 578 | bstrip(env); | 
|---|
| 579 | if (!*env) | 
|---|
| 580 | break; | 
|---|
| 581 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 582 | bstrip(s); | 
|---|
| 583 | if (strlen(s) > 8192 - 5) { | 
|---|
| 584 | Runtime_Error(pszSrcFile, __LINE__, "too big"); | 
|---|
| 585 | break; | 
|---|
| 586 | } | 
|---|
| 587 | p = strrchr(s, '\\'); | 
|---|
| 588 | if (p) | 
|---|
| 589 | strcpy(simple, p + 1); | 
|---|
| 590 | else if (*s) | 
|---|
| 591 | strcpy(simple, s); | 
|---|
| 592 | else | 
|---|
| 593 | strcpy(simple, "*"); | 
|---|
| 594 | if (!p) | 
|---|
| 595 | *s = 0; | 
|---|
| 596 | if (simple[strlen(simple) - 1] == ';') | 
|---|
| 597 | simple[strlen(simple) - 1] = 0; | 
|---|
| 598 | lLen = strlen(simple) + 1; | 
|---|
| 599 | p = env; | 
|---|
| 600 | while (p && *p) { | 
|---|
| 601 | strncpy(path, p, CCHMAXPATH - 1); | 
|---|
| 602 | path[CCHMAXPATH - 1] = 0; | 
|---|
| 603 | t = strchr(path, ';'); | 
|---|
| 604 | if (t) | 
|---|
| 605 | *t = 0; | 
|---|
| 606 | bstrip(path); | 
|---|
| 607 | if (isalpha(*path) && path[1] == ':' && path[2] == '\\') { | 
|---|
| 608 | if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) { | 
|---|
| 609 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 610 | break; | 
|---|
| 611 | } | 
|---|
| 612 | if (!*s || (*s && s[strlen(s) - 1] != ';')) { | 
|---|
| 613 | if (*s) | 
|---|
| 614 | strcat(s, ";"); | 
|---|
| 615 | strcat(s, path); | 
|---|
| 616 | lLen += strlen(path); | 
|---|
| 617 | if (s[strlen(s) - 1] != '\\') { | 
|---|
| 618 | lLen++; | 
|---|
| 619 | strcat(s, PCSZ_BACKSLASH); | 
|---|
| 620 | } | 
|---|
| 621 | rstrip(s); | 
|---|
| 622 | if (*s) { | 
|---|
| 623 | strcat(s, simple); | 
|---|
| 624 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 625 | WinSendDlgItemMsg(hwnd, | 
|---|
| 626 | GREP_MASK, | 
|---|
| 627 | EM_SETSEL, | 
|---|
| 628 | MPFROM2SHORT(strlen(s) - (lLen - 1), | 
|---|
| 629 | strlen(s)), MPVOID); | 
|---|
| 630 | } | 
|---|
| 631 | } | 
|---|
| 632 | } | 
|---|
| 633 | p = strchr(p, ';'); | 
|---|
| 634 | if (p) | 
|---|
| 635 | p++; | 
|---|
| 636 | } | 
|---|
| 637 | } | 
|---|
| 638 | break; | 
|---|
| 639 |  | 
|---|
| 640 | case GREP_WALK: | 
|---|
| 641 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 642 | bstrip(s); | 
|---|
| 643 | if (strlen(s) > 8192 - 5) { | 
|---|
| 644 | Runtime_Error(pszSrcFile, __LINE__, "too big"); | 
|---|
| 645 | break; | 
|---|
| 646 | } | 
|---|
| 647 | *path = 0; | 
|---|
| 648 | if (WinDlgBox(HWND_DESKTOP, | 
|---|
| 649 | hwnd, | 
|---|
| 650 | WalkAllDlgProc, | 
|---|
| 651 | FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) { | 
|---|
| 652 | p = strrchr(s, '\\'); | 
|---|
| 653 | if (p) | 
|---|
| 654 | strcpy(simple, p + 1); | 
|---|
| 655 | else if (*s) | 
|---|
| 656 | strcpy(simple, s); | 
|---|
| 657 | else | 
|---|
| 658 | strcpy(simple, "*"); | 
|---|
| 659 | if (!p) | 
|---|
| 660 | *s = 0; | 
|---|
| 661 | if (simple[strlen(simple) - 1] == ';') | 
|---|
| 662 | simple[strlen(simple) - 1] = 0; | 
|---|
| 663 | lLen = strlen(simple) + 1; | 
|---|
| 664 | if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) { | 
|---|
| 665 | Runtime_Error(pszSrcFile, __LINE__, "too big"); | 
|---|
| 666 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 667 | break; | 
|---|
| 668 | } | 
|---|
| 669 | if (!*s || (*s && s[strlen(s) - 1] != ';')) { | 
|---|
| 670 | if (*s) | 
|---|
| 671 | strcat(s, ";"); | 
|---|
| 672 | strcat(s, path); | 
|---|
| 673 | lLen += strlen(path); | 
|---|
| 674 | if (s[strlen(s) - 1] != '\\') { | 
|---|
| 675 | lLen++; | 
|---|
| 676 | strcat(s, PCSZ_BACKSLASH); | 
|---|
| 677 | } | 
|---|
| 678 | rstrip(s); | 
|---|
| 679 | // 25 Sep 09 SHL fixme to honor append | 
|---|
| 680 | if (*s) { | 
|---|
| 681 | strcat(s, simple); | 
|---|
| 682 | WinSetDlgItemText(hwnd, GREP_MASK, s); | 
|---|
| 683 | WinSendDlgItemMsg(hwnd, | 
|---|
| 684 | GREP_MASK, | 
|---|
| 685 | EM_SETSEL, | 
|---|
| 686 | MPFROM2SHORT(strlen(s) - (lLen - 1), | 
|---|
| 687 | strlen(s)), MPVOID); | 
|---|
| 688 | } | 
|---|
| 689 | } | 
|---|
| 690 | } | 
|---|
| 691 | break; | 
|---|
| 692 |  | 
|---|
| 693 | case GREP_ADD: | 
|---|
| 694 | *s = 0; | 
|---|
| 695 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 696 | bstrip(s); | 
|---|
| 697 | if (*s) { | 
|---|
| 698 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 699 | GREP_LISTBOX, | 
|---|
| 700 | LM_SEARCHSTRING, | 
|---|
| 701 | MPFROM2SHORT(0, LIT_FIRST), | 
|---|
| 702 | MPFROMP(s)); | 
|---|
| 703 | if (sSelect < 0) { | 
|---|
| 704 | WinSendDlgItemMsg(hwnd, | 
|---|
| 705 | GREP_LISTBOX, | 
|---|
| 706 | LM_INSERTITEM, | 
|---|
| 707 | MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s)); | 
|---|
| 708 | changed = TRUE; | 
|---|
| 709 | } | 
|---|
| 710 | } | 
|---|
| 711 | break; | 
|---|
| 712 |  | 
|---|
| 713 | case GREP_DELETE: | 
|---|
| 714 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 715 | GREP_LISTBOX, | 
|---|
| 716 | LM_QUERYSELECTION, | 
|---|
| 717 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
| 718 | if (sSelect >= 0) { | 
|---|
| 719 | WinSendDlgItemMsg(hwnd, | 
|---|
| 720 | GREP_LISTBOX, | 
|---|
| 721 | LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID); | 
|---|
| 722 | if (sSelect >= sLastMaskSelect) | 
|---|
| 723 | sLastMaskSelect--; | 
|---|
| 724 | changed = TRUE; | 
|---|
| 725 | } | 
|---|
| 726 | break; | 
|---|
| 727 |  | 
|---|
| 728 | case GREP_OM: | 
|---|
| 729 | *s = 0; | 
|---|
| 730 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, s); | 
|---|
| 731 | ul = atoi(s) * 30L; | 
|---|
| 732 | sprintf(s, "%lu", ul); | 
|---|
| 733 | WinSetDlgItemText(hwnd, GREP_OLDER, s); | 
|---|
| 734 | break; | 
|---|
| 735 |  | 
|---|
| 736 | case GREP_NM: | 
|---|
| 737 | *s = 0; | 
|---|
| 738 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, s); | 
|---|
| 739 | ul = atoi(s) * 30L; | 
|---|
| 740 | sprintf(s, "%lu", ul); | 
|---|
| 741 | WinSetDlgItemText(hwnd, GREP_NEWER, s); | 
|---|
| 742 | break; | 
|---|
| 743 |  | 
|---|
| 744 | case GREP_GK: | 
|---|
| 745 | *s = 0; | 
|---|
| 746 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, s); | 
|---|
| 747 | ul = atol(s) * 1024L; | 
|---|
| 748 | sprintf(s, "%lu", ul); | 
|---|
| 749 | WinSetDlgItemText(hwnd, GREP_GREATER, s); | 
|---|
| 750 | break; | 
|---|
| 751 |  | 
|---|
| 752 | case GREP_LK: | 
|---|
| 753 | *s = 0; | 
|---|
| 754 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, s); | 
|---|
| 755 | ul = atol(s) * 1024L; | 
|---|
| 756 | sprintf(s, "%lu", ul); | 
|---|
| 757 | WinSetDlgItemText(hwnd, GREP_LESSER, s); | 
|---|
| 758 | break; | 
|---|
| 759 |  | 
|---|
| 760 | case DID_CANCEL: | 
|---|
| 761 | WinDismissDlg(hwnd, 0); | 
|---|
| 762 | break; | 
|---|
| 763 |  | 
|---|
| 764 | case IDM_HELP: | 
|---|
| 765 | if (hwndHelp) | 
|---|
| 766 | WinSendMsg(hwndHelp, | 
|---|
| 767 | HM_DISPLAY_HELP, | 
|---|
| 768 | MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID)); | 
|---|
| 769 | break; | 
|---|
| 770 |  | 
|---|
| 771 | case GREP_LOCALHDS: | 
|---|
| 772 | case GREP_REMOTEHDS: | 
|---|
| 773 | case GREP_ALLHDS: | 
|---|
| 774 | { | 
|---|
| 775 | CHAR szDrive[] = " :\\"; | 
|---|
| 776 | ULONG ulDriveNum; | 
|---|
| 777 | ULONG ulDriveMap; | 
|---|
| 778 | INT x; | 
|---|
| 779 | BOOL incl; | 
|---|
| 780 |  | 
|---|
| 781 | CHAR new[8192]; | 
|---|
| 782 |  | 
|---|
| 783 | *s = 0; | 
|---|
| 784 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); | 
|---|
| 785 | s[8192 - 1] = 0; | 
|---|
| 786 | p = strchr(s, ';'); | 
|---|
| 787 | if (p) | 
|---|
| 788 | *p = 0; | 
|---|
| 789 | p = strrchr(s, '\\'); | 
|---|
| 790 | if (!p) | 
|---|
| 791 | p = strrchr(s, '/'); | 
|---|
| 792 | if (!p) | 
|---|
| 793 | p = strrchr(s, ':'); | 
|---|
| 794 | if (p) | 
|---|
| 795 | strcpy(s, p + 1); | 
|---|
| 796 | if (!*s) | 
|---|
| 797 | strcpy(s, "*"); | 
|---|
| 798 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 799 | DosQCurDisk(&ulDriveNum, &ulDriveMap); | 
|---|
| 800 | *new = 0; | 
|---|
| 801 | for (x = 2; x < 26; x++) { | 
|---|
| 802 | incl = FALSE; | 
|---|
| 803 | if (ulDriveMap & (1L << x)) { | 
|---|
| 804 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 805 | case GREP_ALLHDS: | 
|---|
| 806 | if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_RAMDISK))) | 
|---|
| 807 | incl = TRUE; | 
|---|
| 808 | break; | 
|---|
| 809 | case GREP_LOCALHDS: | 
|---|
| 810 | if (!(driveflags[x] & | 
|---|
| 811 | (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE | | 
|---|
| 812 | DRIVE_VIRTUAL | DRIVE_RAMDISK))) | 
|---|
| 813 | incl = TRUE; | 
|---|
| 814 | break; | 
|---|
| 815 | case GREP_REMOTEHDS: | 
|---|
| 816 | if (!(driveflags[x] & | 
|---|
| 817 | (DRIVE_REMOVABLE | DRIVE_IGNORE)) && | 
|---|
| 818 | (driveflags[x] & DRIVE_REMOTE)) | 
|---|
| 819 | incl = TRUE; | 
|---|
| 820 | break; | 
|---|
| 821 | } | 
|---|
| 822 | } | 
|---|
| 823 | if (incl) { | 
|---|
| 824 | if (strlen(new) + strlen(s) + 5 < 8192 - 1) { | 
|---|
| 825 | if (*new) | 
|---|
| 826 | strcat(new, ";"); | 
|---|
| 827 | *szDrive = x + 'A'; | 
|---|
| 828 | strcat(new, szDrive); | 
|---|
| 829 | strcat(new, s); | 
|---|
| 830 | } | 
|---|
| 831 | } | 
|---|
| 832 | } | 
|---|
| 833 | if (*new) | 
|---|
| 834 | WinSetDlgItemText(hwnd, GREP_MASK, new); | 
|---|
| 835 | } | 
|---|
| 836 | break; | 
|---|
| 837 |  | 
|---|
| 838 | case DID_OK: | 
|---|
| 839 | hwndCollect = WinQueryWindowULong(hwnd, QWL_USER); | 
|---|
| 840 | if (!hwndCollect) | 
|---|
| 841 | Runtime_Error(pszSrcFile, __LINE__, NULL); | 
|---|
| 842 | else { | 
|---|
| 843 | // 07 Feb 08 SHL - fixme to malloc and free in thread | 
|---|
| 844 | static GREP g;                  // Passed to thread | 
|---|
| 845 | p = xmalloc(8192 + 512, pszSrcFile, __LINE__); | 
|---|
| 846 | if (!p) | 
|---|
| 847 | break; | 
|---|
| 848 | memset(&g, 0, sizeof(GREP)); | 
|---|
| 849 | g.size = sizeof(GREP); | 
|---|
| 850 | recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0; | 
|---|
| 851 | absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0; | 
|---|
| 852 | sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0; | 
|---|
| 853 | sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0; | 
|---|
| 854 | searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0; | 
|---|
| 855 | searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0; | 
|---|
| 856 | findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0; | 
|---|
| 857 | gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS); | 
|---|
| 858 | if (gRemember) { | 
|---|
| 859 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse", | 
|---|
| 860 | (PVOID) & recurse, sizeof(BOOL)); | 
|---|
| 861 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute", | 
|---|
| 862 | (PVOID) & absolute, sizeof(BOOL)); | 
|---|
| 863 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Case", | 
|---|
| 864 | (PVOID) & sensitive, sizeof(BOOL)); | 
|---|
| 865 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles", | 
|---|
| 866 | (PVOID) & sayfiles, sizeof(BOOL)); | 
|---|
| 867 | PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles", | 
|---|
| 868 | (PVOID) & searchFiles, sizeof(BOOL)); | 
|---|
| 869 | PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs", | 
|---|
| 870 | (PVOID) & searchEAs, sizeof(BOOL)); | 
|---|
| 871 | } | 
|---|
| 872 | PrfWriteProfileData(fmprof, appname, | 
|---|
| 873 | (CHAR *) PSCZ_GREP_LASTMASK_SELECT, &sLastMaskSelect, sizeof(sLastMaskSelect)); | 
|---|
| 874 | g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0; | 
|---|
| 875 | if (g.finddupes) { | 
|---|
| 876 | g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0; | 
|---|
| 877 | g.nosizedupes = | 
|---|
| 878 | WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0; | 
|---|
| 879 | g.ignoreextdupes = | 
|---|
| 880 | WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0; | 
|---|
| 881 | } | 
|---|
| 882 | // Parse file masks | 
|---|
| 883 | *p = 0; | 
|---|
| 884 | WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p); | 
|---|
| 885 | bstrip(p); | 
|---|
| 886 | if (!*p) { | 
|---|
| 887 | if (!fAlertBeepOff) | 
|---|
| 888 | DosBeep(50, 100); | 
|---|
| 889 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK)); | 
|---|
| 890 | free(p); | 
|---|
| 891 | #         ifdef FORTIFY | 
|---|
| 892 | Fortify_LeaveScope(); | 
|---|
| 893 | #          endif | 
|---|
| 894 | break; | 
|---|
| 895 | } | 
|---|
| 896 | strcpy(g.tosearch, p); | 
|---|
| 897 | strcpy(lastmask, p); | 
|---|
| 898 | // Parse search strings | 
|---|
| 899 | *p = 0; | 
|---|
| 900 | WinQueryWindowText(hwndMLE, 4096, p); | 
|---|
| 901 | strcpy(lasttext, p); | 
|---|
| 902 | { | 
|---|
| 903 | CHAR *pszFrom; | 
|---|
| 904 | CHAR *pszTo; | 
|---|
| 905 | ULONG matched = 0; | 
|---|
| 906 |  | 
|---|
| 907 | pszTo = g.searchPattern; | 
|---|
| 908 | pszFrom = p; | 
|---|
| 909 | while (*pszFrom) { | 
|---|
| 910 | if (*pszFrom == '\r') { | 
|---|
| 911 | pszFrom++; | 
|---|
| 912 | continue; | 
|---|
| 913 | } | 
|---|
| 914 | if (*pszFrom == '\n') { | 
|---|
| 915 | if (*(pszFrom + 1)) | 
|---|
| 916 | matched++; | 
|---|
| 917 | *pszTo = 0; | 
|---|
| 918 | } | 
|---|
| 919 | else | 
|---|
| 920 | *pszTo = *pszFrom; | 
|---|
| 921 | pszTo++; | 
|---|
| 922 | pszFrom++; | 
|---|
| 923 | } | 
|---|
| 924 | if (*g.searchPattern) | 
|---|
| 925 | matched++; | 
|---|
| 926 | *pszTo++ = 0; | 
|---|
| 927 | *pszTo = 0; | 
|---|
| 928 | g.numlines = matched; | 
|---|
| 929 | if (matched) { | 
|---|
| 930 | g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__); | 
|---|
| 931 | if (!g.matched) | 
|---|
| 932 | g.numlines = 0; | 
|---|
| 933 | } | 
|---|
| 934 | } | 
|---|
| 935 | *p = 0; | 
|---|
| 936 | WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p); | 
|---|
| 937 | greater = atol(p); | 
|---|
| 938 | *p = 0; | 
|---|
| 939 | WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p); | 
|---|
| 940 | lesser = atol(p); | 
|---|
| 941 | *p = 0; | 
|---|
| 942 | WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p); | 
|---|
| 943 | newer = atoi(p); | 
|---|
| 944 | *p = 0; | 
|---|
| 945 | WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p); | 
|---|
| 946 | older = atoi(p); | 
|---|
| 947 | if (older || newer) { | 
|---|
| 948 | FDATE fdate; | 
|---|
| 949 | FTIME ftime; | 
|---|
| 950 | struct tm tm; | 
|---|
| 951 | time_t t; | 
|---|
| 952 |  | 
|---|
| 953 | t = time(NULL); | 
|---|
| 954 | tm = *localtime(&t); | 
|---|
| 955 | fdate.day = tm.tm_mday; | 
|---|
| 956 | fdate.month = tm.tm_mon + 1; | 
|---|
| 957 | fdate.year = tm.tm_year - 80; | 
|---|
| 958 | ftime.hours = tm.tm_hour; | 
|---|
| 959 | ftime.minutes = tm.tm_min; | 
|---|
| 960 | ftime.twosecs = tm.tm_sec / 2; | 
|---|
| 961 | if (older) { | 
|---|
| 962 | g.olderthan = SecsSince1980(&fdate, &ftime); | 
|---|
| 963 | g.olderthan -= (older * (24L * 60L * 60L)); | 
|---|
| 964 | } | 
|---|
| 965 | if (newer) { | 
|---|
| 966 | g.newerthan = SecsSince1980(&fdate, &ftime); | 
|---|
| 967 | g.newerthan -= (newer * (24L * 60L * 60L)); | 
|---|
| 968 | } | 
|---|
| 969 | } | 
|---|
| 970 | if (!newer) | 
|---|
| 971 | g.newerthan = 0; | 
|---|
| 972 | if (!older) | 
|---|
| 973 | g.olderthan = 0; | 
|---|
| 974 | g.greaterthan = greater; | 
|---|
| 975 | g.lessthan = lesser; | 
|---|
| 976 | g.absFlag = absolute; | 
|---|
| 977 | g.caseFlag = sensitive; | 
|---|
| 978 | g.dirFlag = recurse; | 
|---|
| 979 | g.sayfiles = sayfiles; | 
|---|
| 980 | g.searchEAs = searchEAs; | 
|---|
| 981 | g.searchFiles = searchFiles; | 
|---|
| 982 | g.findifany = findifany; | 
|---|
| 983 | g.hwndFiles = hwndCollect; | 
|---|
| 984 | g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT); | 
|---|
| 985 | g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED); | 
|---|
| 986 | g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile; | 
|---|
| 987 | g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr; | 
|---|
| 988 | g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag; | 
|---|
| 989 | if (xbeginthread(GrepThread, | 
|---|
| 990 | 524280, | 
|---|
| 991 | &g, | 
|---|
| 992 | pszSrcFile, | 
|---|
| 993 | __LINE__) == -1) | 
|---|
| 994 | { | 
|---|
| 995 | free(p); | 
|---|
| 996 | #         ifdef FORTIFY | 
|---|
| 997 | Fortify_LeaveScope(); | 
|---|
| 998 | #          endif | 
|---|
| 999 | WinDismissDlg(hwnd, 0); | 
|---|
| 1000 | break; | 
|---|
| 1001 | } | 
|---|
| 1002 | DosSleep(100); //05 Aug 07 GKY 128 | 
|---|
| 1003 | free(p); | 
|---|
| 1004 | #       ifdef FORTIFY | 
|---|
| 1005 | Fortify_LeaveScope(); | 
|---|
| 1006 | #        endif | 
|---|
| 1007 | } | 
|---|
| 1008 | if (changed) { | 
|---|
| 1009 | // Save modified mask list | 
|---|
| 1010 | SHORT x; | 
|---|
| 1011 |  | 
|---|
| 1012 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 1013 | GREP_LISTBOX, | 
|---|
| 1014 | LM_QUERYITEMCOUNT, | 
|---|
| 1015 | MPVOID, MPVOID); | 
|---|
| 1016 | // 07 Oct 09 SHL Rewrite if list empty | 
|---|
| 1017 | if (sSelect >= 0) { | 
|---|
| 1018 | CHAR *modew = "w"; | 
|---|
| 1019 |  | 
|---|
| 1020 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_GREPMASKDAT); | 
|---|
| 1021 | if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2) | 
|---|
| 1022 | break; //already gave error msg | 
|---|
| 1023 | fp = xfopen(s, modew, pszSrcFile, __LINE__, FALSE); | 
|---|
| 1024 | if (fp) { | 
|---|
| 1025 | fputs(GetPString(IDS_GREPFILETEXT), fp); | 
|---|
| 1026 | for (x = 0; x < sSelect; x++) { | 
|---|
| 1027 | *s = 0; | 
|---|
| 1028 | WinSendDlgItemMsg(hwnd, | 
|---|
| 1029 | GREP_LISTBOX, | 
|---|
| 1030 | LM_QUERYITEMTEXT, | 
|---|
| 1031 | MPFROM2SHORT(x, 8192), MPFROMP(s)); | 
|---|
| 1032 | bstrip(s); | 
|---|
| 1033 | if (*s) | 
|---|
| 1034 | fprintf(fp, "%s\n", s); | 
|---|
| 1035 | } | 
|---|
| 1036 | fclose(fp); | 
|---|
| 1037 | } | 
|---|
| 1038 | } | 
|---|
| 1039 | } | 
|---|
| 1040 | WinDismissDlg(hwnd, 1); | 
|---|
| 1041 | break; | 
|---|
| 1042 | } | 
|---|
| 1043 | return 0; | 
|---|
| 1044 | } | 
|---|
| 1045 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 1046 | } | 
|---|
| 1047 |  | 
|---|
| 1048 | #pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc) | 
|---|