Changeset 3877


Ignore:
Timestamp:
04/29/04 11:02:37 (20 years ago)
Author:
rico
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r3876 r3877  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20 2004/04/29: Javier Rico
     21
     22   * mbase/MRunIter.cc
     23     - Remove AddRuns(const char*,const char*) dependence on length of
     24       first character chain
     25
     26       
    2027 2004/04/28: Javier Rico
    2128
  • trunk/MagicSoft/Mars/mbase/MRunIter.cc

    r3874 r3877  
    7272Int_t MRunIter::AddRuns(const char* runrange, const char* path)
    7373{
    74   char* last;
    75   char  chcopy[100];
    76   Int_t lowrun=-1;
    77   Int_t upprun;
    78   Int_t totdir=0;
     74  TString chcopy = runrange;
     75  Ssiz_t  last=0;
     76  Int_t   lowrun=-1;
     77  Int_t   upprun;
     78  UInt_t totdir=0;
    7979
    80   //  cout << "Analyzing chain " << runrange << " in path " << path << endl;
    8180
    82   sprintf(chcopy,"%s",runrange);
    83   last=&chcopy[0];
    84 
    85   // loop over the elements of the character chain (break inside the loop)
    86   for(char* cp=last;cp;cp++)
     81  // loop over the elements of the character chain
     82  for(Int_t i=0;i<chcopy.Length();i++)
    8783    {
    88       // look for a digit, a '-' or a ',' or end of string
    89       char c=*cp;
    90       if(! ((c>='0' && c<='9') || c=='-' || c==',' || c=='\0'))
     84      // look for a digit, a '-' or a ','
     85      char c=chcopy[i];
     86      if(! ((c>='0' && c<='9') || c=='-' || c==','))
    9187        return totdir;
    9288     
    9389      // if '-' is found, save the previous number as initial run
    94       if(c=='-' && lowrun<0)
     90      else if(c=='-' && lowrun<0 && i>last)
    9591        {
    96           char chrun[100];
    97           strncpy(chrun,last,cp-last);
    98           lowrun=atoi(chrun);             
    99           last=cp+1;
     92          TSubString chrun = chcopy(last,i-last);
     93          lowrun=atoi(chrun.Data());             
     94          last=i+1;
    10095        }
    10196      // if ',' or the end of the string are found, save the previous run or run range
    102       if(c==',' || c=='\0')
     97      else if(c==',' && i>last)
    10398        {
    104           char chrun[100];
    105           strncpy(chrun,last,cp-last);
    106           upprun=atoi(chrun);
     99          TSubString chrun = chcopy(last,i-last);
     100          upprun=atoi(chrun.Data());             
    107101          if(lowrun>=0 && lowrun<=upprun)
    108102            totdir+=AddRuns(lowrun,upprun,path);
     
    110104            totdir+=AddRun(upprun,path);         
    111105         
    112           if(c=='\0')
    113             break;
    114106          lowrun=-1;
    115           last=cp+1;
     107          last=i+1;
    116108        }
     109      // if find two contiguous separators exit
     110      else if((c=='-' && i==last) || (c==',' && i==last))
     111        return totdir;
    117112    }
     113
     114  // save last run range
     115  TSubString chrun = chcopy(last,chcopy.Length()-last);
     116  upprun=atoi(chrun.Data());             
     117  if(lowrun>=0 && lowrun<=upprun)
     118    totdir+=AddRuns(lowrun,upprun,path);
     119  else if(lowrun<0)
     120    totdir+=AddRun(upprun,path);         
     121
    118122  return totdir;
    119123}
Note: See TracChangeset for help on using the changeset viewer.