Changeset 783 for trunk/dll/objcnr.c


Ignore:
Timestamp:
Aug 14, 2007, 6:09:54 AM (18 years ago)
Author:
Steven Levine
Message:

Rework DosFindFirst/Next loops to optimize memory allocation and code paths
Adjust FilesToGet limits
Update configuration notebook scanning page
Start updating #pragma alloc_text positioning for OpenWatcom compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/objcnr.c

    r775 r783  
    1818  03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
    1919  06 Aug 07 GKY Reduce DosSleep times (ticket 148)
    20 
     20  13 Aug 07 SHL Avoid realloc - not needed; sanitize code
     21  13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
    2122
    2223***********************************************************************/
     
    2425#define INCL_DOS
    2526#define INCL_WIN
     27#define INCL_DOSERRORS
    2628#include <os2.h>
    2729
     
    5961static HWND objcnrwnd;
    6062
    61 #pragma alloc_text(OBJCNR,ProcessDir,FillCnrsThread,ObjCnrDlgProc)
    62 
    63 static VOID ProcessDir(HWND hwndCnr, CHAR * filename, PCNRITEM pciParent,
    64                        CHAR * stopflag)
     63static VOID ProcessDir(HWND hwndCnr,
     64                       CHAR *filename,
     65                      PCNRITEM pciParent,
     66                       CHAR *stopflag)
    6567{
    6668  CHAR maskstr[CCHMAXPATH], *endpath, *p;
    67   ULONG nm, ulM;
     69  ULONG ulFindCnt, ulFindMax;
     70  ULONG ulBufBytes;
    6871  HDIR hdir;
    69   FILEFINDBUF3 *ffb, *fft;
     72  PFILEFINDBUF3 pffbArray;
    7073  APIRET rc;
    7174  RECORDINSERT ri;
    7275  PCNRITEM pciP;
    73 
    74   ffb = xmalloc(sizeof(FILEFINDBUF3), pszSrcFile, __LINE__);
    75   if (!ffb)
    76     return;
     76  HPOINTER hptr;
     77
     78  ulBufBytes = sizeof(FILEFINDBUF3) * FilesToGet;
     79  pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
     80  if (!pffbArray)
     81    return;                             // Error already reported
    7782  strcpy(maskstr, filename);
    7883  if (maskstr[strlen(maskstr) - 1] != '\\')
     
    8186  strcat(maskstr, "*");
    8287  hdir = HDIR_CREATE;
    83   nm = 1;
     88  ulFindCnt = 1;
    8489  rc = DosFindFirst(filename, &hdir,
    8590                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
    8691                    FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
    87                     ffb, sizeof(FILEFINDBUF3), &nm, FIL_STANDARD);
     92                    pffbArray, ulBufBytes, &ulFindCnt, FIL_STANDARD);
    8893  if (!rc)
    8994    DosFindClose(hdir);
    90 
    91   if (rc) {                             /* work around furshluginer FAT bug... */
    92     if (IsRoot(filename))
    93       rc = 0;
    94   }
    95 
    96   if ((!rc && (ffb->attrFile & FILE_DIRECTORY))) {
     95  // work around furshluginer FAT root bug
     96  else if (IsRoot(filename))
     97    rc = 0;
     98
     99  if ((!rc && (pffbArray->attrFile & FILE_DIRECTORY))) {
    97100    pciP = WinSendMsg(hwndCnr,
    98101                      CM_ALLOCRECORD,
     
    100103                      MPFROMLONG(1));
    101104    if (!pciP) {
    102       free(ffb);
     105      Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_ALLOCRECORD");
     106      free(pffbArray);
    103107      return;
    104108    }
     
    125129  }
    126130  else {
    127     free(ffb);
    128     Dos_Error(MB_ENTER,
    129               rc,
    130               HWND_DESKTOP,
    131               pszSrcFile,
    132               __LINE__, GetPString(IDS_CANTFINDDIRTEXT), filename);
     131    free(pffbArray);
     132    Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     133              GetPString(IDS_CANTFINDDIRTEXT), filename);
    133134    return;
    134135  }
    135   {
    136     HPOINTER hptr;
    137 
    138     hptr = WinLoadFileIcon(pciP->pszFileName, FALSE);
    139     if (hptr)
    140       pciP->rc.hptrIcon = hptr;
    141   }
     136
     137  hptr = WinLoadFileIcon(pciP->pszFileName, FALSE);
     138  if (hptr)
     139    pciP->rc.hptrIcon = hptr;
     140
    142141  if (!pciP->rc.hptrIcon || pciP->rc.hptrIcon == hptrFile)      /* OS/2 bug bug bug bug */
    143142    pciP->rc.hptrIcon = hptrDir;
     143
    144144  memset(&ri, 0, sizeof(RECORDINSERT));
    145145  ri.cb = sizeof(RECORDINSERT);
     
    150150  ri.fInvalidateRecord = TRUE;
    151151  if (!WinSendMsg(hwndCnr, CM_INSERTRECORD, MPFROMP(pciP), MPFROMP(&ri))) {
    152     free(ffb);
     152    free(pffbArray);
    153153    return;
    154154  }
     
    156156  if (!isalpha(*maskstr) || maskstr[1] != ':' || maskstr[2] != '\\' ||
    157157      ((driveflags[toupper(*maskstr) - 'A'] & DRIVE_REMOTE) && fRemoteBug))
    158     ulM = 1;
     158    ulFindMax = 1;
    159159  else
    160     ulM = FilesToGet;
    161   if (ulM > 1) {
    162     fft = xrealloc(ffb, sizeof(FILEFINDBUF3) * ulM, pszSrcFile, __LINE__);
    163     if (!fft)
    164       ulM = 1;
    165     else
    166       ffb = fft;
    167   }
    168   nm = ulM;
     160    ulFindMax = FilesToGet;
     161  ulFindCnt = ulFindMax;
    169162  rc = DosFindFirst(maskstr, &hdir,
    170163                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
    171                     FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY, ffb,
    172                     sizeof(FILEFINDBUF3) * ulM, &nm, FIL_STANDARD);
     164                    FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
     165                    pffbArray, ulBufBytes, &ulFindCnt, FIL_STANDARD);
    173166  if (!rc) {
    174 
    175     register PBYTE fb = (PBYTE) ffb;
    176     FILEFINDBUF3 *pffbFile;
     167    PFILEFINDBUF3 pffbFile;
    177168    ULONG x;
    178169
    179170    while (!rc) {
    180       for (x = 0; x < nm; x++) {
    181         pffbFile = (FILEFINDBUF3 *) fb;
     171      pffbFile = pffbArray;
     172      for (x = 0; x < ulFindCnt; x++) {
    182173        if (*stopflag)
    183174          break;
     
    192183        if (!pffbFile->oNextEntryOffset)
    193184          break;
    194         fb += pffbFile->oNextEntryOffset;
    195       }
     185        pffbFile = (PFILEFINDBUF3)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
     186      } // for
    196187      DosSleep(1);
    197188      if (*stopflag)
    198189        break;
    199       nm = ulM;
    200       rc = DosFindNext(hdir, ffb, sizeof(FILEFINDBUF3) * ulM, &nm);
    201     }
     190      ulFindCnt = ulFindMax;
     191      rc = DosFindNext(hdir, pffbArray, ulBufBytes, &ulFindCnt);
     192    } // while
    202193    DosFindClose(hdir);
    203194  }
    204   free(ffb);
     195
     196  if (rc && rc != ERROR_NO_MORE_FILES) {
     197    Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     198              GetPString(IDS_CANTFINDDIRTEXT), filename);
     199  }
     200
     201  free(pffbArray);
    205202  WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pciP),
    206203             MPFROM2SHORT(1, 0));
     
    211208  HAB hab;
    212209  HMQ hmq;
    213   DIRSIZE *dirsize = (DIRSIZE *) args;
    214 
    215   if (!dirsize)
     210  DIRSIZE *dirsize = (DIRSIZE *)args;
     211
     212  if (!dirsize) {
     213    Runtime_Error(pszSrcFile, __LINE__, "no data");
    216214    return;
     215  }
    217216
    218217  DosError(FERR_DISABLEHARDERR);
     
    430429  return WinDefDlgProc(hwnd, msg, mp1, mp2);
    431430}
     431
     432#pragma alloc_text(OBJCNR,ProcessDir,FillCnrsThread,ObjCnrDlgProc)
Note: See TracChangeset for help on using the changeset viewer.