32 #include "YCommandLine.h" 33 #include "YUIException.h" 35 #define YUILogComponent "ui" 41 std::vector<std::string> args;
51 YUI_CHECK_NEW( priv );
53 std::ifstream cmdline(
"/proc/self/cmdline", std::ifstream::in | std::ifstream::binary );
55 while ( cmdline.good() )
58 getline( cmdline, arg,
'\0' );
62 yuiDebug() <<
"Arg #" << priv->args.size()
63 <<
": \"" << arg <<
"\"" << std::endl;
65 priv->args.push_back( arg );
80 return priv->args.size();
87 char ** argArray = (
char **) ( malloc(
argc() *
sizeof(
char * ) ) );
91 for (
int i=0; i <
argc(); i++ )
93 argArray[ i ] = strdup( priv->args[i].c_str() );
104 priv->args.push_back( arg );
111 YUI_CHECK_INDEX( index, 0, (
int) priv->args.size()-1 );
113 return priv->args[ index ];
120 YUI_CHECK_INDEX( index, 0, (
int) priv->args.size()-1 );
122 priv->args.erase( priv->args.begin() + index );
129 YUI_CHECK_INDEX( index, 0, (
int) priv->args.size()-1 );
131 priv->args[ index ] = newArg;
138 for (
int i=0; i <
argc(); i++ )
140 if ( priv->args[i] == argName )
int find(const std::string &argName) const
Find a command line argument 'argName' ("-display" etc.).
~YCommandLine()
Destructor.
YCommandLine()
Constructor.
void replace(int index, const std::string &arg)
Replace command line argument no.
char ** argv() const
Return the arguments in a C compatible fashion: An array of pointers to characters.
void remove(int index)
Remove command line argument no.
void add(const std::string &arg)
Add a command line argument (at the end of the existing ones).
int argc() const
Return the number of arguments in the command line.
std::string arg(int index) const
Return command line argument no.