From a2006d9935f97a233f75942e1a3eab69f27cf4b3 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周日, 19 4月 2015 17:59:23 +0800
Subject: [PATCH] Update c++ example, make special numbers more correct

---
 libscpi/src/utils.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index 26670b9..710d8e0 100644
--- a/libscpi/src/utils.c
+++ b/libscpi/src/utils.c
@@ -138,7 +138,7 @@
  * @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);
+    return SCPI_doubleToStr(val, str, len);
 }
 
 /**
@@ -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