From 322f3de410d200e8dd47eb0595b8cb8575c4e62b Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 24 6月 2015 22:17:10 +0800 Subject: [PATCH] Merge branch 'master' into experimental --- libscpi/src/parser.c | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index ad7ebc4..375f4ac 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -99,12 +99,28 @@ } /** + * Conditionaly write ";" + * @param context + * @return number of characters written + */ +static size_t writeSemicolon(scpi_t * context) { + if (context->output_count > 0) { + return writeData(context, ";", 1); + } else { + return 0; + } +} + +/** * Process command * @param context */ static void processCommand(scpi_t * context) { const scpi_command_t * cmd = context->param_list.cmd; lex_state_t * state = &context->param_list.lex_state; + + /* conditionaly write ; */ + writeSemicolon(context); context->cmd_error = FALSE; context->output_count = 0; @@ -117,9 +133,6 @@ SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); } } - - /* conditionaly write new line */ - writeNewLine(context); /* set error if command callback did not read all parameters */ if (state->pos < (state->buffer + state->len) && !context->cmd_error) { @@ -138,7 +151,7 @@ for (i = 0; context->cmdlist[i].pattern != NULL; i++) { cmd = &context->cmdlist[i]; - if (matchCommand(cmd->pattern, header, len)) { + if (matchCommand(cmd->pattern, header, len, NULL, 0)) { context->param_list.cmd = cmd; return TRUE; } @@ -164,6 +177,7 @@ } state = &context->parser_state; + context->output_count = 0; while (1) { result = 0; @@ -202,6 +216,10 @@ } } + + /* conditionaly write new line */ + writeNewLine(context); + return result; } @@ -743,7 +761,7 @@ if (parameter->type == SCPI_TOKEN_PROGRAM_MNEMONIC) { for (res = 0; options[res].name; ++res) { - if (matchPattern(options[res].name, strlen(options[res].name), parameter->ptr, parameter->len)) { + if (matchPattern(options[res].name, strlen(options[res].name), parameter->ptr, parameter->len, NULL)) { *value = options[res].tag; result = TRUE; break; @@ -999,7 +1017,7 @@ } const char * pattern = context->param_list.cmd->pattern; - return matchCommand(pattern, cmd, strlen(cmd)); + return matchCommand (pattern, cmd, strlen (cmd), NULL, 0); } /** @@ -1016,11 +1034,9 @@ } scpi_bool_t SCPI_Match(const char * pattern, const char * value, size_t len) { - return matchCommand (pattern, value, len); + return matchCommand (pattern, value, len, NULL, 0); } - - - - - +scpi_bool_t SCPI_CommandNumbers(scpi_t * context, int32_t * numbers, size_t len) { + return matchCommand (context->param_list.cmd->pattern, context->param_list.cmd_raw.data, context->param_list.cmd_raw.length, numbers, len); +} -- Gitblit v1.9.1