source: trunk/dll/grep2.c@ 382

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

Use RuntimeError2

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