Changeset 907 for trunk/dll/makelist.c


Ignore:
Timestamp:
Jan 6, 2008, 8:26:17 AM (18 years ago)
Author:
Steven Levine
Message:

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/makelist.c

    r841 r907  
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2003, 2007 Steven H.Levine
     9  Copyright (c) 2003, 2008 Steven H.Levine
    1010
    1111  12 Feb 03 SHL AddToFileList: standardize EA math
     
    1717***********************************************************************/
    1818
     19#include <stdlib.h>
     20#include <string.h>
     21
    1922#define INCL_DOS
    2023#define INCL_WIN
    2124#define INCL_LONGLONG
    22 #include <os2.h>
    23 
    24 #include <stdio.h>
    25 #include <stdlib.h>
    26 #include <string.h>
    27 #include <ctype.h>
    28 
    29 #include "fm3dll.h"
     25
    3026#include "fm3str.h"
     27#include "makelist.h"
     28#include "errutil.h"                    // Dos_Error...
     29#include "strutil.h"                    // GetPString
     30#include "dircnrs.h"
     31#include "fm3dll.h"                     // 05 Jan 08 SHL fixme to be gone
    3132
    3233static PSZ pszSrcFile = __FILE__;
    3334
    34 VOID SortList(LISTINFO * li)
     35VOID SortList(LISTINFO *li)
    3536{
    3637  /* bubble-sort entries by size, descending */
    3738
    38   INT x;
     39  UINT x;
    3940  CHAR *s;
    4041  ULONG l;
     
    6465}
    6566
    66 VOID FreeListInfo(LISTINFO * li)
     67VOID FreeListInfo(LISTINFO *li)
    6768{
    6869  if (li) {
     
    7778}
    7879
    79 VOID FreeList(CHAR ** list)
    80 {
    81   register INT x;
     80VOID FreeList(CHAR **list)
     81{
     82  UINT x;
    8283
    8384  if (list) {
     
    9697}
    9798
    98 INT AddToFileList(CHAR * string, FILEFINDBUF4L * ffb4, FILELIST *** list,
    99                   INT * numfiles, INT * numalloced)
     99INT AddToFileList(CHAR *string, FILEFINDBUF4L *ffb4, FILELIST ***list,
     100                  UINT *pnumfiles, UINT *pnumalloced)
    100101{
    101102  FILELIST *pfl;
     
    103104  if (string && ffb4) {
    104105    // Ensure room for NULL entry
    105     if (((*numfiles) + 3) > *numalloced) {
     106    if (((*pnumfiles) + 3) > *pnumalloced) {
    106107      FILELIST **pflArray;
    107108
    108109      // Use plain realloc for speed
    109110      // 06 Aug 07 SHL fixme to know why + 6
    110       pflArray = realloc(*list, (*numalloced + 6) * sizeof(FILELIST *));
     111      pflArray = realloc(*list, (*pnumalloced + 6) * sizeof(FILELIST *));
    111112      if (!pflArray) {
    112113        Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
    113114        return 1;
    114115      }
    115       (*numalloced) += 6;
     116      (*pnumalloced) += 6;
    116117      *list = pflArray;
    117118    }
     
    132133    pfl->easize = CBLIST_TO_EASIZE(ffb4->cbList);
    133134    strcpy(pfl->fname, string);
    134     (*list)[*numfiles] = pfl;
    135     (*numfiles)++;
     135    (*list)[*pnumfiles] = pfl;
     136    (*pnumfiles)++;
    136137    // Ensure list always ends with two NULL entries
    137138    // 06 Aug 07 SHL fixme to know why
    138     (*list)[*numfiles] = NULL;
    139     (*list)[(*numfiles) + 1] = NULL;
     139    (*list)[*pnumfiles] = NULL;
     140    (*list)[(*pnumfiles) + 1] = NULL;
    140141#ifdef __DEBUG_ALLOC__
    141142    _heap_check();
     
    151152 */
    152153
    153 INT AddToList(CHAR * string, CHAR *** list, INT * numfiles, INT * numalloced)
     154INT AddToList(CHAR *string, CHAR ***list, UINT *pnumfiles, UINT *pnumalloced)
    154155{
    155156  CHAR **ppsz;
     
    157158
    158159  if (string) {
    159     if (((*numfiles) + 3) > *numalloced) {
     160    if (((*pnumfiles) + 3) > *pnumalloced) {
    160161      // Use plain realloc for speed
    161       ppsz = realloc(*list, (*numalloced + 6) * sizeof(CHAR *));
     162      ppsz = realloc(*list, (*pnumalloced + 6) * sizeof(CHAR *));
    162163      if (!ppsz) {
    163164        Runtime_Error(pszSrcFile, __LINE__, "realloc");
    164165        return 1;
    165166      }
    166       (*numalloced) += 6;
     167      (*pnumalloced) += 6;
    167168      *list = ppsz;
    168169    }
     
    173174      return 2;
    174175    }
    175     (*list)[*numfiles] = psz;
    176     strcpy((*list)[*numfiles], string); // Add entry
    177     (*numfiles)++;
    178     (*list)[*numfiles] = NULL;          // Add end marker
    179     (*list)[(*numfiles) + 1] = NULL;    // Add 2nd end marker - fixme to know why?
     176    (*list)[*pnumfiles] = psz;
     177    strcpy((*list)[*pnumfiles], string);        // Add entry
     178    (*pnumfiles)++;
     179    (*list)[*pnumfiles] = NULL;         // Add end marker
     180    (*list)[(*pnumfiles) + 1] = NULL;   // Add 2nd end marker - fixme to know why?
    180181#ifdef __DEBUG_ALLOC__
    181182    _heap_check();
     
    189190  PCNRITEM pci;
    190191  CHAR **list = NULL, **test;
    191   INT numfiles = 0, numalloc = 0, error = 0, attribute = CRA_CURSORED;
     192  UINT numfiles = 0, numalloc = 0;
     193  INT error = 0, attribute = CRA_CURSORED;
    192194
    193195  pci = (PCNRITEM) CurrentRecord(hwndCnr);
     
    220222  PARCITEM pai;
    221223  CHAR **list = NULL;
    222   INT numfiles = 0, numalloc = 0, error = 0, attribute = CRA_CURSORED;
     224  UINT numfiles = 0, numalloc = 0;
     225  INT error = 0, attribute = CRA_CURSORED;
    223226
    224227  pai = (PARCITEM) CurrentRecord(hwndCnr);
     
    239242}
    240243
    241 CHAR **RemoveFromList(CHAR ** list, CHAR * item)
    242 {
    243   register INT x, y;
     244CHAR **RemoveFromList(CHAR **list, CHAR *item)
     245{
     246  UINT x, y;
    244247
    245248  if (list && list[0] && item) {
     
    264267}
    265268
    266 CHAR **CombineLists(CHAR ** prime, CHAR ** add)
    267 {
    268   register INT x;
    269   INT numalloc, numfiles = 0;
     269CHAR **CombineLists(CHAR **prime, CHAR **add)
     270{
     271  UINT x;
     272  UINT numalloc, numfiles = 0;
    270273
    271274  if (add && add[0]) {
Note: See TracChangeset for help on using the changeset viewer.