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

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

Definition at line 302 of file CmdOptions.h.

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

Referenced by ParseArgs().

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

Here is the call graph for this function:


Generated on Fri Mar 19 10:35:39 2010 for ImpalaSrc by  doxygen 1.5.1