silc_getopt
SYNOPSIS
int silc_getopt(int argc, char **argv, const char *optstring, SilcGetOpt op)
DESCRIPTION
Parses comand line options. This function is equivalent to getopt(3). Returns the current parsed option, '?' if option was unknown, ':' if required argument was missing or -1 after all options have been parsed. If options require arguments they are available from the `op' structure, to where the options are parsed. The parsing is stopped immediately when first non-option character, which is not an argument for an option, is encountered.
The `optstring' contains the supported option characters. One character per option is required. If colon (':') follows option character the option requires an argument. If two colons ('::') follows option character the argument is optional. In that case the argument must follow the option in command line, for example -oarg, instead of -o arg.
EXAMPLE
int main(int argc, char **argv) { SilcGetOptStruct op = SILC_GETOPT_INIT; while ((option = silc_getopt(argc, argv, "ab:t::", &op)) != -1) { switch (option) { case 'a': ... break; case 'b': argument = silc_strdup(op.opt_arg); break; case 't': if (op.opt_arg) optional_argument = silc_strdup(op.opt_arg); break; default: exit(1); break; } } }