source: trunk/dll/grep2.c@ 402

Last change on this file since 402 was 402, checked in by root, 19 years ago

Avoid 0 length malloc, optimize option checks
Use xfgets

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