Ken Yourek / ucmd

Dependents:   nucleo_ucmd_helloworld

Committer:
kyourek
Date:
Mon Oct 12 21:09:07 2015 +0000
Revision:
0:9e2fc73e5a12
Initial commit of the ucmd library for mbed.; https://github.com/kyourek/ucmd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kyourek 0:9e2fc73e5a12 1 #ifndef UCMD_H
kyourek 0:9e2fc73e5a12 2 #define UCMD_H
kyourek 0:9e2fc73e5a12 3
kyourek 0:9e2fc73e5a12 4 #include <stdarg.h>
kyourek 0:9e2fc73e5a12 5 #include <stddef.h>
kyourek 0:9e2fc73e5a12 6
kyourek 0:9e2fc73e5a12 7 /* Sets the size of the command buffer when using
kyourek 0:9e2fc73e5a12 8 the command-line application framework. All
kyourek 0:9e2fc73e5a12 9 entered commands must have a size equal to or
kyourek 0:9e2fc73e5a12 10 less than this buffer's size. */
kyourek 0:9e2fc73e5a12 11 #ifndef ucCmdLineApp_CMD_STR_SIZE
kyourek 0:9e2fc73e5a12 12 #define ucCmdLineApp_CMD_STR_SIZE 200
kyourek 0:9e2fc73e5a12 13 #endif
kyourek 0:9e2fc73e5a12 14
kyourek 0:9e2fc73e5a12 15 /* Sets the size of the command response buffer.
kyourek 0:9e2fc73e5a12 16 All response strings must have a size equal to
kyourek 0:9e2fc73e5a12 17 or less than the size of this buffer to avoid
kyourek 0:9e2fc73e5a12 18 truncation. */
kyourek 0:9e2fc73e5a12 19 #ifndef ucCmdLine_RESPONSE_SIZE
kyourek 0:9e2fc73e5a12 20 #define ucCmdLine_RESPONSE_SIZE 200
kyourek 0:9e2fc73e5a12 21 #endif
kyourek 0:9e2fc73e5a12 22
kyourek 0:9e2fc73e5a12 23 /* Sets the number of available command options.
kyourek 0:9e2fc73e5a12 24 The number of created command options must be
kyourek 0:9e2fc73e5a12 25 equal to or less than this number. */
kyourek 0:9e2fc73e5a12 26 #ifndef ucCmdLineOpt_COUNT
kyourek 0:9e2fc73e5a12 27 #define ucCmdLineOpt_COUNT 10
kyourek 0:9e2fc73e5a12 28 #endif
kyourek 0:9e2fc73e5a12 29
kyourek 0:9e2fc73e5a12 30 /* Sets the number of available switch options.
kyourek 0:9e2fc73e5a12 31 The number of created switch options must be
kyourek 0:9e2fc73e5a12 32 equal to or less than this number. */
kyourek 0:9e2fc73e5a12 33 #ifndef ucSwitchOpt_COUNT
kyourek 0:9e2fc73e5a12 34 #define ucSwitchOpt_COUNT 50
kyourek 0:9e2fc73e5a12 35 #endif
kyourek 0:9e2fc73e5a12 36
kyourek 0:9e2fc73e5a12 37 /* Sets the number of available argument options.
kyourek 0:9e2fc73e5a12 38 This is the total number of options available
kyourek 0:9e2fc73e5a12 39 to commands and switches, combined. */
kyourek 0:9e2fc73e5a12 40 #ifndef ucArgOpt_COUNT
kyourek 0:9e2fc73e5a12 41 #define ucArgOpt_COUNT 50
kyourek 0:9e2fc73e5a12 42 #endif
kyourek 0:9e2fc73e5a12 43
kyourek 0:9e2fc73e5a12 44 /* Sets the maximum expected length of a single
kyourek 0:9e2fc73e5a12 45 token in a command line. */
kyourek 0:9e2fc73e5a12 46 #ifndef ucTok_LENGTH_MAX
kyourek 0:9e2fc73e5a12 47 #define ucTok_LENGTH_MAX ucCmdLineApp_CMD_STR_SIZE
kyourek 0:9e2fc73e5a12 48 #endif
kyourek 0:9e2fc73e5a12 49
kyourek 0:9e2fc73e5a12 50 #ifndef ucTok_BOOLEAN_TRUE
kyourek 0:9e2fc73e5a12 51 #define ucTok_BOOLEAN_TRUE "1", "on", "yes", "true"
kyourek 0:9e2fc73e5a12 52 #endif
kyourek 0:9e2fc73e5a12 53
kyourek 0:9e2fc73e5a12 54 #ifndef ucTok_BOOLEAN_FALSE
kyourek 0:9e2fc73e5a12 55 #define ucTok_BOOLEAN_FALSE "0", "off", "no", "false"
kyourek 0:9e2fc73e5a12 56 #endif
kyourek 0:9e2fc73e5a12 57
kyourek 0:9e2fc73e5a12 58 /* Sets the numeric type of numeric argument
kyourek 0:9e2fc73e5a12 59 options. */
kyourek 0:9e2fc73e5a12 60 #ifndef ucArgOpt_NUMERIC_TYPE
kyourek 0:9e2fc73e5a12 61 #define ucArgOpt_NUMERIC_TYPE double
kyourek 0:9e2fc73e5a12 62 #endif
kyourek 0:9e2fc73e5a12 63
kyourek 0:9e2fc73e5a12 64 /* Include this def when using the library with another
kyourek 0:9e2fc73e5a12 65 program on Windows.
kyourek 0:9e2fc73e5a12 66 Exported functions will be decorated with dllimport
kyourek 0:9e2fc73e5a12 67 to make them available to external programs. */
kyourek 0:9e2fc73e5a12 68 #ifdef uc_DECLSPEC_DLLIMPORT
kyourek 0:9e2fc73e5a12 69 #define uc_EXPORTED uc_EXTERN_C __declspec(dllimport)
kyourek 0:9e2fc73e5a12 70 #endif
kyourek 0:9e2fc73e5a12 71
kyourek 0:9e2fc73e5a12 72 /* Include this def when compiling this program on
kyourek 0:9e2fc73e5a12 73 Windows.
kyourek 0:9e2fc73e5a12 74 Exported functions will be decorated with dllexport
kyourek 0:9e2fc73e5a12 75 to make them available to external programs. */
kyourek 0:9e2fc73e5a12 76 #ifdef uc_DECLSPEC_DLLEXPORT
kyourek 0:9e2fc73e5a12 77 #define uc_EXPORTED uc_EXTERN_C __declspec(dllexport)
kyourek 0:9e2fc73e5a12 78 #endif
kyourek 0:9e2fc73e5a12 79
kyourek 0:9e2fc73e5a12 80 /* Prepend extern "C" if we're in a C++
kyourek 0:9e2fc73e5a12 81 compiler. */
kyourek 0:9e2fc73e5a12 82 #ifdef __cplusplus
kyourek 0:9e2fc73e5a12 83 #define uc_EXTERN_C extern "C"
kyourek 0:9e2fc73e5a12 84 #else
kyourek 0:9e2fc73e5a12 85 #define uc_EXTERN_C
kyourek 0:9e2fc73e5a12 86 #endif
kyourek 0:9e2fc73e5a12 87
kyourek 0:9e2fc73e5a12 88 /* Default to setting uc_EXPORTED to the result
kyourek 0:9e2fc73e5a12 89 of our extern "C" check. */
kyourek 0:9e2fc73e5a12 90 #ifndef uc_EXPORTED
kyourek 0:9e2fc73e5a12 91 #define uc_EXPORTED uc_EXTERN_C
kyourek 0:9e2fc73e5a12 92 #endif
kyourek 0:9e2fc73e5a12 93
kyourek 0:9e2fc73e5a12 94 /* Define NULL, if it hasn't been defined. */
kyourek 0:9e2fc73e5a12 95 #ifndef NULL
kyourek 0:9e2fc73e5a12 96 #define NULL ((void*)0)
kyourek 0:9e2fc73e5a12 97 #endif
kyourek 0:9e2fc73e5a12 98
kyourek 0:9e2fc73e5a12 99 /*
kyourek 0:9e2fc73e5a12 100 * Summary:
kyourek 0:9e2fc73e5a12 101 * Definition for the type returned
kyourek 0:9e2fc73e5a12 102 * by functions that use an error code.
kyourek 0:9e2fc73e5a12 103 */
kyourek 0:9e2fc73e5a12 104 typedef int ucErr;
kyourek 0:9e2fc73e5a12 105
kyourek 0:9e2fc73e5a12 106 /*
kyourek 0:9e2fc73e5a12 107 * Summary:
kyourek 0:9e2fc73e5a12 108 * Defines the value that represents no error.
kyourek 0:9e2fc73e5a12 109 */
kyourek 0:9e2fc73e5a12 110 #define ucErr_NONE 0
kyourek 0:9e2fc73e5a12 111
kyourek 0:9e2fc73e5a12 112 /*
kyourek 0:9e2fc73e5a12 113 * Summary:
kyourek 0:9e2fc73e5a12 114 * Boolean type definition. This definition is used
kyourek 0:9e2fc73e5a12 115 * to increase the readability of the source by replacing
kyourek 0:9e2fc73e5a12 116 * integer representations of boolean values with the
kyourek 0:9e2fc73e5a12 117 * more familiar "true" and "false" values.
kyourek 0:9e2fc73e5a12 118 */
kyourek 0:9e2fc73e5a12 119 typedef enum ucBool {
kyourek 0:9e2fc73e5a12 120 ucBool_FALSE = 0,
kyourek 0:9e2fc73e5a12 121 ucBool_TRUE = !ucBool_FALSE
kyourek 0:9e2fc73e5a12 122 } ucBool;
kyourek 0:9e2fc73e5a12 123
kyourek 0:9e2fc73e5a12 124 /*
kyourek 0:9e2fc73e5a12 125 * Summary:
kyourek 0:9e2fc73e5a12 126 * Base structure for tokenized values in a command.
kyourek 0:9e2fc73e5a12 127 */
kyourek 0:9e2fc73e5a12 128 typedef const char ucTok;
kyourek 0:9e2fc73e5a12 129
kyourek 0:9e2fc73e5a12 130 /*
kyourek 0:9e2fc73e5a12 131 * Summary:
kyourek 0:9e2fc73e5a12 132 * Gets the length of the token.
kyourek 0:9e2fc73e5a12 133 * Returns:
kyourek 0:9e2fc73e5a12 134 * The number of characters in the token.
kyourek 0:9e2fc73e5a12 135 */
kyourek 0:9e2fc73e5a12 136 uc_EXPORTED int ucTok_get_length(ucTok*);
kyourek 0:9e2fc73e5a12 137
kyourek 0:9e2fc73e5a12 138 /*
kyourek 0:9e2fc73e5a12 139 * Summary:
kyourek 0:9e2fc73e5a12 140 * Determines whether or not the given token equals the value.
kyourek 0:9e2fc73e5a12 141 * Parameters:
kyourek 0:9e2fc73e5a12 142 * value: The value against which the token is checked for equality.
kyourek 0:9e2fc73e5a12 143 * Returns:
kyourek 0:9e2fc73e5a12 144 * ucBool_TRUE if the token value equals the given value. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 145 */
kyourek 0:9e2fc73e5a12 146 uc_EXPORTED ucBool ucTok_equals(ucTok*, const char *value);
kyourek 0:9e2fc73e5a12 147
kyourek 0:9e2fc73e5a12 148 /*
kyourek 0:9e2fc73e5a12 149 * Summary:
kyourek 0:9e2fc73e5a12 150 * Determines whether or not the given token is considered numeric.
kyourek 0:9e2fc73e5a12 151 * Returns:
kyourek 0:9e2fc73e5a12 152 * ucBool_TRUE if the token is considered numeric. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 153 */
kyourek 0:9e2fc73e5a12 154 uc_EXPORTED ucBool ucTok_is_numeric(ucTok*);
kyourek 0:9e2fc73e5a12 155 uc_EXPORTED ucBool ucTok_try_parse_numeric(ucTok*, double *value);
kyourek 0:9e2fc73e5a12 156 uc_EXPORTED double ucTok_parse_numeric(ucTok*);
kyourek 0:9e2fc73e5a12 157 uc_EXPORTED ucBool ucTok_is_boolean(ucTok*);
kyourek 0:9e2fc73e5a12 158 uc_EXPORTED ucBool ucTok_try_parse_boolean(ucTok*, ucBool *value);
kyourek 0:9e2fc73e5a12 159 uc_EXPORTED ucBool ucTok_parse_boolean(ucTok*);
kyourek 0:9e2fc73e5a12 160
kyourek 0:9e2fc73e5a12 161 /*
kyourek 0:9e2fc73e5a12 162 * Summary:
kyourek 0:9e2fc73e5a12 163 * Determines whether or not the given token is considered a switch.
kyourek 0:9e2fc73e5a12 164 * Returns:
kyourek 0:9e2fc73e5a12 165 * ucBool_TRUE if the token is a switch. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 166 */
kyourek 0:9e2fc73e5a12 167 uc_EXPORTED ucBool ucTok_is_switch(ucTok*);
kyourek 0:9e2fc73e5a12 168
kyourek 0:9e2fc73e5a12 169 /*
kyourek 0:9e2fc73e5a12 170 * Summary:
kyourek 0:9e2fc73e5a12 171 * Gets the next token in the list.
kyourek 0:9e2fc73e5a12 172 * Returns:
kyourek 0:9e2fc73e5a12 173 * A pointer to the token that comes next in the list, or NULL
kyourek 0:9e2fc73e5a12 174 * if no further tokens exist.
kyourek 0:9e2fc73e5a12 175 */
kyourek 0:9e2fc73e5a12 176 uc_EXPORTED ucTok *ucTok_get_next(ucTok*);
kyourek 0:9e2fc73e5a12 177
kyourek 0:9e2fc73e5a12 178 /*
kyourek 0:9e2fc73e5a12 179 * Summary:
kyourek 0:9e2fc73e5a12 180 * Counts the number of tokens in the linked list.
kyourek 0:9e2fc73e5a12 181 * Returns:
kyourek 0:9e2fc73e5a12 182 * The number of tokens in the list.
kyourek 0:9e2fc73e5a12 183 */
kyourek 0:9e2fc73e5a12 184 uc_EXPORTED int ucTok_count(ucTok*);
kyourek 0:9e2fc73e5a12 185
kyourek 0:9e2fc73e5a12 186 /*
kyourek 0:9e2fc73e5a12 187 * Summary:
kyourek 0:9e2fc73e5a12 188 * Gets the value of the token.
kyourek 0:9e2fc73e5a12 189 * Returns:
kyourek 0:9e2fc73e5a12 190 * The string value of the token.
kyourek 0:9e2fc73e5a12 191 */
kyourek 0:9e2fc73e5a12 192 uc_EXPORTED const char *ucTok_get_value(ucTok*);
kyourek 0:9e2fc73e5a12 193
kyourek 0:9e2fc73e5a12 194 /*
kyourek 0:9e2fc73e5a12 195 * Summary:
kyourek 0:9e2fc73e5a12 196 * An argument token. This type is a child of the
kyourek 0:9e2fc73e5a12 197 * base token type. All functions that take an
kyourek 0:9e2fc73e5a12 198 * instance of the base type can be used with an
kyourek 0:9e2fc73e5a12 199 * instance of this type.
kyourek 0:9e2fc73e5a12 200 */
kyourek 0:9e2fc73e5a12 201 typedef const char ucArgTok;
kyourek 0:9e2fc73e5a12 202
kyourek 0:9e2fc73e5a12 203 /*
kyourek 0:9e2fc73e5a12 204 * Summary:
kyourek 0:9e2fc73e5a12 205 * Gets the next argument after the given argument.
kyourek 0:9e2fc73e5a12 206 * Returns:
kyourek 0:9e2fc73e5a12 207 * The next argument in the list.
kyourek 0:9e2fc73e5a12 208 */
kyourek 0:9e2fc73e5a12 209 uc_EXPORTED ucArgTok *ucArgTok_get_next(ucArgTok*);
kyourek 0:9e2fc73e5a12 210
kyourek 0:9e2fc73e5a12 211 /*
kyourek 0:9e2fc73e5a12 212 * Summary:
kyourek 0:9e2fc73e5a12 213 * Counts the number of arguments in the linked list.
kyourek 0:9e2fc73e5a12 214 * Returns:
kyourek 0:9e2fc73e5a12 215 * The number of arguments in the list.
kyourek 0:9e2fc73e5a12 216 */
kyourek 0:9e2fc73e5a12 217 uc_EXPORTED int ucArgTok_count(ucArgTok*);
kyourek 0:9e2fc73e5a12 218
kyourek 0:9e2fc73e5a12 219 /*
kyourek 0:9e2fc73e5a12 220 * Summary:
kyourek 0:9e2fc73e5a12 221 * Finds the argument in the list with the specified value.
kyourek 0:9e2fc73e5a12 222 * Parameters:
kyourek 0:9e2fc73e5a12 223 * arg_value: The value of the argument to find.
kyourek 0:9e2fc73e5a12 224 * Returns:
kyourek 0:9e2fc73e5a12 225 * The argument with the specified value, or NULL if none exists.
kyourek 0:9e2fc73e5a12 226 */
kyourek 0:9e2fc73e5a12 227 uc_EXPORTED ucArgTok *ucArgTok_find(ucArgTok*, const char *arg_value);
kyourek 0:9e2fc73e5a12 228
kyourek 0:9e2fc73e5a12 229 /*
kyourek 0:9e2fc73e5a12 230 * Summary:
kyourek 0:9e2fc73e5a12 231 * Gets a value indicating whether or not the value exists in
kyourek 0:9e2fc73e5a12 232 * the argument list.
kyourek 0:9e2fc73e5a12 233 * Parameters:
kyourek 0:9e2fc73e5a12 234 * arg_value: The value of the argument to be found.
kyourek 0:9e2fc73e5a12 235 * Returns:
kyourek 0:9e2fc73e5a12 236 * ucBool_TRUE if an argument token with the given value is found.
kyourek 0:9e2fc73e5a12 237 * Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 238 */
kyourek 0:9e2fc73e5a12 239 uc_EXPORTED ucBool ucArgTok_contains(ucArgTok*, const char *arg_value);
kyourek 0:9e2fc73e5a12 240
kyourek 0:9e2fc73e5a12 241 /*
kyourek 0:9e2fc73e5a12 242 * Summary:
kyourek 0:9e2fc73e5a12 243 * Type definition for tokens (i.e. switch and command tokens)
kyourek 0:9e2fc73e5a12 244 * that contain arguments. This type is a child of the base
kyourek 0:9e2fc73e5a12 245 * token type. All functions that take an instance of the base
kyourek 0:9e2fc73e5a12 246 * type can be used with an instance of this type.
kyourek 0:9e2fc73e5a12 247 */
kyourek 0:9e2fc73e5a12 248 typedef const char ucArgTokOwner;
kyourek 0:9e2fc73e5a12 249
kyourek 0:9e2fc73e5a12 250 /*
kyourek 0:9e2fc73e5a12 251 * Summary
kyourek 0:9e2fc73e5a12 252 * Gets the first argument that belongs to the given owner.
kyourek 0:9e2fc73e5a12 253 * Returns:
kyourek 0:9e2fc73e5a12 254 * The first argument that belongs to the owner, or NULL if
kyourek 0:9e2fc73e5a12 255 * no arguments exist.
kyourek 0:9e2fc73e5a12 256 */
kyourek 0:9e2fc73e5a12 257 uc_EXPORTED ucArgTok *ucArgTokOwner_get_arg(ucArgTokOwner*);
kyourek 0:9e2fc73e5a12 258
kyourek 0:9e2fc73e5a12 259 /*
kyourek 0:9e2fc73e5a12 260 * Summary:
kyourek 0:9e2fc73e5a12 261 * A switch token. This type is a child of the
kyourek 0:9e2fc73e5a12 262 * base token type. All functions that take an
kyourek 0:9e2fc73e5a12 263 * instance of the base type can be used with an
kyourek 0:9e2fc73e5a12 264 * instance of this type.
kyourek 0:9e2fc73e5a12 265 */
kyourek 0:9e2fc73e5a12 266 typedef const char ucSwitchTok;
kyourek 0:9e2fc73e5a12 267
kyourek 0:9e2fc73e5a12 268 /*
kyourek 0:9e2fc73e5a12 269 * Summary:
kyourek 0:9e2fc73e5a12 270 * Gets the next switch token after the given token.
kyourek 0:9e2fc73e5a12 271 * Returns:
kyourek 0:9e2fc73e5a12 272 * The next switch token after the given token.
kyourek 0:9e2fc73e5a12 273 */
kyourek 0:9e2fc73e5a12 274 uc_EXPORTED ucSwitchTok *ucSwitchTok_get_next(ucSwitchTok*);
kyourek 0:9e2fc73e5a12 275
kyourek 0:9e2fc73e5a12 276 /*
kyourek 0:9e2fc73e5a12 277 * Summary:
kyourek 0:9e2fc73e5a12 278 * Counts the number of switches in the linked list.
kyourek 0:9e2fc73e5a12 279 * Returns:
kyourek 0:9e2fc73e5a12 280 * The number of switches in the list.
kyourek 0:9e2fc73e5a12 281 */
kyourek 0:9e2fc73e5a12 282 uc_EXPORTED int ucSwitchTok_count(ucSwitchTok*);
kyourek 0:9e2fc73e5a12 283
kyourek 0:9e2fc73e5a12 284 /*
kyourek 0:9e2fc73e5a12 285 * Summary:
kyourek 0:9e2fc73e5a12 286 * Finds the switch with the specified value.
kyourek 0:9e2fc73e5a12 287 * Parameters:
kyourek 0:9e2fc73e5a12 288 * switch_value: The value of the switch to be found.
kyourek 0:9e2fc73e5a12 289 * Returns:
kyourek 0:9e2fc73e5a12 290 * The switch with the specified value, or NULL if none exist.
kyourek 0:9e2fc73e5a12 291 */
kyourek 0:9e2fc73e5a12 292 uc_EXPORTED ucSwitchTok *ucSwitchTok_find(ucSwitchTok*, const char *switch_value);
kyourek 0:9e2fc73e5a12 293
kyourek 0:9e2fc73e5a12 294 /*
kyourek 0:9e2fc73e5a12 295 * Summary:
kyourek 0:9e2fc73e5a12 296 * Gets a value indicating whether or not a value exists in the switch list.
kyourek 0:9e2fc73e5a12 297 * Parameters:
kyourek 0:9e2fc73e5a12 298 * switch_value: The value of the switch to be found.
kyourek 0:9e2fc73e5a12 299 * Returns:
kyourek 0:9e2fc73e5a12 300 * ucBool_TRUE if a switch with the given value was found in the list. Otherwise,
kyourek 0:9e2fc73e5a12 301 * ucBool_FALSE.
kyourek 0:9e2fc73e5a12 302 */
kyourek 0:9e2fc73e5a12 303 uc_EXPORTED ucBool ucSwitchTok_contains(ucSwitchTok*, const char *switch_value);
kyourek 0:9e2fc73e5a12 304
kyourek 0:9e2fc73e5a12 305 /*
kyourek 0:9e2fc73e5a12 306 * Summary:
kyourek 0:9e2fc73e5a12 307 * Gets the first argument token of the switch.
kyourek 0:9e2fc73e5a12 308 * Returns:
kyourek 0:9e2fc73e5a12 309 * A pointer to the first argument of the switch, or NULL
kyourek 0:9e2fc73e5a12 310 * if no arguments exist.
kyourek 0:9e2fc73e5a12 311 */
kyourek 0:9e2fc73e5a12 312 uc_EXPORTED ucArgTok *ucSwitchTok_get_arg(ucSwitchTok*);
kyourek 0:9e2fc73e5a12 313
kyourek 0:9e2fc73e5a12 314 /*
kyourek 0:9e2fc73e5a12 315 * Summary:
kyourek 0:9e2fc73e5a12 316 * Type definition for a command token. This is
kyourek 0:9e2fc73e5a12 317 * the first token (the command part) in a list
kyourek 0:9e2fc73e5a12 318 * of tokens. This type is a child of the base
kyourek 0:9e2fc73e5a12 319 * token type. All functions that take an instance
kyourek 0:9e2fc73e5a12 320 * of the base type can be used with an instance
kyourek 0:9e2fc73e5a12 321 * of this type.
kyourek 0:9e2fc73e5a12 322 */
kyourek 0:9e2fc73e5a12 323 typedef const char ucCmdTok;
kyourek 0:9e2fc73e5a12 324
kyourek 0:9e2fc73e5a12 325 /*
kyourek 0:9e2fc73e5a12 326 * Summary:
kyourek 0:9e2fc73e5a12 327 * Gets the first argument of the command.
kyourek 0:9e2fc73e5a12 328 * Returns:
kyourek 0:9e2fc73e5a12 329 * A pointer to the first argument token, or NULL if no arguments
kyourek 0:9e2fc73e5a12 330 * exist for the command.
kyourek 0:9e2fc73e5a12 331 */
kyourek 0:9e2fc73e5a12 332 uc_EXPORTED ucArgTok *ucCmdTok_get_arg(ucCmdTok*);
kyourek 0:9e2fc73e5a12 333
kyourek 0:9e2fc73e5a12 334 /*
kyourek 0:9e2fc73e5a12 335 * Summary:
kyourek 0:9e2fc73e5a12 336 * Gets the first switch of the command.
kyourek 0:9e2fc73e5a12 337 * Returns:
kyourek 0:9e2fc73e5a12 338 * A pointer to the first switch token of the command, or NULL
kyourek 0:9e2fc73e5a12 339 * if no switches exist.
kyourek 0:9e2fc73e5a12 340 */
kyourek 0:9e2fc73e5a12 341 uc_EXPORTED ucSwitchTok *ucCmdTok_get_switch(ucCmdTok*);
kyourek 0:9e2fc73e5a12 342
kyourek 0:9e2fc73e5a12 343 /*
kyourek 0:9e2fc73e5a12 344 * Summary:
kyourek 0:9e2fc73e5a12 345 * A group of tokens that represent the first
kyourek 0:9e2fc73e5a12 346 * of each token type in a command.
kyourek 0:9e2fc73e5a12 347 */
kyourek 0:9e2fc73e5a12 348 typedef struct ucCmdLineToks {
kyourek 0:9e2fc73e5a12 349
kyourek 0:9e2fc73e5a12 350 /*
kyourek 0:9e2fc73e5a12 351 * Summary:
kyourek 0:9e2fc73e5a12 352 * The command token of the command. This token's
kyourek 0:9e2fc73e5a12 353 * value is the invoked command.
kyourek 0:9e2fc73e5a12 354 */
kyourek 0:9e2fc73e5a12 355 ucCmdTok *cmd_tok;
kyourek 0:9e2fc73e5a12 356
kyourek 0:9e2fc73e5a12 357 /*
kyourek 0:9e2fc73e5a12 358 * Summary:
kyourek 0:9e2fc73e5a12 359 * The command's first argument token, or
kyourek 0:9e2fc73e5a12 360 * NULL if no arguments exist.
kyourek 0:9e2fc73e5a12 361 */
kyourek 0:9e2fc73e5a12 362 ucArgTok *arg_tok;
kyourek 0:9e2fc73e5a12 363
kyourek 0:9e2fc73e5a12 364 /*
kyourek 0:9e2fc73e5a12 365 * Summary:
kyourek 0:9e2fc73e5a12 366 * The command's first switch token, or
kyourek 0:9e2fc73e5a12 367 * NULL if no switches exist.
kyourek 0:9e2fc73e5a12 368 */
kyourek 0:9e2fc73e5a12 369 ucSwitchTok *switch_tok;
kyourek 0:9e2fc73e5a12 370
kyourek 0:9e2fc73e5a12 371 } ucCmdLineToks;
kyourek 0:9e2fc73e5a12 372
kyourek 0:9e2fc73e5a12 373 /*
kyourek 0:9e2fc73e5a12 374 * Summary:
kyourek 0:9e2fc73e5a12 375 * Gets the command token of the command. This token's
kyourek 0:9e2fc73e5a12 376 * value is the invoked command.
kyourek 0:9e2fc73e5a12 377 * Returns:
kyourek 0:9e2fc73e5a12 378 * A pointer to the command token.
kyourek 0:9e2fc73e5a12 379 */
kyourek 0:9e2fc73e5a12 380 uc_EXPORTED ucCmdTok *ucCmdLineToks_get_cmd_tok(ucCmdLineToks*);
kyourek 0:9e2fc73e5a12 381
kyourek 0:9e2fc73e5a12 382 /*
kyourek 0:9e2fc73e5a12 383 * Summary:
kyourek 0:9e2fc73e5a12 384 * The command's first argument token, or
kyourek 0:9e2fc73e5a12 385 * NULL if no arguments exist.
kyourek 0:9e2fc73e5a12 386 * Returns:
kyourek 0:9e2fc73e5a12 387 * A pointer to the argument token, or NULL if no argument
kyourek 0:9e2fc73e5a12 388 * tokens exist.
kyourek 0:9e2fc73e5a12 389 */
kyourek 0:9e2fc73e5a12 390 uc_EXPORTED ucArgTok *ucCmdLineToks_get_arg_tok(ucCmdLineToks*);
kyourek 0:9e2fc73e5a12 391
kyourek 0:9e2fc73e5a12 392 /*
kyourek 0:9e2fc73e5a12 393 * Summary:
kyourek 0:9e2fc73e5a12 394 * The command's first switch token, or
kyourek 0:9e2fc73e5a12 395 * NULL if no switches exist.
kyourek 0:9e2fc73e5a12 396 * Returns:
kyourek 0:9e2fc73e5a12 397 * A pointer to the switch token, or NULL if no switch tokens exist.
kyourek 0:9e2fc73e5a12 398 */
kyourek 0:9e2fc73e5a12 399 uc_EXPORTED ucSwitchTok *ucCmdLineToks_get_switch_tok(ucCmdLineToks*);
kyourek 0:9e2fc73e5a12 400
kyourek 0:9e2fc73e5a12 401 /*
kyourek 0:9e2fc73e5a12 402 * Summary:
kyourek 0:9e2fc73e5a12 403 * A command structure. This structure consists
kyourek 0:9e2fc73e5a12 404 * of the parsed command and the ability to respond.
kyourek 0:9e2fc73e5a12 405 */
kyourek 0:9e2fc73e5a12 406 typedef struct ucCmdLine ucCmdLine;
kyourek 0:9e2fc73e5a12 407
kyourek 0:9e2fc73e5a12 408 /*
kyourek 0:9e2fc73e5a12 409 * Summary:
kyourek 0:9e2fc73e5a12 410 * The type of function used by a command structure
kyourek 0:9e2fc73e5a12 411 * to transmit responses.
kyourek 0:9e2fc73e5a12 412 * Parameters:
kyourek 0:9e2fc73e5a12 413 * response: The string to be transmitted.
kyourek 0:9e2fc73e5a12 414 * state: A stateful object.
kyourek 0:9e2fc73e5a12 415 */
kyourek 0:9e2fc73e5a12 416 typedef void (ucCmdLine_TransmitFunc)(const char *response, void *state);
kyourek 0:9e2fc73e5a12 417
kyourek 0:9e2fc73e5a12 418 /*
kyourek 0:9e2fc73e5a12 419 * Summary:
kyourek 0:9e2fc73e5a12 420 * The type of function used by a command structure
kyourek 0:9e2fc73e5a12 421 * to determine whether or not the command is canceled.
kyourek 0:9e2fc73e5a12 422 * Parameters:
kyourek 0:9e2fc73e5a12 423 * state: A stateful object.
kyourek 0:9e2fc73e5a12 424 * Returns:
kyourek 0:9e2fc73e5a12 425 * ucBool_TRUE if the command has been canceled. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 426 */
kyourek 0:9e2fc73e5a12 427 typedef ucBool (ucCmdLine_IsCanceledFunc)(void *state);
kyourek 0:9e2fc73e5a12 428
kyourek 0:9e2fc73e5a12 429 /*
kyourek 0:9e2fc73e5a12 430 * Summary:
kyourek 0:9e2fc73e5a12 431 * The type of the function that is invoked when an
kyourek 0:9e2fc73e5a12 432 * invalid command is encountered. An invalid command
kyourek 0:9e2fc73e5a12 433 * is one that does not exist in the list of command
kyourek 0:9e2fc73e5a12 434 * options.
kyourek 0:9e2fc73e5a12 435 * Parameters:
kyourek 0:9e2fc73e5a12 436 * invalid_command: The invalid command string that was encountered.
kyourek 0:9e2fc73e5a12 437 * state: The stateful object for this callback.
kyourek 0:9e2fc73e5a12 438 * Returns:
kyourek 0:9e2fc73e5a12 439 * ucBool_TRUE if the invalid command was handeled. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 440 */
kyourek 0:9e2fc73e5a12 441 typedef ucBool (ucCmdLine_HandleInvalidCommandFunc)(const char *invalid_command, void *state);
kyourek 0:9e2fc73e5a12 442
kyourek 0:9e2fc73e5a12 443 /*
kyourek 0:9e2fc73e5a12 444 * Summary:
kyourek 0:9e2fc73e5a12 445 * Gets the command token from the command structure.
kyourek 0:9e2fc73e5a12 446 * Returns:
kyourek 0:9e2fc73e5a12 447 * A pointer to the command token of the structure.
kyourek 0:9e2fc73e5a12 448 */
kyourek 0:9e2fc73e5a12 449 uc_EXPORTED ucCmdTok *ucCmdLine_get_cmd_tok(ucCmdLine*);
kyourek 0:9e2fc73e5a12 450
kyourek 0:9e2fc73e5a12 451 /*
kyourek 0:9e2fc73e5a12 452 * Summary:
kyourek 0:9e2fc73e5a12 453 * Sets the command token for the structure.
kyourek 0:9e2fc73e5a12 454 * Parameters:
kyourek 0:9e2fc73e5a12 455 * value: The command token.
kyourek 0:9e2fc73e5a12 456 */
kyourek 0:9e2fc73e5a12 457 uc_EXPORTED void ucCmdLine_set_cmd_tok(ucCmdLine*, ucCmdTok *value);
kyourek 0:9e2fc73e5a12 458
kyourek 0:9e2fc73e5a12 459 /*
kyourek 0:9e2fc73e5a12 460 * Summary:
kyourek 0:9e2fc73e5a12 461 * Fills the buffer with the specified tokens of the command structure.
kyourek 0:9e2fc73e5a12 462 * Parameters:
kyourek 0:9e2fc73e5a12 463 * buffer: A pointer to the token structure whose properties will be set per the command.
kyourek 0:9e2fc73e5a12 464 * Returns:
kyourek 0:9e2fc73e5a12 465 * A pointer to the buffer.
kyourek 0:9e2fc73e5a12 466 */
kyourek 0:9e2fc73e5a12 467 uc_EXPORTED ucCmdLineToks *ucCmdLine_get_cmd_toks(ucCmdLine*, ucCmdLineToks *buffer);
kyourek 0:9e2fc73e5a12 468
kyourek 0:9e2fc73e5a12 469 /*
kyourek 0:9e2fc73e5a12 470 * Summary:
kyourek 0:9e2fc73e5a12 471 * Sets the function used by the command structure to transmit responses.
kyourek 0:9e2fc73e5a12 472 * Parameters:
kyourek 0:9e2fc73e5a12 473 * value: A pointer to the function used to transmit responses.
kyourek 0:9e2fc73e5a12 474 */
kyourek 0:9e2fc73e5a12 475 uc_EXPORTED void ucCmdLine_set_transmit(ucCmdLine*, ucCmdLine_TransmitFunc *value);
kyourek 0:9e2fc73e5a12 476
kyourek 0:9e2fc73e5a12 477 /*
kyourek 0:9e2fc73e5a12 478 * Summary:
kyourek 0:9e2fc73e5a12 479 * Gets the function used by the command structure to transmit responses.
kyourek 0:9e2fc73e5a12 480 * Returns:
kyourek 0:9e2fc73e5a12 481 * A pointer to the function used by the structure to transmit responses.
kyourek 0:9e2fc73e5a12 482 */
kyourek 0:9e2fc73e5a12 483 uc_EXPORTED ucCmdLine_TransmitFunc *ucCmdLine_get_transmit(ucCmdLine*);
kyourek 0:9e2fc73e5a12 484
kyourek 0:9e2fc73e5a12 485 /*
kyourek 0:9e2fc73e5a12 486 * Summary:
kyourek 0:9e2fc73e5a12 487 * Gets the stateful object passed to the command's transmit function.
kyourek 0:9e2fc73e5a12 488 * Returns:
kyourek 0:9e2fc73e5a12 489 * A pointer to the stateful object passed to the command's transmit function.
kyourek 0:9e2fc73e5a12 490 */
kyourek 0:9e2fc73e5a12 491 uc_EXPORTED void *ucCmdLine_get_transmit_state(ucCmdLine*);
kyourek 0:9e2fc73e5a12 492
kyourek 0:9e2fc73e5a12 493 /*
kyourek 0:9e2fc73e5a12 494 * Summary:
kyourek 0:9e2fc73e5a12 495 * Sets the stateful object passed to the command's transmit function.
kyourek 0:9e2fc73e5a12 496 * Parameters:
kyourek 0:9e2fc73e5a12 497 * value: A pointer to the stateful object that is passed to the command's transmit function.
kyourek 0:9e2fc73e5a12 498 */
kyourek 0:9e2fc73e5a12 499 uc_EXPORTED void ucCmdLine_set_transmit_state(ucCmdLine*, void *value);
kyourek 0:9e2fc73e5a12 500
kyourek 0:9e2fc73e5a12 501 /*
kyourek 0:9e2fc73e5a12 502 * Summary:
kyourek 0:9e2fc73e5a12 503 * Determines whether or not the command has been canceled.
kyourek 0:9e2fc73e5a12 504 * Returns:
kyourek 0:9e2fc73e5a12 505 * ucBool_TRUE if the command has been canceled. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 506 */
kyourek 0:9e2fc73e5a12 507 uc_EXPORTED ucBool ucCmdLine_is_canceled(ucCmdLine*);
kyourek 0:9e2fc73e5a12 508
kyourek 0:9e2fc73e5a12 509 /*
kyourek 0:9e2fc73e5a12 510 * Summary:
kyourek 0:9e2fc73e5a12 511 * Sets the function used by the command structure to check for cancellation.
kyourek 0:9e2fc73e5a12 512 * Parameters:
kyourek 0:9e2fc73e5a12 513 * value: A pointer to the function used to check for cancellation.
kyourek 0:9e2fc73e5a12 514 */
kyourek 0:9e2fc73e5a12 515 uc_EXPORTED void ucCmdLine_set_is_canceled(ucCmdLine*, ucCmdLine_IsCanceledFunc *value);
kyourek 0:9e2fc73e5a12 516
kyourek 0:9e2fc73e5a12 517 /*
kyourek 0:9e2fc73e5a12 518 * Summary:
kyourek 0:9e2fc73e5a12 519 * Gets the function used by the command structure to check for cancellation.
kyourek 0:9e2fc73e5a12 520 * Returns:
kyourek 0:9e2fc73e5a12 521 * A pointer to the function used to check for cancellation.
kyourek 0:9e2fc73e5a12 522 */
kyourek 0:9e2fc73e5a12 523 uc_EXPORTED ucCmdLine_IsCanceledFunc *ucCmdLine_get_is_canceled(ucCmdLine*);
kyourek 0:9e2fc73e5a12 524
kyourek 0:9e2fc73e5a12 525 /*
kyourek 0:9e2fc73e5a12 526 * Summary:
kyourek 0:9e2fc73e5a12 527 * Gets the stateful object passed to the command's cancellation function.
kyourek 0:9e2fc73e5a12 528 * Returns:
kyourek 0:9e2fc73e5a12 529 * A pointer to the stateful object passed to the command's cancellation function.
kyourek 0:9e2fc73e5a12 530 */
kyourek 0:9e2fc73e5a12 531 uc_EXPORTED void *ucCmdLine_get_is_canceled_state(ucCmdLine*);
kyourek 0:9e2fc73e5a12 532
kyourek 0:9e2fc73e5a12 533 /*
kyourek 0:9e2fc73e5a12 534 * Summary:
kyourek 0:9e2fc73e5a12 535 * Sets the stateful object passed to the command's cancellation function.
kyourek 0:9e2fc73e5a12 536 * Parameters:
kyourek 0:9e2fc73e5a12 537 * value: The stateful object passed to the command's cancellation function.
kyourek 0:9e2fc73e5a12 538 */
kyourek 0:9e2fc73e5a12 539 uc_EXPORTED void ucCmdLine_set_is_canceled_state(ucCmdLine*, void *value);
kyourek 0:9e2fc73e5a12 540
kyourek 0:9e2fc73e5a12 541 uc_EXPORTED void ucCmdLine_set_handle_invalid_command(ucCmdLine*, ucCmdLine_HandleInvalidCommandFunc *value);
kyourek 0:9e2fc73e5a12 542
kyourek 0:9e2fc73e5a12 543 uc_EXPORTED ucCmdLine_HandleInvalidCommandFunc *ucCmdLine_get_handle_invalid_command(ucCmdLine*);
kyourek 0:9e2fc73e5a12 544
kyourek 0:9e2fc73e5a12 545 uc_EXPORTED void ucCmdLine_set_handle_invalid_command_state(ucCmdLine*, void *value);
kyourek 0:9e2fc73e5a12 546
kyourek 0:9e2fc73e5a12 547 uc_EXPORTED void *ucCmdLine_get_handle_invalid_command_state(ucCmdLine*);
kyourek 0:9e2fc73e5a12 548
kyourek 0:9e2fc73e5a12 549 uc_EXPORTED size_t ucCmdLine_get_response_size_max(ucCmdLine*);
kyourek 0:9e2fc73e5a12 550
kyourek 0:9e2fc73e5a12 551 /*
kyourek 0:9e2fc73e5a12 552 * Summary:
kyourek 0:9e2fc73e5a12 553 * Gets a static, default instance of the command structure.
kyourek 0:9e2fc73e5a12 554 * Returns:
kyourek 0:9e2fc73e5a12 555 * The static, default instance of the command structure.
kyourek 0:9e2fc73e5a12 556 */
kyourek 0:9e2fc73e5a12 557 uc_EXPORTED ucCmdLine *ucCmdLine_get_instance(void);
kyourek 0:9e2fc73e5a12 558
kyourek 0:9e2fc73e5a12 559 /*
kyourek 0:9e2fc73e5a12 560 * Summary:
kyourek 0:9e2fc73e5a12 561 * Formats the command's response using the given parameters.
kyourek 0:9e2fc73e5a12 562 * Parameters:
kyourek 0:9e2fc73e5a12 563 * format: The format string.
kyourek 0:9e2fc73e5a12 564 * ...: Parameters to the format string.
kyourek 0:9e2fc73e5a12 565 * Returns:
kyourek 0:9e2fc73e5a12 566 * The formatted string.
kyourek 0:9e2fc73e5a12 567 */
kyourek 0:9e2fc73e5a12 568 uc_EXPORTED const char *ucCmdLine_format_response(ucCmdLine*, const char *format, ...);
kyourek 0:9e2fc73e5a12 569
kyourek 0:9e2fc73e5a12 570 /*
kyourek 0:9e2fc73e5a12 571 * Summary:
kyourek 0:9e2fc73e5a12 572 * Formats the command's response using the given parameters.
kyourek 0:9e2fc73e5a12 573 * Parameters:
kyourek 0:9e2fc73e5a12 574 * format: The format string.
kyourek 0:9e2fc73e5a12 575 * arg_list: A variable length argument list with parameters to the format string.
kyourek 0:9e2fc73e5a12 576 * Returns:
kyourek 0:9e2fc73e5a12 577 * The formatted string.
kyourek 0:9e2fc73e5a12 578 */
kyourek 0:9e2fc73e5a12 579 uc_EXPORTED const char *ucCmdLine_format_response_va(ucCmdLine*, const char *format, va_list arg_list);
kyourek 0:9e2fc73e5a12 580
kyourek 0:9e2fc73e5a12 581 /*
kyourek 0:9e2fc73e5a12 582 * Summary
kyourek 0:9e2fc73e5a12 583 * Responds to the command.
kyourek 0:9e2fc73e5a12 584 * Parameters:
kyourek 0:9e2fc73e5a12 585 * response: The response string.
kyourek 0:9e2fc73e5a12 586 */
kyourek 0:9e2fc73e5a12 587 uc_EXPORTED void ucCmdLine_respond(ucCmdLine*, const char *response);
kyourek 0:9e2fc73e5a12 588
kyourek 0:9e2fc73e5a12 589 /*
kyourek 0:9e2fc73e5a12 590 * Summary:
kyourek 0:9e2fc73e5a12 591 * Sets whether or not the command structure is quiet, meaning no response
kyourek 0:9e2fc73e5a12 592 * strings will be sent.
kyourek 0:9e2fc73e5a12 593 * Parameters:
kyourek 0:9e2fc73e5a12 594 * value: A boolean true value if the command structure should not send
kyourek 0:9e2fc73e5a12 595 * any response strings. Otherwise, false.
kyourek 0:9e2fc73e5a12 596 */
kyourek 0:9e2fc73e5a12 597 uc_EXPORTED void ucCmdLine_set_is_quiet(ucCmdLine*, ucBool value);
kyourek 0:9e2fc73e5a12 598
kyourek 0:9e2fc73e5a12 599 /*
kyourek 0:9e2fc73e5a12 600 * Summary:
kyourek 0:9e2fc73e5a12 601 * Gets a flag that indicates whether or not the command structure is quiet,
kyourek 0:9e2fc73e5a12 602 * meaning no response strings are sent.
kyourek 0:9e2fc73e5a12 603 * Returns:
kyourek 0:9e2fc73e5a12 604 * A boolean true value if the command structure is not sending any
kyourek 0:9e2fc73e5a12 605 * response strings. Otherwise, false.
kyourek 0:9e2fc73e5a12 606 */
kyourek 0:9e2fc73e5a12 607 uc_EXPORTED ucBool ucCmdLine_get_is_quiet(ucCmdLine*);
kyourek 0:9e2fc73e5a12 608
kyourek 0:9e2fc73e5a12 609 uc_EXPORTED void ucCmdLine_acknowledge_command(ucCmdLine*);
kyourek 0:9e2fc73e5a12 610 uc_EXPORTED const char* ucCmdLine_get_command_acknowledgment(ucCmdLine*);
kyourek 0:9e2fc73e5a12 611 uc_EXPORTED const char* ucCmdLine_get_response_terminator(ucCmdLine*);
kyourek 0:9e2fc73e5a12 612 uc_EXPORTED void ucCmdLine_set_response_terminator(ucCmdLine*, const char *value);
kyourek 0:9e2fc73e5a12 613 uc_EXPORTED void ucCmdLine_set_command_acknowledgment(ucCmdLine*, const char *value);
kyourek 0:9e2fc73e5a12 614 uc_EXPORTED void ucCmdLine_terminate_response(ucCmdLine*);
kyourek 0:9e2fc73e5a12 615
kyourek 0:9e2fc73e5a12 616 /*
kyourek 0:9e2fc73e5a12 617 * Summary:
kyourek 0:9e2fc73e5a12 618 * Base type for command, argument, and switch options.
kyourek 0:9e2fc73e5a12 619 */
kyourek 0:9e2fc73e5a12 620 typedef struct ucOpt ucOpt;
kyourek 0:9e2fc73e5a12 621
kyourek 0:9e2fc73e5a12 622 /*
kyourek 0:9e2fc73e5a12 623 * Summary:
kyourek 0:9e2fc73e5a12 624 * Gets the name of the option.
kyourek 0:9e2fc73e5a12 625 * Returns:
kyourek 0:9e2fc73e5a12 626 * The name of the option.
kyourek 0:9e2fc73e5a12 627 */
kyourek 0:9e2fc73e5a12 628 uc_EXPORTED const char* ucOpt_get_name(ucOpt*);
kyourek 0:9e2fc73e5a12 629
kyourek 0:9e2fc73e5a12 630 /*
kyourek 0:9e2fc73e5a12 631 * Summary:
kyourek 0:9e2fc73e5a12 632 * Gets the description of the option.
kyourek 0:9e2fc73e5a12 633 * Returns:
kyourek 0:9e2fc73e5a12 634 * The description of the option.
kyourek 0:9e2fc73e5a12 635 */
kyourek 0:9e2fc73e5a12 636 uc_EXPORTED const char *ucOpt_get_desc(ucOpt*);
kyourek 0:9e2fc73e5a12 637
kyourek 0:9e2fc73e5a12 638 /*
kyourek 0:9e2fc73e5a12 639 * Summary:
kyourek 0:9e2fc73e5a12 640 * Gets a flag that indicates whether or not the option
kyourek 0:9e2fc73e5a12 641 * is required.
kyourek 0:9e2fc73e5a12 642 * Returns:
kyourek 0:9e2fc73e5a12 643 * ucBool_TRUE if the option is required. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 644 */
kyourek 0:9e2fc73e5a12 645 uc_EXPORTED ucBool ucOpt_is_required(ucOpt*);
kyourek 0:9e2fc73e5a12 646
kyourek 0:9e2fc73e5a12 647 /*
kyourek 0:9e2fc73e5a12 648 * Summary:
kyourek 0:9e2fc73e5a12 649 * Uses the provided command structure to send help information
kyourek 0:9e2fc73e5a12 650 * for this option.
kyourek 0:9e2fc73e5a12 651 * Parameters:
kyourek 0:9e2fc73e5a12 652 * cmd: A pointer to the command structure used to respond
kyourek 0:9e2fc73e5a12 653 * with the help information.
kyourek 0:9e2fc73e5a12 654 * prefix: A string used to prefix the help information.
kyourek 0:9e2fc73e5a12 655 */
kyourek 0:9e2fc73e5a12 656 uc_EXPORTED void ucOpt_send_help(ucOpt*, ucCmdLine *cmd, const char *prefix);
kyourek 0:9e2fc73e5a12 657
kyourek 0:9e2fc73e5a12 658 /*
kyourek 0:9e2fc73e5a12 659 * Summary:
kyourek 0:9e2fc73e5a12 660 * An argument option. This type is a child
kyourek 0:9e2fc73e5a12 661 * of the base option type.
kyourek 0:9e2fc73e5a12 662 */
kyourek 0:9e2fc73e5a12 663 typedef struct ucArgOpt ucArgOpt;
kyourek 0:9e2fc73e5a12 664
kyourek 0:9e2fc73e5a12 665 /*
kyourek 0:9e2fc73e5a12 666 * Summary:
kyourek 0:9e2fc73e5a12 667 * Gets the minimum allowed token count of the argument option.
kyourek 0:9e2fc73e5a12 668 * Returns:
kyourek 0:9e2fc73e5a12 669 * The minimum number of argument tokens allowed for this option.
kyourek 0:9e2fc73e5a12 670 */
kyourek 0:9e2fc73e5a12 671 uc_EXPORTED int ucArgOpt_get_min_tok_count(ucArgOpt*);
kyourek 0:9e2fc73e5a12 672
kyourek 0:9e2fc73e5a12 673 /*
kyourek 0:9e2fc73e5a12 674 * Summary:
kyourek 0:9e2fc73e5a12 675 * Gets the maximum allowed token count of the argument option.
kyourek 0:9e2fc73e5a12 676 * Returns:
kyourek 0:9e2fc73e5a12 677 * The maximum number of argument tokens allowed for this option.
kyourek 0:9e2fc73e5a12 678 */
kyourek 0:9e2fc73e5a12 679 uc_EXPORTED int ucArgOpt_get_max_tok_count(ucArgOpt*);
kyourek 0:9e2fc73e5a12 680
kyourek 0:9e2fc73e5a12 681 uc_EXPORTED ucBool ucArgOpt_is_boolean(ucArgOpt*);
kyourek 0:9e2fc73e5a12 682
kyourek 0:9e2fc73e5a12 683 /*
kyourek 0:9e2fc73e5a12 684 * Summary:
kyourek 0:9e2fc73e5a12 685 * Gets a flag that indicates whether or not this argument option
kyourek 0:9e2fc73e5a12 686 * is numeric.
kyourek 0:9e2fc73e5a12 687 * Returns:
kyourek 0:9e2fc73e5a12 688 * ucBool_TRUE if the argument is numeric. Otherwise, ucBool_FALSE.
kyourek 0:9e2fc73e5a12 689 */
kyourek 0:9e2fc73e5a12 690 uc_EXPORTED ucBool ucArgOpt_is_numeric(ucArgOpt*);
kyourek 0:9e2fc73e5a12 691
kyourek 0:9e2fc73e5a12 692 /*
kyourek 0:9e2fc73e5a12 693 * Summary:
kyourek 0:9e2fc73e5a12 694 * Gets the minimum value if this argument option is numeric.
kyourek 0:9e2fc73e5a12 695 * Returns:
kyourek 0:9e2fc73e5a12 696 * The minimum numeric value of the argument.
kyourek 0:9e2fc73e5a12 697 */
kyourek 0:9e2fc73e5a12 698 uc_EXPORTED ucArgOpt_NUMERIC_TYPE ucArgOpt_get_numeric_min(ucArgOpt*);
kyourek 0:9e2fc73e5a12 699
kyourek 0:9e2fc73e5a12 700 /*
kyourek 0:9e2fc73e5a12 701 * Summary:
kyourek 0:9e2fc73e5a12 702 * Gets the maximum value if this argument is numeric.
kyourek 0:9e2fc73e5a12 703 * Returns:
kyourek 0:9e2fc73e5a12 704 * The maximum numeric value of the argument.
kyourek 0:9e2fc73e5a12 705 */
kyourek 0:9e2fc73e5a12 706 uc_EXPORTED ucArgOpt_NUMERIC_TYPE ucArgOpt_get_numeric_max(ucArgOpt*);
kyourek 0:9e2fc73e5a12 707
kyourek 0:9e2fc73e5a12 708 /*
kyourek 0:9e2fc73e5a12 709 * Summary:
kyourek 0:9e2fc73e5a12 710 * Creates a new argument option.
kyourek 0:9e2fc73e5a12 711 * Parameters:
kyourek 0:9e2fc73e5a12 712 * name: The name of the option.
kyourek 0:9e2fc73e5a12 713 * desc: The description of the option.
kyourek 0:9e2fc73e5a12 714 * next: The next option in the chain that the created option precedes,
kyourek 0:9e2fc73e5a12 715 * or NULL if the created option is the last.
kyourek 0:9e2fc73e5a12 716 * Returns:
kyourek 0:9e2fc73e5a12 717 * A pointer to the newly created argument option.
kyourek 0:9e2fc73e5a12 718 */
kyourek 0:9e2fc73e5a12 719 uc_EXPORTED ucArgOpt *ucArgOpt_create(const char *name, const char *desc, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 720
kyourek 0:9e2fc73e5a12 721 /*
kyourek 0:9e2fc73e5a12 722 * Summary:
kyourek 0:9e2fc73e5a12 723 * Creates a new argument option that allows multiple tokens.
kyourek 0:9e2fc73e5a12 724 * Parameters:
kyourek 0:9e2fc73e5a12 725 * name: The name of the option.
kyourek 0:9e2fc73e5a12 726 * desc: The description of the option.
kyourek 0:9e2fc73e5a12 727 * min_tok_count: The minimum number of argument tokens allowed for this option.
kyourek 0:9e2fc73e5a12 728 * max_tok_count: The maximum number of argument tokens allowed for this option.
kyourek 0:9e2fc73e5a12 729 * Returns:
kyourek 0:9e2fc73e5a12 730 * A pointer to the newly created argument option.
kyourek 0:9e2fc73e5a12 731 */
kyourek 0:9e2fc73e5a12 732 uc_EXPORTED ucArgOpt *ucArgOpt_create_multiple(const char *name, const char *desc, int min_tok_count, int max_tok_count);
kyourek 0:9e2fc73e5a12 733
kyourek 0:9e2fc73e5a12 734 /*
kyourek 0:9e2fc73e5a12 735 * Summary:
kyourek 0:9e2fc73e5a12 736 * Creates a new, required argument option.
kyourek 0:9e2fc73e5a12 737 * Parameters:
kyourek 0:9e2fc73e5a12 738 * name: The name of the option.
kyourek 0:9e2fc73e5a12 739 * desc: The description of the option.
kyourek 0:9e2fc73e5a12 740 * next: The next option in the chain that the created option precedes,
kyourek 0:9e2fc73e5a12 741 * or NULL if the created option is the last.
kyourek 0:9e2fc73e5a12 742 * Returns:
kyourek 0:9e2fc73e5a12 743 * A pointer to the newly created argument option. The option will have its
kyourek 0:9e2fc73e5a12 744 * 'required' property set to true.
kyourek 0:9e2fc73e5a12 745 */
kyourek 0:9e2fc73e5a12 746 uc_EXPORTED ucArgOpt *ucArgOpt_create_required(const char *name, const char *desc, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 747
kyourek 0:9e2fc73e5a12 748 uc_EXPORTED ucArgOpt *ucArgOpt_create_boolean(const char *desc, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 749 uc_EXPORTED ucArgOpt *ucArgOpt_create_required_boolean(const char *desc, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 750
kyourek 0:9e2fc73e5a12 751 /*
kyourek 0:9e2fc73e5a12 752 * Summary:
kyourek 0:9e2fc73e5a12 753 * Creates a new, numeric argument option.
kyourek 0:9e2fc73e5a12 754 * Parameters:
kyourek 0:9e2fc73e5a12 755 * desc: The description of the argument.
kyourek 0:9e2fc73e5a12 756 * numeric_min: The minimum value of the argument.
kyourek 0:9e2fc73e5a12 757 * numeric_max: The maximum value of the argument.
kyourek 0:9e2fc73e5a12 758 * next: A pointer to the next option in the chain that the created option precedes,
kyourek 0:9e2fc73e5a12 759 * or NULL if the created option is the last.
kyourek 0:9e2fc73e5a12 760 * Returns:
kyourek 0:9e2fc73e5a12 761 * A pointer to the newly created argument option.
kyourek 0:9e2fc73e5a12 762 */
kyourek 0:9e2fc73e5a12 763 uc_EXPORTED ucArgOpt *ucArgOpt_create_numeric(const char *desc, ucArgOpt_NUMERIC_TYPE numeric_min, ucArgOpt_NUMERIC_TYPE numeric_max, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 764
kyourek 0:9e2fc73e5a12 765 /*
kyourek 0:9e2fc73e5a12 766 * Summary:
kyourek 0:9e2fc73e5a12 767 * Creates a new, numeric argument option that accepts multiple argument tokens.
kyourek 0:9e2fc73e5a12 768 * Parameters:
kyourek 0:9e2fc73e5a12 769 * desc: The description of the argument.
kyourek 0:9e2fc73e5a12 770 * min_tok_count: The minimum number of allowed argument tokens.
kyourek 0:9e2fc73e5a12 771 * max_tok_count: The maximum number of allowed argument tokens.
kyourek 0:9e2fc73e5a12 772 * numeric_min: The minimum value of the argument.
kyourek 0:9e2fc73e5a12 773 * numeric_max: The maximum value of the argument.
kyourek 0:9e2fc73e5a12 774 * Returns:
kyourek 0:9e2fc73e5a12 775 * A pointer to the newly created argument option.
kyourek 0:9e2fc73e5a12 776 */
kyourek 0:9e2fc73e5a12 777 uc_EXPORTED ucArgOpt *ucArgOpt_create_multiple_numeric(const char *desc, int min_tok_count, int max_tok_count, ucArgOpt_NUMERIC_TYPE numeric_min, ucArgOpt_NUMERIC_TYPE numeric_max);
kyourek 0:9e2fc73e5a12 778
kyourek 0:9e2fc73e5a12 779 /*
kyourek 0:9e2fc73e5a12 780 * Summary:
kyourek 0:9e2fc73e5a12 781 * Creates a new, numeric, required argument option.
kyourek 0:9e2fc73e5a12 782 * Parameters:
kyourek 0:9e2fc73e5a12 783 * desc: The description of the argument.
kyourek 0:9e2fc73e5a12 784 * numeric_min: The minimum value of the argument.
kyourek 0:9e2fc73e5a12 785 * numeric_max: The maximum value of the argument.
kyourek 0:9e2fc73e5a12 786 * next: A pointer to the next option in the chain that the created option precedes,
kyourek 0:9e2fc73e5a12 787 * or NULL if the created option is the last.
kyourek 0:9e2fc73e5a12 788 * Returns:
kyourek 0:9e2fc73e5a12 789 * A pointer to the newly created argument option. The option will have its
kyourek 0:9e2fc73e5a12 790 * 'required' property set to true.
kyourek 0:9e2fc73e5a12 791 */
kyourek 0:9e2fc73e5a12 792 uc_EXPORTED ucArgOpt *ucArgOpt_create_required_numeric(const char *desc, ucArgOpt_NUMERIC_TYPE numeric_min, ucArgOpt_NUMERIC_TYPE numeric_max, ucArgOpt *next);
kyourek 0:9e2fc73e5a12 793
kyourek 0:9e2fc73e5a12 794 /*
kyourek 0:9e2fc73e5a12 795 * Summary:
kyourek 0:9e2fc73e5a12 796 * Gets the next argument option after the given option.
kyourek 0:9e2fc73e5a12 797 * Returns:
kyourek 0:9e2fc73e5a12 798 * A pointer to the option that the given option precedes,
kyourek 0:9e2fc73e5a12 799 * or NULL of no further options exist.
kyourek 0:9e2fc73e5a12 800 */
kyourek 0:9e2fc73e5a12 801 uc_EXPORTED ucArgOpt *ucArgOpt_get_next(ucArgOpt*);
kyourek 0:9e2fc73e5a12 802
kyourek 0:9e2fc73e5a12 803 /*
kyourek 0:9e2fc73e5a12 804 * Summary:
kyourek 0:9e2fc73e5a12 805 * Releases memory used by the argument option.
kyourek 0:9e2fc73e5a12 806 */
kyourek 0:9e2fc73e5a12 807 uc_EXPORTED void ucArgOpt_destroy(ucArgOpt*);
kyourek 0:9e2fc73e5a12 808
kyourek 0:9e2fc73e5a12 809 /*
kyourek 0:9e2fc73e5a12 810 * Summary:
kyourek 0:9e2fc73e5a12 811 * Releases memory used by the argument option
kyourek 0:9e2fc73e5a12 812 * and all proceeding options in the list.
kyourek 0:9e2fc73e5a12 813 */
kyourek 0:9e2fc73e5a12 814 uc_EXPORTED void ucArgOpt_destroy_chain(ucArgOpt*);
kyourek 0:9e2fc73e5a12 815
kyourek 0:9e2fc73e5a12 816 /*
kyourek 0:9e2fc73e5a12 817 * Summary:
kyourek 0:9e2fc73e5a12 818 * Base structure for options (switches and commands)
kyourek 0:9e2fc73e5a12 819 * that contain argument options. This type is a child
kyourek 0:9e2fc73e5a12 820 * of the base option type.
kyourek 0:9e2fc73e5a12 821 */
kyourek 0:9e2fc73e5a12 822 typedef struct ucArgOptOwner ucArgOptOwner;
kyourek 0:9e2fc73e5a12 823
kyourek 0:9e2fc73e5a12 824 /*
kyourek 0:9e2fc73e5a12 825 * Summary:
kyourek 0:9e2fc73e5a12 826 * Gets the first argument option of the given option owner.
kyourek 0:9e2fc73e5a12 827 * Returns:
kyourek 0:9e2fc73e5a12 828 * A pointer to the first argument option of the given option owner.
kyourek 0:9e2fc73e5a12 829 */
kyourek 0:9e2fc73e5a12 830 uc_EXPORTED ucArgOpt *ucArgOptOwner_get_arg_opt(ucArgOptOwner*);
kyourek 0:9e2fc73e5a12 831
kyourek 0:9e2fc73e5a12 832 /*
kyourek 0:9e2fc73e5a12 833 * Summary:
kyourek 0:9e2fc73e5a12 834 * A command switch option. This type is a child
kyourek 0:9e2fc73e5a12 835 * of the base option type.
kyourek 0:9e2fc73e5a12 836 */
kyourek 0:9e2fc73e5a12 837 typedef struct ucSwitchOpt ucSwitchOpt;
kyourek 0:9e2fc73e5a12 838
kyourek 0:9e2fc73e5a12 839 /*
kyourek 0:9e2fc73e5a12 840 * Summary:
kyourek 0:9e2fc73e5a12 841 * Creates a new switch option.
kyourek 0:9e2fc73e5a12 842 * Parameters:
kyourek 0:9e2fc73e5a12 843 * name: The name of the switch.
kyourek 0:9e2fc73e5a12 844 * desc: A description of the switch.
kyourek 0:9e2fc73e5a12 845 * arg_opt: The first argument option of the switch.
kyourek 0:9e2fc73e5a12 846 * next: The switch option that the created option precedes,
kyourek 0:9e2fc73e5a12 847 * or NULL if no further switch options exist.
kyourek 0:9e2fc73e5a12 848 * Returns:
kyourek 0:9e2fc73e5a12 849 * A pointer to the newly created switch option.
kyourek 0:9e2fc73e5a12 850 */
kyourek 0:9e2fc73e5a12 851 uc_EXPORTED ucSwitchOpt *ucSwitchOpt_create(const char *name, const char *desc, ucArgOpt *arg_opt, ucSwitchOpt *next);
kyourek 0:9e2fc73e5a12 852
kyourek 0:9e2fc73e5a12 853 /*
kyourek 0:9e2fc73e5a12 854 * Summary:
kyourek 0:9e2fc73e5a12 855 * Creates a new, required switch option.
kyourek 0:9e2fc73e5a12 856 * Parameters:
kyourek 0:9e2fc73e5a12 857 * name: The name of the switch.
kyourek 0:9e2fc73e5a12 858 * desc: A description of the switch.
kyourek 0:9e2fc73e5a12 859 * arg_opt: The first argument option of the switch.
kyourek 0:9e2fc73e5a12 860 * next: The switch option that the created option precedes,
kyourek 0:9e2fc73e5a12 861 * or NULL if no further switch options exist.
kyourek 0:9e2fc73e5a12 862 * Returns:
kyourek 0:9e2fc73e5a12 863 * A pointer to the newly created switch option. The option's
kyourek 0:9e2fc73e5a12 864 * 'required' property will be set to true.
kyourek 0:9e2fc73e5a12 865 */
kyourek 0:9e2fc73e5a12 866 uc_EXPORTED ucSwitchOpt *ucSwitchOpt_create_required(const char *name, const char *desc, ucArgOpt *arg_opt, ucSwitchOpt *next);
kyourek 0:9e2fc73e5a12 867
kyourek 0:9e2fc73e5a12 868 /*
kyourek 0:9e2fc73e5a12 869 * Summary:
kyourek 0:9e2fc73e5a12 870 * Gets the first argument option of the given switch.
kyourek 0:9e2fc73e5a12 871 * Returns:
kyourek 0:9e2fc73e5a12 872 * A pointer to the first argument option of the switch, or NULL
kyourek 0:9e2fc73e5a12 873 * if no argument options exist.
kyourek 0:9e2fc73e5a12 874 */
kyourek 0:9e2fc73e5a12 875 uc_EXPORTED ucArgOpt *ucSwitchOpt_get_arg_opt(ucSwitchOpt*);
kyourek 0:9e2fc73e5a12 876
kyourek 0:9e2fc73e5a12 877 /*
kyourek 0:9e2fc73e5a12 878 * Summary:
kyourek 0:9e2fc73e5a12 879 * Finds the switch option in the linked list with the given name.
kyourek 0:9e2fc73e5a12 880 * Parameters:
kyourek 0:9e2fc73e5a12 881 * name: The name of the switch option to be found.
kyourek 0:9e2fc73e5a12 882 * Returns:
kyourek 0:9e2fc73e5a12 883 * The switch option with the given name, or NULL if
kyourek 0:9e2fc73e5a12 884 * no switch option is found.
kyourek 0:9e2fc73e5a12 885 */
kyourek 0:9e2fc73e5a12 886 uc_EXPORTED ucSwitchOpt *ucSwitchOpt_find(ucSwitchOpt*, const char *name);
kyourek 0:9e2fc73e5a12 887
kyourek 0:9e2fc73e5a12 888 /*
kyourek 0:9e2fc73e5a12 889 * Summary:
kyourek 0:9e2fc73e5a12 890 * Gets the next switch option.
kyourek 0:9e2fc73e5a12 891 * Returns:
kyourek 0:9e2fc73e5a12 892 * A pointer to the next switch option in the list, or NULL
kyourek 0:9e2fc73e5a12 893 * if no further options exist.
kyourek 0:9e2fc73e5a12 894 */
kyourek 0:9e2fc73e5a12 895 uc_EXPORTED ucSwitchOpt *ucSwitchOpt_get_next(ucSwitchOpt*);
kyourek 0:9e2fc73e5a12 896
kyourek 0:9e2fc73e5a12 897 /*
kyourek 0:9e2fc73e5a12 898 * Summary:
kyourek 0:9e2fc73e5a12 899 * Releases memory used by the switch option.
kyourek 0:9e2fc73e5a12 900 */
kyourek 0:9e2fc73e5a12 901 uc_EXPORTED void ucSwitchOpt_destroy(ucSwitchOpt*);
kyourek 0:9e2fc73e5a12 902
kyourek 0:9e2fc73e5a12 903 /*
kyourek 0:9e2fc73e5a12 904 * Summary:
kyourek 0:9e2fc73e5a12 905 * Releases memory used by the switch option and all
kyourek 0:9e2fc73e5a12 906 * proceeding options in the list. All memory used by
kyourek 0:9e2fc73e5a12 907 * any argument options belonging to the switches in
kyourek 0:9e2fc73e5a12 908 * the list is also released.
kyourek 0:9e2fc73e5a12 909 */
kyourek 0:9e2fc73e5a12 910 uc_EXPORTED void ucSwitchOpt_destroy_chain(ucSwitchOpt*);
kyourek 0:9e2fc73e5a12 911
kyourek 0:9e2fc73e5a12 912 /*
kyourek 0:9e2fc73e5a12 913 * Summary:
kyourek 0:9e2fc73e5a12 914 * Type that can be used to parse command lines.
kyourek 0:9e2fc73e5a12 915 * The result of the parse can be used as the command
kyourek 0:9e2fc73e5a12 916 * token for a command structure.
kyourek 0:9e2fc73e5a12 917 */
kyourek 0:9e2fc73e5a12 918 typedef struct ucCmdParser ucCmdParser;
kyourek 0:9e2fc73e5a12 919
kyourek 0:9e2fc73e5a12 920 /*
kyourek 0:9e2fc73e5a12 921 * Summary:
kyourek 0:9e2fc73e5a12 922 * Gets a static, default instance of the parser.
kyourek 0:9e2fc73e5a12 923 * Returns:
kyourek 0:9e2fc73e5a12 924 * The static, default instance of the parser, or NULL
kyourek 0:9e2fc73e5a12 925 * if an error occurred.
kyourek 0:9e2fc73e5a12 926 */
kyourek 0:9e2fc73e5a12 927 uc_EXPORTED ucCmdParser *ucCmdParser_get_instance(void);
kyourek 0:9e2fc73e5a12 928
kyourek 0:9e2fc73e5a12 929 /*
kyourek 0:9e2fc73e5a12 930 * Summary:
kyourek 0:9e2fc73e5a12 931 * Parses a command so that it can be used as a command token.
kyourek 0:9e2fc73e5a12 932 * Parameters:
kyourek 0:9e2fc73e5a12 933 * cmd: The command string to be parsed. This string is mutated.
kyourek 0:9e2fc73e5a12 934 * Returns:
kyourek 0:9e2fc73e5a12 935 * A pointer to the command token that was parsed, or NULL if an
kyourek 0:9e2fc73e5a12 936 * error occurred.
kyourek 0:9e2fc73e5a12 937 */
kyourek 0:9e2fc73e5a12 938 uc_EXPORTED ucCmdTok *ucCmdParser_parse(ucCmdParser*, char *cmd);
kyourek 0:9e2fc73e5a12 939
kyourek 0:9e2fc73e5a12 940 /*
kyourek 0:9e2fc73e5a12 941 * Summary:
kyourek 0:9e2fc73e5a12 942 * A command option. This type is a child of the
kyourek 0:9e2fc73e5a12 943 * base option type.
kyourek 0:9e2fc73e5a12 944 */
kyourek 0:9e2fc73e5a12 945 typedef struct ucCmdLineOpt ucCmdLineOpt;
kyourek 0:9e2fc73e5a12 946
kyourek 0:9e2fc73e5a12 947 /*
kyourek 0:9e2fc73e5a12 948 * Summary:
kyourek 0:9e2fc73e5a12 949 * Defines the signature of the function called when a command option is processed.
kyourek 0:9e2fc73e5a12 950 * Parameters:
kyourek 0:9e2fc73e5a12 951 * cmd: The parsed command structure that represents the function parameters.
kyourek 0:9e2fc73e5a12 952 * state: The state pointer with which the command option was created.
kyourek 0:9e2fc73e5a12 953 * Returns:
kyourek 0:9e2fc73e5a12 954 * A message that can be used to respond to the command.
kyourek 0:9e2fc73e5a12 955 */
kyourek 0:9e2fc73e5a12 956 typedef const char *(ucCmdLineOpt_Func)(ucCmdLine *cmd, void *state);
kyourek 0:9e2fc73e5a12 957
kyourek 0:9e2fc73e5a12 958 /*
kyourek 0:9e2fc73e5a12 959 * Summary:
kyourek 0:9e2fc73e5a12 960 * Creates a new command option.
kyourek 0:9e2fc73e5a12 961 * Parameters:
kyourek 0:9e2fc73e5a12 962 * func: A pointer to the function that is called when this command is invoked or selected.
kyourek 0:9e2fc73e5a12 963 * state: A pointer that gets passed to the function to maintain state.
kyourek 0:9e2fc73e5a12 964 * name: The name of the command.
kyourek 0:9e2fc73e5a12 965 * desc: The description of the command.
kyourek 0:9e2fc73e5a12 966 * arg_opt: The argument options available to the command.
kyourek 0:9e2fc73e5a12 967 * switch_opt: The switch options available to the command.
kyourek 0:9e2fc73e5a12 968 * next: The next command that the created command precedes, or NULL if no further commands exist.
kyourek 0:9e2fc73e5a12 969 * Returns:
kyourek 0:9e2fc73e5a12 970 * A pointer to the newly created command option.
kyourek 0:9e2fc73e5a12 971 */
kyourek 0:9e2fc73e5a12 972 uc_EXPORTED ucCmdLineOpt *ucCmdLineOpt_create(ucCmdLineOpt_Func *func, void *state, const char *name, const char *desc, ucArgOpt *arg_opt, ucSwitchOpt *switch_opt, ucCmdLineOpt* next);
kyourek 0:9e2fc73e5a12 973
kyourek 0:9e2fc73e5a12 974 /*
kyourek 0:9e2fc73e5a12 975 * Summary:
kyourek 0:9e2fc73e5a12 976 * Gets the next command option after the given option.
kyourek 0:9e2fc73e5a12 977 * Returns:
kyourek 0:9e2fc73e5a12 978 * A pointer to the next command option.
kyourek 0:9e2fc73e5a12 979 */
kyourek 0:9e2fc73e5a12 980 uc_EXPORTED ucCmdLineOpt *ucCmdLineOpt_get_next(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 981
kyourek 0:9e2fc73e5a12 982 /*
kyourek 0:9e2fc73e5a12 983 * Summary:
kyourek 0:9e2fc73e5a12 984 * Gets the first argument option of the command.
kyourek 0:9e2fc73e5a12 985 * Returns:
kyourek 0:9e2fc73e5a12 986 * A pointer to the first argument option of the command,
kyourek 0:9e2fc73e5a12 987 * or NULL if no argument options exist.
kyourek 0:9e2fc73e5a12 988 */
kyourek 0:9e2fc73e5a12 989 uc_EXPORTED ucArgOpt *ucCmdLineOpt_get_arg_opt(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 990
kyourek 0:9e2fc73e5a12 991 /*
kyourek 0:9e2fc73e5a12 992 * Summary:
kyourek 0:9e2fc73e5a12 993 * Gets the first switch option of the command option.
kyourek 0:9e2fc73e5a12 994 * Returns:
kyourek 0:9e2fc73e5a12 995 * A pointer to the first switch option of the command option,
kyourek 0:9e2fc73e5a12 996 * or NULL if no switch options exist.
kyourek 0:9e2fc73e5a12 997 */
kyourek 0:9e2fc73e5a12 998 uc_EXPORTED ucSwitchOpt *ucCmdLineOpt_get_switch_opt(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 999
kyourek 0:9e2fc73e5a12 1000 /*
kyourek 0:9e2fc73e5a12 1001 * Summary:
kyourek 0:9e2fc73e5a12 1002 * Finds the command option that matches the given name.
kyourek 0:9e2fc73e5a12 1003 * Parameters:
kyourek 0:9e2fc73e5a12 1004 * name: The name of the command whose option is to be found.
kyourek 0:9e2fc73e5a12 1005 * Returns:
kyourek 0:9e2fc73e5a12 1006 * A pointer to the command option that matches the given name, or NULL
kyourek 0:9e2fc73e5a12 1007 * if no option is found.
kyourek 0:9e2fc73e5a12 1008 */
kyourek 0:9e2fc73e5a12 1009 uc_EXPORTED ucCmdLineOpt *ucCmdLineOpt_find_by_name(ucCmdLineOpt*, const char *name);
kyourek 0:9e2fc73e5a12 1010
kyourek 0:9e2fc73e5a12 1011 /*
kyourek 0:9e2fc73e5a12 1012 * Summary:
kyourek 0:9e2fc73e5a12 1013 * Gets the pointer to the function invoked when the command option
kyourek 0:9e2fc73e5a12 1014 * is processed.
kyourek 0:9e2fc73e5a12 1015 * Returns:
kyourek 0:9e2fc73e5a12 1016 * A pointer to the function invoked when the command option is processed.
kyourek 0:9e2fc73e5a12 1017 */
kyourek 0:9e2fc73e5a12 1018 uc_EXPORTED ucCmdLineOpt_Func *ucCmdLineOpt_get_func(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 1019
kyourek 0:9e2fc73e5a12 1020 /*
kyourek 0:9e2fc73e5a12 1021 * Summary:
kyourek 0:9e2fc73e5a12 1022 * Gets the state pointer that is passed to the command option's function
kyourek 0:9e2fc73e5a12 1023 * when it is invoked.
kyourek 0:9e2fc73e5a12 1024 * Returns:
kyourek 0:9e2fc73e5a12 1025 * A pointer to the command option's state.
kyourek 0:9e2fc73e5a12 1026 */
kyourek 0:9e2fc73e5a12 1027 uc_EXPORTED void *ucCmdLineOpt_get_state(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 1028
kyourek 0:9e2fc73e5a12 1029 /*
kyourek 0:9e2fc73e5a12 1030 * Summary:
kyourek 0:9e2fc73e5a12 1031 * Releases memory used by the command option.
kyourek 0:9e2fc73e5a12 1032 */
kyourek 0:9e2fc73e5a12 1033 uc_EXPORTED void ucCmdLineOpt_destroy(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 1034
kyourek 0:9e2fc73e5a12 1035 /*
kyourek 0:9e2fc73e5a12 1036 * Summary:
kyourek 0:9e2fc73e5a12 1037 * Releases memory used by the command option and all proceeding options
kyourek 0:9e2fc73e5a12 1038 * in the list. All memory used by any argument options, switch options,
kyourek 0:9e2fc73e5a12 1039 * and switch-argument options is also released.
kyourek 0:9e2fc73e5a12 1040 */
kyourek 0:9e2fc73e5a12 1041 uc_EXPORTED void ucCmdLineOpt_destroy_chain(ucCmdLineOpt*);
kyourek 0:9e2fc73e5a12 1042
kyourek 0:9e2fc73e5a12 1043 /*
kyourek 0:9e2fc73e5a12 1044 * Summary:
kyourek 0:9e2fc73e5a12 1045 * Invokes the function of the command option that matches the command structure.
kyourek 0:9e2fc73e5a12 1046 * Parameters:
kyourek 0:9e2fc73e5a12 1047 * cmd: The command structure whose option is invoked.
kyourek 0:9e2fc73e5a12 1048 * Returns:
kyourek 0:9e2fc73e5a12 1049 * The response to the command.
kyourek 0:9e2fc73e5a12 1050 */
kyourek 0:9e2fc73e5a12 1051 uc_EXPORTED const char *ucCmdLineOpt_process(ucCmdLineOpt*, ucCmdLine *cmd);
kyourek 0:9e2fc73e5a12 1052
kyourek 0:9e2fc73e5a12 1053 /*
kyourek 0:9e2fc73e5a12 1054 * Summary:
kyourek 0:9e2fc73e5a12 1055 * Uses the provided command structure to respond with a usage string
kyourek 0:9e2fc73e5a12 1056 * for this command option.
kyourek 0:9e2fc73e5a12 1057 * Parameters:
kyourek 0:9e2fc73e5a12 1058 * cmd: The command structure used to respond with the usage string.
kyourek 0:9e2fc73e5a12 1059 */
kyourek 0:9e2fc73e5a12 1060 uc_EXPORTED void ucCmdLineOpt_send_usage(ucCmdLineOpt*, ucCmdLine *cmd);
kyourek 0:9e2fc73e5a12 1061
kyourek 0:9e2fc73e5a12 1062 /*
kyourek 0:9e2fc73e5a12 1063 * Summary:
kyourek 0:9e2fc73e5a12 1064 * Uses the provided command structure to respond with help information
kyourek 0:9e2fc73e5a12 1065 * for the this command option.
kyourek 0:9e2fc73e5a12 1066 * Parameters:
kyourek 0:9e2fc73e5a12 1067 * cmd: The command structure used to respond with the help information.
kyourek 0:9e2fc73e5a12 1068 */
kyourek 0:9e2fc73e5a12 1069 uc_EXPORTED void ucCmdLineOpt_send_help(ucCmdLineOpt*, ucCmdLine *cmd);
kyourek 0:9e2fc73e5a12 1070
kyourek 0:9e2fc73e5a12 1071 /*
kyourek 0:9e2fc73e5a12 1072 * Summary:
kyourek 0:9e2fc73e5a12 1073 * An application that runs with a set of command options.
kyourek 0:9e2fc73e5a12 1074 */
kyourek 0:9e2fc73e5a12 1075 typedef struct ucCmdLineApp ucCmdLineApp;
kyourek 0:9e2fc73e5a12 1076
kyourek 0:9e2fc73e5a12 1077 /*
kyourek 0:9e2fc73e5a12 1078 * Summary:
kyourek 0:9e2fc73e5a12 1079 * The type of the function used by an application to
kyourek 0:9e2fc73e5a12 1080 * receive data.
kyourek 0:9e2fc73e5a12 1081 * Parameters:
kyourek 0:9e2fc73e5a12 1082 * buf: A string buffer that can be used to store the data received.
kyourek 0:9e2fc73e5a12 1083 * buf_size: The size of the string buffer used to store received data.
kyourek 0:9e2fc73e5a12 1084 * state: A stateful object.
kyourek 0:9e2fc73e5a12 1085 * Returns:
kyourek 0:9e2fc73e5a12 1086 * The data that was received.
kyourek 0:9e2fc73e5a12 1087 */
kyourek 0:9e2fc73e5a12 1088 typedef char *(ucCmdLineApp_ReceiveFunc)(char *buf, size_t buf_size, void *state);
kyourek 0:9e2fc73e5a12 1089
kyourek 0:9e2fc73e5a12 1090 /*
kyourek 0:9e2fc73e5a12 1091 * Summary:
kyourek 0:9e2fc73e5a12 1092 * Sets the escape string that will cause the app to exit.
kyourek 0:9e2fc73e5a12 1093 * Parameters:
kyourek 0:9e2fc73e5a12 1094 * value: The escape string that, when returned in a response,
kyourek 0:9e2fc73e5a12 1095 * causes the app to exit.
kyourek 0:9e2fc73e5a12 1096 */
kyourek 0:9e2fc73e5a12 1097 uc_EXPORTED void ucCmdLineApp_set_escape_response(ucCmdLineApp*, const char *value);
kyourek 0:9e2fc73e5a12 1098
kyourek 0:9e2fc73e5a12 1099 /*
kyourek 0:9e2fc73e5a12 1100 * Summary:
kyourek 0:9e2fc73e5a12 1101 * Gets the escape string that causes the app to exit.
kyourek 0:9e2fc73e5a12 1102 * Returns:
kyourek 0:9e2fc73e5a12 1103 * The escape string that, when returned in a response,
kyourek 0:9e2fc73e5a12 1104 * causes the app to exit.
kyourek 0:9e2fc73e5a12 1105 */
kyourek 0:9e2fc73e5a12 1106 uc_EXPORTED const char *ucCmdLineApp_get_escape_response(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1107
kyourek 0:9e2fc73e5a12 1108 /*
kyourek 0:9e2fc73e5a12 1109 * Summary:
kyourek 0:9e2fc73e5a12 1110 * Runs the application with the given options.
kyourek 0:9e2fc73e5a12 1111 * Parameters:
kyourek 0:9e2fc73e5a12 1112 * cmd_opt: A pointer to the first command option for the app.
kyourek 0:9e2fc73e5a12 1113 * Returns:
kyourek 0:9e2fc73e5a12 1114 * An error code, if one occurred.
kyourek 0:9e2fc73e5a12 1115 */
kyourek 0:9e2fc73e5a12 1116 uc_EXPORTED ucErr ucCmdLineApp_run(ucCmdLineApp*, ucCmdLineOpt *cmd_opt);
kyourek 0:9e2fc73e5a12 1117
kyourek 0:9e2fc73e5a12 1118 /*
kyourek 0:9e2fc73e5a12 1119 * Summary:
kyourek 0:9e2fc73e5a12 1120 * Gets a static, default instance of the application.
kyourek 0:9e2fc73e5a12 1121 * Returns:
kyourek 0:9e2fc73e5a12 1122 * The static, default instance of the application.
kyourek 0:9e2fc73e5a12 1123 */
kyourek 0:9e2fc73e5a12 1124 uc_EXPORTED ucCmdLineApp *ucCmdLineApp_get_instance(void);
kyourek 0:9e2fc73e5a12 1125
kyourek 0:9e2fc73e5a12 1126 /*
kyourek 0:9e2fc73e5a12 1127 * Summary:
kyourek 0:9e2fc73e5a12 1128 * Sets the function that the app uses to receive data.
kyourek 0:9e2fc73e5a12 1129 * Parameters:
kyourek 0:9e2fc73e5a12 1130 * value: A pointer to the function used to receive data.
kyourek 0:9e2fc73e5a12 1131 */
kyourek 0:9e2fc73e5a12 1132 uc_EXPORTED void ucCmdLineApp_set_receive(ucCmdLineApp*, ucCmdLineApp_ReceiveFunc *value);
kyourek 0:9e2fc73e5a12 1133
kyourek 0:9e2fc73e5a12 1134 /*
kyourek 0:9e2fc73e5a12 1135 * Summary:
kyourek 0:9e2fc73e5a12 1136 * Gets the function that the app uses to receive data.
kyourek 0:9e2fc73e5a12 1137 * Returns:
kyourek 0:9e2fc73e5a12 1138 * A pointer to the function used to receive data.
kyourek 0:9e2fc73e5a12 1139 */
kyourek 0:9e2fc73e5a12 1140 uc_EXPORTED ucCmdLineApp_ReceiveFunc *ucCmdLineApp_get_receive(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1141
kyourek 0:9e2fc73e5a12 1142 /*
kyourek 0:9e2fc73e5a12 1143 * Summary:
kyourek 0:9e2fc73e5a12 1144 * Gets the stateful object passed to the application's receive function.
kyourek 0:9e2fc73e5a12 1145 * Returns:
kyourek 0:9e2fc73e5a12 1146 * A pointer to the stateful object passed to the application's receive function.
kyourek 0:9e2fc73e5a12 1147 */
kyourek 0:9e2fc73e5a12 1148 uc_EXPORTED void *ucCmdLineApp_get_receive_state(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1149
kyourek 0:9e2fc73e5a12 1150 /*
kyourek 0:9e2fc73e5a12 1151 * Summary:
kyourek 0:9e2fc73e5a12 1152 * Sets the stateful object passed to the application's receive function.
kyourek 0:9e2fc73e5a12 1153 * Parameters:
kyourek 0:9e2fc73e5a12 1154 * value: The stateful object passed to the application's receive function.
kyourek 0:9e2fc73e5a12 1155 */
kyourek 0:9e2fc73e5a12 1156 uc_EXPORTED void ucCmdLineApp_set_receive_state(ucCmdLineApp*, void *value);
kyourek 0:9e2fc73e5a12 1157
kyourek 0:9e2fc73e5a12 1158 /*
kyourek 0:9e2fc73e5a12 1159 * Summary:
kyourek 0:9e2fc73e5a12 1160 * Sets the command used to quit the application.
kyourek 0:9e2fc73e5a12 1161 * Parameters:
kyourek 0:9e2fc73e5a12 1162 * value: The value of the command that quits the application.
kyourek 0:9e2fc73e5a12 1163 */
kyourek 0:9e2fc73e5a12 1164 uc_EXPORTED void ucCmdLineApp_set_quit_command(ucCmdLineApp*, const char *value);
kyourek 0:9e2fc73e5a12 1165
kyourek 0:9e2fc73e5a12 1166 /*
kyourek 0:9e2fc73e5a12 1167 * Summary:
kyourek 0:9e2fc73e5a12 1168 * Gets the value of the command that quits the application.
kyourek 0:9e2fc73e5a12 1169 * Returns:
kyourek 0:9e2fc73e5a12 1170 * The value of the command that quits the application.
kyourek 0:9e2fc73e5a12 1171 */
kyourek 0:9e2fc73e5a12 1172 uc_EXPORTED const char *ucCmdLineApp_get_quit_command(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1173
kyourek 0:9e2fc73e5a12 1174 /*
kyourek 0:9e2fc73e5a12 1175 * Summary:
kyourek 0:9e2fc73e5a12 1176 * Sets the value of the command that shows help information.
kyourek 0:9e2fc73e5a12 1177 * Parameters:
kyourek 0:9e2fc73e5a12 1178 * value: The value of the command that shows help information.
kyourek 0:9e2fc73e5a12 1179 */
kyourek 0:9e2fc73e5a12 1180 uc_EXPORTED void ucCmdLineApp_set_help_command(ucCmdLineApp*, const char *value);
kyourek 0:9e2fc73e5a12 1181
kyourek 0:9e2fc73e5a12 1182 /*
kyourek 0:9e2fc73e5a12 1183 * Summary:
kyourek 0:9e2fc73e5a12 1184 * Gets the value of the command that shows help information.
kyourek 0:9e2fc73e5a12 1185 * Returns:
kyourek 0:9e2fc73e5a12 1186 * The value of the command that shows help information.
kyourek 0:9e2fc73e5a12 1187 */
kyourek 0:9e2fc73e5a12 1188 uc_EXPORTED const char *ucCmdLineApp_get_help_command(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1189
kyourek 0:9e2fc73e5a12 1190 /*
kyourek 0:9e2fc73e5a12 1191 * Summary:
kyourek 0:9e2fc73e5a12 1192 * Sets the command structure that the application uses.
kyourek 0:9e2fc73e5a12 1193 * Parameters:
kyourek 0:9e2fc73e5a12 1194 * value: The command structure to be used by the application.
kyourek 0:9e2fc73e5a12 1195 */
kyourek 0:9e2fc73e5a12 1196 uc_EXPORTED void ucCmdLineApp_set_cmd(ucCmdLineApp*, ucCmdLine *value);
kyourek 0:9e2fc73e5a12 1197
kyourek 0:9e2fc73e5a12 1198 /*
kyourek 0:9e2fc73e5a12 1199 * Summary:
kyourek 0:9e2fc73e5a12 1200 * Gets the command structure used by the application.
kyourek 0:9e2fc73e5a12 1201 * Returns:
kyourek 0:9e2fc73e5a12 1202 * A pointer to the command structure used by the application.
kyourek 0:9e2fc73e5a12 1203 */
kyourek 0:9e2fc73e5a12 1204 uc_EXPORTED ucCmdLine *ucCmdLineApp_get_cmd(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1205
kyourek 0:9e2fc73e5a12 1206 /*
kyourek 0:9e2fc73e5a12 1207 * Summary:
kyourek 0:9e2fc73e5a12 1208 * Gets the command parser used by the application.
kyourek 0:9e2fc73e5a12 1209 * Returns:
kyourek 0:9e2fc73e5a12 1210 * A pointer to the command parser used by the application.
kyourek 0:9e2fc73e5a12 1211 */
kyourek 0:9e2fc73e5a12 1212 uc_EXPORTED ucCmdParser *ucCmdLineApp_get_cmd_parser(ucCmdLineApp*);
kyourek 0:9e2fc73e5a12 1213
kyourek 0:9e2fc73e5a12 1214 /*
kyourek 0:9e2fc73e5a12 1215 * Summary:
kyourek 0:9e2fc73e5a12 1216 * Gets the size of the application's command-string buffer.
kyourek 0:9e2fc73e5a12 1217 * Returns:
kyourek 0:9e2fc73e5a12 1218 * The size of the command-string buffer.
kyourek 0:9e2fc73e5a12 1219 */
kyourek 0:9e2fc73e5a12 1220 uc_EXPORTED size_t ucCmdLineApp_get_cmd_str_size_max(ucCmdLineApp *p);
kyourek 0:9e2fc73e5a12 1221
kyourek 0:9e2fc73e5a12 1222 #endif
kyourek 0:9e2fc73e5a12 1223