Changeset 402 for trunk/dll/grep2.c


Ignore:
Timestamp:
Jul 29, 2006, 9:59:34 PM (19 years ago)
Author:
root
Message:

Avoid 0 length malloc, optimize option checks
Use xfgets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep2.c

    r382 r402  
    33
    44  $Id$
     5
     6  Grep dialog for collector
    57
    68  Copyright (c) 1993-98 M. Kimes
     
    1214  06 Jun 05 SHL Rework for VAC3.65 compat, lose excess statics
    1315  17 Jul 06 SHL Use Runtime_Error
     16  28 Jul 06 SHL Avoid 0 length malloc, optimize option checks
     17  29 Jul 06 SHL Use xfgets
    1418
    1519  fixme for more excess locals to be gone
     
    288292    if (fp)
    289293    {
    290       while (!feof(fp))
    291       {
    292         if (!fgets(s, 8192 + 4, fp))
     294      while (!feof(fp)) {
     295        if (!xfgets_bstripcr(s, 8192 + 4, fp,pszSrcFile,__LINE__))
    293296          break;
    294         bstripcr(s);
    295         if (*s && *s != ';')
     297        if (*s && *s != ';') {
    296298          WinSendDlgItemMsg(hwnd,
    297299                            GREP_LISTBOX,
     
    299301                            MPFROM2SHORT(LIT_SORTASCENDING, 0),
    300302                            MPFROMP(s));
     303        }
    301304      }
    302305      fclose(fp);
     
    305308    FillPathListBox(hwnd,
    306309                    WinWindowFromID(hwnd, GREP_DRIVELIST),
    307                     (HWND) 0,
     310                    (HWND)0,
    308311                    NULL,
    309312                    FALSE);
     
    319322  case UM_SETDIR:
    320323    PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP),
    321                         (HPS) 0,
     324                        (HPS)0,
    322325                        FALSE,
    323326                        TRUE);
     
    327330    /* set focus to window hwnd in mp1 */
    328331    if (mp1)
    329       WinSetFocus(HWND_DESKTOP, (HWND) mp1);
     332      WinSetFocus(HWND_DESKTOP, (HWND)mp1);
    330333    return 0;
    331334
     
    917920      if (!hwndCollect)
    918921        Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
    919       else
    920       {
     922      else {
    921923        static GREP g;          // Passed to thread
    922924
     
    926928        memset(&g, 0, sizeof(GREP));
    927929        g.size = sizeof(GREP);
    928         if (WinQueryButtonCheckstate(hwnd, GREP_RECURSE))
    929           recurse = TRUE;
    930         else
    931           recurse = FALSE;
    932         if (WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE))
    933           absolute = TRUE;
    934         else
    935           absolute = FALSE;
    936         if (WinQueryButtonCheckstate(hwnd, GREP_CASE))
    937           sensitive = TRUE;
    938         else
    939           sensitive = FALSE;
    940         if (WinQueryButtonCheckstate(hwnd, GREP_SAYFILES))
    941           sayfiles = TRUE;
    942         else
    943           sayfiles = FALSE;
    944         if (WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS))
    945           searchEAs = TRUE;
    946         else
    947           searchEAs = FALSE;
    948         if (WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES))
    949           searchFiles = TRUE;
    950         else
    951           searchFiles = FALSE;
    952         if (WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY))
    953           findifany = TRUE;
    954         else
    955           findifany = FALSE;
    956         if (WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES))
    957           g.finddupes = TRUE;
    958         else
    959           g.finddupes = FALSE;
    960         if (g.finddupes)
    961         {
    962           if (WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES))
    963             g.CRCdupes = TRUE;
    964           else
    965             g.CRCdupes = FALSE;
    966           if (WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES))
    967             g.nosizedupes = TRUE;
    968           else
    969             g.nosizedupes = FALSE;
    970           if (WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES))
    971             g.ignoreextdupes = TRUE;
    972           else
    973             g.ignoreextdupes = FALSE;
    974         }
     930        recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0;
     931        absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0;
     932        sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0;
     933        sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0;
     934        searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0;
     935        searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0;
     936        findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0;
     937        g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0;
     938        if (g.finddupes) {
     939          g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0;
     940          g.nosizedupes = WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0;
     941          g.ignoreextdupes = WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0;
     942        }
     943        // Parse file masks
    975944        *p = 0;
    976         WinQueryDlgItemText(hwnd,
    977                             GREP_MASK,
    978                             8192,
    979                             p);
     945        WinQueryDlgItemText(hwnd,GREP_MASK,8192,p);
    980946        bstrip(p);
    981947        if (!*p)
    982948        {
    983949          DosBeep(50, 100);
    984           WinSetFocus(HWND_DESKTOP,
    985                       WinWindowFromID(hwnd, GREP_MASK));
     950          WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd, GREP_MASK));
    986951          free(p);
    987952          break;
     
    989954        strcpy(g.tosearch, p);
    990955        strcpy(lastmask, p);
     956        // Parse search strings
    991957        *p = 0;
    992         WinQueryWindowText(hwndMLE,
    993                            4096,
    994                            p);
     958        WinQueryWindowText(hwndMLE,4096,p);
    995959        strcpy(lasttext, p);
    996960        {
     
    1024988          *pszTo = 0;
    1025989          g.numlines = matched;
    1026           g.matched = xmalloc(g.numlines,pszSrcFile,__LINE__);
    1027           if (!g.matched)
    1028             g.numlines = 0;
     990          if (matched) {
     991            g.matched = xmalloc(g.numlines,pszSrcFile,__LINE__);
     992            if (!g.matched)
     993              g.numlines = 0;
     994          }
    1029995        }
    1030996        *p = 0;
    1031         WinQueryDlgItemText(hwnd,
    1032                             GREP_GREATER,
    1033                             34,
    1034                             p);
     997        WinQueryDlgItemText(hwnd,GREP_GREATER,34,p);
    1035998        greater = atol(p);
    1036999        *p = 0;
    1037         WinQueryDlgItemText(hwnd,
    1038                             GREP_LESSER,
    1039                             34,
    1040                             p);
     1000        WinQueryDlgItemText(hwnd,GREP_LESSER,34,p);
    10411001        lesser = atol(p);
    10421002        *p = 0;
    1043         WinQueryDlgItemText(hwnd,
    1044                             GREP_NEWER,
    1045                             34,
    1046                             p);
     1003        WinQueryDlgItemText(hwnd,GREP_NEWER,34,p);
    10471004        newer = atoi(p);
    10481005        *p = 0;
    1049         WinQueryDlgItemText(hwnd,
    1050                             GREP_OLDER,
    1051                             34,
    1052                             p);
     1006        WinQueryDlgItemText(hwnd,GREP_OLDER,34,p);
    10531007        older = atoi(p);
    1054         if (older || newer)
    1055         {
     1008        if (older || newer) {
    10561009          FDATE fdate;
    10571010          FTIME ftime;
     
    10671020          ftime.minutes = tm.tm_min;
    10681021          ftime.twosecs = tm.tm_sec / 2;
    1069           if (older)
    1070           {
     1022          if (older) {
    10711023            g.olderthan = SecsSince1980(&fdate, &ftime);
    10721024            g.olderthan -= (older * (24L * 60L * 60L));
    10731025          }
    1074           if (newer)
    1075           {
     1026          if (newer) {
    10761027            g.newerthan = SecsSince1980(&fdate, &ftime);
    10771028            g.newerthan -= (newer * (24L * 60L * 60L));
     
    10971048        g.antiattr = ((DIRCNRDATA *) INSTDATA(hwndCollect)) -> mask.antiattr;
    10981049        g.stopflag = &((DIRCNRDATA *) INSTDATA(hwndCollect)) -> stopflag;
    1099         if (_beginthread(dogrep, NULL, 524280, (PVOID)&g) == -1)
    1100         {
     1050        if (_beginthread(dogrep, NULL, 524280, (PVOID)&g) == -1) {
    11011051          Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_COULDNTSTARTTHREADTEXT));
    11021052          free(p);
     
    11081058        free(p);
    11091059      }
    1110       if (changed)
    1111       {
     1060      if (changed) {
    11121061        SHORT x;
    1113 
    11141062        sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
    11151063                                            GREP_LISTBOX,
     
    11171065                                            MPVOID,
    11181066                                            MPVOID);
    1119         if (sSelect > 0)
    1120         {
     1067        if (sSelect > 0) {
    11211068          save_dir2(s);
    11221069          if (s[strlen(s) - 1] != '\\')
     
    11241071          strcat(s, "GREPMASK.DAT");
    11251072          fp = xfopen(s, "w",pszSrcFile,__LINE__);
    1126           if (fp)
    1127           {
     1073          if (fp) {
    11281074            fputs(GetPString(IDS_GREPFILETEXT), fp);
    1129             for (x = 0; x < sSelect; x++)
    1130             {
     1075            for (x = 0; x < sSelect; x++) {
    11311076              *s = 0;
    11321077              WinSendDlgItemMsg(hwnd,
Note: See TracChangeset for help on using the changeset viewer.