From f4d3fcc03f61df6becf302f555b27da7e361eae5 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周一, 21 10月 2013 17:00:47 +0800
Subject: [PATCH] Merge branch 'master' of git://github.com/andrey-nakin/scpi-parser into andrey-nakin-master

---
 libscpi/src/parser.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 059c8f9..b036fb0 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -617,3 +617,35 @@
     return TRUE;
 }
 
+/**
+ * Parse choice parameter
+ * @param context
+ * @param options
+ * @param value
+ * @param mandatory
+ * @return 
+ */
+bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], size_t * value, bool_t mandatory) {
+    const char * param;
+    size_t param_len;
+    size_t res;
+
+    if (!options || !value) {
+        return FALSE;
+    }
+
+    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
+        return FALSE;
+    }
+
+	for (res = 0; options[res]; ++res) {
+	    if (matchPattern(options[res], strlen(options[res]), param, param_len)) {
+			*value = res;
+			return TRUE;
+		}
+    }
+
+	SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
+    return FALSE;
+}
+

--
Gitblit v1.9.1