Module Xgetopt is released into the public domain. You are free to use it in any way you like.
This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
Functions | |
int | getopt (int argc, char *argv[], char *optstring) |
parse command line options | |
Variables | |
char * | optarg |
optarg points to the current option's argument. | |
int | optind = 0 |
argv index of next argument to process. | |
int | opterr |
opterr is not used by this version of getopt(). |
|
The getopt() function parses the command line arguments. Its arguments
Option letters may be combined, e.g.,
getopt() places in the external variable
When all options have been processed (i.e., up to the first non-option argument), getopt() returns
The special option
BOOL CMyApp::ProcessCommandLine(int argc, char *argv[]) { int c; while ((c = getopt(argc, argv, "aBn:")) != EOF) { switch (c) { case 'a': TRACE(_T("option a\n")); // // set some flag here // break; case 'B': TRACE( _T("option B\n")); // // set some other flag here // break; case 'n': TRACE(_T("option n: value=%d\n"), atoi(optarg)); // // do something with value here // break; case '?': TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]); return FALSE; break; default: TRACE(_T("WARNING: no handler for option %c\n"), c); return FALSE; break; } } // // check for non-option args here // return TRUE; } |
|
On return from getopt(), |
|
This version of getopt() does not fill |
|
getopt() places in the external variable |