Changeset 1335 for trunk/dll/grep2.c


Ignore:
Timestamp:
Dec 13, 2008, 12:49:02 AM (17 years ago)
Author:
Steven Levine
Message:

Ticket 26: Add exception handlers to all threads using xbeginthread

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep2.c

    r1283 r1335  
    44  $Id$
    55
    6   Grep dialog for collector
     6  grep dialog for collector
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2004, 2006 Steven H. Levine
     9  Copyright (c) 2004, 2008 Steven H. Levine
    1010
    1111  01 Aug 04 SHL Rework lstrip/rstrip usage
     
    2222  19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
    2323  24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
     24  10 Dec 08 SHL Integrate exception handler support
    2425
    2526  fixme for more excess locals to be gone
     
    3233#include <share.h>
    3334#include <time.h>
    34 #include <process.h>                    // _beginthread
     35// #include <process.h>                    // _beginthread
    3536
    3637#define INCL_DOS
     
    6061#include "dirs.h"                       // save_dir2
    6162#include "fortify.h"
     63#include "excputil.h"                   // xbeginthread
    6264
    6365#pragma data_seg(DATA1)
     
    8082      *(CHAR *)mp2 = 0;
    8183      {
    82         CHAR *p;
    83         CHAR *pp;
    84 
    85         p = GetPString(IDS_ENVVARNAMES);
    86         while (*p == ' ')
    87           p++;
    88         while (*p) {
    89           *szPath = 0;
    90           pp = szPath;
    91           while (*p && *p != ' ')
    92             *pp++ = *p++;
    93           *pp = 0;
    94           while (*p == ' ')
    95             p++;
    96           if (*szPath)
    97             WinSendDlgItemMsg(hwnd,
    98                               ENV_LISTBOX,
    99                               LM_INSERTITEM,
    100                               MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath));
    101         }
     84        CHAR *p;
     85        CHAR *pp;
     86
     87        p = GetPString(IDS_ENVVARNAMES);
     88        while (*p == ' ')
     89          p++;
     90        while (*p) {
     91          *szPath = 0;
     92          pp = szPath;
     93          while (*p && *p != ' ')
     94            *pp++ = *p++;
     95          *pp = 0;
     96          while (*p == ' ')
     97            p++;
     98          if (*szPath)
     99            WinSendDlgItemMsg(hwnd,
     100                              ENV_LISTBOX,
     101                              LM_INSERTITEM,
     102                              MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath));
     103        }
    102104      }
    103105      WinSendDlgItemMsg(hwnd,
    104                         ENV_NAME,
    105                         EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
     106                        ENV_NAME,
     107                        EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
    106108      WinSetDlgItemText(hwnd, ENV_NAME, lastenv);
    107109      WinSendDlgItemMsg(hwnd,
    108                         ENV_NAME,
    109                         EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
     110                        ENV_NAME,
     111                        EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
    110112    }
    111113    else
     
    118120      switch (SHORT2FROMMP(mp1)) {
    119121      case LN_SELECT:
    120         {
    121           sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    122                                               ENV_LISTBOX,
    123                                               LM_QUERYSELECTION,
    124                                               MPFROMSHORT(LIT_FIRST), MPVOID);
    125           if (sSelect >= 0) {
    126             *s = 0;
    127             WinSendDlgItemMsg(hwnd,
    128                               ENV_LISTBOX,
    129                               LM_QUERYITEMTEXT,
    130                               MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
    131             bstrip(s);
    132             if (*s)
    133               WinSetDlgItemText(hwnd, ENV_NAME, s);
    134           }
    135         }
    136         break;
     122        {
     123          sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     124                                              ENV_LISTBOX,
     125                                              LM_QUERYSELECTION,
     126                                              MPFROMSHORT(LIT_FIRST), MPVOID);
     127          if (sSelect >= 0) {
     128            *s = 0;
     129            WinSendDlgItemMsg(hwnd,
     130                              ENV_LISTBOX,
     131                              LM_QUERYITEMTEXT,
     132                              MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
     133            bstrip(s);
     134            if (*s)
     135              WinSetDlgItemText(hwnd, ENV_NAME, s);
     136          }
     137        }
     138        break;
    137139      case LN_ENTER:
    138         PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
    139         break;
     140        PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
     141        break;
    140142      }
    141143    }
     
    150152      p = WinQueryWindowPtr(hwnd, QWL_USER);
    151153      if (p) {
    152         WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
    153         bstrip(p);
    154         if (!*p) {
    155           DosBeep(50, 100);
    156           WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
    157         }
    158         else {
    159           strcpy(lastenv, p);
    160           WinDismissDlg(hwnd, 1);
    161         }
     154        WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
     155        bstrip(p);
     156        if (!*p) {
     157          DosBeep(50, 100);
     158          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
     159        }
     160        else {
     161          strcpy(lastenv, p);
     162          WinDismissDlg(hwnd, 1);
     163        }
    162164      }
    163165      break;
    164166    case IDM_HELP:
    165167      if (hwndHelp)
    166         WinSendMsg(hwndHelp,
    167                    HM_DISPLAY_HELP,
    168                    MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
     168        WinSendMsg(hwndHelp,
     169                   HM_DISPLAY_HELP,
     170                   MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
    169171      break;
    170172    }
     
    212214    WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2);
    213215    WinSendDlgItemMsg(hwnd,
    214                       GREP_MASK,
    215                       EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
     216                      GREP_MASK,
     217                      EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
    216218    MLEsetlimit(hwndMLE, 4096);
    217219    MLEsetformat(hwndMLE, MLFIE_NOTRANS);
    218220    WinSendDlgItemMsg(hwnd,
    219                       GREP_NEWER,
    220                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     221                      GREP_NEWER,
     222                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    221223    WinSendDlgItemMsg(hwnd,
    222                       GREP_OLDER,
    223                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     224                      GREP_OLDER,
     225                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    224226    WinSendDlgItemMsg(hwnd,
    225                       GREP_GREATER,
    226                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     227                      GREP_GREATER,
     228                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    227229    WinSendDlgItemMsg(hwnd,
    228                       GREP_LESSER,
    229                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     230                      GREP_LESSER,
     231                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    230232    WinSetDlgItemText(hwnd, GREP_MASK, lastmask);
    231233    WinSendDlgItemMsg(hwnd,
    232                       GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID);
     234                      GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID);
    233235    PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep",
    234                         (PVOID) & gRemember, &size);
     236                        (PVOID) & gRemember, &size);
    235237    WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember);
    236238    if (gRemember) {
    237239      PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse",
    238                           (PVOID) & recurse, &size);
     240                          (PVOID) & recurse, &size);
    239241      PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute",
    240                           (PVOID) & absolute, &size);
     242                          (PVOID) & absolute, &size);
    241243      PrfQueryProfileData(fmprof, FM3Str, "Grep_Case",
    242                           (PVOID) & sensitive, &size);
     244                          (PVOID) & sensitive, &size);
    243245      PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles",
    244                           (PVOID) & sayfiles, &size);
     246                          (PVOID) & sayfiles, &size);
    245247      PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles",
    246                           (PVOID) & searchFiles, &size);
     248                          (PVOID) & searchFiles, &size);
    247249      PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
    248                           (PVOID) & searchEAs, &size);
     250                          (PVOID) & searchEAs, &size);
    249251    }
    250252    if (!gRemember) {
     
    261263      MLEsetcurposa(hwndMLE, 4096);
    262264      if (!searchEAs)
    263         searchFiles = TRUE;
     265        searchFiles = TRUE;
    264266    }
    265267    WinCheckButton(hwnd, GREP_RECURSE, recurse);
     
    288290    if (fp) {
    289291      while (!feof(fp)) {
    290         if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
    291           break;
    292         if (*s && *s != ';') {
    293           WinSendDlgItemMsg(hwnd,
    294                             GREP_LISTBOX,
    295                             LM_INSERTITEM,
    296                             MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
    297         }
     292        if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
     293          break;
     294        if (*s && *s != ';') {
     295          WinSendDlgItemMsg(hwnd,
     296                            GREP_LISTBOX,
     297                            LM_INSERTITEM,
     298                            MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
     299        }
    298300      }
    299301      fclose(fp);
     
    301303
    302304    FillPathListBox(hwnd,
    303                     WinWindowFromID(hwnd, GREP_DRIVELIST),
    304                     (HWND) 0, NULL, FALSE);
     305                    WinWindowFromID(hwnd, GREP_DRIVELIST),
     306                    (HWND) 0, NULL, FALSE);
    305307    break;
    306308
     
    311313  case UM_SETDIR:
    312314    PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
    313                         (HPS) 0, FALSE, TRUE);
     315                        (HPS) 0, FALSE, TRUE);
    314316    return 0;
    315317
     
    324326    case GREP_REMEMBERFLAGS:
    325327      {
    326         BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
    327 
    328         PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
    329                             (PVOID) & gRemember, sizeof(BOOL));
     328        BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
     329
     330        PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
     331                            (PVOID) & gRemember, sizeof(BOOL));
    330332      }
    331333      break;
     
    334336      switch (SHORT2FROMMP(mp1)) {
    335337      case LN_KILLFOCUS:
    336         WinSetDlgItemText(hwnd,
    337                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    338         break;
     338        WinSetDlgItemText(hwnd,
     339                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     340        break;
    339341      case LN_SETFOCUS:
    340         WinSetDlgItemText(hwnd,
    341                           GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
    342         break;
     342        WinSetDlgItemText(hwnd,
     343                          GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
     344        break;
    343345      case LN_ENTER:
    344         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    345         bstrip(s);
    346         p = strrchr(s, '\\');
    347         if (p)
    348           strcpy(simple, p);
    349         else if (*s) {
    350           strcpy(simple, "\\");
    351           strcat(simple, s);
    352           *s = 0;
    353         }
    354         else
    355           strcpy(simple, "\\*");
    356         if (simple[strlen(simple) - 1] == ';')
    357           simple[strlen(simple) - 1] = 0;
    358         lLen = strlen(simple) + 1;
    359         if (strlen(s) > 8192 - lLen) {
    360           Runtime_Error(pszSrcFile, __LINE__, "too big");
    361           WinSetDlgItemText(hwnd, GREP_MASK, s);
    362           break;
    363         }
    364 
    365         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    366                                             GREP_DRIVELIST,
    367                                             LM_QUERYSELECTION,
    368                                             MPFROMSHORT(LIT_FIRST), MPVOID);
    369         if (sSelect >= 0) {
    370           if (*s && s[strlen(s) - 1] != ';')
    371             strcat(s, ";");
    372           WinSendDlgItemMsg(hwnd,
    373                             GREP_DRIVELIST,
    374                             LM_QUERYITEMTEXT,
    375                             MPFROM2SHORT(sSelect,
    376                                         (8192 - strlen(s)) - lLen),
    377                             MPFROMP(&s[strlen(s)]));
    378           rstrip(s);
    379           if (*s) {
    380             strcat(s, simple);
    381             WinSetDlgItemText(hwnd, GREP_MASK, s);
    382             WinSendDlgItemMsg(hwnd,
    383                               GREP_MASK,
    384                               EM_SETSEL,
    385                               MPFROM2SHORT(strlen(s) - (lLen + 1),
    386                                            strlen(s)), MPVOID);
    387             PostMsg(hwnd,
    388                     UM_FOCUSME,
    389                     MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
    390           }
    391         }
    392         break;                          // LN_ENTER
     346        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     347        bstrip(s);
     348        p = strrchr(s, '\\');
     349        if (p)
     350          strcpy(simple, p);
     351        else if (*s) {
     352          strcpy(simple, "\\");
     353          strcat(simple, s);
     354          *s = 0;
     355        }
     356        else
     357          strcpy(simple, "\\*");
     358        if (simple[strlen(simple) - 1] == ';')
     359          simple[strlen(simple) - 1] = 0;
     360        lLen = strlen(simple) + 1;
     361        if (strlen(s) > 8192 - lLen) {
     362          Runtime_Error(pszSrcFile, __LINE__, "too big");
     363          WinSetDlgItemText(hwnd, GREP_MASK, s);
     364          break;
     365        }
     366
     367        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     368                                            GREP_DRIVELIST,
     369                                            LM_QUERYSELECTION,
     370                                            MPFROMSHORT(LIT_FIRST), MPVOID);
     371        if (sSelect >= 0) {
     372          if (*s && s[strlen(s) - 1] != ';')
     373            strcat(s, ";");
     374          WinSendDlgItemMsg(hwnd,
     375                            GREP_DRIVELIST,
     376                            LM_QUERYITEMTEXT,
     377                            MPFROM2SHORT(sSelect,
     378                                        (8192 - strlen(s)) - lLen),
     379                            MPFROMP(&s[strlen(s)]));
     380          rstrip(s);
     381          if (*s) {
     382            strcat(s, simple);
     383            WinSetDlgItemText(hwnd, GREP_MASK, s);
     384            WinSendDlgItemMsg(hwnd,
     385                              GREP_MASK,
     386                              EM_SETSEL,
     387                              MPFROM2SHORT(strlen(s) - (lLen + 1),
     388                                           strlen(s)), MPVOID);
     389            PostMsg(hwnd,
     390                    UM_FOCUSME,
     391                    MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
     392          }
     393        }
     394        break;                          // LN_ENTER
    393395      }                                 // switch
    394396      break;
     
    397399      switch (SHORT2FROMMP(mp1)) {
    398400      case LN_KILLFOCUS:
    399         WinSetDlgItemText(hwnd,
    400                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    401         break;
     401        WinSetDlgItemText(hwnd,
     402                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     403        break;
    402404      case LN_SETFOCUS:
    403         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
    404         break;
     405        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
     406        break;
    405407      case LN_ENTER:
    406408      case LN_SELECT:
    407         if ((SHORT2FROMMP(mp1) == LN_ENTER &&
    408              !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) ||
    409             (SHORT2FROMMP(mp1) == LN_SELECT &&
    410              WinQueryButtonCheckstate(hwnd, GREP_APPEND)))
    411           break;
    412         {
    413           sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    414                                               GREP_LISTBOX,
    415                                               LM_QUERYSELECTION,
    416                                               MPFROMSHORT(LIT_FIRST), MPVOID);
    417           if (sSelect >= 0) {
    418             *s = 0;
    419             if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
    420               WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    421               bstrip(s);
    422               if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
    423                 strcat(s, ";");
    424             }
    425             WinSendDlgItemMsg(hwnd,
    426                               GREP_LISTBOX,
    427                               LM_QUERYITEMTEXT,
    428                               MPFROM2SHORT(sSelect, 8192 - strlen(s)),
    429                               MPFROMP(s + strlen(s)));
    430             bstrip(s);
    431             if (*s)
    432               WinSetDlgItemText(hwnd, GREP_MASK, s);
    433           }
    434         }
    435         break;
     409        if ((SHORT2FROMMP(mp1) == LN_ENTER &&
     410             !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) ||
     411            (SHORT2FROMMP(mp1) == LN_SELECT &&
     412             WinQueryButtonCheckstate(hwnd, GREP_APPEND)))
     413          break;
     414        {
     415          sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     416                                              GREP_LISTBOX,
     417                                              LM_QUERYSELECTION,
     418                                              MPFROMSHORT(LIT_FIRST), MPVOID);
     419          if (sSelect >= 0) {
     420            *s = 0;
     421            if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
     422              WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     423              bstrip(s);
     424              if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
     425                strcat(s, ";");
     426            }
     427            WinSendDlgItemMsg(hwnd,
     428                              GREP_LISTBOX,
     429                              LM_QUERYITEMTEXT,
     430                              MPFROM2SHORT(sSelect, 8192 - strlen(s)),
     431                              MPFROMP(s + strlen(s)));
     432            bstrip(s);
     433            if (*s)
     434              WinSetDlgItemText(hwnd, GREP_MASK, s);
     435          }
     436        }
     437        break;
    436438      }
    437439      break;
     
    439441    case GREP_MASK:
    440442      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    441         WinSetDlgItemText(hwnd,
    442                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     443        WinSetDlgItemText(hwnd,
     444                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    443445      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    444         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
     446        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
    445447      break;
    446448    case GREP_SEARCH:
    447449      if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
    448         WinSetDlgItemText(hwnd,
    449                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     450        WinSetDlgItemText(hwnd,
     451                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    450452      if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
    451         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
     453        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
    452454      break;
    453455    case GREP_GREATER:
    454456      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    455         WinSetDlgItemText(hwnd,
    456                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     457        WinSetDlgItemText(hwnd,
     458                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    457459      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    458         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
     460        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
    459461      break;
    460462    case GREP_LESSER:
    461463      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    462         WinSetDlgItemText(hwnd,
    463                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     464        WinSetDlgItemText(hwnd,
     465                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    464466      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    465         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
     467        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
    466468      break;
    467469    case GREP_NEWER:
    468470      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    469         WinSetDlgItemText(hwnd,
    470                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     471        WinSetDlgItemText(hwnd,
     472                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    471473      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    472         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
     474        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
    473475      break;
    474476    case GREP_OLDER:
    475477      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    476         WinSetDlgItemText(hwnd,
    477                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     478        WinSetDlgItemText(hwnd,
     479                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    478480      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    479         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
     481        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
    480482      break;
    481483    case GREP_FINDDUPES:
    482484      {
    483         BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
    484 
    485         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes);
    486         WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes);
    487         WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes);
    488         WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes);
    489         WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes);
    490         WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
    491                         finddupes);
    492         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes);
    493         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes);
    494         WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes);
    495         WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes);
    496         WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes);
    497         WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes);
    498         WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes);
    499         WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes);
    500         WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes);
    501         WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes);
    502         WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes);
    503         if (finddupes)
    504           WinCheckButton(hwnd, GREP_RECURSE, TRUE);
     485        BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
     486
     487        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes);
     488        WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes);
     489        WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes);
     490        WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes);
     491        WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes);
     492        WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
     493                        finddupes);
     494        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes);
     495        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes);
     496        WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes);
     497        WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes);
     498        WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes);
     499        WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes);
     500        WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes);
     501        WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes);
     502        WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes);
     503        WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes);
     504        WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes);
     505        if (finddupes)
     506          WinCheckButton(hwnd, GREP_RECURSE, TRUE);
    505507      }
    506508    }
     
    511513    case GREP_ENV:
    512514      {
    513         CHAR *t;
    514         CHAR env[8192];
    515 
    516         *path = 0;
    517         if (!WinDlgBox(HWND_DESKTOP,
    518                        hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
    519           break;
    520         }
    521         bstrip(path);
    522         if (!*path)
    523           break;
    524         if (!stricmp(path, "LIBPATH"))
    525           LoadLibPath(env, 8192);
    526         else {
    527           p = getenv(path);
    528           if (!p)
    529             break;
    530           strcpy(env, p);
    531         }
    532         bstrip(env);
    533         if (!*env)
    534           break;
    535         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    536         bstrip(s);
    537         if (strlen(s) > 8192 - 5) {
    538           Runtime_Error(pszSrcFile, __LINE__, "too big");
    539           break;
    540         }
    541         p = strrchr(s, '\\');
    542         if (p)
    543           strcpy(simple, p + 1);
    544         else if (*s)
    545           strcpy(simple, s);
    546         else
    547           strcpy(simple, "*");
    548         if (!p)
    549           *s = 0;
    550         if (simple[strlen(simple) - 1] == ';')
    551           simple[strlen(simple) - 1] = 0;
    552         lLen = strlen(simple) + 1;
    553         p = env;
    554         while (p && *p) {
    555           strncpy(path, p, CCHMAXPATH - 1);
    556           path[CCHMAXPATH - 1] = 0;
    557           t = strchr(path, ';');
    558           if (t)
    559             *t = 0;
    560           bstrip(path);
    561           if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
    562             if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
    563               WinSetDlgItemText(hwnd, GREP_MASK, s);
    564               break;
    565             }
    566             if (!*s || (*s && s[strlen(s) - 1] != ';')) {
    567               if (*s)
    568                 strcat(s, ";");
    569               strcat(s, path);
    570               lLen += strlen(path);
    571               if (s[strlen(s) - 1] != '\\') {
    572                 lLen++;
    573                 strcat(s, "\\");
    574               }
    575               rstrip(s);
    576               if (*s) {
    577                 strcat(s, simple);
    578                 WinSetDlgItemText(hwnd, GREP_MASK, s);
    579                 WinSendDlgItemMsg(hwnd,
    580                                   GREP_MASK,
    581                                   EM_SETSEL,
    582                                   MPFROM2SHORT(strlen(s) - (lLen - 1),
    583                                                strlen(s)), MPVOID);
    584               }
    585             }
    586           }
    587           p = strchr(p, ';');
    588           if (p)
    589             p++;
    590         }
     515        CHAR *t;
     516        CHAR env[8192];
     517
     518        *path = 0;
     519        if (!WinDlgBox(HWND_DESKTOP,
     520                       hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
     521          break;
     522        }
     523        bstrip(path);
     524        if (!*path)
     525          break;
     526        if (!stricmp(path, "LIBPATH"))
     527          LoadLibPath(env, 8192);
     528        else {
     529          p = getenv(path);
     530          if (!p)
     531            break;
     532          strcpy(env, p);
     533        }
     534        bstrip(env);
     535        if (!*env)
     536          break;
     537        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     538        bstrip(s);
     539        if (strlen(s) > 8192 - 5) {
     540          Runtime_Error(pszSrcFile, __LINE__, "too big");
     541          break;
     542        }
     543        p = strrchr(s, '\\');
     544        if (p)
     545          strcpy(simple, p + 1);
     546        else if (*s)
     547          strcpy(simple, s);
     548        else
     549          strcpy(simple, "*");
     550        if (!p)
     551          *s = 0;
     552        if (simple[strlen(simple) - 1] == ';')
     553          simple[strlen(simple) - 1] = 0;
     554        lLen = strlen(simple) + 1;
     555        p = env;
     556        while (p && *p) {
     557          strncpy(path, p, CCHMAXPATH - 1);
     558          path[CCHMAXPATH - 1] = 0;
     559          t = strchr(path, ';');
     560          if (t)
     561            *t = 0;
     562          bstrip(path);
     563          if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
     564            if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
     565              WinSetDlgItemText(hwnd, GREP_MASK, s);
     566              break;
     567            }
     568            if (!*s || (*s && s[strlen(s) - 1] != ';')) {
     569              if (*s)
     570                strcat(s, ";");
     571              strcat(s, path);
     572              lLen += strlen(path);
     573              if (s[strlen(s) - 1] != '\\') {
     574                lLen++;
     575                strcat(s, "\\");
     576              }
     577              rstrip(s);
     578              if (*s) {
     579                strcat(s, simple);
     580                WinSetDlgItemText(hwnd, GREP_MASK, s);
     581                WinSendDlgItemMsg(hwnd,
     582                                  GREP_MASK,
     583                                  EM_SETSEL,
     584                                  MPFROM2SHORT(strlen(s) - (lLen - 1),
     585                                               strlen(s)), MPVOID);
     586              }
     587            }
     588          }
     589          p = strchr(p, ';');
     590          if (p)
     591            p++;
     592        }
    591593      }
    592594      break;
     
    596598      bstrip(s);
    597599      if (strlen(s) > 8192 - 5) {
    598         Runtime_Error(pszSrcFile, __LINE__, "too big");
    599         break;
     600        Runtime_Error(pszSrcFile, __LINE__, "too big");
     601        break;
    600602      }
    601603      *path = 0;
    602604      if (WinDlgBox(HWND_DESKTOP,
    603                     hwnd,
    604                     WalkAllDlgProc,
    605                     FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
    606         p = strrchr(s, '\\');
    607         if (p)
    608           strcpy(simple, p + 1);
    609         else if (*s)
    610           strcpy(simple, s);
    611         else
    612           strcpy(simple, "*");
    613         if (!p)
    614           *s = 0;
    615         if (simple[strlen(simple) - 1] == ';')
    616           simple[strlen(simple) - 1] = 0;
    617         lLen = strlen(simple) + 1;
    618         if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
    619           Runtime_Error(pszSrcFile, __LINE__, "too big");
    620           WinSetDlgItemText(hwnd, GREP_MASK, s);
    621           break;
    622         }
    623         if (!*s || (*s && s[strlen(s) - 1] != ';')) {
    624           if (*s)
    625             strcat(s, ";");
    626           strcat(s, path);
    627           lLen += strlen(path);
    628           if (s[strlen(s) - 1] != '\\') {
    629             lLen++;
    630             strcat(s, "\\");
    631           }
    632           rstrip(s);
    633           if (*s) {
    634             strcat(s, simple);
    635             WinSetDlgItemText(hwnd, GREP_MASK, s);
    636             WinSendDlgItemMsg(hwnd,
    637                               GREP_MASK,
    638                               EM_SETSEL,
    639                               MPFROM2SHORT(strlen(s) - (lLen - 1),
    640                                            strlen(s)), MPVOID);
    641           }
    642         }
     605                    hwnd,
     606                    WalkAllDlgProc,
     607                    FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
     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        lLen = strlen(simple) + 1;
     620        if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
     621          Runtime_Error(pszSrcFile, __LINE__, "too big");
     622          WinSetDlgItemText(hwnd, GREP_MASK, s);
     623          break;
     624        }
     625        if (!*s || (*s && s[strlen(s) - 1] != ';')) {
     626          if (*s)
     627            strcat(s, ";");
     628          strcat(s, path);
     629          lLen += strlen(path);
     630          if (s[strlen(s) - 1] != '\\') {
     631            lLen++;
     632            strcat(s, "\\");
     633          }
     634          rstrip(s);
     635          if (*s) {
     636            strcat(s, simple);
     637            WinSetDlgItemText(hwnd, GREP_MASK, s);
     638            WinSendDlgItemMsg(hwnd,
     639                              GREP_MASK,
     640                              EM_SETSEL,
     641                              MPFROM2SHORT(strlen(s) - (lLen - 1),
     642                                           strlen(s)), MPVOID);
     643          }
     644        }
    643645      }
    644646      break;
     
    649651      bstrip(s);
    650652      if (*s) {
    651         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    652                                             GREP_LISTBOX,
    653                                             LM_SEARCHSTRING,
    654                                             MPFROM2SHORT(0, LIT_FIRST),
    655                                             MPFROMP(s));
    656         if (sSelect < 0) {
    657           WinSendDlgItemMsg(hwnd,
    658                             GREP_LISTBOX,
    659                             LM_INSERTITEM,
    660                             MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
    661           changed = TRUE;
    662         }
     653        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     654                                            GREP_LISTBOX,
     655                                            LM_SEARCHSTRING,
     656                                            MPFROM2SHORT(0, LIT_FIRST),
     657                                            MPFROMP(s));
     658        if (sSelect < 0) {
     659          WinSendDlgItemMsg(hwnd,
     660                            GREP_LISTBOX,
     661                            LM_INSERTITEM,
     662                            MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
     663          changed = TRUE;
     664        }
    663665      }
    664666      break;
     
    666668    case GREP_DELETE:
    667669      sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    668                                           GREP_LISTBOX,
    669                                           LM_QUERYSELECTION,
    670                                           MPFROMSHORT(LIT_FIRST), MPVOID);
     670                                          GREP_LISTBOX,
     671                                          LM_QUERYSELECTION,
     672                                          MPFROMSHORT(LIT_FIRST), MPVOID);
    671673      if (sSelect >= 0) {
    672         WinSendDlgItemMsg(hwnd,
    673                           GREP_LISTBOX,
    674                           LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
    675         changed = TRUE;
     674        WinSendDlgItemMsg(hwnd,
     675                          GREP_LISTBOX,
     676                          LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
     677        changed = TRUE;
    676678      }
    677679      break;
     
    715717    case IDM_HELP:
    716718      if (hwndHelp)
    717         WinSendMsg(hwndHelp,
    718                    HM_DISPLAY_HELP,
    719                    MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
     719        WinSendMsg(hwndHelp,
     720                   HM_DISPLAY_HELP,
     721                   MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
    720722      break;
    721723
     
    724726    case GREP_ALLHDS:
    725727      {
    726         CHAR szDrive[] = " :\\";
    727         ULONG ulDriveNum;
    728         ULONG ulDriveMap;
    729         INT x;
    730         BOOL incl;
    731 
    732         CHAR new[8192];
    733 
    734         *s = 0;
    735         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    736         s[8192 - 1] = 0;
    737         p = strchr(s, ';');
    738         if (p)
    739           *p = 0;
    740         p = strrchr(s, '\\');
    741         if (!p)
    742           p = strrchr(s, '/');
    743         if (!p)
    744           p = strrchr(s, ':');
    745         if (p)
    746           strcpy(s, p + 1);
    747         if (!*s)
    748           strcpy(s, "*");
    749         DosError(FERR_DISABLEHARDERR);
    750         DosQCurDisk(&ulDriveNum, &ulDriveMap);
    751         *new = 0;
    752         for (x = 2; x < 26; x++) {
    753           incl = FALSE;
    754           if (ulDriveMap & (1L << x)) {
    755             switch (SHORT1FROMMP(mp1)) {
    756             case GREP_ALLHDS:
    757               if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_RAMDISK)))
    758                 incl = TRUE;
    759               break;
    760             case GREP_LOCALHDS:
    761               if (!(driveflags[x] &
    762                     (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
    763                      DRIVE_VIRTUAL | DRIVE_RAMDISK)))
    764                 incl = TRUE;
    765               break;
    766             case GREP_REMOTEHDS:
    767               if (!(driveflags[x] &
    768                     (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
    769                   (driveflags[x] & DRIVE_REMOTE))
    770                 incl = TRUE;
    771               break;
    772             }
    773           }
    774           if (incl) {
    775             if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
    776               if (*new)
    777                 strcat(new, ";");
    778               *szDrive = x + 'A';
    779               strcat(new, szDrive);
    780               strcat(new, s);
    781             }
    782           }
    783         }
    784         if (*new)
    785           WinSetDlgItemText(hwnd, GREP_MASK, new);
     728        CHAR szDrive[] = " :\\";
     729        ULONG ulDriveNum;
     730        ULONG ulDriveMap;
     731        INT x;
     732        BOOL incl;
     733
     734        CHAR new[8192];
     735
     736        *s = 0;
     737        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     738        s[8192 - 1] = 0;
     739        p = strchr(s, ';');
     740        if (p)
     741          *p = 0;
     742        p = strrchr(s, '\\');
     743        if (!p)
     744          p = strrchr(s, '/');
     745        if (!p)
     746          p = strrchr(s, ':');
     747        if (p)
     748          strcpy(s, p + 1);
     749        if (!*s)
     750          strcpy(s, "*");
     751        DosError(FERR_DISABLEHARDERR);
     752        DosQCurDisk(&ulDriveNum, &ulDriveMap);
     753        *new = 0;
     754        for (x = 2; x < 26; x++) {
     755          incl = FALSE;
     756          if (ulDriveMap & (1L << x)) {
     757            switch (SHORT1FROMMP(mp1)) {
     758            case GREP_ALLHDS:
     759              if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_RAMDISK)))
     760                incl = TRUE;
     761              break;
     762            case GREP_LOCALHDS:
     763              if (!(driveflags[x] &
     764                    (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
     765                     DRIVE_VIRTUAL | DRIVE_RAMDISK)))
     766                incl = TRUE;
     767              break;
     768            case GREP_REMOTEHDS:
     769              if (!(driveflags[x] &
     770                    (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
     771                  (driveflags[x] & DRIVE_REMOTE))
     772                incl = TRUE;
     773              break;
     774            }
     775          }
     776          if (incl) {
     777            if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
     778              if (*new)
     779                strcat(new, ";");
     780              *szDrive = x + 'A';
     781              strcat(new, szDrive);
     782              strcat(new, s);
     783            }
     784          }
     785        }
     786        if (*new)
     787          WinSetDlgItemText(hwnd, GREP_MASK, new);
    786788      }
    787789      break;
     
    790792      hwndCollect = WinQueryWindowULong(hwnd, QWL_USER);
    791793      if (!hwndCollect)
    792         Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
     794        Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
    793795      else {
    794         // 07 Feb 08 SHL - fixme to malloc and free in thread
    795         static GREP g;          // Passed to thread
    796 
    797         p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
    798         if (!p)
    799           break;
    800         memset(&g, 0, sizeof(GREP));
    801         g.size = sizeof(GREP);
    802         recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
    803         absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
    804         sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
    805         sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
    806         searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
    807         searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
    808         findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
    809         gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
    810         if (gRemember) {
    811           PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse",
    812                               (PVOID) & recurse, sizeof(BOOL));
    813           PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute",
    814                               (PVOID) & absolute, sizeof(BOOL));
    815           PrfWriteProfileData(fmprof, FM3Str, "Grep_Case",
    816                               (PVOID) & sensitive, sizeof(BOOL));
    817           PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles",
    818                               (PVOID) & sayfiles, sizeof(BOOL));
    819           PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles",
    820                               (PVOID) & searchFiles, sizeof(BOOL));
    821           PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
    822                               (PVOID) & searchEAs, sizeof(BOOL));
    823         }
    824         g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
    825         if (g.finddupes) {
    826           g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
    827           g.nosizedupes =
    828             WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
    829           g.ignoreextdupes =
    830             WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
    831         }
    832         // Parse file masks
    833         *p = 0;
    834         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
    835         bstrip(p);
    836         if (!*p) {
    837           DosBeep(50, 100);
    838           WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
    839           free(p);
     796        // 07 Feb 08 SHL - fixme to malloc and free in thread
     797        static GREP g;          // Passed to thread
     798
     799        p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
     800        if (!p)
     801          break;
     802        memset(&g, 0, sizeof(GREP));
     803        g.size = sizeof(GREP);
     804        recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
     805        absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
     806        sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
     807        sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
     808        searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
     809        searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
     810        findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
     811        gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
     812        if (gRemember) {
     813          PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse",
     814                              (PVOID) & recurse, sizeof(BOOL));
     815          PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute",
     816                              (PVOID) & absolute, sizeof(BOOL));
     817          PrfWriteProfileData(fmprof, FM3Str, "Grep_Case",
     818                              (PVOID) & sensitive, sizeof(BOOL));
     819          PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles",
     820                              (PVOID) & sayfiles, sizeof(BOOL));
     821          PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles",
     822                              (PVOID) & searchFiles, sizeof(BOOL));
     823          PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
     824                              (PVOID) & searchEAs, sizeof(BOOL));
     825        }
     826        g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
     827        if (g.finddupes) {
     828          g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
     829          g.nosizedupes =
     830            WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
     831          g.ignoreextdupes =
     832            WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
     833        }
     834        // Parse file masks
     835        *p = 0;
     836        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
     837        bstrip(p);
     838        if (!*p) {
     839          DosBeep(50, 100);
     840          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
     841          free(p);
    840842#         ifdef FORTIFY
    841           Fortify_LeaveScope();
     843          Fortify_LeaveScope();
    842844#          endif
    843           break;
    844         }
    845         strcpy(g.tosearch, p);
    846         strcpy(lastmask, p);
    847         // Parse search strings
    848         *p = 0;
    849         WinQueryWindowText(hwndMLE, 4096, p);
    850         strcpy(lasttext, p);
    851         {
    852           CHAR *pszFrom;
    853           CHAR *pszTo;
    854           ULONG matched = 0;
    855 
    856           pszTo = g.searchPattern;
    857           pszFrom = p;
    858           while (*pszFrom) {
    859             if (*pszFrom == '\r') {
    860               pszFrom++;
    861               continue;
    862             }
    863             if (*pszFrom == '\n') {
    864               if (*(pszFrom + 1))
    865                 matched++;
    866               *pszTo = 0;
    867             }
    868             else
    869               *pszTo = *pszFrom;
    870             pszTo++;
    871             pszFrom++;
    872           }
    873           if (*g.searchPattern)
    874             matched++;
    875           *pszTo++ = 0;
    876           *pszTo = 0;
    877           g.numlines = matched;
    878           if (matched) {
    879             g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
    880             if (!g.matched)
    881               g.numlines = 0;
    882           }
    883         }
    884         *p = 0;
    885         WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
    886         greater = atol(p);
    887         *p = 0;
    888         WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
    889         lesser = atol(p);
    890         *p = 0;
    891         WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
    892         newer = atoi(p);
    893         *p = 0;
    894         WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
    895         older = atoi(p);
    896         if (older || newer) {
    897           FDATE fdate;
    898           FTIME ftime;
    899           struct tm tm;
    900           time_t t;
    901 
    902           t = time(NULL);
    903           tm = *localtime(&t);
    904           fdate.day = tm.tm_mday;
    905           fdate.month = tm.tm_mon + 1;
    906           fdate.year = tm.tm_year - 80;
    907           ftime.hours = tm.tm_hour;
    908           ftime.minutes = tm.tm_min;
    909           ftime.twosecs = tm.tm_sec / 2;
    910           if (older) {
    911             g.olderthan = SecsSince1980(&fdate, &ftime);
    912             g.olderthan -= (older * (24L * 60L * 60L));
    913           }
    914           if (newer) {
    915             g.newerthan = SecsSince1980(&fdate, &ftime);
    916             g.newerthan -= (newer * (24L * 60L * 60L));
    917           }
    918         }
    919         if (!newer)
    920           g.newerthan = 0;
    921         if (!older)
    922           g.olderthan = 0;
    923         g.greaterthan = greater;
    924         g.lessthan = lesser;
    925         g.absFlag = absolute;
    926         g.caseFlag = sensitive;
    927         g.dirFlag = recurse;
    928         g.sayfiles = sayfiles;
    929         g.searchEAs = searchEAs;
    930         g.searchFiles = searchFiles;
    931         g.findifany = findifany;
    932         g.hwndFiles = hwndCollect;
    933         g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT);
    934         g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED);
    935         g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
    936         g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
    937         g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
    938         if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) {
    939           Runtime_Error(pszSrcFile, __LINE__,
    940                         GetPString(IDS_COULDNTSTARTTHREADTEXT));
    941           free(p);
     845          break;
     846        }
     847        strcpy(g.tosearch, p);
     848        strcpy(lastmask, p);
     849        // Parse search strings
     850        *p = 0;
     851        WinQueryWindowText(hwndMLE, 4096, p);
     852        strcpy(lasttext, p);
     853        {
     854          CHAR *pszFrom;
     855          CHAR *pszTo;
     856          ULONG matched = 0;
     857
     858          pszTo = g.searchPattern;
     859          pszFrom = p;
     860          while (*pszFrom) {
     861            if (*pszFrom == '\r') {
     862              pszFrom++;
     863              continue;
     864            }
     865            if (*pszFrom == '\n') {
     866              if (*(pszFrom + 1))
     867                matched++;
     868              *pszTo = 0;
     869            }
     870            else
     871              *pszTo = *pszFrom;
     872            pszTo++;
     873            pszFrom++;
     874          }
     875          if (*g.searchPattern)
     876            matched++;
     877          *pszTo++ = 0;
     878          *pszTo = 0;
     879          g.numlines = matched;
     880          if (matched) {
     881            g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
     882            if (!g.matched)
     883              g.numlines = 0;
     884          }
     885        }
     886        *p = 0;
     887        WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
     888        greater = atol(p);
     889        *p = 0;
     890        WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
     891        lesser = atol(p);
     892        *p = 0;
     893        WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
     894        newer = atoi(p);
     895        *p = 0;
     896        WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
     897        older = atoi(p);
     898        if (older || newer) {
     899          FDATE fdate;
     900          FTIME ftime;
     901          struct tm tm;
     902          time_t t;
     903
     904          t = time(NULL);
     905          tm = *localtime(&t);
     906          fdate.day = tm.tm_mday;
     907          fdate.month = tm.tm_mon + 1;
     908          fdate.year = tm.tm_year - 80;
     909          ftime.hours = tm.tm_hour;
     910          ftime.minutes = tm.tm_min;
     911          ftime.twosecs = tm.tm_sec / 2;
     912          if (older) {
     913            g.olderthan = SecsSince1980(&fdate, &ftime);
     914            g.olderthan -= (older * (24L * 60L * 60L));
     915          }
     916          if (newer) {
     917            g.newerthan = SecsSince1980(&fdate, &ftime);
     918            g.newerthan -= (newer * (24L * 60L * 60L));
     919          }
     920        }
     921        if (!newer)
     922          g.newerthan = 0;
     923        if (!older)
     924          g.olderthan = 0;
     925        g.greaterthan = greater;
     926        g.lessthan = lesser;
     927        g.absFlag = absolute;
     928        g.caseFlag = sensitive;
     929        g.dirFlag = recurse;
     930        g.sayfiles = sayfiles;
     931        g.searchEAs = searchEAs;
     932        g.searchFiles = searchFiles;
     933        g.findifany = findifany;
     934        g.hwndFiles = hwndCollect;
     935        g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT);
     936        g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED);
     937        g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
     938        g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
     939        g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
     940        if (xbeginthread(GrepThread,
     941                         524280,
     942                         &g,
     943                         pszSrcFile,
     944                         __LINE__) == -1)
     945        {
     946          free(p);
    942947#         ifdef FORTIFY
    943           Fortify_LeaveScope();
     948          Fortify_LeaveScope();
    944949#          endif
    945           WinDismissDlg(hwnd, 0);
    946           break;
    947         }
    948         DosSleep(100); //05 Aug 07 GKY 128
    949         free(p);
     950          WinDismissDlg(hwnd, 0);
     951          break;
     952        }
     953        DosSleep(100); //05 Aug 07 GKY 128
     954        free(p);
    950955#       ifdef FORTIFY
    951         Fortify_LeaveScope();
     956        Fortify_LeaveScope();
    952957#        endif
    953958      }
    954959      if (changed) {
    955         // Grep mask list changed
    956         SHORT x;
    957 
    958         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    959                                             GREP_LISTBOX,
    960                                             LM_QUERYITEMCOUNT,
    961                                             MPVOID, MPVOID);
    962         if (sSelect > 0) {
    963           BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT");
    964           if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
    965             break; //already gave error msg
    966           fp = xfopen(s, "w", pszSrcFile, __LINE__);
    967           if (fp) {
    968             fputs(GetPString(IDS_GREPFILETEXT), fp);
    969             for (x = 0; x < sSelect; x++) {
    970               *s = 0;
    971               WinSendDlgItemMsg(hwnd,
    972                                 GREP_LISTBOX,
    973                                 LM_QUERYITEMTEXT,
    974                                 MPFROM2SHORT(x, 8192), MPFROMP(s));
    975               bstrip(s);
    976               if (*s)
    977                 fprintf(fp, "%s\n", s);
    978             }
    979             fclose(fp);
    980           }
    981         }
     960        // Grep mask list changed
     961        SHORT x;
     962
     963        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     964                                            GREP_LISTBOX,
     965                                            LM_QUERYITEMCOUNT,
     966                                            MPVOID, MPVOID);
     967        if (sSelect > 0) {
     968          BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT");
     969          if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
     970            break; //already gave error msg
     971          fp = xfopen(s, "w", pszSrcFile, __LINE__);
     972          if (fp) {
     973            fputs(GetPString(IDS_GREPFILETEXT), fp);
     974            for (x = 0; x < sSelect; x++) {
     975              *s = 0;
     976              WinSendDlgItemMsg(hwnd,
     977                                GREP_LISTBOX,
     978                                LM_QUERYITEMTEXT,
     979                                MPFROM2SHORT(x, 8192), MPFROMP(s));
     980              bstrip(s);
     981              if (*s)
     982                fprintf(fp, "%s\n", s);
     983            }
     984            fclose(fp);
     985          }
     986        }
    982987      }
    983988      WinDismissDlg(hwnd, 1);
Note: See TracChangeset for help on using the changeset viewer.