Ignore:
Timestamp:
10/13/08 15:54:30 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MArgs.cc

    r8930 r9141  
    3131//
    3232// Arguments beginning with a trailing '-' are called 'options'.
     33//
    3334// Arguments without a trailing '-' are considered 'arguments'
     35//
     36// All arguments appearing after '--' on the commandline are
     37//  also cosidered as 'arguments'
    3438//
    3539//////////////////////////////////////////////////////////////////////////////
     
    5761//  fArgv: A TList containing all other command line arguments
    5862//
    59 //  If root==kFALSE all root commandline options are deleted from
    60 //  the list, namely: -b
    61 //
    62 MArgs::MArgs(int argc, char **argv, Bool_t root) : fArgc(argc)
     63MArgs::MArgs(int argc, char **argv) : fArgc(argc)
    6364{
    6465    TString cmdline;
     
    7677        fArgv.Add(new MArgsEntry(argv[i]));
    7778    }
    78 
    79     if (root)
    80         return;
    81 
    82     HasOnlyAndRemove("-b");
     79}
     80
     81// --------------------------------------------------------------------------
     82//
     83//  Remove all root commandline options from the list,
     84//  namely: -b, -n, -q, -l, -?, -h, --help, -config
     85//
     86//  Returns the number of found root options (max 8)
     87//
     88Int_t MArgs::RemoveRootArgs()
     89{
     90    Int_t n = 0;
     91
     92    n += HasOnlyAndRemove("-b");
     93    n += HasOnlyAndRemove("-n");
     94    n += HasOnlyAndRemove("-q");
     95    n += HasOnlyAndRemove("-l");
     96    n += HasOnlyAndRemove("-?");
     97    n += HasOnlyAndRemove("-h");
     98    n += HasOnlyAndRemove("--help");
     99    n += HasOnlyAndRemove("-config");
     100
     101    return n;
    83102}
    84103
     
    109128        TString *s = NULL;
    110129        while ((s=dynamic_cast<TString*>(Next())))
    111             if (s->BeginsWith("-"))
     130            if (*s!="--" && s->BeginsWith("-"))
    112131                gLog << *s << endl;
    113132        return;
     
    119138        TString *s = NULL;
    120139        while ((s=dynamic_cast<TString*>(Next())))
    121             if (!s->BeginsWith("-"))
     140            if (*s!="--" && !s->BeginsWith("-"))
    122141                gLog << *s << endl;
    123142        return;
     
    283302    Int_t num = 0;
    284303
    285     TIter Next(&fArgv);
    286     TString *s = NULL;
    287     while ((s=dynamic_cast<TString*>(Next())))
    288     {
    289         if (s->BeginsWith("-"))
     304    Bool_t allarg = kFALSE;
     305
     306    TIter Next(&fArgv);
     307    TString *s = NULL;
     308    while ((s=dynamic_cast<TString*>(Next())))
     309    {
     310        if (*s=="--")
     311        {
     312            allarg = kTRUE;
     313            continue;
     314        }
     315
     316        if (s->BeginsWith("-") && !allarg)
    290317            continue;
    291318
     
    305332    Int_t num = 0;
    306333
    307     TIter Next(&fArgv);
    308     TString *s = NULL;
    309     while ((s=dynamic_cast<TString*>(Next())))
    310         if (!s->BeginsWith("-"))
    311             num++;
     334    Bool_t allarg = kFALSE;
     335
     336    TIter Next(&fArgv);
     337    TString *s = NULL;
     338    while ((s=dynamic_cast<TString*>(Next())))
     339    {
     340        if (*s=="--")
     341        {
     342            allarg = kTRUE;
     343            continue;
     344        }
     345
     346        if (s->BeginsWith("-") && !allarg)
     347            continue;
     348
     349        num++;
     350    }
    312351
    313352    return num;
     
    325364    TString *s = NULL;
    326365    while ((s=dynamic_cast<TString*>(Next())))
     366    {
     367        if (*s=="--")
     368            return num;
     369
    327370        if (s->BeginsWith("-"))
    328371            num++;
     372    }
    329373
    330374    return num;
     
    337381Int_t MArgs::GetNumEntries() const
    338382{
    339     return fArgv.GetSize();
     383    return fArgv.FindObject("--") ? fArgv.GetSize()-1 : fArgv.GetSize();
    340384}
    341385
  • trunk/MagicSoft/Mars/mbase/MArgs.h

    r8930 r9141  
    3131
    3232public:
    33     MArgs(int argc, char **argv, Bool_t root=kFALSE);
     33    MArgs(int argc, char **argv);
    3434
    3535    // TObject
     
    4040
    4141    // MArgs
     42    Int_t    RemoveRootArgs();
     43
    4244    Int_t    GetInt(const TString name) const;
    4345    Double_t GetFloat(const TString name) const;
Note: See TracChangeset for help on using the changeset viewer.