parsing command line strings
What's the best way to parse command line arguments for a shell program? Also, what's the most amount of arguments a command can have, such as "ls" or "rm" (the max arguments/options any command can have)? I'm using execvp( cmd, args ) to run the command, where cmd is the command and args is the parsed string of arguments and options will a NULL value at the end. Assume the path variable is set in the environment and all variables have been innitialized.
Code:
//Assume the cmd variable contains the full string "ls -l"
token = strtok( cmd, " " ); //holds tokens in the string
cmd = token; //the first token is the command
//store the rest of the tokens in the arguments array
while ( token != NULL )
{
token = strtok( NULL, " " );
args[ count ] = token;
count++;
}
code = execvp( cmd, args );