Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

String Impala::CmdOptions::DoParseArgs ( int  argc,
char *  argv[],
CString  usageStr,
int  nrReqArgs 
) [inline, private]

Definition at line 315 of file CmdOptions.h.

References CheckDynamicOption(), Impala::FileExists(), Impala::FileNameBase(), GetOptIdx(), IsOpt(), Impala::MakeString(), mArg, mOptParName, mOptVal, and ReadIniFile().

Referenced by ParseArgs().

00316     {
00317         if (argc < nrReqArgs + 1)
00318         {
00319             for(int i=0 ; i<argc ; i++)
00320                 std::cout << argv[i] << std::endl;
00321             return "Need more arguments: " + MakeString(argc-1) + " found, "
00322                 + MakeString(nrReqArgs) + " expected";
00323         }
00324         
00325         // search for ini file name in the arguments
00326         String fileName(argv[0]);
00327         bool sawIniOption = false;
00328         fileName = FileNameBase(fileName) + ".ini";
00329         int i = 1;
00330         while (i < argc)
00331         {
00332             String s = String(argv[i]);
00333             if (s == "--ini")
00334             {
00335                 if (i+1 >= argc)
00336                     return "Missing value for --ini";
00337 
00338                 if (argv[i+1][0] == '-')
00339                     return "Missing value for --ini";
00340 
00341                 sawIniOption = true;
00342                 fileName = String(argv[i+1]);
00343                 break;
00344             }
00345             i++;
00346         }
00347         if (sawIniOption && !FileExists(fileName))
00348             return "Couldn't open ini file " + fileName;
00349 
00350         ReadIniFile(fileName);
00351 
00352         i = 1;
00353         while (i < argc)
00354         {
00355             String s = String(argv[i]);
00356             if ((s == "-h") || (s == "--help"))
00357                 return "help";
00358 
00359             if (IsOpt(s))
00360             {
00361                 s = s.substr(s.rfind('-',2)+1); // remove --
00362                 CheckDynamicOption(s); // add data::something like options
00363                 int idx = GetOptIdx(s);
00364                 if (idx < 0)
00365                 {
00366                     if (s != "ini")
00367                         return "Unknown option --" + s;
00368 
00369                 }
00370                 else if (mOptParName[idx] != "")
00371                 {
00372                     if (i+1 >= argc)
00373                         return "Missing value for --" + s;
00374 
00375                     if (argv[i+1][0] == '-')
00376                         return "Missing value for --" + s;
00377 
00378                     String tmp(argv[i+1]);
00379                     if (tmp[0] == '"')
00380                     {   // follow embedding quotes
00381                         while (tmp[tmp.size()-1] != '"')
00382                         {
00383                             i++;
00384                             if (i + 1 >= argc)
00385                                 return "Quoted string not terminated";
00386 
00387                             tmp = tmp + " " + String(argv[i+1]);
00388                         }
00389                         tmp = tmp.substr(1, tmp.size()-2);
00390                         if (tmp[0] == '"') // mpi programs still get these
00391                             tmp = tmp.substr(1, tmp.size()-2);
00392                     }
00393                     mOptVal[idx] = tmp;
00394                     i++;
00395                 }
00396                 else
00397                 {
00398                     mOptVal[idx] = "1";
00399                 }
00400             }
00401             else
00402             {
00403                 if (s[0] == '"') // mpi programs still get these
00404                     s = s.substr(1, s.size()-2);
00405                 mArg.push_back(s);
00406             }
00407             i++;
00408         }
00409 
00410         if (mArg.size() < nrReqArgs)
00411             return "Need more arguments";
00412 
00413         return String();
00414     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:13:57 2011 for ImpalaSrc by  doxygen 1.5.1