From f1cd7de018b623d19a8f42ac47f0271a28eedcce Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周日, 19 4月 2015 06:43:16 +0800 Subject: [PATCH] Implement Traversal of the Header Tree. Solve #22 --- libscpi/src/utils.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index c40ddb6..710d8e0 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -441,6 +441,51 @@ return result; } +/** + * Compose command from previsou command anc current command + * + * @param prev pointer to previous command + * @param current pointer of current command + * + * prev and current should be in the same memory buffer + */ +scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) { + size_t i; + + /* Invalid input */ + if (current == NULL || current->ptr == NULL || current->len == 0) + return FALSE; + + /* no previous command - nothing to do*/ + if (prev->ptr == NULL || prev->len == 0) + return TRUE; + + /* Common command or command root - nothing to do */ + if (current->ptr[0] == '*' || current->ptr[0] == ':') + return TRUE; + + /* Previsou command was common command - nothing to do */ + if (prev->ptr[0] == '*') + return TRUE; + + /* Find last occurence of ':' */ + for (i = prev->len; i > 0; i--) { + if (prev->ptr[i - 1] == ':') { + break; + } + } + + /* Previous command was simple command - nothing to do*/ + if (i == 0) + return TRUE; + + current->ptr -= i; + current->len += i; + memmove(current->ptr, prev->ptr, i); + return TRUE; +} + + #if !HAVE_STRNLEN /* use FreeBSD strnlen */ -- Gitblit v1.9.1