Changeset 190 for trunk/dll/grep2.c
- Timestamp:
- Jun 6, 2005, 7:51:12 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep2.c
r130 r190 5 5 6 6 Copyright (c) 1993-98 M. Kimes 7 Copyright (c) 2004, 2005 Steven H. Levine7 Copyright (c) 2004, 2005 Steven H. Levine 8 8 9 9 01 Aug 04 SHL Rework lstrip/rstrip usage 10 10 23 May 05 SHL Use QWL_USER 11 06 Jun 05 SHL indent -i2 11 12 12 13 ***********************************************************************/ … … 35 36 #pragma alloc_text(GREP,GrepDlgProc,EnvDlgProc) 36 37 37 38 MRESULT EXPENTRY EnvDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) { 39 38 MRESULT EXPENTRY EnvDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 39 { 40 40 static CHAR lastenv[CCHMAXPATH] = "DPATH"; 41 41 42 switch(msg) { 43 case WM_INITDLG: 44 if(mp2) { 45 WinSetWindowPtr(hwnd,QWL_USER,mp2); 46 *(CHAR *)mp2 = 0; 47 { 48 char *p,*pp,temp[CCHMAXPATH]; 49 50 p = GetPString(IDS_ENVVARNAMES); 51 while(*p == ' ') 52 p++; 53 while(*p) { 54 *temp = 0; 55 pp = temp; 56 while(*p && *p != ' ') 57 *pp++ = *p++; 58 *pp = 0; 59 while(*p == ' ') 60 p++; 61 if(*temp) 62 WinSendDlgItemMsg(hwnd, 63 ENV_LISTBOX, 64 LM_INSERTITEM, 65 MPFROM2SHORT(LIT_END,0), 66 MPFROMP(temp)); 67 } 68 } 69 WinSendDlgItemMsg(hwnd, 70 ENV_NAME, 71 EM_SETTEXTLIMIT, 72 MPFROM2SHORT(CCHMAXPATH,0), 73 MPVOID); 74 WinSetDlgItemText(hwnd, 75 ENV_NAME, 76 lastenv); 77 WinSendDlgItemMsg(hwnd, 78 ENV_NAME, 79 EM_SETSEL, 80 MPFROM2SHORT(0,CCHMAXPATH), 81 MPVOID); 82 } 42 switch (msg) 43 { 44 case WM_INITDLG: 45 if (mp2) 46 { 47 WinSetWindowPtr(hwnd, QWL_USER, mp2); 48 *(CHAR *) mp2 = 0; 49 { 50 CHAR *p; 51 CHAR *pp; 52 CHAR temp[CCHMAXPATH]; 53 54 p = GetPString(IDS_ENVVARNAMES); 55 while (*p == ' ') 56 p++; 57 while (*p) 58 { 59 *temp = 0; 60 pp = temp; 61 while (*p && *p != ' ') 62 *pp++ = *p++; 63 *pp = 0; 64 while (*p == ' ') 65 p++; 66 if (*temp) 67 WinSendDlgItemMsg(hwnd, 68 ENV_LISTBOX, 69 LM_INSERTITEM, 70 MPFROM2SHORT(LIT_END, 0), 71 MPFROMP(temp)); 72 } 73 } 74 WinSendDlgItemMsg(hwnd, 75 ENV_NAME, 76 EM_SETTEXTLIMIT, 77 MPFROM2SHORT(CCHMAXPATH, 0), 78 MPVOID); 79 WinSetDlgItemText(hwnd, 80 ENV_NAME, 81 lastenv); 82 WinSendDlgItemMsg(hwnd, 83 ENV_NAME, 84 EM_SETSEL, 85 MPFROM2SHORT(0, CCHMAXPATH), 86 MPVOID); 87 } 88 else 89 WinDismissDlg(hwnd, 0); 90 break; 91 92 case WM_CONTROL: 93 switch (SHORT1FROMMP(mp1)) 94 { 95 case ENV_LISTBOX: 96 switch (SHORT2FROMMP(mp1)) 97 { 98 case LN_SELECT: 99 { 100 SHORT sSelect; 101 CHAR s[CCHMAXPATH]; 102 103 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 104 ENV_LISTBOX, 105 LM_QUERYSELECTION, 106 MPFROMSHORT(LIT_FIRST), 107 MPVOID); 108 if (sSelect >= 0) 109 { 110 *s = 0; 111 WinSendDlgItemMsg(hwnd, 112 ENV_LISTBOX, 113 LM_QUERYITEMTEXT, 114 MPFROM2SHORT(sSelect, CCHMAXPATH), 115 MPFROMP(s)); 116 bstrip(s); 117 if (*s) 118 WinSetDlgItemText(hwnd, 119 ENV_NAME, 120 s); 121 } 122 } 123 break; 124 case LN_ENTER: 125 PostMsg(hwnd, 126 WM_COMMAND, 127 MPFROM2SHORT(DID_OK, 0), 128 MPVOID); 129 break; 130 } 131 } 132 return 0; 133 134 case WM_COMMAND: 135 switch (SHORT1FROMMP(mp1)) 136 { 137 case DID_CANCEL: 138 WinDismissDlg(hwnd, 0); 139 break; 140 case DID_OK: 141 { 142 CHAR *p = WinQueryWindowPtr(hwnd, QWL_USER); 143 144 if (p) 145 { 146 WinQueryDlgItemText(hwnd, 147 ENV_NAME, 148 CCHMAXPATH, 149 p); 150 bstrip(p); 151 if (*p) 152 { 153 strcpy(lastenv, p); 154 WinDismissDlg(hwnd, 1); 155 } 156 else 157 { 158 DosBeep(250, 100); 159 WinSetFocus(HWND_DESKTOP, 160 WinWindowFromID(hwnd, ENV_NAME)); 161 } 162 } 163 } 164 break; 165 case IDM_HELP: 166 if (hwndHelp) 167 WinSendMsg(hwndHelp, 168 HM_DISPLAY_HELP, 169 MPFROM2SHORT(HELP_ENV, 0), 170 MPFROMSHORT(HM_RESOURCEID)); 171 break; 172 } 173 return 0; 174 } 175 return WinDefDlgProc(hwnd, msg, mp1, mp2); 176 } 177 178 MRESULT EXPENTRY GrepDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 179 { 180 HWND hwndCollect; 181 HWND hwndMLE = WinWindowFromID(hwnd, GREP_SEARCH); 182 183 static CHAR lastmask[8192] = "*"; 184 static CHAR lasttext[4096] = ""; 185 static BOOL recurse = TRUE; 186 static BOOL sensitive = FALSE; 187 static BOOL absolute = FALSE; 188 static BOOL sayfiles = FALSE; 189 static BOOL searchEAs = TRUE; 190 static BOOL searchFiles = TRUE; 191 static BOOL changed = FALSE; 192 static BOOL findifany = TRUE; 193 static UINT newer = 0; 194 static UINT older = 0; 195 static ULONG greater = 0; 196 static ULONG lesser = 0; 197 198 switch (msg) 199 { 200 case WM_INITDLG: 201 if (!mp2) 202 { 203 WinDismissDlg(hwnd, 0); 204 break; 205 } 206 WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2); 207 WinSendDlgItemMsg(hwnd, 208 GREP_MASK, 209 EM_SETTEXTLIMIT, 210 MPFROM2SHORT(8192, 0), 211 MPVOID); 212 MLEsetlimit(hwndMLE, 4096); 213 MLEsetformat(hwndMLE, MLFIE_NOTRANS); 214 WinSendDlgItemMsg(hwnd, 215 GREP_NEWER, 216 EM_SETTEXTLIMIT, 217 MPFROM2SHORT(34, 0), 218 MPVOID); 219 WinSendDlgItemMsg(hwnd, 220 GREP_OLDER, 221 EM_SETTEXTLIMIT, 222 MPFROM2SHORT(34, 0), 223 MPVOID); 224 WinSendDlgItemMsg(hwnd, 225 GREP_GREATER, 226 EM_SETTEXTLIMIT, 227 MPFROM2SHORT(34, 0), 228 MPVOID); 229 WinSendDlgItemMsg(hwnd, 230 GREP_LESSER, 231 EM_SETTEXTLIMIT, 232 MPFROM2SHORT(34, 0), 233 MPVOID); 234 WinSetDlgItemText(hwnd, 235 GREP_MASK, 236 lastmask); 237 WinSendDlgItemMsg(hwnd, 238 GREP_MASK, 239 EM_SETSEL, 240 MPFROM2SHORT(0, 8192), 241 MPVOID); 242 WinSetWindowText(hwndMLE, lasttext); 243 if (*lasttext) 244 { 245 MLEsetcurpos(hwndMLE, 0); 246 MLEsetcurposa(hwndMLE, 4096); 247 if (!searchEAs) 248 searchFiles = TRUE; 249 } 250 WinCheckButton(hwnd, GREP_RECURSE, recurse); 251 WinCheckButton(hwnd, GREP_ABSOLUTE, absolute); 252 WinCheckButton(hwnd, GREP_CASE, sensitive); 253 WinCheckButton(hwnd, GREP_SAYFILES, sayfiles); 254 WinCheckButton(hwnd, GREP_SEARCHEAS, searchEAs); 255 WinCheckButton(hwnd, GREP_SEARCHFILES, searchFiles); 256 WinCheckButton(hwnd, GREP_FINDIFANY, findifany); 257 { 258 CHAR s[35]; 259 260 sprintf(s, "%lu", greater); 261 WinSetDlgItemText(hwnd, GREP_GREATER, s); 262 sprintf(s, "%lu", lesser); 263 WinSetDlgItemText(hwnd, GREP_LESSER, s); 264 sprintf(s, "%u", newer); 265 WinSetDlgItemText(hwnd, GREP_NEWER, s); 266 sprintf(s, "%u", older); 267 WinSetDlgItemText(hwnd, GREP_OLDER, s); 268 } 269 WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), FALSE); 270 WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), FALSE); 271 WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), FALSE); 272 { 273 FILE *fp; 274 static CHAR s[8192 + 14]; 275 276 save_dir2(s); 277 if (s[strlen(s) - 1] != '\\') 278 strcat(s, "\\"); 279 strcat(s, "GREPMASK.DAT"); 280 fp = _fsopen(s, "r", SH_DENYWR); 281 if (fp) 282 { 283 while (!feof(fp)) 284 { 285 if (!fgets(s, 8192 + 4, fp)) 286 break; 287 bstripcr(s); 288 if (*s && *s != ';') 289 WinSendDlgItemMsg(hwnd, 290 GREP_LISTBOX, 291 LM_INSERTITEM, 292 MPFROM2SHORT(LIT_SORTASCENDING, 0), 293 MPFROMP(s)); 294 } 295 fclose(fp); 296 } 297 } 298 FillPathListBox(hwnd, 299 WinWindowFromID(hwnd, GREP_DRIVELIST), 300 (HWND) 0, 301 NULL, 302 FALSE); 303 break; 304 305 case WM_ADJUSTWINDOWPOS: 306 PostMsg(hwnd, 307 UM_SETDIR, 308 MPVOID, 309 MPVOID); 310 break; 311 312 case UM_SETDIR: 313 PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP), 314 (HPS) 0, 315 FALSE, 316 TRUE); 317 return 0; 318 319 case UM_FOCUSME: 320 /* set focus to window hwnd in mp1 */ 321 if (mp1) 322 WinSetFocus(HWND_DESKTOP, (HWND) mp1); 323 return 0; 324 325 case WM_CONTROL: 326 switch (SHORT1FROMMP(mp1)) 327 { 328 case GREP_DRIVELIST: 329 switch (SHORT2FROMMP(mp1)) 330 { 331 case LN_KILLFOCUS: 332 WinSetDlgItemText(hwnd, 333 GREP_HELP, 334 GetPString(IDS_ARCDEFAULTHELPTEXT)); 335 break; 336 case LN_SETFOCUS: 337 WinSetDlgItemText(hwnd, 338 GREP_HELP, 339 GetPString(IDS_2CLICKADDDRVMASKTEXT)); 340 break; 341 case LN_ENTER: 342 { 343 SHORT sSelect; 344 static CHAR s[8192]; 345 static CHAR simple[8192]; 346 static CHAR *p; 347 LONG len; 348 349 WinQueryDlgItemText(hwnd, 350 GREP_MASK, 351 8192, 352 s); 353 bstrip(s); 354 p = strrchr(s, '\\'); 355 if (p) 356 strcpy(simple, p); 357 else if (*s) 358 { 359 strcpy(simple, "\\"); 360 strcat(simple, s); 361 *s = 0; 362 } 363 else 364 strcpy(simple, "\\*"); 365 if (simple[strlen(simple) - 1] == ';') 366 simple[strlen(simple) - 1] = 0; 367 len = strlen(simple) + 1; 368 if (strlen(s) > 8192 - len) 369 { 370 DosBeep(250, 100); 371 WinSetDlgItemText(hwnd, 372 GREP_MASK, 373 s); 374 break; 375 } 376 377 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 378 GREP_DRIVELIST, 379 LM_QUERYSELECTION, 380 MPFROMSHORT(LIT_FIRST), 381 MPVOID); 382 if (sSelect >= 0) 383 { 384 if (*s && s[strlen(s) - 1] != ';') 385 strcat(s, ";"); 386 WinSendDlgItemMsg(hwnd, 387 GREP_DRIVELIST, 388 LM_QUERYITEMTEXT, 389 MPFROM2SHORT(sSelect, 390 (8192 - strlen(s)) - len), 391 MPFROMP(&s[strlen(s)])); 392 rstrip(s); 393 if (*s) 394 { 395 strcat(s, simple); 396 WinSetDlgItemText(hwnd, 397 GREP_MASK, 398 s); 399 WinSendDlgItemMsg(hwnd, 400 GREP_MASK, 401 EM_SETSEL, 402 MPFROM2SHORT(strlen(s) - (len + 1), 403 strlen(s)), 404 MPVOID); 405 PostMsg(hwnd, 406 UM_FOCUSME, 407 MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), 408 MPVOID); 409 } 410 } 411 } 412 break; 413 } 414 break; 415 case GREP_LISTBOX: 416 switch (SHORT2FROMMP(mp1)) 417 { 418 case LN_KILLFOCUS: 419 WinSetDlgItemText(hwnd, 420 GREP_HELP, 421 GetPString(IDS_ARCDEFAULTHELPTEXT)); 422 break; 423 case LN_SETFOCUS: 424 WinSetDlgItemText(hwnd, 425 GREP_HELP, 426 GetPString(IDS_ADDSELDELMASKTEXT)); 427 break; 428 case LN_ENTER: 429 case LN_SELECT: 430 if ((SHORT2FROMMP(mp1) == LN_ENTER && 431 !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) || 432 (SHORT2FROMMP(mp1) == LN_SELECT && 433 WinQueryButtonCheckstate(hwnd, GREP_APPEND))) 434 break; 435 { 436 SHORT sSelect; 437 static CHAR s[8192]; 438 439 *s = 0; 440 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 441 GREP_LISTBOX, 442 LM_QUERYSELECTION, 443 MPFROMSHORT(LIT_FIRST), 444 MPVOID); 445 if (sSelect >= 0) 446 { 447 if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) 448 { 449 WinQueryDlgItemText(hwnd, 450 GREP_MASK, 451 8192, 452 s); 453 bstrip(s); 454 if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';') 455 strcat(s, ";"); 456 } 457 WinSendDlgItemMsg(hwnd, 458 GREP_LISTBOX, 459 LM_QUERYITEMTEXT, 460 MPFROM2SHORT(sSelect, 8192 - strlen(s)), 461 MPFROMP(s + strlen(s))); 462 bstrip(s); 463 if (*s) 464 WinSetDlgItemText(hwnd, 465 GREP_MASK, 466 s); 467 } 468 } 469 break; 470 } 471 break; 472 case GREP_MASK: 473 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 474 WinSetDlgItemText(hwnd, 475 GREP_HELP, 476 GetPString(IDS_ARCDEFAULTHELPTEXT)); 477 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 478 WinSetDlgItemText(hwnd, 479 GREP_HELP, 480 GetPString(IDS_MASKSFINDTEXT)); 481 break; 482 case GREP_SEARCH: 483 if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS) 484 WinSetDlgItemText(hwnd, 485 GREP_HELP, 486 GetPString(IDS_ARCDEFAULTHELPTEXT)); 487 if (SHORT2FROMMP(mp1) == MLN_SETFOCUS) 488 WinSetDlgItemText(hwnd, 489 GREP_HELP, 490 GetPString(IDS_TEXTFINDTEXT)); 491 break; 492 case GREP_GREATER: 493 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 494 WinSetDlgItemText(hwnd, 495 GREP_HELP, 496 GetPString(IDS_ARCDEFAULTHELPTEXT)); 497 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 498 WinSetDlgItemText(hwnd, 499 GREP_HELP, 500 GetPString(IDS_MINSIZEFINDTEXT)); 501 break; 502 case GREP_LESSER: 503 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 504 WinSetDlgItemText(hwnd, 505 GREP_HELP, 506 GetPString(IDS_ARCDEFAULTHELPTEXT)); 507 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 508 WinSetDlgItemText(hwnd, 509 GREP_HELP, 510 GetPString(IDS_MAXSIZEFINDTEXT)); 511 break; 512 case GREP_NEWER: 513 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 514 WinSetDlgItemText(hwnd, 515 GREP_HELP, 516 GetPString(IDS_ARCDEFAULTHELPTEXT)); 517 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 518 WinSetDlgItemText(hwnd, 519 GREP_HELP, 520 GetPString(IDS_MAXAGEFINDTEXT)); 521 break; 522 case GREP_OLDER: 523 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 524 WinSetDlgItemText(hwnd, 525 GREP_HELP, 526 GetPString(IDS_ARCDEFAULTHELPTEXT)); 527 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 528 WinSetDlgItemText(hwnd, 529 GREP_HELP, 530 GetPString(IDS_MINAGEFINDTEXT)); 531 break; 532 case GREP_FINDDUPES: 533 { 534 BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES); 535 536 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes); 537 WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes); 538 WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes); 539 WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes); 540 WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes); 541 WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), finddupes); 542 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes); 543 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes); 544 WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes); 545 WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes); 546 WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes); 547 WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes); 548 WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes); 549 WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes); 550 WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes); 551 WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes); 552 WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes); 553 if (finddupes) 554 WinCheckButton(hwnd, GREP_RECURSE, TRUE); 555 } 556 } 557 return 0; 558 559 case WM_COMMAND: 560 switch (SHORT1FROMMP(mp1)) 561 { 562 case GREP_ENV: 563 { 564 CHAR path[CCHMAXPATH]; 565 CHAR *p; 566 CHAR *t; 567 568 static CHAR s[8192]; 569 static CHAR simple[8192]; 570 static CHAR env[8192]; 571 LONG len; 572 573 *path = 0; 574 if (!WinDlgBox(HWND_DESKTOP, 575 hwnd, 576 EnvDlgProc, 577 FM3ModHandle, 578 ENV_FRAME, 579 path)) 580 { 581 break; 582 } 583 bstrip(path); 584 if (!*path) 585 break; 586 if (!stricmp(path, "LIBPATH")) 587 LoadLibPath(env, 8192); 588 else 589 { 590 p = getenv(path); 591 if (!p) 592 break; 593 strcpy(env, p); 594 } 595 bstrip(env); 596 if (!*env) 597 break; 598 WinQueryDlgItemText(hwnd, 599 GREP_MASK, 600 8192, 601 s); 602 bstrip(s); 603 if (strlen(s) > 8192 - 5) 604 { 605 DosBeep(50, 100); 606 break; 607 } 608 p = strrchr(s, '\\'); 609 if (p) 610 strcpy(simple, p + 1); 611 else if (*s) 612 strcpy(simple, s); 613 else 614 strcpy(simple, "*"); 615 if (!p) 616 *s = 0; 617 if (simple[strlen(simple) - 1] == ';') 618 simple[strlen(simple) - 1] = 0; 619 len = strlen(simple) + 1; 620 p = env; 621 while (p && *p) 622 { 623 strncpy(path, p, CCHMAXPATH - 1); 624 path[CCHMAXPATH - 1] = 0; 625 t = strchr(path, ';'); 626 if (t) 627 *t = 0; 628 bstrip(path); 629 if (isalpha(*path) && path[1] == ':' && path[2] == '\\') 630 { 631 if (strlen(s) > (8192 - len) - (strlen(path) + 1)) 632 { 633 WinSetDlgItemText(hwnd, 634 GREP_MASK, 635 s); 636 break; 637 } 638 if (!*s || (*s && s[strlen(s) - 1] != ';')) 639 { 640 if (*s) 641 strcat(s, ";"); 642 strcat(s, path); 643 len += strlen(path); 644 if (s[strlen(s) - 1] != '\\') 645 { 646 len++; 647 strcat(s, "\\"); 648 } 649 rstrip(s); 650 if (*s) 651 { 652 strcat(s, simple); 653 WinSetDlgItemText(hwnd, 654 GREP_MASK, 655 s); 656 WinSendDlgItemMsg(hwnd, 657 GREP_MASK, 658 EM_SETSEL, 659 MPFROM2SHORT(strlen(s) - (len - 1), 660 strlen(s)), 661 MPVOID); 662 } 663 } 664 } 665 p = strchr(p, ';'); 666 if (p) 667 p++; 668 } 669 } 670 break; 671 672 case GREP_WALK: 673 { 674 CHAR path[CCHMAXPATH]; 675 CHAR *p; 676 LONG len; 677 678 static CHAR s[8192]; 679 static CHAR simple[8192]; 680 681 WinQueryDlgItemText(hwnd, 682 GREP_MASK, 683 8192, 684 s); 685 bstrip(s); 686 if (strlen(s) > 8192 - 5) 687 { 688 DosBeep(50, 100); 689 break; 690 } 691 *path = 0; 692 if (WinDlgBox(HWND_DESKTOP, 693 hwnd, 694 WalkAllDlgProc, 695 FM3ModHandle, 696 WALK_FRAME, 697 MPFROMP(path)) && 698 *path) 699 { 700 p = strrchr(s, '\\'); 701 if (p) 702 strcpy(simple, p + 1); 703 else if (*s) 704 strcpy(simple, s); 705 else 706 strcpy(simple, "*"); 707 if (!p) 708 *s = 0; 709 if (simple[strlen(simple) - 1] == ';') 710 simple[strlen(simple) - 1] = 0; 711 len = strlen(simple) + 1; 712 if (strlen(s) > (8192 - len) - (strlen(path) + 1)) 713 { 714 DosBeep(250, 100); 715 WinSetDlgItemText(hwnd, 716 GREP_MASK, 717 s); 718 break; 719 } 720 if (!*s || (*s && s[strlen(s) - 1] != ';')) 721 { 722 if (*s) 723 strcat(s, ";"); 724 strcat(s, path); 725 len += strlen(path); 726 if (s[strlen(s) - 1] != '\\') 727 { 728 len++; 729 strcat(s, "\\"); 730 } 731 rstrip(s); 732 if (*s) 733 { 734 strcat(s, simple); 735 WinSetDlgItemText(hwnd, 736 GREP_MASK, 737 s); 738 WinSendDlgItemMsg(hwnd, 739 GREP_MASK, 740 EM_SETSEL, 741 MPFROM2SHORT(strlen(s) - (len - 1), 742 strlen(s)), 743 MPVOID); 744 } 745 } 746 } 747 } 748 break; 749 750 case GREP_ADD: 751 { 752 SHORT sSelect; 753 754 static CHAR s[8192]; 755 756 *s = 0; 757 WinQueryDlgItemText(hwnd, 758 GREP_MASK, 759 8192, 760 s); 761 bstrip(s); 762 if (*s) 763 { 764 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 765 GREP_LISTBOX, 766 LM_SEARCHSTRING, 767 MPFROM2SHORT(0, LIT_FIRST), 768 MPFROMP(s)); 769 if (sSelect < 0) 770 { 771 WinSendDlgItemMsg(hwnd, 772 GREP_LISTBOX, 773 LM_INSERTITEM, 774 MPFROM2SHORT(LIT_SORTASCENDING, 0), 775 MPFROMP(s)); 776 changed = TRUE; 777 } 778 } 779 } 780 break; 781 782 case GREP_DELETE: 783 { 784 SHORT sSelect; 785 786 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 787 GREP_LISTBOX, 788 LM_QUERYSELECTION, 789 MPFROMSHORT(LIT_FIRST), 790 MPVOID); 791 if (sSelect >= 0) 792 { 793 WinSendDlgItemMsg(hwnd, 794 GREP_LISTBOX, 795 LM_DELETEITEM, 796 MPFROM2SHORT(sSelect, 0), 797 MPVOID); 798 changed = TRUE; 799 } 800 } 801 break; 802 803 case GREP_OM: 804 { 805 CHAR str[81]; 806 UINT temp; 807 808 *str = 0; 809 WinQueryDlgItemText(hwnd, 810 GREP_OLDER, 811 34, 812 str); 813 temp = atoi(str) * 30L; 814 sprintf(str, "%u", temp); 815 WinSetDlgItemText(hwnd, 816 GREP_OLDER, 817 str); 818 } 819 break; 820 821 case GREP_NM: 822 { 823 CHAR str[81]; 824 UINT temp; 825 826 *str = 0; 827 WinQueryDlgItemText(hwnd, 828 GREP_NEWER, 829 34, 830 str); 831 temp = atoi(str) * 30L; 832 sprintf(str, "%u", temp); 833 WinSetDlgItemText(hwnd, 834 GREP_NEWER, 835 str); 836 } 837 break; 838 839 case GREP_GK: 840 { 841 CHAR str[81]; 842 ULONG temp; 843 844 *str = 0; 845 WinQueryDlgItemText(hwnd, 846 GREP_GREATER, 847 34, 848 str); 849 temp = atol(str) * 1024L; 850 sprintf(str, "%lu", temp); 851 WinSetDlgItemText(hwnd, GREP_GREATER, str); 852 } 853 break; 854 855 case GREP_LK: 856 { 857 CHAR str[81]; 858 ULONG temp; 859 860 *str = 0; 861 WinQueryDlgItemText(hwnd, 862 GREP_LESSER, 863 34, 864 str); 865 temp = atol(str) * 1024L; 866 sprintf(str, "%lu", temp); 867 WinSetDlgItemText(hwnd, 868 GREP_LESSER, 869 str); 870 } 871 break; 872 873 case DID_CANCEL: 874 WinDismissDlg(hwnd, 0); 875 break; 876 877 case IDM_HELP: 878 if (hwndHelp) 879 WinSendMsg(hwndHelp, 880 HM_DISPLAY_HELP, 881 MPFROM2SHORT(HELP_GREP, 0), 882 MPFROMSHORT(HM_RESOURCEID)); 883 break; 884 885 case GREP_LOCALHDS: 886 case GREP_REMOTEHDS: 887 case GREP_ALLHDS: 888 { 889 CHAR *p; 890 CHAR *szDrive = " :\\"; 891 ULONG ulDriveNum; 892 ULONG ulDriveMap; 893 INT x; 894 BOOL incl; 895 896 static CHAR str[8192]; 897 static CHAR new[8192]; 898 899 *str = *new = 0; 900 WinQueryDlgItemText(hwnd, 901 GREP_MASK, 902 8192, 903 str); 904 str[8192 - 1] = 0; 905 p = strchr(str, ';'); 906 if (p) 907 *p = 0; 908 p = strrchr(str, '\\'); 909 if (!p) 910 p = strrchr(str, '/'); 911 if (!p) 912 p = strrchr(str, ':'); 913 if (p) 914 strcpy(str, p + 1); 915 if (!*str) 916 strcpy(str, "*"); 917 *new = 0; 918 DosError(FERR_DISABLEHARDERR); 919 DosQCurDisk(&ulDriveNum, 920 &ulDriveMap); 921 for (x = 2; x < 26; x++) 922 { 923 if (ulDriveMap & (1L << x)) 924 { 925 incl = FALSE; 926 switch (SHORT1FROMMP(mp1)) 927 { 928 case GREP_ALLHDS: 929 if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE))) 930 incl = TRUE; 931 break; 932 case GREP_LOCALHDS: 933 if (!(driveflags[x] & 934 (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE))) 935 incl = TRUE; 936 break; 937 case GREP_REMOTEHDS: 938 if (!(driveflags[x] & 939 (DRIVE_REMOVABLE | DRIVE_IGNORE)) && 940 (driveflags[x] & DRIVE_REMOTE)) 941 incl = TRUE; 942 break; 943 } 944 } 945 if (incl) 946 { 947 if (strlen(new) + strlen(str) + 5 < 8192 - 1) 948 { 949 if (*new) 950 strcat(new, ";"); 951 *szDrive = x + 'A'; 952 strcat(new, szDrive); 953 strcat(new, str); 954 } 955 } 956 } 957 if (*new) 958 WinSetDlgItemText(hwnd, 959 GREP_MASK, 960 new); 961 } 962 break; 963 964 case DID_OK: 965 hwndCollect = WinQueryWindowULong(hwnd, QWL_USER); 966 if (!hwndCollect) 967 DosBeep(50, 100); 83 968 else 84 WinDismissDlg(hwnd,0); 85 break; 86 87 case WM_CONTROL: 88 switch(SHORT1FROMMP(mp1)) { 89 case ENV_LISTBOX: 90 switch(SHORT2FROMMP(mp1)) { 91 case LN_SELECT: 92 { 93 SHORT sSelect; 94 CHAR s[CCHMAXPATH]; 95 96 sSelect = (SHORT)WinSendDlgItemMsg(hwnd, 97 ENV_LISTBOX, 98 LM_QUERYSELECTION, 99 MPFROMSHORT(LIT_FIRST), 100 MPVOID); 101 if(sSelect >= 0) { 102 *s = 0; 103 WinSendDlgItemMsg(hwnd, 104 ENV_LISTBOX, 105 LM_QUERYITEMTEXT, 106 MPFROM2SHORT(sSelect,CCHMAXPATH), 107 MPFROMP(s)); 108 bstrip(s); 109 if(*s) 110 WinSetDlgItemText(hwnd, 111 ENV_NAME, 112 s); 113 } 114 } 115 break; 116 case LN_ENTER: 117 PostMsg(hwnd, 118 WM_COMMAND, 119 MPFROM2SHORT(DID_OK,0), 120 MPVOID); 121 break; 122 } 123 } 124 return 0; 125 126 case WM_COMMAND: 127 switch(SHORT1FROMMP(mp1)) { 128 case DID_CANCEL: 129 WinDismissDlg(hwnd,0); 130 break; 131 case DID_OK: 132 { 133 CHAR *p = WinQueryWindowPtr(hwnd,QWL_USER); 134 135 if(p) { 136 WinQueryDlgItemText(hwnd, 137 ENV_NAME, 138 CCHMAXPATH, 139 p); 140 bstrip(p); 141 if(*p) { 142 strcpy(lastenv,p); 143 WinDismissDlg(hwnd,1); 144 } 145 else { 146 DosBeep(250,100); 147 WinSetFocus(HWND_DESKTOP, 148 WinWindowFromID(hwnd,ENV_NAME)); 149 } 150 } 151 } 152 break; 153 case IDM_HELP: 154 if(hwndHelp) 155 WinSendMsg(hwndHelp, 156 HM_DISPLAY_HELP, 157 MPFROM2SHORT(HELP_ENV,0), 158 MPFROMSHORT(HM_RESOURCEID)); 159 break; 160 } 161 return 0; 969 { 970 CHAR *str; 971 972 static GREP g; 973 974 str = malloc(8192 + 512); 975 if (!str) 976 { 977 DosBeep(50, 100); 978 break; 979 } 980 memset(&g, 0, sizeof(GREP)); 981 *str = 0; 982 g.size = sizeof(GREP); 983 if (WinQueryButtonCheckstate(hwnd, GREP_RECURSE)) 984 recurse = TRUE; 985 else 986 recurse = FALSE; 987 if (WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE)) 988 absolute = TRUE; 989 else 990 absolute = FALSE; 991 if (WinQueryButtonCheckstate(hwnd, GREP_CASE)) 992 sensitive = TRUE; 993 else 994 sensitive = FALSE; 995 if (WinQueryButtonCheckstate(hwnd, GREP_SAYFILES)) 996 sayfiles = TRUE; 997 else 998 sayfiles = FALSE; 999 if (WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS)) 1000 searchEAs = TRUE; 1001 else 1002 searchEAs = FALSE; 1003 if (WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES)) 1004 searchFiles = TRUE; 1005 else 1006 searchFiles = FALSE; 1007 if (WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY)) 1008 findifany = TRUE; 1009 else 1010 findifany = FALSE; 1011 if (WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES)) 1012 g.finddupes = TRUE; 1013 else 1014 g.finddupes = FALSE; 1015 if (g.finddupes) 1016 { 1017 if (WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES)) 1018 g.CRCdupes = TRUE; 1019 else 1020 g.CRCdupes = FALSE; 1021 if (WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES)) 1022 g.nosizedupes = TRUE; 1023 else 1024 g.nosizedupes = FALSE; 1025 if (WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES)) 1026 g.ignoreextdupes = TRUE; 1027 else 1028 g.ignoreextdupes = FALSE; 1029 } 1030 *str = 0; 1031 WinQueryDlgItemText(hwnd, 1032 GREP_MASK, 1033 8192, 1034 str); 1035 bstrip(str); 1036 if (!*str) 1037 { 1038 DosBeep(50, 100); 1039 WinSetFocus(HWND_DESKTOP, 1040 WinWindowFromID(hwnd, GREP_MASK)); 1041 free(str); 1042 break; 1043 } 1044 strcpy(g.tosearch, str); 1045 strcpy(lastmask, str); 1046 *str = 0; 1047 WinQueryWindowText(hwndMLE, 1048 4096, 1049 str); 1050 strcpy(lasttext, str); 1051 { 1052 CHAR *p; 1053 CHAR *pp; 1054 ULONG matched = 0; 1055 1056 pp = g.searchPattern; 1057 p = str; 1058 while (*p) 1059 { 1060 if (*p == '\r') 1061 { 1062 p++; 1063 continue; 1064 } 1065 if (*p == '\n') 1066 { 1067 if (*(p + 1)) 1068 matched++; 1069 *pp = 0; 1070 } 1071 else 1072 *pp = *p; 1073 pp++; 1074 p++; 1075 } 1076 if (*g.searchPattern) 1077 matched++; 1078 *pp = 0; 1079 pp++; 1080 *pp = 0; 1081 g.numlines = matched; 1082 g.matched = malloc(g.numlines); 1083 if (!g.matched) 1084 g.numlines = 0; 1085 } 1086 *str = 0; 1087 WinQueryDlgItemText(hwnd, 1088 GREP_GREATER, 1089 34, 1090 str); 1091 greater = atol(str); 1092 *str = 0; 1093 WinQueryDlgItemText(hwnd, 1094 GREP_LESSER, 1095 34, 1096 str); 1097 lesser = atol(str); 1098 *str = 0; 1099 WinQueryDlgItemText(hwnd, 1100 GREP_NEWER, 1101 34, 1102 str); 1103 newer = atoi(str); 1104 *str = 0; 1105 WinQueryDlgItemText(hwnd, 1106 GREP_OLDER, 1107 34, 1108 str); 1109 older = atoi(str); 1110 if (older || newer) 1111 { 1112 FDATE fdate; 1113 FTIME ftime; 1114 struct tm tm; 1115 time_t t; 1116 1117 t = time(NULL); 1118 tm = *localtime(&t); 1119 fdate.day = tm.tm_mday; 1120 fdate.month = tm.tm_mon + 1; 1121 fdate.year = tm.tm_year - 80; 1122 ftime.hours = tm.tm_hour; 1123 ftime.minutes = tm.tm_min; 1124 ftime.twosecs = tm.tm_sec / 2; 1125 if (older) 1126 { 1127 g.olderthan = SecsSince1980(&fdate, &ftime); 1128 g.olderthan -= (older * (24L * 60L * 60L)); 1129 } 1130 if (newer) 1131 { 1132 g.newerthan = SecsSince1980(&fdate, &ftime); 1133 g.newerthan -= (newer * (24L * 60L * 60L)); 1134 } 1135 } 1136 if (!newer) 1137 g.newerthan = 0; 1138 if (!older) 1139 g.olderthan = 0; 1140 g.greaterthan = greater; 1141 g.lessthan = lesser; 1142 g.absFlag = absolute; 1143 g.caseFlag = sensitive; 1144 g.dirFlag = recurse; 1145 g.sayfiles = sayfiles; 1146 g.searchEAs = searchEAs; 1147 g.searchFiles = searchFiles; 1148 g.findifany = findifany; 1149 g.hwndFiles = hwndCollect; 1150 g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT); 1151 g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED); 1152 g.attrFile = ((DIRCNRDATA *) INSTDATA(hwndCollect)) -> mask.attrFile; 1153 g.antiattr = ((DIRCNRDATA *) INSTDATA(hwndCollect)) -> mask.antiattr; 1154 g.stopflag = &((DIRCNRDATA *) INSTDATA(hwndCollect)) -> stopflag; 1155 if (_beginthread(dogrep, NULL, 524280, (PVOID) & g) == -1) 1156 { 1157 free(str); 1158 DosBeep(50, 100); 1159 WinDismissDlg(hwnd, 0); 1160 break; 1161 } 1162 else 1163 DosSleep(128L); 1164 free(str); 1165 } 1166 if (changed) 1167 { 1168 FILE *fp; 1169 SHORT sSelect; 1170 SHORT x; 1171 1172 static CHAR s[8192 + 14]; 1173 1174 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 1175 GREP_LISTBOX, 1176 LM_QUERYITEMCOUNT, 1177 MPVOID, 1178 MPVOID); 1179 if (sSelect > 0) 1180 { 1181 save_dir2(s); 1182 if (s[strlen(s) - 1] != '\\') 1183 strcat(s, "\\"); 1184 strcat(s, "GREPMASK.DAT"); 1185 fp = fopen(s, "w"); 1186 if (fp) 1187 { 1188 fputs(GetPString(IDS_GREPFILETEXT), fp); 1189 for (x = 0; x < sSelect; x++) 1190 { 1191 *s = 0; 1192 WinSendDlgItemMsg(hwnd, 1193 GREP_LISTBOX, 1194 LM_QUERYITEMTEXT, 1195 MPFROM2SHORT(x, 8192), 1196 MPFROMP(s)); 1197 bstrip(s); 1198 if (*s) 1199 fprintf(fp, "%s\n", s); 1200 } 1201 fclose(fp); 1202 } 1203 } 1204 } 1205 WinDismissDlg(hwnd, 1); 1206 break; 1207 } 1208 return 0; 162 1209 } 163 return WinDefDlgProc(hwnd, msg,mp1,mp2);1210 return WinDefDlgProc(hwnd, msg, mp1, mp2); 164 1211 } 165 166 167 MRESULT EXPENTRY GrepDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {168 169 static CHAR lastmask[8192] = "*",lasttext[4096] = "";170 static BOOL recurse = TRUE,sensitive = FALSE,absolute = FALSE,171 sayfiles = FALSE,searchEAs = TRUE,searchFiles = TRUE,172 changed = FALSE,findifany = TRUE;173 static UINT newer = 0L,older = 0L;174 static ULONG greater = 0L,lesser = 0L;175 HWND hwndCollect,hwndMLE = WinWindowFromID(hwnd,GREP_SEARCH);176 177 switch(msg) {178 case WM_INITDLG:179 if(!mp2) {180 WinDismissDlg(hwnd,0);181 break;182 }183 WinSetWindowULong(hwnd,QWL_USER,*(HWND *)mp2);184 WinSendDlgItemMsg(hwnd,185 GREP_MASK,186 EM_SETTEXTLIMIT,187 MPFROM2SHORT(8192,0),188 MPVOID);189 MLEsetlimit(hwndMLE,4096);190 MLEsetformat(hwndMLE,MLFIE_NOTRANS);191 WinSendDlgItemMsg(hwnd,192 GREP_NEWER,193 EM_SETTEXTLIMIT,194 MPFROM2SHORT(34,0),195 MPVOID);196 WinSendDlgItemMsg(hwnd,197 GREP_OLDER,198 EM_SETTEXTLIMIT,199 MPFROM2SHORT(34,0),200 MPVOID);201 WinSendDlgItemMsg(hwnd,202 GREP_GREATER,203 EM_SETTEXTLIMIT,204 MPFROM2SHORT(34,0),205 MPVOID);206 WinSendDlgItemMsg(hwnd,207 GREP_LESSER,208 EM_SETTEXTLIMIT,209 MPFROM2SHORT(34,0),210 MPVOID);211 WinSetDlgItemText(hwnd,212 GREP_MASK,213 lastmask);214 WinSendDlgItemMsg(hwnd,215 GREP_MASK,216 EM_SETSEL,217 MPFROM2SHORT(0,8192),218 MPVOID);219 WinSetWindowText(hwndMLE,lasttext);220 if(*lasttext) {221 MLEsetcurpos(hwndMLE,0);222 MLEsetcurposa(hwndMLE,4096);223 if(!searchEAs)224 searchFiles = TRUE;225 }226 WinCheckButton(hwnd,GREP_RECURSE,recurse);227 WinCheckButton(hwnd,GREP_ABSOLUTE,absolute);228 WinCheckButton(hwnd,GREP_CASE,sensitive);229 WinCheckButton(hwnd,GREP_SAYFILES,sayfiles);230 WinCheckButton(hwnd,GREP_SEARCHEAS,searchEAs);231 WinCheckButton(hwnd,GREP_SEARCHFILES,searchFiles);232 WinCheckButton(hwnd,GREP_FINDIFANY,findifany);233 {234 CHAR s[35];235 236 sprintf(s,"%lu",greater);237 WinSetDlgItemText(hwnd,GREP_GREATER,s);238 sprintf(s,"%lu",lesser);239 WinSetDlgItemText(hwnd,GREP_LESSER,s);240 sprintf(s,"%u",newer);241 WinSetDlgItemText(hwnd,GREP_NEWER,s);242 sprintf(s,"%u",older);243 WinSetDlgItemText(hwnd,GREP_OLDER,s);244 }245 WinEnableWindow(WinWindowFromID(hwnd,GREP_IGNOREEXTDUPES),FALSE);246 WinEnableWindow(WinWindowFromID(hwnd,GREP_CRCDUPES),FALSE);247 WinEnableWindow(WinWindowFromID(hwnd,GREP_NOSIZEDUPES),FALSE);248 {249 FILE *fp;250 static CHAR s[8192 + 14];251 252 save_dir2(s);253 if(s[strlen(s) - 1] != '\\')254 strcat(s,"\\");255 strcat(s,"GREPMASK.DAT");256 fp = _fsopen(s,"r",SH_DENYWR);257 if(fp) {258 while(!feof(fp)) {259 if(!fgets(s,8192 + 4,fp))260 break;261 bstripcr(s);262 if(*s && *s != ';')263 WinSendDlgItemMsg(hwnd,264 GREP_LISTBOX,265 LM_INSERTITEM,266 MPFROM2SHORT(LIT_SORTASCENDING,0),267 MPFROMP(s));268 }269 fclose(fp);270 }271 }272 FillPathListBox(hwnd,273 WinWindowFromID(hwnd,GREP_DRIVELIST),274 (HWND)0,275 NULL,276 FALSE);277 break;278 279 case WM_ADJUSTWINDOWPOS:280 PostMsg(hwnd,281 UM_SETDIR,282 MPVOID,283 MPVOID);284 break;285 286 case UM_SETDIR:287 PaintRecessedWindow(WinWindowFromID(hwnd,GREP_HELP),288 (HPS)0,289 FALSE,290 TRUE);291 return 0;292 293 case UM_FOCUSME:294 /* set focus to window hwnd in mp1 */295 if(mp1)296 WinSetFocus(HWND_DESKTOP,(HWND)mp1);297 return 0;298 299 case WM_CONTROL:300 switch(SHORT1FROMMP(mp1)) {301 case GREP_DRIVELIST:302 switch(SHORT2FROMMP(mp1)) {303 case LN_KILLFOCUS:304 WinSetDlgItemText(hwnd,305 GREP_HELP,306 GetPString(IDS_ARCDEFAULTHELPTEXT));307 break;308 case LN_SETFOCUS:309 WinSetDlgItemText(hwnd,310 GREP_HELP,311 GetPString(IDS_2CLICKADDDRVMASKTEXT));312 break;313 case LN_ENTER:314 {315 SHORT sSelect;316 static CHAR s[8192],simple[8192],*p;317 LONG len;318 319 WinQueryDlgItemText(hwnd,320 GREP_MASK,321 8192,322 s);323 bstrip(s);324 p = strrchr(s,'\\');325 if(p)326 strcpy(simple,p);327 else if(*s) {328 strcpy(simple,"\\");329 strcat(simple,s);330 *s = 0;331 }332 else333 strcpy(simple,"\\*");334 if(simple[strlen(simple) - 1] == ';')335 simple[strlen(simple) - 1] = 0;336 len = strlen(simple) + 1;337 if(strlen(s) > 8192 - len) {338 DosBeep(250,100);339 WinSetDlgItemText(hwnd,340 GREP_MASK,341 s);342 break;343 }344 345 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,346 GREP_DRIVELIST,347 LM_QUERYSELECTION,348 MPFROMSHORT(LIT_FIRST),349 MPVOID);350 if(sSelect >= 0) {351 if(*s && s[strlen(s) - 1] != ';')352 strcat(s,";");353 WinSendDlgItemMsg(hwnd,354 GREP_DRIVELIST,355 LM_QUERYITEMTEXT,356 MPFROM2SHORT(sSelect,357 (8192 - strlen(s)) - len),358 MPFROMP(&s[strlen(s)]));359 rstrip(s);360 if(*s) {361 strcat(s,simple);362 WinSetDlgItemText(hwnd,363 GREP_MASK,364 s);365 WinSendDlgItemMsg(hwnd,366 GREP_MASK,367 EM_SETSEL,368 MPFROM2SHORT(strlen(s) - (len + 1),369 strlen(s)),370 MPVOID);371 PostMsg(hwnd,372 UM_FOCUSME,373 MPFROMLONG(WinWindowFromID(hwnd,GREP_MASK)),374 MPVOID);375 }376 }377 }378 break;379 }380 break;381 case GREP_LISTBOX:382 switch(SHORT2FROMMP(mp1)) {383 case LN_KILLFOCUS:384 WinSetDlgItemText(hwnd,385 GREP_HELP,386 GetPString(IDS_ARCDEFAULTHELPTEXT));387 break;388 case LN_SETFOCUS:389 WinSetDlgItemText(hwnd,390 GREP_HELP,391 GetPString(IDS_ADDSELDELMASKTEXT));392 break;393 case LN_ENTER:394 case LN_SELECT:395 if((SHORT2FROMMP(mp1) == LN_ENTER &&396 !WinQueryButtonCheckstate(hwnd,GREP_APPEND)) ||397 (SHORT2FROMMP(mp1) == LN_SELECT &&398 WinQueryButtonCheckstate(hwnd,GREP_APPEND)))399 break;400 {401 SHORT sSelect;402 static CHAR s[8192];403 404 *s = 0;405 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,406 GREP_LISTBOX,407 LM_QUERYSELECTION,408 MPFROMSHORT(LIT_FIRST),409 MPVOID);410 if(sSelect >= 0) {411 if(WinQueryButtonCheckstate(hwnd,GREP_APPEND)) {412 WinQueryDlgItemText(hwnd,413 GREP_MASK,414 8192,415 s);416 bstrip(s);417 if(*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')418 strcat(s,";");419 }420 WinSendDlgItemMsg(hwnd,421 GREP_LISTBOX,422 LM_QUERYITEMTEXT,423 MPFROM2SHORT(sSelect,8192 - strlen(s)),424 MPFROMP(s + strlen(s)));425 bstrip(s);426 if(*s)427 WinSetDlgItemText(hwnd,428 GREP_MASK,429 s);430 }431 }432 break;433 }434 break;435 case GREP_MASK:436 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)437 WinSetDlgItemText(hwnd,438 GREP_HELP,439 GetPString(IDS_ARCDEFAULTHELPTEXT));440 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)441 WinSetDlgItemText(hwnd,442 GREP_HELP,443 GetPString(IDS_MASKSFINDTEXT));444 break;445 case GREP_SEARCH:446 if(SHORT2FROMMP(mp1) == MLN_KILLFOCUS)447 WinSetDlgItemText(hwnd,448 GREP_HELP,449 GetPString(IDS_ARCDEFAULTHELPTEXT));450 if(SHORT2FROMMP(mp1) == MLN_SETFOCUS)451 WinSetDlgItemText(hwnd,452 GREP_HELP,453 GetPString(IDS_TEXTFINDTEXT));454 break;455 case GREP_GREATER:456 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)457 WinSetDlgItemText(hwnd,458 GREP_HELP,459 GetPString(IDS_ARCDEFAULTHELPTEXT));460 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)461 WinSetDlgItemText(hwnd,462 GREP_HELP,463 GetPString(IDS_MINSIZEFINDTEXT));464 break;465 case GREP_LESSER:466 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)467 WinSetDlgItemText(hwnd,468 GREP_HELP,469 GetPString(IDS_ARCDEFAULTHELPTEXT));470 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)471 WinSetDlgItemText(hwnd,472 GREP_HELP,473 GetPString(IDS_MAXSIZEFINDTEXT));474 break;475 case GREP_NEWER:476 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)477 WinSetDlgItemText(hwnd,478 GREP_HELP,479 GetPString(IDS_ARCDEFAULTHELPTEXT));480 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)481 WinSetDlgItemText(hwnd,482 GREP_HELP,483 GetPString(IDS_MAXAGEFINDTEXT));484 break;485 case GREP_OLDER:486 if(SHORT2FROMMP(mp1) == EN_KILLFOCUS)487 WinSetDlgItemText(hwnd,488 GREP_HELP,489 GetPString(IDS_ARCDEFAULTHELPTEXT));490 if(SHORT2FROMMP(mp1) == EN_SETFOCUS)491 WinSetDlgItemText(hwnd,492 GREP_HELP,493 GetPString(IDS_MINAGEFINDTEXT));494 break;495 case GREP_FINDDUPES:496 {497 BOOL finddupes = WinQueryButtonCheckstate(hwnd,GREP_FINDDUPES);498 499 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCH),!finddupes);500 WinEnableWindow(WinWindowFromID(hwnd,GREP_ABSOLUTE),!finddupes);501 WinEnableWindow(WinWindowFromID(hwnd,GREP_CASE),!finddupes);502 WinEnableWindow(WinWindowFromID(hwnd,GREP_CRCDUPES),finddupes);503 WinEnableWindow(WinWindowFromID(hwnd,GREP_NOSIZEDUPES),finddupes);504 WinEnableWindow(WinWindowFromID(hwnd,GREP_IGNOREEXTDUPES),finddupes);505 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCHFILES),!finddupes);506 WinEnableWindow(WinWindowFromID(hwnd,GREP_SEARCHEAS),!finddupes);507 WinEnableWindow(WinWindowFromID(hwnd,GREP_GREATER),!finddupes);508 WinEnableWindow(WinWindowFromID(hwnd,GREP_LESSER),!finddupes);509 WinEnableWindow(WinWindowFromID(hwnd,GREP_NEWER),!finddupes);510 WinEnableWindow(WinWindowFromID(hwnd,GREP_OLDER),!finddupes);511 WinEnableWindow(WinWindowFromID(hwnd,GREP_FINDIFANY),!finddupes);512 WinEnableWindow(WinWindowFromID(hwnd,GREP_GK),!finddupes);513 WinEnableWindow(WinWindowFromID(hwnd,GREP_LK),!finddupes);514 WinEnableWindow(WinWindowFromID(hwnd,GREP_NM),!finddupes);515 WinEnableWindow(WinWindowFromID(hwnd,GREP_OM),!finddupes);516 if(finddupes)517 WinCheckButton(hwnd,GREP_RECURSE,TRUE);518 }519 }520 return 0;521 522 case WM_COMMAND:523 switch(SHORT1FROMMP(mp1)) {524 case GREP_ENV:525 {526 CHAR path[CCHMAXPATH];527 CHAR *p,*t;528 static CHAR s[8192],simple[8192],env[8192];529 LONG len;530 531 *path = 0;532 if (!WinDlgBox(HWND_DESKTOP,533 hwnd,534 EnvDlgProc,535 FM3ModHandle,536 ENV_FRAME,537 path)) {538 break;539 }540 bstrip(path);541 if (!*path)542 break;543 if(!stricmp(path,"LIBPATH"))544 LoadLibPath(env,8192);545 else {546 p = getenv(path);547 if(!p)548 break;549 strcpy(env,p);550 }551 bstrip(env);552 if(!*env)553 break;554 WinQueryDlgItemText(hwnd,555 GREP_MASK,556 8192,557 s);558 bstrip(s);559 if(strlen(s) > 8192 - 5) {560 DosBeep(50,100);561 break;562 }563 p = strrchr(s,'\\');564 if(p)565 strcpy(simple,p + 1);566 else if(*s)567 strcpy(simple,s);568 else569 strcpy(simple,"*");570 if(!p)571 *s = 0;572 if(simple[strlen(simple) - 1] == ';')573 simple[strlen(simple) - 1] = 0;574 len = strlen(simple) + 1;575 p = env;576 while(p && *p) {577 strncpy(path,p,CCHMAXPATH - 1);578 path[CCHMAXPATH - 1] = 0;579 t = strchr(path,';');580 if(t)581 *t = 0;582 bstrip(path);583 if(isalpha(*path) && path[1] == ':' && path[2] == '\\') {584 if(strlen(s) > (8192 - len) - (strlen(path) + 1)) {585 WinSetDlgItemText(hwnd,586 GREP_MASK,587 s);588 break;589 }590 if(!*s || (*s && s[strlen(s) - 1] != ';')) {591 if(*s)592 strcat(s,";");593 strcat(s,path);594 len += strlen(path);595 if(s[strlen(s) - 1] != '\\') {596 len++;597 strcat(s,"\\");598 }599 rstrip(s);600 if(*s) {601 strcat(s,simple);602 WinSetDlgItemText(hwnd,603 GREP_MASK,604 s);605 WinSendDlgItemMsg(hwnd,606 GREP_MASK,607 EM_SETSEL,608 MPFROM2SHORT(strlen(s) - (len - 1),609 strlen(s)),610 MPVOID);611 }612 }613 }614 p = strchr(p,';');615 if(p)616 p++;617 }618 }619 break;620 621 case GREP_WALK:622 {623 CHAR path[CCHMAXPATH],*p;624 static CHAR s[8192],simple[8192];625 LONG len;626 627 WinQueryDlgItemText(hwnd,628 GREP_MASK,629 8192,630 s);631 bstrip(s);632 if(strlen(s) > 8192 - 5) {633 DosBeep(50,100);634 break;635 }636 *path = 0;637 if(WinDlgBox(HWND_DESKTOP,638 hwnd,639 WalkAllDlgProc,640 FM3ModHandle,641 WALK_FRAME,642 MPFROMP(path)) &&643 *path) {644 p = strrchr(s,'\\');645 if(p)646 strcpy(simple,p + 1);647 else if(*s)648 strcpy(simple,s);649 else650 strcpy(simple,"*");651 if(!p)652 *s = 0;653 if(simple[strlen(simple) - 1] == ';')654 simple[strlen(simple) - 1] = 0;655 len = strlen(simple) + 1;656 if(strlen(s) > (8192 - len) - (strlen(path) + 1)) {657 DosBeep(250,100);658 WinSetDlgItemText(hwnd,659 GREP_MASK,660 s);661 break;662 }663 if(!*s || (*s && s[strlen(s) - 1] != ';')) {664 if(*s)665 strcat(s,";");666 strcat(s,path);667 len += strlen(path);668 if(s[strlen(s) - 1] != '\\') {669 len++;670 strcat(s,"\\");671 }672 rstrip(s);673 if(*s) {674 strcat(s,simple);675 WinSetDlgItemText(hwnd,676 GREP_MASK,677 s);678 WinSendDlgItemMsg(hwnd,679 GREP_MASK,680 EM_SETSEL,681 MPFROM2SHORT(strlen(s) - (len - 1),682 strlen(s)),683 MPVOID);684 }685 }686 }687 }688 break;689 690 case GREP_ADD:691 {692 static CHAR s[8192];693 SHORT sSelect;694 695 *s = 0;696 WinQueryDlgItemText(hwnd,697 GREP_MASK,698 8192,699 s);700 bstrip(s);701 if(*s) {702 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,703 GREP_LISTBOX,704 LM_SEARCHSTRING,705 MPFROM2SHORT(0,LIT_FIRST),706 MPFROMP(s));707 if(sSelect < 0) {708 WinSendDlgItemMsg(hwnd,709 GREP_LISTBOX,710 LM_INSERTITEM,711 MPFROM2SHORT(LIT_SORTASCENDING,0),712 MPFROMP(s));713 changed = TRUE;714 }715 }716 }717 break;718 719 case GREP_DELETE:720 {721 SHORT sSelect;722 723 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,724 GREP_LISTBOX,725 LM_QUERYSELECTION,726 MPFROMSHORT(LIT_FIRST),727 MPVOID);728 if(sSelect >= 0) {729 WinSendDlgItemMsg(hwnd,730 GREP_LISTBOX,731 LM_DELETEITEM,732 MPFROM2SHORT(sSelect,0),733 MPVOID);734 changed = TRUE;735 }736 }737 break;738 739 case GREP_OM:740 {741 CHAR str[81];742 UINT temp;743 744 *str = 0;745 WinQueryDlgItemText(hwnd,746 GREP_OLDER,747 34,748 str);749 temp = atoi(str) * 30L;750 sprintf(str,"%u",temp);751 WinSetDlgItemText(hwnd,752 GREP_OLDER,753 str);754 }755 break;756 757 case GREP_NM:758 {759 CHAR str[81];760 UINT temp;761 762 *str = 0;763 WinQueryDlgItemText(hwnd,764 GREP_NEWER,765 34,766 str);767 temp = atoi(str) * 30L;768 sprintf(str,"%u",temp);769 WinSetDlgItemText(hwnd,770 GREP_NEWER,771 str);772 }773 break;774 775 case GREP_GK:776 {777 CHAR str[81];778 ULONG temp;779 780 *str = 0;781 WinQueryDlgItemText(hwnd,782 GREP_GREATER,783 34,784 str);785 temp = atol(str) * 1024L;786 sprintf(str,"%lu",temp);787 WinSetDlgItemText(hwnd,GREP_GREATER,str);788 }789 break;790 791 case GREP_LK:792 {793 CHAR str[81];794 ULONG temp;795 796 *str = 0;797 WinQueryDlgItemText(hwnd,798 GREP_LESSER,799 34,800 str);801 temp = atol(str) * 1024L;802 sprintf(str,"%lu",temp);803 WinSetDlgItemText(hwnd,804 GREP_LESSER,805 str);806 }807 break;808 809 case DID_CANCEL:810 WinDismissDlg(hwnd,0);811 break;812 813 case IDM_HELP:814 if(hwndHelp)815 WinSendMsg(hwndHelp,816 HM_DISPLAY_HELP,817 MPFROM2SHORT(HELP_GREP,0),818 MPFROMSHORT(HM_RESOURCEID));819 break;820 821 case GREP_LOCALHDS:822 case GREP_REMOTEHDS:823 case GREP_ALLHDS:824 {825 static CHAR str[8192],new[8192];826 CHAR *p,*szDrive = " :\\";827 ULONG ulDriveNum,ulDriveMap;828 INT x;829 BOOL incl;830 831 *str = *new = 0;832 WinQueryDlgItemText(hwnd,833 GREP_MASK,834 8192,835 str);836 str[8192 - 1] = 0;837 p = strchr(str,';');838 if(p)839 *p = 0;840 p = strrchr(str,'\\');841 if(!p)842 p = strrchr(str,'/');843 if(!p)844 p = strrchr(str,':');845 if(p)846 strcpy(str,p + 1);847 if(!*str)848 strcpy(str,"*");849 *new = 0;850 DosError(FERR_DISABLEHARDERR);851 DosQCurDisk(&ulDriveNum,852 &ulDriveMap);853 for(x = 2;x < 26;x++) {854 if(ulDriveMap & (1L << x)) {855 incl = FALSE;856 switch(SHORT1FROMMP(mp1)) {857 case GREP_ALLHDS:858 if(!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE)))859 incl = TRUE;860 break;861 case GREP_LOCALHDS:862 if(!(driveflags[x] &863 (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE)))864 incl = TRUE;865 break;866 case GREP_REMOTEHDS:867 if(!(driveflags[x] &868 (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&869 (driveflags[x] & DRIVE_REMOTE))870 incl = TRUE;871 break;872 }873 }874 if(incl) {875 if(strlen(new) + strlen(str) + 5 < 8192 - 1) {876 if(*new)877 strcat(new,";");878 *szDrive = x + 'A';879 strcat(new,szDrive);880 strcat(new,str);881 }882 }883 }884 if(*new)885 WinSetDlgItemText(hwnd,886 GREP_MASK,887 new);888 }889 break;890 891 case DID_OK:892 hwndCollect = WinQueryWindowULong(hwnd,QWL_USER);893 if(!hwndCollect)894 DosBeep(50,100);895 else {896 897 static GREP g;898 CHAR *str;899 900 str = malloc(8192 + 512);901 if(!str) {902 DosBeep(50,100);903 break;904 }905 memset(&g,0,sizeof(GREP));906 *str = 0;907 g.size = sizeof(GREP);908 if(WinQueryButtonCheckstate(hwnd,GREP_RECURSE))909 recurse = TRUE;910 else911 recurse = FALSE;912 if(WinQueryButtonCheckstate(hwnd,GREP_ABSOLUTE))913 absolute = TRUE;914 else915 absolute = FALSE;916 if(WinQueryButtonCheckstate(hwnd,GREP_CASE))917 sensitive = TRUE;918 else919 sensitive = FALSE;920 if(WinQueryButtonCheckstate(hwnd,GREP_SAYFILES))921 sayfiles = TRUE;922 else923 sayfiles = FALSE;924 if(WinQueryButtonCheckstate(hwnd,GREP_SEARCHEAS))925 searchEAs = TRUE;926 else927 searchEAs = FALSE;928 if(WinQueryButtonCheckstate(hwnd,GREP_SEARCHFILES))929 searchFiles = TRUE;930 else931 searchFiles = FALSE;932 if(WinQueryButtonCheckstate(hwnd,GREP_FINDIFANY))933 findifany = TRUE;934 else935 findifany = FALSE;936 if(WinQueryButtonCheckstate(hwnd,GREP_FINDDUPES))937 g.finddupes = TRUE;938 else939 g.finddupes = FALSE;940 if(g.finddupes) {941 if(WinQueryButtonCheckstate(hwnd,GREP_CRCDUPES))942 g.CRCdupes = TRUE;943 else944 g.CRCdupes = FALSE;945 if(WinQueryButtonCheckstate(hwnd,GREP_NOSIZEDUPES))946 g.nosizedupes = TRUE;947 else948 g.nosizedupes = FALSE;949 if(WinQueryButtonCheckstate(hwnd,GREP_IGNOREEXTDUPES))950 g.ignoreextdupes = TRUE;951 else952 g.ignoreextdupes = FALSE;953 }954 *str = 0;955 WinQueryDlgItemText(hwnd,956 GREP_MASK,957 8192,958 str);959 bstrip(str);960 if(!*str) {961 DosBeep(50,100);962 WinSetFocus(HWND_DESKTOP,963 WinWindowFromID(hwnd,GREP_MASK));964 free(str);965 break;966 }967 strcpy(g.tosearch,str);968 strcpy(lastmask,str);969 *str = 0;970 WinQueryWindowText(hwndMLE,971 4096,972 str);973 strcpy(lasttext,str);974 {975 CHAR *p,*pp;976 ULONG matched = 0;977 978 pp = g.searchPattern;979 p = str;980 while(*p) {981 if(*p == '\r') {982 p++;983 continue;984 }985 if(*p == '\n') {986 if(*(p + 1))987 matched++;988 *pp = 0;989 }990 else991 *pp = *p;992 pp++;993 p++;994 }995 if(*g.searchPattern)996 matched++;997 *pp = 0;998 pp++;999 *pp = 0;1000 g.numlines = matched;1001 g.matched = malloc(g.numlines);1002 if(!g.matched)1003 g.numlines = 0;1004 }1005 *str = 0;1006 WinQueryDlgItemText(hwnd,1007 GREP_GREATER,1008 34,1009 str);1010 greater = atol(str);1011 *str = 0;1012 WinQueryDlgItemText(hwnd,1013 GREP_LESSER,1014 34,1015 str);1016 lesser = atol(str);1017 *str = 0;1018 WinQueryDlgItemText(hwnd,1019 GREP_NEWER,1020 34,1021 str);1022 newer = atoi(str);1023 *str = 0;1024 WinQueryDlgItemText(hwnd,1025 GREP_OLDER,1026 34,1027 str);1028 older = atoi(str);1029 if(older || newer) {1030 1031 FDATE fdate;1032 FTIME ftime;1033 struct tm tm;1034 time_t t;1035 1036 t = time(NULL);1037 tm = *localtime(&t);1038 fdate.day = tm.tm_mday;1039 fdate.month = tm.tm_mon + 1;1040 fdate.year = tm.tm_year - 80;1041 ftime.hours = tm.tm_hour;1042 ftime.minutes = tm.tm_min;1043 ftime.twosecs = tm.tm_sec / 2;1044 if(older) {1045 g.olderthan = SecsSince1980(&fdate,&ftime);1046 g.olderthan -= (older * (24L * 60L * 60L));1047 }1048 if(newer) {1049 g.newerthan = SecsSince1980(&fdate,&ftime);1050 g.newerthan -= (newer * (24L * 60L * 60L));1051 }1052 }1053 if(!newer)1054 g.newerthan = 0;1055 if(!older)1056 g.olderthan = 0;1057 g.greaterthan = greater;1058 g.lessthan = lesser;1059 g.absFlag = absolute;1060 g.caseFlag = sensitive;1061 g.dirFlag = recurse;1062 g.sayfiles = sayfiles;1063 g.searchEAs = searchEAs;1064 g.searchFiles = searchFiles;1065 g.findifany = findifany;1066 g.hwndFiles = hwndCollect;1067 g.hwnd = WinQueryWindow(hwndCollect,QW_PARENT);1068 g.hwndCurFile = WinWindowFromID(g.hwnd,DIR_SELECTED);1069 g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;1070 g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;1071 g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;1072 if(_beginthread(dogrep,NULL,524280,(PVOID)&g) == -1) {1073 free(str);1074 DosBeep(50,100);1075 WinDismissDlg(hwnd,0);1076 break;1077 }1078 else1079 DosSleep(128L);1080 free(str);1081 }1082 if(changed) {1083 1084 FILE *fp;1085 static CHAR s[8192 + 14];1086 SHORT sSelect,x;1087 1088 sSelect = (SHORT)WinSendDlgItemMsg(hwnd,1089 GREP_LISTBOX,1090 LM_QUERYITEMCOUNT,1091 MPVOID,1092 MPVOID);1093 if(sSelect > 0) {1094 save_dir2(s);1095 if(s[strlen(s) - 1] != '\\')1096 strcat(s,"\\");1097 strcat(s,"GREPMASK.DAT");1098 fp = fopen(s,"w");1099 if(fp) {1100 fputs(GetPString(IDS_GREPFILETEXT),fp);1101 for(x = 0;x < sSelect;x++) {1102 *s = 0;1103 WinSendDlgItemMsg(hwnd,1104 GREP_LISTBOX,1105 LM_QUERYITEMTEXT,1106 MPFROM2SHORT(x,8192),1107 MPFROMP(s));1108 bstrip(s);1109 if(*s)1110 fprintf(fp,"%s\n",s);1111 }1112 fclose(fp);1113 }1114 }1115 }1116 WinDismissDlg(hwnd,1);1117 break;1118 }1119 return 0;1120 }1121 return WinDefDlgProc(hwnd,msg,mp1,mp2);1122 }1123
Note:
See TracChangeset
for help on using the changeset viewer.