TF++, Miscellaneous classes and modules in C++:

◆ parse_cmdline()

Tparsed tfxx::cmdline::parse_cmdline ( tfxx::cmdline::Commandline c,
const char **  keys,
const bool &  debug = false 
)

parse command line arguments for file names and options ,A tutorial is available in the detailed description of the Interface provided through xcmdline.h

See also
TEST: Commandline evaluation.
Examples:
tests/commandlinetest.cc.

Definition at line 83 of file xcmdline.cc.

References tfxx::cmdline::Commandline::extra(), tfxx::cmdline::Filename::name, tfxx::cmdline::Commandline::next(), and tfxx::cmdline::Filename::options.

Referenced by main().

86  {
87  // fill a search list
88  // ------------------
89  helper::Tkeylist keylist;
90  const char* key=*keys;
91  while (key != NULL)
92  {
93  std::string keystring(key);
94  keylist.push_back(keystring+":");
95  ++keys;
96  key=*keys;
97  }
98  // report search list if requested
99  if (debug)
100  {
101  std::cout << "DEBUG (parse_cmdline): keys are ";
102  helper::Tkeylist::const_iterator i=keylist.begin();
103  while (i!=keylist.end())
104  {
105  std::cout << "\"" << *i << "\" ";
106  ++i;
107  }
108  std::cout << std::endl;
109  }
110 
111  // parse rest of command line
112  // --------------------------
113  Tparsed retval;
114  Filename filename;
115  bool first=true;
116  while (c.extra())
117  {
118  helper::CmdlineArgument ca(c.next(), keylist);
119  if (first)
120  {
121  first=false;
122  filename.name=ca.value();
123  }
124  else
125  {
126  if (ca.isoption())
127  {
128  filename.options.insert(ca.option());
129  }
130  else
131  {
132  retval.push_back(filename);
133  filename.options.clear();
134  filename.name=ca.value();
135  }
136  }
137  }
138  if (!first) { retval.push_back(filename); }
139 
140  return(retval);
141  } // parse_cmdline
std::list< Filename > Tparsed
list to hold file names with options ,A tutorial is available in the detailed description of the Inte...
Definition: xcmdline.h:218
std::list< std::string > Tkeylist
Definition: xcmdline.cc:44
char * next()
returns char-array of next commandline argument
Definition: commandline.h:243
bool extra() const
true if there are more commandline arguments
Definition: commandline.h:240
Here is the call graph for this function:
Here is the caller graph for this function: