I am trying to parse command line arguments using Getopt.
However, some of my arguments are from the form host myhost server myserver where host and server are constants and myhost and myserver are changing arguments.
Can I parse options like that?
You might be able to preprocess the
argvarray (preferably copying it to a new location rather than trying to modify it in-place) to conform to the expected form, then usegetopt. However, that’s probably a lot more work that it’s worth and might still have corner cases that break.getoptis intended only for use with utilities whose options conform to the POSIX guidelines. I would just write your own argument-processing code; actually that’s my preference even whengetoptwould work because I usually prefer data-driven (e.g. an array of structs describing the possible options/arguments, their types, and how they should be stored) command line processing to code-driven (switchstatement with explicit code for each option).