-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCommandLine.h
118 lines (85 loc) · 3.29 KB
/
CommandLine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
CommandLine
Validate and parse a command line
Usage:
1) Send message "setOptionsMatrix" with definition of expected options
2) Send message "parse" to process the command line parameters
3) When parse successful, query the options, option values and parameters
Sample: CommandLineParser.m (enclosed)
Written by Ivo Kendra, 2009. This is a free software, use at your own risk.
*/
#import <Foundation/Foundation.h>
#define CL_OPTION_REQUIRED @"RQD"
#define CL_OPTION_OPTIONAL @"OPT"
#define CL_OPTION_REQUIRED_WITH_VALUE @"RQDV"
#define CL_OPTION_OPTIONAL_WITH_VALUE @"OPTV"
#define CL_OPTION_VALUE_EXPECTED @"VALUE_EXPECTED"
#define CL_OPTION_VALUE_FOUND @"FOUND"
#define CL_MAXOPTIONS 128
#define CL_ERRORMESSAGE_OK @"Success"
#define CL_ERRORMESSAGE_SYNTAX_ERROR @"Syntax error near:"
#define CL_ERRORMESSAGE_UNKNOWN_OPTION @"Unknown option:"
#define CL_ERRORMESSAGE_PARAMS_MISSING @"Missing required parameters"
#define CL_ERRORMESSAGE_MISSING_VALUE @"Missing value for option:"
#define CL_ERRORMESSAGE_OPTION_NOT_FOUND @"Required option not found:"
#define CL_BEGIN_OPTION '-'
#define CL_SPACE ' '
#define CL_T '\t'
#define CL_N '\n'
#define CL_STATE_OPTION 1
#define CL_STATE_PARAMETER 2
#define CL_STATE_WHITE 3
@interface CommandLine : NSObject {
@private
int minNumberOfParams;
int parameterCount;
NSDictionary *optionsMatrix;
NSString *commandLine;
NSMutableDictionary *parsedCommandLine;
NSString *lastParsedOption;
NSString *commandLineStr;
BOOL resultSuccess;
NSString *resultText;
}
/*
Default constructor
*/
- (CommandLine *) init;
/*
Initialize the CommandLine class with already prepared command line string
*/
- (CommandLine *) initWithCommandLine: (NSString *) commandLineString;
/*
Initialize the CommandLine class simply by passing the argc and argv parameters
*/
- (CommandLine *) initWithArgc: (int) argc andArgv: (char *[]) argv;
- (void) cL_setOptionsMatrix: (NSDictionary *) matrix andMinNumberOfParams: (NSInteger) numberOfParams;
/*
Parse the command line.
Returns value:
YES if parsing was successful. You can enumerate the parsedCommandLine dictionary for
the list of parsed values, or use cL_option* and cL_parameter methods to retrieve particular options
or parameters
NO if error occured. Get resultText for detailed error message
*/
- (BOOL) cL_parse;
/*
Returns YES is option is set
*/
- (BOOL) cL_optionIsSet: (NSString *) option;
/*
Return the value of the option (if found)
*/
- (NSString *) cL_optionGetValue: (NSString *) option;
/*
Return the value of the parameter (if found)
*/
- (NSString *) cL_parameterGetValue: (int) parameter;
@property(readwrite, copy) NSDictionary *optionsMatrix;
@property(readwrite, copy) NSString *commandLine;
@property(readonly, copy) NSString *commandLineStr;
@property(readonly) NSMutableDictionary *parsedCommandLine;
@property(readwrite, copy) NSString *lastParsedOption;
@property(readwrite) BOOL resultSuccess;
@property(readwrite, copy) NSString *resultText;
@end