summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-15 15:26:50 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-15 15:26:50 -0400
commitf6d11094382e205d56b1c2b6b334265ab23b0803 (patch)
tree51fb1108dba3574f57002ece1697528e0b6d0b2f
parent4f3c377fad09d348b0b9df636256ec3eecbc25d4 (diff)
add the rest of the generic query and parameter routines to parser
-rw-r--r--parser.c108
1 files changed, 107 insertions, 1 deletions
diff --git a/parser.c b/parser.c
index 0ed2a1c..4e9df89 100644
--- a/parser.c
+++ b/parser.c
@@ -15,8 +15,17 @@ END DESCRIPTION **********************************************************/
//STATICS
static int query_int (gchar** response, int n);
static int query_min_max_float (gchar** response, char *parameter, float min_val, float max_val);
+static int query_min_max_int (gchar** response, char *parameter, int min_val, int max_val);
+static int query_string (gchar** response, char *in);
static int query_float (gchar** response, float value);
+
static int process_float_param (char *parameter, float *value, float min_val, float max_val, int zero_mode);
+static int process_int_param (char *parameter, int *value, int item_count, int *valid_nums, int allow_on_off);
+static int process_int_range (char *parameter, int *value, int min_val, int max_val);
+static int process_on_off (char *parameter, int *value);
+static int process_two_ints (char *parameter, int *value, int min, int max);
+static int process_four_ints (char *parameter, int *value, int v1, int v2, int v3, int v4);
+
static int check_channel_ok (int channel, int enabled_channels, char chankey);
static int Parser_id_word(char *id_me, int *channel, int *with_id_code);
static int Parser_find_commands(int commands[], int command_depth);
@@ -947,6 +956,22 @@ static int query_int (gchar** response, int n)
return OK;
}
+static int query_min_max_int (gchar** response, char *parameter, int min_val, int max_val)
+{
+ int report_val;
+
+ if (Is_Min_Command(parameter)) {
+ report_val=min_val;
+ } else if (Is_Max_Command(parameter)) {
+ report_val=max_val;
+ } else {
+ return SyntaxError;
+ }
+
+ *response = g_printf ("%d", report_val);
+ return OK;
+}
+
static int query_min_max_float (gchar** response, char *parameter, float min_val, float max_val)
{
float report_val;
@@ -969,6 +994,12 @@ static int query_float (gchar** response, float value)
return OK;
}
+static int query_string (gchar** response, char *in)
+{
+ *response = g_strdup (in);
+ return OK;
+}
+
static int process_float_param (char *parameter, float *value, float min_val, float max_val, int zero_mode)
{
int status;
@@ -1001,6 +1032,82 @@ static int process_float_param (char *parameter, float *value, float min_val, fl
return status;
}
+#define USE_ON_OFF 0
+#define NO_ON_OFF 1
+static int process_int_param (char *parameter, int *value, int item_count, int *valid_nums, int allow_on_off)
+{
+ int status, i, min_val, max_val, is_valid, items_in_list;
+
+ status = OK;
+ is_valid = 0;
+
+ min_val = valid_nums[0];
+ max_val = valid_nums[item_count - 1];
+
+ if (String_is_it_numeric(parameter)) {
+ *value = atoi(parameter);
+ for (i = 0; (i < item_count) && (is_valid == 0); i++) {
+ if (*value == valid_nums[i]) {
+ is_valid = 1;
+ }
+ }
+ if (is_valid == 0) {
+ status = IllegalParameter;
+ }
+ } else if (!strcmp(parameter,"off") && (allow_on_off == USE_ON_OFF)) {
+ *value = 0;
+ } else if (!strcmp(parameter,"on") && (allow_on_off == USE_ON_OFF)) {
+ *value = 1;
+ } else if (Is_Min_Command(parameter) && (allow_on_off == NO_ON_OFF)) {
+ *value = min_val;
+ } else if (Is_Max_Command(parameter) && (allow_on_off == NO_ON_OFF)) {
+ *value = max_val;
+ } else {
+ status=SyntaxError;
+ }
+
+ return status;
+}
+
+static int process_int_range (char *parameter, int *value, int min_val, int max_val)
+{
+ int status;
+ status = OK;
+
+ if (String_is_it_numeric(parameter)) {
+ *value = atoi(parameter);
+ if ((*value<min_val) || (*value>max_val)) {
+ status = OutOfRange;
+ }
+ } else if (Is_Min_Command(parameter)) {
+ *value = min_val;
+ } else if (Is_Max_Command(parameter)) {
+ *value = max_val;
+ } else {
+ status=SyntaxError;
+ }
+
+ return status;
+}
+
+static int process_on_off (char *parameter, int *value)
+{
+ static const int valid_choices[2] = {0, 1};
+ return process_int_param (parameter, value, 2, valid_choices, USE_ON_OFF);
+}
+
+static int process_two_ints (char *parameter, int *value, int min, int max)
+{
+ int valid_choices[2] = {min, max};
+ return process_int_param (parameter, value, 2, valid_choices, NO_ON_OFF);
+}
+
+static int process_four_ints (char *parameter, int *value, int v1, int v2, int v3, int v4)
+{
+ int valid_choices[4] = {v1, v2, v3, v4};
+ return process_int_param (parameter, value, 4, valid_choices, NO_ON_OFF);
+}
+
static int check_channel_ok (int channel, int enabled_channels, char chankey)
{
/* how many channels overall */
@@ -1016,7 +1123,6 @@ static int check_channel_ok (int channel, int enabled_channels, char chankey)
return OK;
}
-
static int Go_syst_err_11(gchar** response, int channel, char *parameter,char *units,int command_type)
{
switch (command_type) {