Changeset 1161 for trunk/dll/grep2.c


Ignore:
Timestamp:
Sep 5, 2008, 11:42:27 PM (17 years ago)
Author:
John Small
Message:

Ticket 187: Draft 1: Functions only

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep2.c

    r1119 r1161  
    3131#include <ctype.h>
    3232#include <share.h>
    33 #include <process.h>                    // _beginthread
     33#include <process.h>                    // _beginthread
    3434
    3535#define INCL_DOS
    3636#define INCL_WIN
    37 #define INCL_LONGLONG                   // dircnrs.h
    38 #define INCL_WINSTDCNR                  // makelist.h
     37#define INCL_LONGLONG                   // dircnrs.h
     38#define INCL_WINSTDCNR                  // makelist.h
    3939
    4040#include "fm3dlg.h"
     
    4242#include "mle.h"
    4343#include "grep.h"
    44 #include "errutil.h"                    // Dos_Error...
    45 #include "strutil.h"                    // GetPString
     44#include "errutil.h"                    // Dos_Error...
     45#include "strutil.h"                    // GetPString
    4646#include "pathutil.h"                   // BldFullPathName
     47#include "walkem.h"                     // FillPathListBox
     48#include "grep2.h"
    4749#include "fm3dll.h"
     50#include "misc.h"                       // LoadLibPath
    4851#include "fortify.h"
    4952
     
    6770      *(CHAR *)mp2 = 0;
    6871      {
    69         CHAR *p;
    70         CHAR *pp;
    71 
    72         p = GetPString(IDS_ENVVARNAMES);
    73         while (*p == ' ')
    74           p++;
    75         while (*p) {
    76           *szPath = 0;
    77           pp = szPath;
    78           while (*p && *p != ' ')
    79             *pp++ = *p++;
    80           *pp = 0;
    81           while (*p == ' ')
    82             p++;
    83           if (*szPath)
    84             WinSendDlgItemMsg(hwnd,
    85                               ENV_LISTBOX,
    86                               LM_INSERTITEM,
    87                               MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath));
    88         }
     72        CHAR *p;
     73        CHAR *pp;
     74
     75        p = GetPString(IDS_ENVVARNAMES);
     76        while (*p == ' ')
     77          p++;
     78        while (*p) {
     79          *szPath = 0;
     80          pp = szPath;
     81          while (*p && *p != ' ')
     82            *pp++ = *p++;
     83          *pp = 0;
     84          while (*p == ' ')
     85            p++;
     86          if (*szPath)
     87            WinSendDlgItemMsg(hwnd,
     88                              ENV_LISTBOX,
     89                              LM_INSERTITEM,
     90                              MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath));
     91        }
    8992      }
    9093      WinSendDlgItemMsg(hwnd,
    91                         ENV_NAME,
    92                         EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
     94                        ENV_NAME,
     95                        EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
    9396      WinSetDlgItemText(hwnd, ENV_NAME, lastenv);
    9497      WinSendDlgItemMsg(hwnd,
    95                         ENV_NAME,
    96                         EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
     98                        ENV_NAME,
     99                        EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
    97100    }
    98101    else
     
    105108      switch (SHORT2FROMMP(mp1)) {
    106109      case LN_SELECT:
    107         {
    108           sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    109                                               ENV_LISTBOX,
    110                                               LM_QUERYSELECTION,
    111                                               MPFROMSHORT(LIT_FIRST), MPVOID);
    112           if (sSelect >= 0) {
    113             *s = 0;
    114             WinSendDlgItemMsg(hwnd,
    115                               ENV_LISTBOX,
    116                               LM_QUERYITEMTEXT,
    117                               MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
    118             bstrip(s);
    119             if (*s)
    120               WinSetDlgItemText(hwnd, ENV_NAME, s);
    121           }
    122         }
    123         break;
     110        {
     111          sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     112                                              ENV_LISTBOX,
     113                                              LM_QUERYSELECTION,
     114                                              MPFROMSHORT(LIT_FIRST), MPVOID);
     115          if (sSelect >= 0) {
     116            *s = 0;
     117            WinSendDlgItemMsg(hwnd,
     118                              ENV_LISTBOX,
     119                              LM_QUERYITEMTEXT,
     120                              MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
     121            bstrip(s);
     122            if (*s)
     123              WinSetDlgItemText(hwnd, ENV_NAME, s);
     124          }
     125        }
     126        break;
    124127      case LN_ENTER:
    125         PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
    126         break;
     128        PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
     129        break;
    127130      }
    128131    }
     
    137140      p = WinQueryWindowPtr(hwnd, QWL_USER);
    138141      if (p) {
    139         WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
    140         bstrip(p);
    141         if (!*p) {
    142           DosBeep(50, 100);
    143           WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
    144         }
    145         else {
    146           strcpy(lastenv, p);
    147           WinDismissDlg(hwnd, 1);
    148         }
     142        WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p);
     143        bstrip(p);
     144        if (!*p) {
     145          DosBeep(50, 100);
     146          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME));
     147        }
     148        else {
     149          strcpy(lastenv, p);
     150          WinDismissDlg(hwnd, 1);
     151        }
    149152      }
    150153      break;
    151154    case IDM_HELP:
    152155      if (hwndHelp)
    153         WinSendMsg(hwndHelp,
    154                    HM_DISPLAY_HELP,
    155                    MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
     156        WinSendMsg(hwndHelp,
     157                   HM_DISPLAY_HELP,
     158                   MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID));
    156159      break;
    157160    }
     
    199202    WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2);
    200203    WinSendDlgItemMsg(hwnd,
    201                       GREP_MASK,
    202                       EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
     204                      GREP_MASK,
     205                      EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID);
    203206    MLEsetlimit(hwndMLE, 4096);
    204207    MLEsetformat(hwndMLE, MLFIE_NOTRANS);
    205208    WinSendDlgItemMsg(hwnd,
    206                       GREP_NEWER,
    207                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     209                      GREP_NEWER,
     210                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    208211    WinSendDlgItemMsg(hwnd,
    209                       GREP_OLDER,
    210                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     212                      GREP_OLDER,
     213                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    211214    WinSendDlgItemMsg(hwnd,
    212                       GREP_GREATER,
    213                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     215                      GREP_GREATER,
     216                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    214217    WinSendDlgItemMsg(hwnd,
    215                       GREP_LESSER,
    216                       EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
     218                      GREP_LESSER,
     219                      EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID);
    217220    WinSetDlgItemText(hwnd, GREP_MASK, lastmask);
    218221    WinSendDlgItemMsg(hwnd,
    219                       GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID);
     222                      GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID);
    220223    PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep",
    221                         (PVOID) & gRemember, &size);
     224                        (PVOID) & gRemember, &size);
    222225    WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember);
    223226    if (gRemember) {
    224227      PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse",
    225                           (PVOID) & recurse, &size);
     228                          (PVOID) & recurse, &size);
    226229      PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute",
    227                           (PVOID) & absolute, &size);
     230                          (PVOID) & absolute, &size);
    228231      PrfQueryProfileData(fmprof, FM3Str, "Grep_Case",
    229                           (PVOID) & sensitive, &size);
     232                          (PVOID) & sensitive, &size);
    230233      PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles",
    231                           (PVOID) & sayfiles, &size);
     234                          (PVOID) & sayfiles, &size);
    232235      PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles",
    233                           (PVOID) & searchFiles, &size);
     236                          (PVOID) & searchFiles, &size);
    234237      PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
    235                           (PVOID) & searchEAs, &size);
     238                          (PVOID) & searchEAs, &size);
    236239    }
    237240    if (!gRemember) {
     
    248251      MLEsetcurposa(hwndMLE, 4096);
    249252      if (!searchEAs)
    250         searchFiles = TRUE;
     253        searchFiles = TRUE;
    251254    }
    252255    WinCheckButton(hwnd, GREP_RECURSE, recurse);
     
    275278    if (fp) {
    276279      while (!feof(fp)) {
    277         if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
    278           break;
    279         if (*s && *s != ';') {
    280           WinSendDlgItemMsg(hwnd,
    281                             GREP_LISTBOX,
    282                             LM_INSERTITEM,
    283                             MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
    284         }
     280        if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__))
     281          break;
     282        if (*s && *s != ';') {
     283          WinSendDlgItemMsg(hwnd,
     284                            GREP_LISTBOX,
     285                            LM_INSERTITEM,
     286                            MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
     287        }
    285288      }
    286289      fclose(fp);
     
    288291
    289292    FillPathListBox(hwnd,
    290                     WinWindowFromID(hwnd, GREP_DRIVELIST),
    291                     (HWND) 0, NULL, FALSE);
     293                    WinWindowFromID(hwnd, GREP_DRIVELIST),
     294                    (HWND) 0, NULL, FALSE);
    292295    break;
    293296
     
    298301  case UM_SETDIR:
    299302    PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
    300                         (HPS) 0, FALSE, TRUE);
     303                        (HPS) 0, FALSE, TRUE);
    301304    return 0;
    302305
     
    311314    case GREP_REMEMBERFLAGS:
    312315      {
    313         BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
    314 
    315         PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
    316                             (PVOID) & gRemember, sizeof(BOOL));
     316        BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
     317
     318        PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep",
     319                            (PVOID) & gRemember, sizeof(BOOL));
    317320      }
    318321      break;
     
    321324      switch (SHORT2FROMMP(mp1)) {
    322325      case LN_KILLFOCUS:
    323         WinSetDlgItemText(hwnd,
    324                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    325         break;
     326        WinSetDlgItemText(hwnd,
     327                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     328        break;
    326329      case LN_SETFOCUS:
    327         WinSetDlgItemText(hwnd,
    328                           GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
    329         break;
     330        WinSetDlgItemText(hwnd,
     331                          GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT));
     332        break;
    330333      case LN_ENTER:
    331         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    332         bstrip(s);
    333         p = strrchr(s, '\\');
    334         if (p)
    335           strcpy(simple, p);
    336         else if (*s) {
    337           strcpy(simple, "\\");
    338           strcat(simple, s);
    339           *s = 0;
    340         }
    341         else
    342           strcpy(simple, "\\*");
    343         if (simple[strlen(simple) - 1] == ';')
    344           simple[strlen(simple) - 1] = 0;
    345         lLen = strlen(simple) + 1;
    346         if (strlen(s) > 8192 - lLen) {
    347           Runtime_Error(pszSrcFile, __LINE__, "too big");
    348           WinSetDlgItemText(hwnd, GREP_MASK, s);
    349           break;
    350         }
    351 
    352         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    353                                             GREP_DRIVELIST,
    354                                             LM_QUERYSELECTION,
    355                                             MPFROMSHORT(LIT_FIRST), MPVOID);
    356         if (sSelect >= 0) {
    357           if (*s && s[strlen(s) - 1] != ';')
    358             strcat(s, ";");
    359           WinSendDlgItemMsg(hwnd,
    360                             GREP_DRIVELIST,
    361                             LM_QUERYITEMTEXT,
    362                             MPFROM2SHORT(sSelect,
    363                                         (8192 - strlen(s)) - lLen),
    364                             MPFROMP(&s[strlen(s)]));
    365           rstrip(s);
    366           if (*s) {
    367             strcat(s, simple);
    368             WinSetDlgItemText(hwnd, GREP_MASK, s);
    369             WinSendDlgItemMsg(hwnd,
    370                               GREP_MASK,
    371                               EM_SETSEL,
    372                               MPFROM2SHORT(strlen(s) - (lLen + 1),
    373                                            strlen(s)), MPVOID);
    374             PostMsg(hwnd,
    375                     UM_FOCUSME,
    376                     MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
    377           }
    378         }
    379         break;                          // LN_ENTER
    380       }                                 // switch
     334        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     335        bstrip(s);
     336        p = strrchr(s, '\\');
     337        if (p)
     338          strcpy(simple, p);
     339        else if (*s) {
     340          strcpy(simple, "\\");
     341          strcat(simple, s);
     342          *s = 0;
     343        }
     344        else
     345          strcpy(simple, "\\*");
     346        if (simple[strlen(simple) - 1] == ';')
     347          simple[strlen(simple) - 1] = 0;
     348        lLen = strlen(simple) + 1;
     349        if (strlen(s) > 8192 - lLen) {
     350          Runtime_Error(pszSrcFile, __LINE__, "too big");
     351          WinSetDlgItemText(hwnd, GREP_MASK, s);
     352          break;
     353        }
     354
     355        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     356                                            GREP_DRIVELIST,
     357                                            LM_QUERYSELECTION,
     358                                            MPFROMSHORT(LIT_FIRST), MPVOID);
     359        if (sSelect >= 0) {
     360          if (*s && s[strlen(s) - 1] != ';')
     361            strcat(s, ";");
     362          WinSendDlgItemMsg(hwnd,
     363                            GREP_DRIVELIST,
     364                            LM_QUERYITEMTEXT,
     365                            MPFROM2SHORT(sSelect,
     366                                        (8192 - strlen(s)) - lLen),
     367                            MPFROMP(&s[strlen(s)]));
     368          rstrip(s);
     369          if (*s) {
     370            strcat(s, simple);
     371            WinSetDlgItemText(hwnd, GREP_MASK, s);
     372            WinSendDlgItemMsg(hwnd,
     373                              GREP_MASK,
     374                              EM_SETSEL,
     375                              MPFROM2SHORT(strlen(s) - (lLen + 1),
     376                                           strlen(s)), MPVOID);
     377            PostMsg(hwnd,
     378                    UM_FOCUSME,
     379                    MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID);
     380          }
     381        }
     382        break;                          // LN_ENTER
     383      }                                 // switch
    381384      break;
    382385
     
    384387      switch (SHORT2FROMMP(mp1)) {
    385388      case LN_KILLFOCUS:
    386         WinSetDlgItemText(hwnd,
    387                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    388         break;
     389        WinSetDlgItemText(hwnd,
     390                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     391        break;
    389392      case LN_SETFOCUS:
    390         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
    391         break;
     393        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT));
     394        break;
    392395      case LN_ENTER:
    393396      case LN_SELECT:
    394         if ((SHORT2FROMMP(mp1) == LN_ENTER &&
    395              !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) ||
    396             (SHORT2FROMMP(mp1) == LN_SELECT &&
    397              WinQueryButtonCheckstate(hwnd, GREP_APPEND)))
    398           break;
    399         {
    400           sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    401                                               GREP_LISTBOX,
    402                                               LM_QUERYSELECTION,
    403                                               MPFROMSHORT(LIT_FIRST), MPVOID);
    404           if (sSelect >= 0) {
    405             *s = 0;
    406             if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
    407               WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    408               bstrip(s);
    409               if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
    410                 strcat(s, ";");
    411             }
    412             WinSendDlgItemMsg(hwnd,
    413                               GREP_LISTBOX,
    414                               LM_QUERYITEMTEXT,
    415                               MPFROM2SHORT(sSelect, 8192 - strlen(s)),
    416                               MPFROMP(s + strlen(s)));
    417             bstrip(s);
    418             if (*s)
    419               WinSetDlgItemText(hwnd, GREP_MASK, s);
    420           }
    421         }
    422         break;
     397        if ((SHORT2FROMMP(mp1) == LN_ENTER &&
     398             !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) ||
     399            (SHORT2FROMMP(mp1) == LN_SELECT &&
     400             WinQueryButtonCheckstate(hwnd, GREP_APPEND)))
     401          break;
     402        {
     403          sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     404                                              GREP_LISTBOX,
     405                                              LM_QUERYSELECTION,
     406                                              MPFROMSHORT(LIT_FIRST), MPVOID);
     407          if (sSelect >= 0) {
     408            *s = 0;
     409            if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) {
     410              WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     411              bstrip(s);
     412              if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';')
     413                strcat(s, ";");
     414            }
     415            WinSendDlgItemMsg(hwnd,
     416                              GREP_LISTBOX,
     417                              LM_QUERYITEMTEXT,
     418                              MPFROM2SHORT(sSelect, 8192 - strlen(s)),
     419                              MPFROMP(s + strlen(s)));
     420            bstrip(s);
     421            if (*s)
     422              WinSetDlgItemText(hwnd, GREP_MASK, s);
     423          }
     424        }
     425        break;
    423426      }
    424427      break;
     
    426429    case GREP_MASK:
    427430      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    428         WinSetDlgItemText(hwnd,
    429                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     431        WinSetDlgItemText(hwnd,
     432                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    430433      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    431         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
     434        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT));
    432435      break;
    433436    case GREP_SEARCH:
    434437      if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
    435         WinSetDlgItemText(hwnd,
    436                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     438        WinSetDlgItemText(hwnd,
     439                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    437440      if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
    438         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
     441        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT));
    439442      break;
    440443    case GREP_GREATER:
    441444      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    442         WinSetDlgItemText(hwnd,
    443                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     445        WinSetDlgItemText(hwnd,
     446                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    444447      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    445         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
     448        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT));
    446449      break;
    447450    case GREP_LESSER:
    448451      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    449         WinSetDlgItemText(hwnd,
    450                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     452        WinSetDlgItemText(hwnd,
     453                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    451454      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    452         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
     455        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT));
    453456      break;
    454457    case GREP_NEWER:
    455458      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    456         WinSetDlgItemText(hwnd,
    457                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     459        WinSetDlgItemText(hwnd,
     460                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    458461      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    459         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
     462        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT));
    460463      break;
    461464    case GREP_OLDER:
    462465      if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
    463         WinSetDlgItemText(hwnd,
    464                           GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
     466        WinSetDlgItemText(hwnd,
     467                          GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
    465468      if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
    466         WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
     469        WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT));
    467470      break;
    468471    case GREP_FINDDUPES:
    469472      {
    470         BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
    471 
    472         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes);
    473         WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes);
    474         WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes);
    475         WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes);
    476         WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes);
    477         WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
    478                         finddupes);
    479         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes);
    480         WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes);
    481         WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes);
    482         WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes);
    483         WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes);
    484         WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes);
    485         WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes);
    486         WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes);
    487         WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes);
    488         WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes);
    489         WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes);
    490         if (finddupes)
    491           WinCheckButton(hwnd, GREP_RECURSE, TRUE);
     473        BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES);
     474
     475        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes);
     476        WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes);
     477        WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes);
     478        WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes);
     479        WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes);
     480        WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES),
     481                        finddupes);
     482        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes);
     483        WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes);
     484        WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes);
     485        WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes);
     486        WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes);
     487        WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes);
     488        WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes);
     489        WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes);
     490        WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes);
     491        WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes);
     492        WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes);
     493        if (finddupes)
     494          WinCheckButton(hwnd, GREP_RECURSE, TRUE);
    492495      }
    493496    }
     
    498501    case GREP_ENV:
    499502      {
    500         CHAR *t;
    501         CHAR env[8192];
    502 
    503         *path = 0;
    504         if (!WinDlgBox(HWND_DESKTOP,
    505                        hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
    506           break;
    507         }
    508         bstrip(path);
    509         if (!*path)
    510           break;
    511         if (!stricmp(path, "LIBPATH"))
    512           LoadLibPath(env, 8192);
    513         else {
    514           p = getenv(path);
    515           if (!p)
    516             break;
    517           strcpy(env, p);
    518         }
    519         bstrip(env);
    520         if (!*env)
    521           break;
    522         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    523         bstrip(s);
    524         if (strlen(s) > 8192 - 5) {
    525           Runtime_Error(pszSrcFile, __LINE__, "too big");
    526           break;
    527         }
    528         p = strrchr(s, '\\');
    529         if (p)
    530           strcpy(simple, p + 1);
    531         else if (*s)
    532           strcpy(simple, s);
    533         else
    534           strcpy(simple, "*");
    535         if (!p)
    536           *s = 0;
    537         if (simple[strlen(simple) - 1] == ';')
    538           simple[strlen(simple) - 1] = 0;
    539         lLen = strlen(simple) + 1;
    540         p = env;
    541         while (p && *p) {
    542           strncpy(path, p, CCHMAXPATH - 1);
    543           path[CCHMAXPATH - 1] = 0;
    544           t = strchr(path, ';');
    545           if (t)
    546             *t = 0;
    547           bstrip(path);
    548           if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
    549             if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
    550               WinSetDlgItemText(hwnd, GREP_MASK, s);
    551               break;
    552             }
    553             if (!*s || (*s && s[strlen(s) - 1] != ';')) {
    554               if (*s)
    555                 strcat(s, ";");
    556               strcat(s, path);
    557               lLen += strlen(path);
    558               if (s[strlen(s) - 1] != '\\') {
    559                 lLen++;
    560                 strcat(s, "\\");
    561               }
    562               rstrip(s);
    563               if (*s) {
    564                 strcat(s, simple);
    565                 WinSetDlgItemText(hwnd, GREP_MASK, s);
    566                 WinSendDlgItemMsg(hwnd,
    567                                   GREP_MASK,
    568                                   EM_SETSEL,
    569                                   MPFROM2SHORT(strlen(s) - (lLen - 1),
    570                                                strlen(s)), MPVOID);
    571               }
    572             }
    573           }
    574           p = strchr(p, ';');
    575           if (p)
    576             p++;
    577         }
     503        CHAR *t;
     504        CHAR env[8192];
     505
     506        *path = 0;
     507        if (!WinDlgBox(HWND_DESKTOP,
     508                       hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) {
     509          break;
     510        }
     511        bstrip(path);
     512        if (!*path)
     513          break;
     514        if (!stricmp(path, "LIBPATH"))
     515          LoadLibPath(env, 8192);
     516        else {
     517          p = getenv(path);
     518          if (!p)
     519            break;
     520          strcpy(env, p);
     521        }
     522        bstrip(env);
     523        if (!*env)
     524          break;
     525        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     526        bstrip(s);
     527        if (strlen(s) > 8192 - 5) {
     528          Runtime_Error(pszSrcFile, __LINE__, "too big");
     529          break;
     530        }
     531        p = strrchr(s, '\\');
     532        if (p)
     533          strcpy(simple, p + 1);
     534        else if (*s)
     535          strcpy(simple, s);
     536        else
     537          strcpy(simple, "*");
     538        if (!p)
     539          *s = 0;
     540        if (simple[strlen(simple) - 1] == ';')
     541          simple[strlen(simple) - 1] = 0;
     542        lLen = strlen(simple) + 1;
     543        p = env;
     544        while (p && *p) {
     545          strncpy(path, p, CCHMAXPATH - 1);
     546          path[CCHMAXPATH - 1] = 0;
     547          t = strchr(path, ';');
     548          if (t)
     549            *t = 0;
     550          bstrip(path);
     551          if (isalpha(*path) && path[1] == ':' && path[2] == '\\') {
     552            if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
     553              WinSetDlgItemText(hwnd, GREP_MASK, s);
     554              break;
     555            }
     556            if (!*s || (*s && s[strlen(s) - 1] != ';')) {
     557              if (*s)
     558                strcat(s, ";");
     559              strcat(s, path);
     560              lLen += strlen(path);
     561              if (s[strlen(s) - 1] != '\\') {
     562                lLen++;
     563                strcat(s, "\\");
     564              }
     565              rstrip(s);
     566              if (*s) {
     567                strcat(s, simple);
     568                WinSetDlgItemText(hwnd, GREP_MASK, s);
     569                WinSendDlgItemMsg(hwnd,
     570                                  GREP_MASK,
     571                                  EM_SETSEL,
     572                                  MPFROM2SHORT(strlen(s) - (lLen - 1),
     573                                               strlen(s)), MPVOID);
     574              }
     575            }
     576          }
     577          p = strchr(p, ';');
     578          if (p)
     579            p++;
     580        }
    578581      }
    579582      break;
     
    583586      bstrip(s);
    584587      if (strlen(s) > 8192 - 5) {
    585         Runtime_Error(pszSrcFile, __LINE__, "too big");
    586         break;
     588        Runtime_Error(pszSrcFile, __LINE__, "too big");
     589        break;
    587590      }
    588591      *path = 0;
    589592      if (WinDlgBox(HWND_DESKTOP,
    590                     hwnd,
    591                     WalkAllDlgProc,
    592                     FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
    593         p = strrchr(s, '\\');
    594         if (p)
    595           strcpy(simple, p + 1);
    596         else if (*s)
    597           strcpy(simple, s);
    598         else
    599           strcpy(simple, "*");
    600         if (!p)
    601           *s = 0;
    602         if (simple[strlen(simple) - 1] == ';')
    603           simple[strlen(simple) - 1] = 0;
    604         lLen = strlen(simple) + 1;
    605         if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
    606           Runtime_Error(pszSrcFile, __LINE__, "too big");
    607           WinSetDlgItemText(hwnd, GREP_MASK, s);
    608           break;
    609         }
    610         if (!*s || (*s && s[strlen(s) - 1] != ';')) {
    611           if (*s)
    612             strcat(s, ";");
    613           strcat(s, path);
    614           lLen += strlen(path);
    615           if (s[strlen(s) - 1] != '\\') {
    616             lLen++;
    617             strcat(s, "\\");
    618           }
    619           rstrip(s);
    620           if (*s) {
    621             strcat(s, simple);
    622             WinSetDlgItemText(hwnd, GREP_MASK, s);
    623             WinSendDlgItemMsg(hwnd,
    624                               GREP_MASK,
    625                               EM_SETSEL,
    626                               MPFROM2SHORT(strlen(s) - (lLen - 1),
    627                                            strlen(s)), MPVOID);
    628           }
    629         }
     593                    hwnd,
     594                    WalkAllDlgProc,
     595                    FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) {
     596        p = strrchr(s, '\\');
     597        if (p)
     598          strcpy(simple, p + 1);
     599        else if (*s)
     600          strcpy(simple, s);
     601        else
     602          strcpy(simple, "*");
     603        if (!p)
     604          *s = 0;
     605        if (simple[strlen(simple) - 1] == ';')
     606          simple[strlen(simple) - 1] = 0;
     607        lLen = strlen(simple) + 1;
     608        if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) {
     609          Runtime_Error(pszSrcFile, __LINE__, "too big");
     610          WinSetDlgItemText(hwnd, GREP_MASK, s);
     611          break;
     612        }
     613        if (!*s || (*s && s[strlen(s) - 1] != ';')) {
     614          if (*s)
     615            strcat(s, ";");
     616          strcat(s, path);
     617          lLen += strlen(path);
     618          if (s[strlen(s) - 1] != '\\') {
     619            lLen++;
     620            strcat(s, "\\");
     621          }
     622          rstrip(s);
     623          if (*s) {
     624            strcat(s, simple);
     625            WinSetDlgItemText(hwnd, GREP_MASK, s);
     626            WinSendDlgItemMsg(hwnd,
     627                              GREP_MASK,
     628                              EM_SETSEL,
     629                              MPFROM2SHORT(strlen(s) - (lLen - 1),
     630                                           strlen(s)), MPVOID);
     631          }
     632        }
    630633      }
    631634      break;
     
    636639      bstrip(s);
    637640      if (*s) {
    638         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    639                                             GREP_LISTBOX,
    640                                             LM_SEARCHSTRING,
    641                                             MPFROM2SHORT(0, LIT_FIRST),
    642                                             MPFROMP(s));
    643         if (sSelect < 0) {
    644           WinSendDlgItemMsg(hwnd,
    645                             GREP_LISTBOX,
    646                             LM_INSERTITEM,
    647                             MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
    648           changed = TRUE;
    649         }
     641        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     642                                            GREP_LISTBOX,
     643                                            LM_SEARCHSTRING,
     644                                            MPFROM2SHORT(0, LIT_FIRST),
     645                                            MPFROMP(s));
     646        if (sSelect < 0) {
     647          WinSendDlgItemMsg(hwnd,
     648                            GREP_LISTBOX,
     649                            LM_INSERTITEM,
     650                            MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
     651          changed = TRUE;
     652        }
    650653      }
    651654      break;
     
    653656    case GREP_DELETE:
    654657      sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    655                                           GREP_LISTBOX,
    656                                           LM_QUERYSELECTION,
    657                                           MPFROMSHORT(LIT_FIRST), MPVOID);
     658                                          GREP_LISTBOX,
     659                                          LM_QUERYSELECTION,
     660                                          MPFROMSHORT(LIT_FIRST), MPVOID);
    658661      if (sSelect >= 0) {
    659         WinSendDlgItemMsg(hwnd,
    660                           GREP_LISTBOX,
    661                           LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
    662         changed = TRUE;
     662        WinSendDlgItemMsg(hwnd,
     663                          GREP_LISTBOX,
     664                          LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID);
     665        changed = TRUE;
    663666      }
    664667      break;
     
    702705    case IDM_HELP:
    703706      if (hwndHelp)
    704         WinSendMsg(hwndHelp,
    705                    HM_DISPLAY_HELP,
    706                    MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
     707        WinSendMsg(hwndHelp,
     708                   HM_DISPLAY_HELP,
     709                   MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID));
    707710      break;
    708711
     
    711714    case GREP_ALLHDS:
    712715      {
    713         CHAR szDrive[] = " :\\";
    714         ULONG ulDriveNum;
    715         ULONG ulDriveMap;
    716         INT x;
    717         BOOL incl;
    718 
    719         CHAR new[8192];
    720 
    721         *s = 0;
    722         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
    723         s[8192 - 1] = 0;
    724         p = strchr(s, ';');
    725         if (p)
    726           *p = 0;
    727         p = strrchr(s, '\\');
    728         if (!p)
    729           p = strrchr(s, '/');
    730         if (!p)
    731           p = strrchr(s, ':');
    732         if (p)
    733           strcpy(s, p + 1);
    734         if (!*s)
    735           strcpy(s, "*");
    736         DosError(FERR_DISABLEHARDERR);
    737         DosQCurDisk(&ulDriveNum, &ulDriveMap);
    738         *new = 0;
    739         for (x = 2; x < 26; x++) {
    740           if (ulDriveMap & (1L << x)) {
    741             incl = FALSE;
    742             switch (SHORT1FROMMP(mp1)) {
    743             case GREP_ALLHDS:
    744               if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE)))
    745                 incl = TRUE;
    746               break;
    747             case GREP_LOCALHDS:
    748               if (!(driveflags[x] &
    749                     (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
    750                      DRIVE_VIRTUAL)))
    751                 incl = TRUE;
    752               break;
    753             case GREP_REMOTEHDS:
    754               if (!(driveflags[x] &
    755                     (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
    756                   (driveflags[x] & DRIVE_REMOTE))
    757                 incl = TRUE;
    758               break;
    759             }
    760           }
    761           if (incl) {
    762             if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
    763               if (*new)
    764                 strcat(new, ";");
    765               *szDrive = x + 'A';
    766               strcat(new, szDrive);
    767               strcat(new, s);
    768             }
    769           }
    770         }
    771         if (*new)
    772           WinSetDlgItemText(hwnd, GREP_MASK, new);
     716        CHAR szDrive[] = " :\\";
     717        ULONG ulDriveNum;
     718        ULONG ulDriveMap;
     719        INT x;
     720        BOOL incl;
     721
     722        CHAR new[8192];
     723
     724        *s = 0;
     725        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s);
     726        s[8192 - 1] = 0;
     727        p = strchr(s, ';');
     728        if (p)
     729          *p = 0;
     730        p = strrchr(s, '\\');
     731        if (!p)
     732          p = strrchr(s, '/');
     733        if (!p)
     734          p = strrchr(s, ':');
     735        if (p)
     736          strcpy(s, p + 1);
     737        if (!*s)
     738          strcpy(s, "*");
     739        DosError(FERR_DISABLEHARDERR);
     740        DosQCurDisk(&ulDriveNum, &ulDriveMap);
     741        *new = 0;
     742        for (x = 2; x < 26; x++) {
     743          if (ulDriveMap & (1L << x)) {
     744            incl = FALSE;
     745            switch (SHORT1FROMMP(mp1)) {
     746            case GREP_ALLHDS:
     747              if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE)))
     748                incl = TRUE;
     749              break;
     750            case GREP_LOCALHDS:
     751              if (!(driveflags[x] &
     752                    (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE |
     753                     DRIVE_VIRTUAL)))
     754                incl = TRUE;
     755              break;
     756            case GREP_REMOTEHDS:
     757              if (!(driveflags[x] &
     758                    (DRIVE_REMOVABLE | DRIVE_IGNORE)) &&
     759                  (driveflags[x] & DRIVE_REMOTE))
     760                incl = TRUE;
     761              break;
     762            }
     763          }
     764          if (incl) {
     765            if (strlen(new) + strlen(s) + 5 < 8192 - 1) {
     766              if (*new)
     767                strcat(new, ";");
     768              *szDrive = x + 'A';
     769              strcat(new, szDrive);
     770              strcat(new, s);
     771            }
     772          }
     773        }
     774        if (*new)
     775          WinSetDlgItemText(hwnd, GREP_MASK, new);
    773776      }
    774777      break;
     
    777780      hwndCollect = WinQueryWindowULong(hwnd, QWL_USER);
    778781      if (!hwndCollect)
    779         Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
     782        Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
    780783      else {
    781         // 07 Feb 08 SHL - fixme to malloc and free in thread
    782         static GREP g;          // Passed to thread
    783 
    784         p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
    785         if (!p)
    786           break;
    787         memset(&g, 0, sizeof(GREP));
    788         g.size = sizeof(GREP);
    789         recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
    790         absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
    791         sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
    792         sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
    793         searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
    794         searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
    795         findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
    796         gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
    797         if (gRemember) {
    798           PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse",
    799                               (PVOID) & recurse, sizeof(BOOL));
    800           PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute",
    801                               (PVOID) & absolute, sizeof(BOOL));
    802           PrfWriteProfileData(fmprof, FM3Str, "Grep_Case",
    803                               (PVOID) & sensitive, sizeof(BOOL));
    804           PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles",
    805                               (PVOID) & sayfiles, sizeof(BOOL));
    806           PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles",
    807                               (PVOID) & searchFiles, sizeof(BOOL));
    808           PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
    809                               (PVOID) & searchEAs, sizeof(BOOL));
    810         }
    811         g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
    812         if (g.finddupes) {
    813           g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
    814           g.nosizedupes =
    815             WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
    816           g.ignoreextdupes =
    817             WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
    818         }
    819         // Parse file masks
    820         *p = 0;
    821         WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
    822         bstrip(p);
    823         if (!*p) {
    824           DosBeep(50, 100);
    825           WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
    826           free(p);
     784        // 07 Feb 08 SHL - fixme to malloc and free in thread
     785        static GREP g;          // Passed to thread
     786
     787        p = xmalloc(8192 + 512, pszSrcFile, __LINE__);
     788        if (!p)
     789          break;
     790        memset(&g, 0, sizeof(GREP));
     791        g.size = sizeof(GREP);
     792        recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
     793        absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
     794        sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
     795        sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
     796        searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
     797        searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
     798        findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
     799        gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS);
     800        if (gRemember) {
     801          PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse",
     802                              (PVOID) & recurse, sizeof(BOOL));
     803          PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute",
     804                              (PVOID) & absolute, sizeof(BOOL));
     805          PrfWriteProfileData(fmprof, FM3Str, "Grep_Case",
     806                              (PVOID) & sensitive, sizeof(BOOL));
     807          PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles",
     808                              (PVOID) & sayfiles, sizeof(BOOL));
     809          PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles",
     810                              (PVOID) & searchFiles, sizeof(BOOL));
     811          PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs",
     812                              (PVOID) & searchEAs, sizeof(BOOL));
     813        }
     814        g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
     815        if (g.finddupes) {
     816          g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
     817          g.nosizedupes =
     818            WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
     819          g.ignoreextdupes =
     820            WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
     821        }
     822        // Parse file masks
     823        *p = 0;
     824        WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p);
     825        bstrip(p);
     826        if (!*p) {
     827          DosBeep(50, 100);
     828          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK));
     829          free(p);
    827830#         ifdef FORTIFY
    828831          Fortify_LeaveScope();
    829832#          endif
    830           break;
    831         }
    832         strcpy(g.tosearch, p);
    833         strcpy(lastmask, p);
    834         // Parse search strings
    835         *p = 0;
    836         WinQueryWindowText(hwndMLE, 4096, p);
    837         strcpy(lasttext, p);
    838         {
    839           CHAR *pszFrom;
    840           CHAR *pszTo;
    841           ULONG matched = 0;
    842 
    843           pszTo = g.searchPattern;
    844           pszFrom = p;
    845           while (*pszFrom) {
    846             if (*pszFrom == '\r') {
    847               pszFrom++;
    848               continue;
    849             }
    850             if (*pszFrom == '\n') {
    851               if (*(pszFrom + 1))
    852                 matched++;
    853               *pszTo = 0;
    854             }
    855             else
    856               *pszTo = *pszFrom;
    857             pszTo++;
    858             pszFrom++;
    859           }
    860           if (*g.searchPattern)
    861             matched++;
    862           *pszTo++ = 0;
    863           *pszTo = 0;
    864           g.numlines = matched;
    865           if (matched) {
    866             g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
    867             if (!g.matched)
    868               g.numlines = 0;
    869           }
    870         }
    871         *p = 0;
    872         WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
    873         greater = atol(p);
    874         *p = 0;
    875         WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
    876         lesser = atol(p);
    877         *p = 0;
    878         WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
    879         newer = atoi(p);
    880         *p = 0;
    881         WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
    882         older = atoi(p);
    883         if (older || newer) {
    884           FDATE fdate;
    885           FTIME ftime;
    886           struct tm tm;
    887           time_t t;
    888 
    889           t = time(NULL);
    890           tm = *localtime(&t);
    891           fdate.day = tm.tm_mday;
    892           fdate.month = tm.tm_mon + 1;
    893           fdate.year = tm.tm_year - 80;
    894           ftime.hours = tm.tm_hour;
    895           ftime.minutes = tm.tm_min;
    896           ftime.twosecs = tm.tm_sec / 2;
    897           if (older) {
    898             g.olderthan = SecsSince1980(&fdate, &ftime);
    899             g.olderthan -= (older * (24L * 60L * 60L));
    900           }
    901           if (newer) {
    902             g.newerthan = SecsSince1980(&fdate, &ftime);
    903             g.newerthan -= (newer * (24L * 60L * 60L));
    904           }
    905         }
    906         if (!newer)
    907           g.newerthan = 0;
    908         if (!older)
    909           g.olderthan = 0;
    910         g.greaterthan = greater;
    911         g.lessthan = lesser;
    912         g.absFlag = absolute;
    913         g.caseFlag = sensitive;
    914         g.dirFlag = recurse;
    915         g.sayfiles = sayfiles;
    916         g.searchEAs = searchEAs;
    917         g.searchFiles = searchFiles;
    918         g.findifany = findifany;
    919         g.hwndFiles = hwndCollect;
    920         g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT);
    921         g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED);
    922         g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
    923         g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
    924         g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
    925         if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) {
    926           Runtime_Error(pszSrcFile, __LINE__,
    927                         GetPString(IDS_COULDNTSTARTTHREADTEXT));
    928           free(p);
     833          break;
     834        }
     835        strcpy(g.tosearch, p);
     836        strcpy(lastmask, p);
     837        // Parse search strings
     838        *p = 0;
     839        WinQueryWindowText(hwndMLE, 4096, p);
     840        strcpy(lasttext, p);
     841        {
     842          CHAR *pszFrom;
     843          CHAR *pszTo;
     844          ULONG matched = 0;
     845
     846          pszTo = g.searchPattern;
     847          pszFrom = p;
     848          while (*pszFrom) {
     849            if (*pszFrom == '\r') {
     850              pszFrom++;
     851              continue;
     852            }
     853            if (*pszFrom == '\n') {
     854              if (*(pszFrom + 1))
     855                matched++;
     856              *pszTo = 0;
     857            }
     858            else
     859              *pszTo = *pszFrom;
     860            pszTo++;
     861            pszFrom++;
     862          }
     863          if (*g.searchPattern)
     864            matched++;
     865          *pszTo++ = 0;
     866          *pszTo = 0;
     867          g.numlines = matched;
     868          if (matched) {
     869            g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__);
     870            if (!g.matched)
     871              g.numlines = 0;
     872          }
     873        }
     874        *p = 0;
     875        WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p);
     876        greater = atol(p);
     877        *p = 0;
     878        WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p);
     879        lesser = atol(p);
     880        *p = 0;
     881        WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p);
     882        newer = atoi(p);
     883        *p = 0;
     884        WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p);
     885        older = atoi(p);
     886        if (older || newer) {
     887          FDATE fdate;
     888          FTIME ftime;
     889          struct tm tm;
     890          time_t t;
     891
     892          t = time(NULL);
     893          tm = *localtime(&t);
     894          fdate.day = tm.tm_mday;
     895          fdate.month = tm.tm_mon + 1;
     896          fdate.year = tm.tm_year - 80;
     897          ftime.hours = tm.tm_hour;
     898          ftime.minutes = tm.tm_min;
     899          ftime.twosecs = tm.tm_sec / 2;
     900          if (older) {
     901            g.olderthan = SecsSince1980(&fdate, &ftime);
     902            g.olderthan -= (older * (24L * 60L * 60L));
     903          }
     904          if (newer) {
     905            g.newerthan = SecsSince1980(&fdate, &ftime);
     906            g.newerthan -= (newer * (24L * 60L * 60L));
     907          }
     908        }
     909        if (!newer)
     910          g.newerthan = 0;
     911        if (!older)
     912          g.olderthan = 0;
     913        g.greaterthan = greater;
     914        g.lessthan = lesser;
     915        g.absFlag = absolute;
     916        g.caseFlag = sensitive;
     917        g.dirFlag = recurse;
     918        g.sayfiles = sayfiles;
     919        g.searchEAs = searchEAs;
     920        g.searchFiles = searchFiles;
     921        g.findifany = findifany;
     922        g.hwndFiles = hwndCollect;
     923        g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT);
     924        g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED);
     925        g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile;
     926        g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr;
     927        g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag;
     928        if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) {
     929          Runtime_Error(pszSrcFile, __LINE__,
     930                        GetPString(IDS_COULDNTSTARTTHREADTEXT));
     931          free(p);
    929932#         ifdef FORTIFY
    930933          Fortify_LeaveScope();
    931934#          endif
    932           WinDismissDlg(hwnd, 0);
    933           break;
    934         }
    935         DosSleep(100); //05 Aug 07 GKY 128
    936         free(p);
     935          WinDismissDlg(hwnd, 0);
     936          break;
     937        }
     938        DosSleep(100); //05 Aug 07 GKY 128
     939        free(p);
    937940#       ifdef FORTIFY
    938941        Fortify_LeaveScope();
     
    940943      }
    941944      if (changed) {
    942         // Grep mask list changed
    943         SHORT x;
    944 
    945         sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    946                                             GREP_LISTBOX,
    947                                             LM_QUERYITEMCOUNT,
    948                                             MPVOID, MPVOID);
     945        // Grep mask list changed
     946        SHORT x;
     947
     948        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
     949                                            GREP_LISTBOX,
     950                                            LM_QUERYITEMCOUNT,
     951                                            MPVOID, MPVOID);
    949952        if (sSelect > 0) {
    950953          BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT");
    951954          if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
    952955            break; //already gave error msg
    953           fp = xfopen(s, "w", pszSrcFile, __LINE__);
    954           if (fp) {
    955             fputs(GetPString(IDS_GREPFILETEXT), fp);
    956             for (x = 0; x < sSelect; x++) {
    957               *s = 0;
    958               WinSendDlgItemMsg(hwnd,
    959                                 GREP_LISTBOX,
    960                                 LM_QUERYITEMTEXT,
    961                                 MPFROM2SHORT(x, 8192), MPFROMP(s));
    962               bstrip(s);
    963               if (*s)
    964                 fprintf(fp, "%s\n", s);
    965             }
    966             fclose(fp);
    967           }
    968         }
     956          fp = xfopen(s, "w", pszSrcFile, __LINE__);
     957          if (fp) {
     958            fputs(GetPString(IDS_GREPFILETEXT), fp);
     959            for (x = 0; x < sSelect; x++) {
     960              *s = 0;
     961              WinSendDlgItemMsg(hwnd,
     962                                GREP_LISTBOX,
     963                                LM_QUERYITEMTEXT,
     964                                MPFROM2SHORT(x, 8192), MPFROMP(s));
     965              bstrip(s);
     966              if (*s)
     967                fprintf(fp, "%s\n", s);
     968            }
     969            fclose(fp);
     970          }
     971        }
    969972      }
    970973      WinDismissDlg(hwnd, 1);
Note: See TracChangeset for help on using the changeset viewer.