FreeRDP
winpr/include/winpr/cmdline.h
1 
20 #ifndef WINPR_CMDLINE_H
21 #define WINPR_CMDLINE_H
22 
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
25 
26 /* Command-Line Argument Flags */
27 
28 #define COMMAND_LINE_INPUT_FLAG_MASK 0x0000FFFF
29 #define COMMAND_LINE_OUTPUT_FLAG_MASK 0xFFFF0000
30 
31 /* Command-Line Argument Input Flags */
32 
33 #define COMMAND_LINE_VALUE_FLAG 0x00000001
34 #define COMMAND_LINE_VALUE_REQUIRED 0x00000002
35 #define COMMAND_LINE_VALUE_OPTIONAL 0x00000004
36 #define COMMAND_LINE_VALUE_BOOL 0x00000008
37 
38 #define COMMAND_LINE_ADVANCED 0x00000100
39 #define COMMAND_LINE_PRINT 0x00000200
40 #define COMMAND_LINE_PRINT_HELP 0x00000400
41 #define COMMAND_LINE_PRINT_VERSION 0x00000800
42 #define COMMAND_LINE_PRINT_BUILDCONFIG 0x00001000
43 
44 /* Command-Line Argument Output Flags */
45 
46 #define COMMAND_LINE_ARGUMENT_PRESENT 0x80000000
47 #define COMMAND_LINE_VALUE_PRESENT 0x40000000
48 
49 /* Command-Line Parsing Flags */
50 
51 #define COMMAND_LINE_SIGIL_NONE 0x00000001
52 #define COMMAND_LINE_SIGIL_SLASH 0x00000002
53 #define COMMAND_LINE_SIGIL_DASH 0x00000004
54 #define COMMAND_LINE_SIGIL_DOUBLE_DASH 0x00000008
55 #define COMMAND_LINE_SIGIL_PLUS_MINUS 0x00000010
56 #define COMMAND_LINE_SIGIL_ENABLE_DISABLE 0x00000020
57 #define COMMAND_LINE_SIGIL_NOT_ESCAPED 0x00000040
58 
59 #define COMMAND_LINE_SEPARATOR_COLON 0x00000100
60 #define COMMAND_LINE_SEPARATOR_EQUAL 0x00000200
61 #define COMMAND_LINE_SEPARATOR_SPACE 0x00000400
62 
63 /* Suppress COMMAND_LINE_ERROR_NO_KEYWORD return. */
64 #define COMMAND_LINE_IGN_UNKNOWN_KEYWORD 0x00001000
65 #define COMMAND_LINE_SILENCE_PARSER 0x00002000
66 
67 /* Command-Line Parsing Error Codes */
68 
69 #define COMMAND_LINE_ERROR -1000
70 #define COMMAND_LINE_ERROR_NO_KEYWORD -1001
71 #define COMMAND_LINE_ERROR_UNEXPECTED_VALUE -1002
72 #define COMMAND_LINE_ERROR_MISSING_VALUE -1003
73 #define COMMAND_LINE_ERROR_MISSING_ARGUMENT -1004
74 #define COMMAND_LINE_ERROR_UNEXPECTED_SIGIL -1005
75 #define COMMAND_LINE_ERROR_MEMORY -1006
76 #define COMMAND_LINE_ERROR_LAST -1999
77 
78 /* Command-Line Parsing Status Codes */
79 
80 #define COMMAND_LINE_STATUS_PRINT -2001
81 #define COMMAND_LINE_STATUS_PRINT_HELP -2002
82 #define COMMAND_LINE_STATUS_PRINT_VERSION -2003
83 #define COMMAND_LINE_STATUS_PRINT_BUILDCONFIG -2004
84 #define COMMAND_LINE_STATUS_PRINT_LAST -2999
85 
86 /* Command-Line Macros */
87 
88 #define CommandLineSwitchStart(_arg) \
89  if (0) \
90  { \
91  }
92 #define CommandLineSwitchCase(_arg, _name) else if (strcmp(_arg->Name, _name) == 0)
93 #define CommandLineSwitchDefault(_arg) else
94 #define CommandLineSwitchEnd(_arg)
95 
96 #define BoolValueTrue ((LPSTR)1)
97 #define BoolValueFalse ((LPSTR)0)
98 
99 typedef struct
100 {
101  LPCSTR Name;
102  DWORD Flags;
103  LPCSTR Format;
104  LPCSTR Default;
105  LPSTR Value;
106  LONG Index;
107  LPCSTR Alias;
108  LPCSTR Text;
110 
111 typedef struct
112 {
113  LPCWSTR Name;
114  DWORD Flags;
115  LPCSTR Format;
116  LPWSTR Default;
117  LPWSTR Value;
118  LONG Index;
119  LPCWSTR Alias;
120  LPCWSTR Text;
122 
123 #ifdef UNICODE
124 #define COMMAND_LINE_ARGUMENT COMMAND_LINE_ARGUMENT_W
125 #else
126 #define COMMAND_LINE_ARGUMENT COMMAND_LINE_ARGUMENT_A
127 #endif
128 
129 typedef int (*COMMAND_LINE_PRE_FILTER_FN_A)(void* context, int index, int argc, LPSTR* argv);
130 typedef int (*COMMAND_LINE_PRE_FILTER_FN_W)(void* context, int index, int argc, LPWSTR* argv);
131 
132 typedef int (*COMMAND_LINE_POST_FILTER_FN_A)(void* context, COMMAND_LINE_ARGUMENT_A* arg);
133 typedef int (*COMMAND_LINE_POST_FILTER_FN_W)(void* context, COMMAND_LINE_ARGUMENT_W* arg);
134 
135 #ifdef __cplusplus
136 extern "C"
137 {
138 #endif
139 
140  WINPR_API int CommandLineClearArgumentsA(COMMAND_LINE_ARGUMENT_A* options);
141  WINPR_API int CommandLineClearArgumentsW(COMMAND_LINE_ARGUMENT_W* options);
142 
143  WINPR_API int CommandLineParseArgumentsA(int argc, LPSTR* argv,
144  COMMAND_LINE_ARGUMENT_A* options, DWORD flags,
145  void* context, COMMAND_LINE_PRE_FILTER_FN_A preFilter,
146  COMMAND_LINE_POST_FILTER_FN_A postFilter);
147  WINPR_API int CommandLineParseArgumentsW(int argc, LPWSTR* argv,
148  COMMAND_LINE_ARGUMENT_W* options, DWORD flags,
149  void* context, COMMAND_LINE_PRE_FILTER_FN_W preFilter,
150  COMMAND_LINE_POST_FILTER_FN_W postFilter);
151 
152  WINPR_API const COMMAND_LINE_ARGUMENT_A*
153  CommandLineFindArgumentA(const COMMAND_LINE_ARGUMENT_A* options, LPCSTR Name);
154  WINPR_API const COMMAND_LINE_ARGUMENT_W*
155  CommandLineFindArgumentW(const COMMAND_LINE_ARGUMENT_W* options, LPCWSTR Name);
156 
157  WINPR_API const COMMAND_LINE_ARGUMENT_A*
158  CommandLineFindNextArgumentA(const COMMAND_LINE_ARGUMENT_A* argument);
159 
166  WINPR_API void CommandLineParserFree(char** ptr);
167 
168  WINPR_ATTR_MALLOC(CommandLineParserFree, 1)
169  WINPR_API char** CommandLineParseCommaSeparatedValues(const char* list, size_t* count);
170 
171  WINPR_ATTR_MALLOC(CommandLineParserFree, 1)
172  WINPR_API char** CommandLineParseCommaSeparatedValuesEx(const char* name, const char* list,
173  size_t* count);
174 
175  WINPR_ATTR_MALLOC(free, 1)
176  WINPR_API char* CommandLineToCommaSeparatedValues(int argc, char* argv[]);
177 
178  WINPR_ATTR_MALLOC(free, 1)
179  WINPR_API char* CommandLineToCommaSeparatedValuesEx(int argc, char* argv[],
180  const char* filters[], size_t number);
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #ifdef UNICODE
187 #define CommandLineClearArguments CommandLineClearArgumentsW
188 #define CommandLineParseArguments CommandLineParseArgumentsW
189 #define CommandLineFindArgument CommandLineFindArgumentW
190 #else
191 #define CommandLineClearArguments CommandLineClearArgumentsA
192 #define CommandLineParseArguments CommandLineParseArgumentsA
193 #define CommandLineFindArgument CommandLineFindArgumentA
194 #endif
195 
196 #endif /* WINPR_CMDLINE_H */