BeRTOS
Functions
parser.c File Reference

Channel protocol parser and commands. More...

#include "parser.h"
#include "cfg/cfg_parser.h"
#include <io/kfile.h>
#include <struct/hashtable.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

static const void * get_key_from_command (const void *cmd, uint8_t *length)
 Hashtable hook to extract the key from a command.
 DECLARE_HASHTABLE_STATIC (commands, CONFIG_MAX_COMMANDS_NUMBER, get_key_from_command)
 Hashtable that handles the commands that can be executed.
static bool get_word (const char **begin, const char **end)
 Tokenize one word at a time from a text.
static bool parseArgs (const char *fmt, const char *input, parms argv[])
 Command arguments parser.
const char * parser_rl_match (UNUSED_ARG(void *, dummy), const char *word, int word_len)
 Hook provided by the parser for matching of command names (TAB completion) for readline.
struct CmdTemplateparser_get_cmd_template (const char *input)
 Find the template for the command contained in the text line.
bool parser_get_cmd_arguments (const char *input, const struct CmdTemplate *cmdp, parms args[CONFIG_PARSER_MAX_ARGS])
 Extract the arguments for the command contained in the text line.
bool parser_process_line (const char *input)
 Command input handler.
void parser_register_cmd (const struct CmdTemplate *cmd)
 Register a new command into the parser.
void parser_init (void)
 Initialize the parser module.

Detailed Description

Channel protocol parser and commands.

This file contains the channel protocol parser and the definition of the protocol commands. Commands are defined in a "CmdTemplate" type array, containing:

The arguments and results are passed to command function using an union: the element of the union to use for each argument is determined by format strings present in the CmdTemplate table.

Author:
Bernie Innocenti <bernie@codewiz.org>
Stefano Fedrigo <aleph@develer.com>
Giovanni Bajo <rasky@develer.com>

Definition in file parser.c.


Function Documentation

static bool get_word ( const char **  begin,
const char **  end 
) [static]

Tokenize one word at a time from a text.

This function is similar to strtok, but does not use any implicit context, nor it does modify the input buffer in any form. The word is returned as a STL-like [begin,end) range.

To extract the first word, make both begin and end point at the start of the text, and call the function. Then, subsequent calls will return the following words (assuming the begin/end variable are not modified between calls).

Parameters:
beginWill contain the index of the first character of the word
endWill contain the index of the character after the last character of the word
Returns:
True if a word was extracted, false if we got to the end of the string without extracting any word.

Definition at line 92 of file parser.c.

static bool parseArgs ( const char *  fmt,
const char *  input,
parms  argv[] 
) [static]

Command arguments parser.

Using the format pointed by the argument fmt parses the input string filling the array argv with input parameters of the correct type.

Parameters:
fmtParameters format string.
inputInput string.
argvArray filled with parameters.
Returns:
False in case of errors, otherwise true.

Definition at line 123 of file parser.c.