Points&Forces (core)
Software tools facilitating the task of surveying architecture
|
A cross-platform command line library which can parse almost any of the standard command line formats in use today. It is designed explicitly to be portable to any platform and has been tested on Windows and Linux. See CSimpleOptTempl for the class definition. More...
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Classes | |
class | CSimpleOptTempl< SOCHAR > |
Implementation of the SimpleOpt class. More... | |
struct | CSimpleOptTempl< SOCHAR >::SOption |
Structure used to define all known options. More... | |
Macros | |
#define | SO_STATICBUF 50 |
#define | _T(s) (char*)s |
#define | SO_END_OF_OPTIONS { -1, NULL, SO_NONE } |
this option definition must be the last entry in the table More... | |
#define | SO_ASSERT(b) |
assertion used to test input data More... | |
#define | CSimpleOpt CSimpleOptA |
TCHAR version dependent on if _UNICODE is defined. More... | |
Typedefs | |
typedef enum _ESOError | ESOError |
Error values. More... | |
typedef enum _ESOArgType | ESOArgType |
typedef CSimpleOptTempl< char > | CSimpleOptA |
ASCII/MBCS version of CSimpleOpt. More... | |
typedef CSimpleOptTempl< wchar_t > | CSimpleOptW |
wchar_t version of CSimpleOpt More... | |
Enumerations | |
enum | _ESOError { SO_SUCCESS = 0 , SO_OPT_INVALID = -1 , SO_OPT_MULTIPLE = -2 , SO_ARG_INVALID = -3 , SO_ARG_INVALID_TYPE = -4 , SO_ARG_MISSING = -5 , SO_ARG_INVALID_DATA = -6 } |
Error values. More... | |
enum | _ESOFlags { SO_O_EXACT = 0x0001 , SO_O_NOSLASH = 0x0002 , SO_O_SHORTARG = 0x0004 , SO_O_CLUMP = 0x0008 , SO_O_USEALL = 0x0010 , SO_O_NOERR = 0x0020 , SO_O_PEDANTIC = 0x0040 , SO_O_ICASE_SHORT = 0x0100 , SO_O_ICASE_LONG = 0x0200 , SO_O_ICASE_WORD = 0x0400 , SO_O_ICASE = 0x0700 } |
Option flags. More... | |
enum | _ESOArgType { SO_NONE , SO_REQ_SEP , SO_REQ_CMB , SO_OPT , SO_MULTI } |
A cross-platform command line library which can parse almost any of the standard command line formats in use today. It is designed explicitly to be portable to any platform and has been tested on Windows and Linux. See CSimpleOptTempl for the class definition.
- | 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 |
The SimpleOpt class is used by following these steps:
#include "SimpleOpt.h"
CSimpleOpt::SOption 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 }, // "-?"
CSimpleOpt 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());
The licence text below is the boilerplate "MIT Licence" used from: http://www.opensource.org/licenses/mit-license.php Copyright (c) 2006-2013, Brodie Thiesfield Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Definition in file SimpleOpt.h.
#define _T | ( | s | ) | (char*)s |
Definition at line 197 of file SimpleOpt.h.
#define CSimpleOpt CSimpleOptA |
TCHAR version dependent on if _UNICODE is defined.
Definition at line 1048 of file SimpleOpt.h.
#define SO_ASSERT | ( | b | ) |
assertion used to test input data
Definition at line 318 of file SimpleOpt.h.
#define SO_END_OF_OPTIONS { -1, NULL, SO_NONE } |
this option definition must be the last entry in the table
Definition at line 307 of file SimpleOpt.h.
#define SO_STATICBUF 50 |
Definition at line 192 of file SimpleOpt.h.
typedef CSimpleOptTempl<char> CSimpleOptA |
ASCII/MBCS version of CSimpleOpt.
Definition at line 1038 of file SimpleOpt.h.
typedef CSimpleOptTempl<wchar_t> CSimpleOptW |
wchar_t version of CSimpleOpt
Definition at line 1041 of file SimpleOpt.h.
typedef enum _ESOArgType ESOArgType |
Types of arguments that options may have. Note that some of the _ESOFlags are not compatible with all argument types. SO_O_SHORTARG requires that relevant options use either SO_REQ_CMB or SO_OPT. SO_O_CLUMP requires that relevant options use only SO_NONE.
enum _ESOArgType |
Types of arguments that options may have. Note that some of the _ESOFlags are not compatible with all argument types. SO_O_SHORTARG requires that relevant options use either SO_REQ_CMB or SO_OPT. SO_O_CLUMP requires that relevant options use only SO_NONE.
Definition at line 283 of file SimpleOpt.h.
enum _ESOError |
Error values.
Definition at line 201 of file SimpleOpt.h.
enum _ESOFlags |
Option flags.
Definition at line 231 of file SimpleOpt.h.