Is there a way in C to parse a piece of text and obtain values for argv and argc, as if the text had been passed to an application on the command line?
This doesn\'
The always-wonderful glib has g_shell_parse_args()
which sounds like what you're after.
If you're not interested in even quoting, this might be overkill. All you need to do is tokenize, using whitespace as a token character. Writing a simple routine to do that shouldn't take long, really.
If you're not super-stingy on memory, doing it in one pass without reallocations should be easy; just assume a worst-case of every second character being a space, thus assuming a string of n
characters contains at most (n + 1) / 2
arguments, and (of course) at most n
bytes of argument text (excluding terminators).