| | |
| | | #include <ctype.h> |
| | | |
| | | #include "utils_private.h" |
| | | #include "scpi/utils.h" |
| | | |
| | | static size_t patternSeparatorShortPos(const char * pattern, size_t len); |
| | | static size_t patternSeparatorPos(const char * pattern, size_t len); |
| | |
| | | * @param val integer value |
| | | * @param str converted textual representation |
| | | * @param len string buffer length |
| | | * @param base output base |
| | | * @return number of bytes written to str (without '\0') |
| | | */ |
| | | size_t longToStr(int32_t val, char * str, size_t len, int8_t base) { |
| | | size_t SCPI_LongToStr(int32_t val, char * str, size_t len, int8_t base) { |
| | | const char digits[] = "0123456789ABCDEF"; |
| | | |
| | | #define ADD_CHAR(c) if (pos < len) str[pos++] = (c) |
| | |
| | | * @param len string buffer length |
| | | * @return number of bytes written to str (without '\0') |
| | | */ |
| | | size_t doubleToStr(double val, char * str, size_t len) { |
| | | return snprintf(str, len, "%lg", val); |
| | | size_t SCPI_DoubleToStr(double val, char * str, size_t len) { |
| | | return SCPIDEFINE_doubleToStr(val, str, len); |
| | | } |
| | | |
| | | /** |
| | |
| | | return FALSE; |
| | | } |
| | | |
| | | if (SCPI_strncasecmp(str1, str2, len2) == 0) { |
| | | if (SCPIDEFINE_strncasecmp(str1, str2, len2) == 0) { |
| | | return TRUE; |
| | | } |
| | | |
| | |
| | | return FALSE; |
| | | } |
| | | |
| | | if (SCPI_strncasecmp(str1, str2, len1) == 0) { |
| | | if (SCPIDEFINE_strncasecmp(str1, str2, len1) == 0) { |
| | | result = TRUE; |
| | | } |
| | | |
| | |
| | | const char * pattern_end = pattern + pattern_len; |
| | | |
| | | const char * cmd_ptr = cmd; |
| | | size_t cmd_len = SCPI_strnlen(cmd, len); |
| | | size_t cmd_len = SCPIDEFINE_strnlen(cmd, len); |
| | | const char * cmd_end = cmd + cmd_len; |
| | | |
| | | /* now support optional keywords in pattern style, e.g. [:MEASure]:VOLTage:DC? */ |
| | |
| | | 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 */ |