Changeset 781 for trunk/dll/dirsize.c


Ignore:
Timestamp:
Aug 12, 2007, 5:04:05 AM (18 years ago)
Author:
Steven Levine
Message:

ProcessDir: remove unneeded reallocs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/dirsize.c

    r780 r781  
    2828  03 Aug 07 SHL DirSizeProc; correct sizing and positioning to be deterministic
    2929  06 Aug 07 GKY Reduce DosSleep times (ticket 148)
    30 
     30  11 Aug 07 SHL ProcessDir: remove unneeded reallocs
    3131
    3232***********************************************************************/
     
    3636#define INCL_GPI
    3737#define INCL_LONGLONG
     38#define INCL_DOSERRORS
    3839#include <os2.h>
    3940
     
    99100  ULONGLONG ull;
    100101  HDIR hdir;
    101   FILEFINDBUF4 *pffb, *pffbTemp;
     102  FILEFINDBUF4 *pffb;
    102103  APIRET rc;
    103104  RECORDINSERT ri;
     
    107108  *pullTotalBytes = 0;                  // In case we fail
    108109
    109   pffb = xmalloc(sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
     110  pffb = xmalloc(sizeof(FILEFINDBUF4) * FilesToGet, pszSrcFile, __LINE__);
    110111  if (!pffb)
    111     return FALSE;
     112    return FALSE;                       // Error already reported
     113
    112114  strcpy(maskstr, pszFileName);
    113115  if (maskstr[strlen(maskstr) - 1] != '\\')
     
    115117  pEndMask = &maskstr[strlen(maskstr)]; // Point after last backslash
    116118  strcat(maskstr, "*");
    117   //printf("%s\n",maskstr);
    118119
    119120  hdir = HDIR_CREATE;
    120121  nm = 1;
     122  // 11 Aug 07 SHL fixme to know if we can bypass memset
    121123  memset(pffb, 0, sizeof(FILEFINDBUF4));
    122124  DosError(FERR_DISABLEHARDERR);
    123   //printf("FIND1\n");
     125  // Check directory exists
    124126  rc = DosFindFirst(pszFileName, &hdir,
    125127                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
     
    156158    pci->pszDispAttr = NullStr;
    157159    pci->pszSubject = NullStr;
    158   }
     160  } // if got something
    159161  else {
     162    // No match
    160163    free(pffb);
    161     Dos_Error(MB_ENTER,
    162               rc,
    163               HWND_DESKTOP,
    164               pszSrcFile,
    165               __LINE__, GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
     164    Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     165              GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
    166166    return FALSE;
    167167  }
     
    188188  // fixme to know why - it appears to be indirectly saving length, but why?
    189189  pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName);
    190   pci->pszLongName = pci->pszFileName;          // fixme to be sure?
     190  pci->pszLongName = pci->pszFileName;  // fixme to be sure?
    191191  pci->rc.pszIcon = pci->pszFileName;
    192192  pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
     
    207207    return FALSE;
    208208  }
     209
     210  // Find files and directories in this directory
    209211  hdir = HDIR_CREATE;
    210   pffbTemp = pffb;
    211212  nm = FilesToGet;
    212   pffb = xrealloc(pffb, (nm + 1) * sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
    213   if (!pffb) { //Error already sent
    214         free(pffbTemp);
    215         return FALSE;
    216       }
    217213  rc = DosFindFirst(maskstr, &hdir,
    218214                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
    219215                    FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY,
    220                     pffb, (nm + 1) * sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);
     216                    pffb, nm * sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);
    221217  if (!rc) {
    222     register PBYTE fb = (PBYTE) pffb;
     218    PBYTE fb = (PBYTE)pffb;
    223219    FILEFINDBUF4 *pffbFile;
    224220    ULONG x;
    225     UINT y = 1;
    226221
    227222    while (!rc) {
    228223      priority_normal();
    229       //printf("Found %lu\n",nm);
    230224      for (x = 0; x < nm; x++) {
    231         pffbFile = (FILEFINDBUF4 *) fb;
    232         //printf("%s\n",pffbFile->achName);
    233         //fflush(stdout);
     225        pffbFile = (FILEFINDBUF4 *)fb;
    234226        // Total size skipping . and ..
    235227        if ((~pffbFile->attrFile & FILE_DIRECTORY) ||
     
    256248          break;
    257249        fb += pffbFile->oNextEntryOffset;
    258       }                                 // for matches
     250      } // for matches
    259251      if (*pchStopFlag)
    260         break;
     252        break;
    261253      DosSleep(1);
    262       pffbTemp = pffb;
    263       nm = FilesToGet;                          /* FilesToGet */
    264       y++;
    265       pffb = xrealloc(pffb, y * (nm + 1) * sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
    266       if (!pffb) { //Error already sent
    267         free(pffbTemp);
    268         break;
    269       }
     254      nm = FilesToGet;
    270255      DosError(FERR_DISABLEHARDERR);
    271       rc = DosFindNext(hdir, pffb, y * (nm + 1) * sizeof(FILEFINDBUF4), &nm);
    272     }                                   // while more found
     256      rc = DosFindNext(hdir, pffb, sizeof(FILEFINDBUF4) * FilesToGet, &nm);
     257    } // while more found
     258
     259    if (rc != ERROR_NO_MORE_FILES) {
     260      Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     261                GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
     262    }
     263
    273264    DosFindClose(hdir);
    274265    priority_normal();
    275   }
     266  } // if got files or directories
    276267
    277268  free(pffb);
     
    323314        // Need unique buffer 23 Jul 07 SHL
    324315        pci->pszLongName = xmalloc(2, pszSrcFile, __LINE__);
    325         pci->pszLongName[0] = 0;                // Make null string
    326         pci->pszLongName[1] = 1;                // Flag root - hack cough
     316        pci->pszLongName[0] = 0;        // Make null string
     317        pci->pszLongName[1] = 1;        // Flag root - hack cough
    327318      }
    328319      else
     
    632623            p = strchr(pci->pszFileName, '\r');
    633624            if (p) {
    634               /* draw text */
    635               if (!pci->cbFile)         /* no size */
     625              // draw text
     626              if (!pci->cbFile)         // no size
    636627                GpiSetColor(oi->hps, CLR_DARKGRAY);
    637               else if (!pci->easize)    /* no size below */
     628              else if (!pci->easize)    // no size below
    638629                GpiSetColor(oi->hps, CLR_DARKBLUE);
    639630              else
     
    656647              // Place text above graph box with a bit of whitespace between
    657648              ptl.x = oi->rclItem.xLeft;
    658               ptl.y = yBottom + boxHeight + 8;          // 03 Aug 07 SHL
     649              ptl.y = yBottom + boxHeight + 8;  // 03 Aug 07 SHL
    659650              // GpiMove(oi->hps, &ptl);
    660651              GpiCharStringAt(oi->hps, &ptl, strlen(pci->pszFileName),
     
    663654              *p = '\r';                // Restore
    664655
    665               /* draw the graph box */
     656              // draw the graph box
    666657              // GpiQueryTextBox(oi->hps, 1, "#", TXTBOX_COUNT, aptl);  // 03 Aug 07 SHL
    667               /* draw black outline */
     658              // draw black outline
    668659              GpiSetColor(oi->hps, CLR_BLACK);
    669660              ptl.x = oi->rclItem.xLeft;
     
    673664              ptl.y = yBottom + boxHeight;
    674665              GpiBox(oi->hps, DRO_OUTLINE, &ptl, 0, 0);
    675               /* fill with gray */
     666              // fill with gray
    676667              GpiSetColor(oi->hps, CLR_PALEGRAY);
    677668              ptl.x = oi->rclItem.xLeft + 1;
     
    682673              GpiBox(oi->hps, DRO_OUTLINEFILL, &ptl, 0, 0);
    683674
    684               /* draw shadow at bottom & right sides */
     675              // draw shadow at bottom & right sides
    685676              GpiSetColor(oi->hps, CLR_DARKGRAY);
    686677              ptl.x = oi->rclItem.xLeft + 1;
     
    692683              GpiLine(oi->hps, &ptl);
    693684
    694               /* draw highlight at top and left sides */
     685              // draw highlight at top and left sides
    695686              GpiSetColor(oi->hps, CLR_WHITE);
    696687              ptl.x = oi->rclItem.xLeft + 1;
     
    699690              GpiLine(oi->hps, &ptl);
    700691
    701               /* draw shadow of box */
     692              // draw shadow of box
    702693              GpiSetColor(oi->hps, CLR_DARKGRAY);
    703694              ptl.x = oi->rclItem.xLeft + 2;
     
    715706              GpiLine(oi->hps, &ptl);
    716707
    717               /* fill box with graph bar, flags is integer % */
     708              // fill box with graph bar, flags is integer %
    718709              if (pci->flags) {
    719                 if (*(pci->pszLongName + 1) == 1)       /* is root record */
     710                if (*(pci->pszLongName + 1) == 1)       // is root record
    720711                  GpiSetColor(oi->hps, CLR_DARKGREEN);
    721712                else
     
    728719                GpiBox(oi->hps, DRO_OUTLINEFILL, &ptl, 0, 0);
    729720
    730                 /* draw highlights and shadows on graph */
     721                // draw highlights and shadows on graph
    731722                if (*(pci->pszLongName + 1) == 1)
    732723                  GpiSetColor(oi->hps, CLR_GREEN);
     
    756747              }
    757748
    758               /* draw hash marks in box */
     749              // draw hash marks in box
    759750              GpiSetColor(oi->hps, CLR_WHITE);
    760751              clr = CLR_WHITE;
Note: See TracChangeset for help on using the changeset viewer.