| - + | switch character only (e.g. use stdin for input) + |
| -o + | short (single character) + |
| -long + | long (multiple character, single switch character) + |
| --longer + | long (multiple character, multiple switch characters) + |
| --option + | short/long option flag (no argument) + |
| --option ARG + | short/long option with separate required argument + |
| --option=ARG + | short/long option with combined required argument + |
| --option[=ARG] + | short/long option with combined optional argument + |
| -oARG + | short option with combined required argument + |
| -o[ARG] + | short option with combined optional argument + |
| --multi ARG1 ARG2 + | Multiple arguments + |
| --multi N ARG-1 ARG-2 ... ARG-N + | Variable number of arguments + |
+ \#include "SimpleOpt.h" ++ +
+@link CSimpleOptTempl::SOption CSimpleOpt::SOption @endlink g_rgOptions[] = {
+ { OPT_FLAG, _T("-a"), SO_NONE }, // "-a"
+ { OPT_FLAG, _T("-b"), SO_NONE }, // "-b"
+ { OPT_ARG, _T("-f"), SO_REQ_SEP }, // "-f ARG"
+ { OPT_HELP, _T("-?"), SO_NONE }, // "-?"
+ { OPT_HELP, _T("--help"), SO_NONE }, // "--help"
+ SO_END_OF_OPTIONS // END
+};
+
+
+ Note that all options must start with a hyphen even if the slash will
+ be accepted. This is because the slash character is automatically
+ converted into a hyphen to test against the list of options.
+ For example, the following line matches both "-?" and "/?"
+ (on Windows).
+
+
+ { OPT_HELP, _T("-?"), SO_NONE }, // "-?"
+
+
+ +@link CSimpleOptTempl CSimpleOpt @endlink args(argc, argv, g_rgOptions); ++ +
+while (args.Next()) {
+ if (args.LastError() == SO_SUCCESS) {
+ handle option: use OptionId(), OptionText() and OptionArg()
+ }
+ else {
+ handle error: see ESOError enums
+ }
+}
+
+
+ +ShowFiles(args.FileCount(), args.Files()); ++ +
| Library | SimpleOpt + |
|---|---|
| Author | Brodie Thiesfield [code at jellycan dot com] + |
| Source | http://code.jellycan.com/simpleopt/ + |