BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cli.h
Go to the documentation of this file.
1 /* Copyright 2012-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
130 #ifndef BSP430_UTILITY_CLI_H
131 #define BSP430_UTILITY_CLI_H
132 
133 #include <bsp430/core.h>
134 
145 #ifndef configBSP430_CLI_COMMAND_COMPLETION
146 #define configBSP430_CLI_COMMAND_COMPLETION 0
147 #endif /* configBSP430_CLI_COMMAND_COMPLETION */
148 
170 #ifndef configBSP430_CLI_COMMAND_COMPLETION_HELPER
171 #define configBSP430_CLI_COMMAND_COMPLETION_HELPER 0
172 #endif /* configBSP430_CLI_COMMAND_COMPLETION_HELPER */
173 
196 const char * xBSP430cliNextToken (const char ** commandp,
197  size_t * remainingp,
198  size_t * lenp);
199 
226 const char * xBSP430cliNextQToken (const char ** commandp,
227  size_t * remainingp,
228  size_t * lenp);
229 
230 /* Forward declarations */
231 struct sBSP430cliCommand;
232 struct sBSP430cliCommandLink;
235 
247 typedef struct sBSP430cliCommandLink {
252 
255 
258  const struct sBSP430cliCommand * cmd;
259 
261 
285 typedef void (* vBSP430cliCompletionHelper) (const struct sBSP430cliCompletionHelper * self,
286  const char * argstr,
287  size_t argstr_len,
288  struct sBSP430cliCompletionData * cdp);
289 
308 
325 
330  const char * const * strings;
331 
333  size_t len;
335 
359  const char * argstr,
360  size_t argstr_len,
361  struct sBSP430cliCompletionData * cdp);
362 
389 const char * const * xBSP430cliHelperStringsExtract (const struct sBSP430cliCompletionHelperStrings * chsp,
390  const char ** argstrp,
391  size_t * argstr_lenp);
392 
403 typedef int (* iBSP430cliHandlerFunction) (struct sBSP430cliCommandLink * chain,
404  void * param,
405  const char * argstr,
406  size_t argstr_len);
407 
418 typedef int (* iBSP430cliSimpleHandler) (const char * argstr);
419 
423 typedef struct sBSP430cliCommand {
430  const char * key;
431 
440  const char * help;
441 
442 #if defined(BSP430_DOXYGEN) \
443  || ((configBSP430_CLI_COMMAND_COMPLETION - 0) \
444  && (configBSP430_CLI_COMMAND_COMPLETION_HELPER - 0))
445 
449 #endif /* configBSP430_CLI_COMMAND_COMPLETION_HELPER */
450 
459  const struct sBSP430cliCommand * const child;
460 
465  const struct sBSP430cliCommand * const next;
466 
470 
479  union uParam {
481  void * const ptr;
482 
487  } param;
488 
490 
495 typedef struct sBSP430cliMatchCallback {
501  void (* callback) (struct sBSP430cliMatchCallback * self,
502  const sBSP430cliCommand * cmd);
504 
550 int iBSP430cliMatchCommand (const sBSP430cliCommand * cmds,
551  const char * command,
552  size_t command_len,
553  const sBSP430cliCommand ** matchp,
554  sBSP430cliMatchCallback * match_callback,
555  const char ** argstrp,
556  size_t * argstr_lenp);
557 
580  void * param,
581  const char * command);
582 
604 int
606  void * param,
607  const char * command,
608  iBSP430cliHandlerFunction chain_handler,
609  iBSP430cliHandlerFunction handler);
610 
632 int iBSP430cliStoreExtractedI (const char ** argstrp,
633  size_t * argstr_lenp,
634  int * destp);
635 
657 int iBSP430cliStoreExtractedUI (const char ** argstrp,
658  size_t * argstr_lenp,
659  unsigned int * destp);
660 
682 int iBSP430cliStoreExtractedL (const char ** argstrp,
683  size_t * argstr_lenp,
684  long * destp);
685 
707 int iBSP430cliStoreExtractedUL (const char ** argstrp,
708  size_t * argstr_lenp,
709  unsigned long * destp);
710 
725  void * param,
726  const char * argstr,
727  size_t argstr_len);
728 
747  void * param,
748  const char * argstr,
749  size_t argstr_len);
750 
769  void * param,
770  const char * argstr,
771  size_t argstr_len);
772 
791  void * param,
792  const char * argstr,
793  size_t argstr_len);
794 
813  void * param,
814  const char * argstr,
815  size_t argstr_len);
816 
824 
829 
833 
838 
842 
846 
850 };
851 
871  enum eBSP430cliErrorType errtype,
872  const char * argstr,
873  size_t argstr_len);
874 
888 
893  enum eBSP430cliErrorType errtype,
894  const char * argstr,
895  size_t argstr_len);
896 
906 #if defined(BSP430_DOXYGEN) || (BSP430_CONSOLE - 0)
908  enum eBSP430cliErrorType errtype,
909  const char * argstr,
910  size_t argstr_len);
911 #endif /* configBSP430_CONSOLE */
912 
929 #if defined(BSP430_DOXYGEN) || (BSP430_CONSOLE - 0)
931  const char * argstr);
932 #endif /* configBSP430_CONSOLE */
933 
934 
946 #if defined(BSP430_DOXYGEN) || (BSP430_CONSOLE - 0)
948 #endif /* configBSP430_CONSOLE */
949 
965 
977 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLI_CONSOLE_BUFFER_SIZE)
978 #define BSP430_CLI_CONSOLE_BUFFER_SIZE 0
979 #endif /* BSP430_CLI_CONSOLE_BUFFER_SIZE */
980 
985 typedef enum eBSP430cliConsole {
996 
1000 
1004 
1025 
1041 
1045 
1051 
1058 
1060 
1073  const char * command;
1074 
1076  size_t command_len;
1077 
1084 
1090  const char ** returned_candidates;
1091 
1095 
1097  size_t ncandidates;
1098 
1103  const char * append;
1104 
1108  size_t append_len;
1110 
1125  const char * candidate);
1126 
1139 const char * xBSP430cliConsoleBuffer (void);
1140 
1151 #if defined(BSP430_DOXYGEN) || (0 < BSP430_CLI_CONSOLE_BUFFER_SIZE)
1152 void vBSP430cliConsoleBufferClear (void);
1153 #endif /* BSP430_CLI_CONSOLE_BUFFER_SIZE */
1154 
1173 #if defined(BSP430_DOXYGEN) || (0 < BSP430_CLI_CONSOLE_BUFFER_SIZE)
1174 int iBSP430cliConsoleBufferExtend (const char * text, size_t len);
1175 #endif /* BSP430_CLI_CONSOLE_BUFFER_SIZE */
1176 
1209 #if defined(BSP430_DOXYGEN) || (0 < BSP430_CLI_CONSOLE_BUFFER_SIZE)
1211 #endif /* BSP430_CLI_CONSOLE_BUFFER_SIZE */
1212 
1235 int iBSP430cliConsoleBufferConsumeEscape (int flags);
1236 
1264 #if defined(BSP430_DOXYGEN) || (configBSP430_CLI_COMMAND_COMPLETION - 0)
1266 #endif /* configBSP430_CLI_COMMAND_COMPLETION */
1267 
1268 #ifndef BSP430_CLI_CONSOLE_BUFFER_MAX_COMPLETIONS
1269 
1276 #define BSP430_CLI_CONSOLE_BUFFER_MAX_COMPLETIONS 5
1277 #endif /* BSP430_CLI_CONSOLE_BUFFER_MAX_COMPLETIONS */
1278 
1306 #if defined(BSP430_DOXYGEN) || (configBSP430_CLI_COMMAND_COMPLETION - 0)
1307 int iBSP430cliConsoleBufferCompletion (const sBSP430cliCommand * command_set,
1308  const char ** commandp);
1309 #endif /* configBSP430_CLI_COMMAND_COMPLETION */
1310 
1311 #endif /* BSP430_UTILITY_CLI_H */
void vBSP430cliCompletionHelperCallback(sBSP430cliCompletionData *cdp, const char *candidate)
const char * command
Definition: cli.h:1073
Definition: cli.h:1003
int iBSP430cliHandlerStoreL(struct sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
Definition: cli.h:1024
Definition: cli.h:828
int iBSP430cliParseCommand(const sBSP430cliCommand *cmds, void *param, const char *command, iBSP430cliHandlerFunction chain_handler, iBSP430cliHandlerFunction handler)
size_t ncandidates
Definition: cli.h:1097
Definition: cli.h:1040
struct sBSP430cliMatchCallback sBSP430cliMatchCallback
vBSP430cliCompletionHelper helper
Definition: cli.h:306
Definition: cli.h:845
int iBSP430cliStoreExtractedI(const char **argstrp, size_t *argstr_lenp, int *destp)
eBSP430cliConsole
Definition: cli.h:985
int iBSP430cliStoreExtractedL(const char **argstrp, size_t *argstr_lenp, long *destp)
sBSP430cliCompletionHelper completion_helper
Definition: cli.h:324
size_t command_len
Definition: cli.h:1076
eBSP430cliErrorType
Definition: cli.h:821
Definition: cli.h:849
Common header included by all BSP430 leaf headers.
int iBSP430cliConsoleBufferExtend(const char *text, size_t len)
iBSP430cliSimpleHandler const simple_handler
Definition: cli.h:486
struct sBSP430cliCompletionHelper sBSP430cliCompletionHelper
size_t append_len
Definition: cli.h:1108
int iBSP430cliNullDiagnostic(sBSP430cliCommandLink *chain, enum eBSP430cliErrorType errtype, const char *argstr, size_t argstr_len)
Definition: cli.h:304
int iBSP430cliHandlerSimple(sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
iBSP430cliHandlerFunction const handler
Definition: cli.h:469
void vBSP430cliConsoleDisplayHelp(const sBSP430cliCommand *cmd)
void(* callback)(struct sBSP430cliMatchCallback *self, const sBSP430cliCommand *cmd)
Definition: cli.h:501
int iBSP430cliHandlerStoreI(struct sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
const char ** returned_candidates
Definition: cli.h:1090
int iBSP430cliConsoleDiagnostic(sBSP430cliCommandLink *chain, enum eBSP430cliErrorType errtype, const char *argstr, size_t argstr_len)
Definition: cli.h:837
int iBSP430cliConsoleBufferProcessInput(void)
int iBSP430cliStoreExtractedUI(const char **argstrp, size_t *argstr_lenp, unsigned int *destp)
int(* iBSP430cliHandlerFunction)(struct sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
Definition: cli.h:403
const char * append
Definition: cli.h:1103
const struct sBSP430cliCommand *const next
Definition: cli.h:465
struct sBSP430cliCompletionHelperStrings sBSP430cliCompletionHelperStrings
const sBSP430cliCompletionHelper * completion_helper
Definition: cli.h:448
Definition: cli.h:823
int iBSP430cliStoreExtractedUL(const char **argstrp, size_t *argstr_lenp, unsigned long *destp)
Definition: cli.h:995
struct sBSP430cliCommandLink sBSP430cliCommandLink
void vBSP430cliSetDiagnosticFunction(iBSP430cliDiagnosticFunction diagnostic_function)
void vBSP430cliConsoleBufferClear(void)
const char *const * strings
Definition: cli.h:330
Definition: cli.h:841
int iBSP430cliExecuteCommand(const sBSP430cliCommand *cmds, void *param, const char *command)
int iBSP430cliHandlerStoreUI(struct sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
Definition: cli.h:479
union sBSP430cliCommand::uParam param
const struct sBSP430cliCommand *const child
Definition: cli.h:459
Definition: cli.h:1057
Definition: cli.h:1044
struct sBSP430cliCompletionData sBSP430cliCompletionData
Definition: cli.h:423
void *const ptr
Definition: cli.h:481
Definition: cli.h:832
int iBSP430cliHandlerStoreUL(struct sBSP430cliCommandLink *chain, void *param, const char *argstr, size_t argstr_len)
int(* iBSP430cliDiagnosticFunction)(sBSP430cliCommandLink *chain, enum eBSP430cliErrorType errtype, const char *argstr, size_t argstr_len)
Definition: cli.h:870
const char * help
Definition: cli.h:440
const char * xBSP430cliNextToken(const char **commandp, size_t *remainingp, size_t *lenp)
int(* iBSP430cliSimpleHandler)(const char *argstr)
Definition: cli.h:418
int iBSP430cliConsoleBufferCompletion(const sBSP430cliCommand *command_set, const char **commandp)
int iBSP430cliCommandCompletion(sBSP430cliCompletionData *cdp)
struct sBSP430cliCommand sBSP430cliCommand
sBSP430cliCommandLink * xBSP430cliReverseChain(sBSP430cliCommandLink *chain)
void(* vBSP430cliCompletionHelper)(const struct sBSP430cliCompletionHelper *self, const char *argstr, size_t argstr_len, struct sBSP430cliCompletionData *cdp)
Definition: cli.h:285
int iBSP430cliConsoleBufferConsumeEscape(int flags)
const sBSP430cliCommand * command_set
Definition: cli.h:1083
const char * key
Definition: cli.h:430
void vBSP430cliConsoleDisplayChain(struct sBSP430cliCommandLink *chain, const char *argstr)
int iBSP430cliMatchCommand(const sBSP430cliCommand *cmds, const char *command, size_t command_len, const sBSP430cliCommand **matchp, sBSP430cliMatchCallback *match_callback, const char **argstrp, size_t *argstr_lenp)
Definition: cli.h:495
void vBSP430cliCompletionHelperStrings(const struct sBSP430cliCompletionHelper *self, const char *argstr, size_t argstr_len, struct sBSP430cliCompletionData *cdp)
Definition: cli.h:1050
size_t len
Definition: cli.h:333
const char * xBSP430cliConsoleBuffer(void)
const char *const * xBSP430cliHelperStringsExtract(const struct sBSP430cliCompletionHelperStrings *chsp, const char **argstrp, size_t *argstr_lenp)
const char * xBSP430cliNextQToken(const char **commandp, size_t *remainingp, size_t *lenp)
Definition: cli.h:999
Definition: cli.h:1067
size_t max_returned_candidates
Definition: cli.h:1094