summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/parser.c b/parser.c
index daba910..9428a23 100644
--- a/parser.c
+++ b/parser.c
@@ -500,8 +500,6 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
int in_pos; /* this identifies the single character of in being processed */
int command_depth; /* how many command words have been parsed */
int old_command_depth; /* save this if in case of a compound message */
- char current_command[max_input_word_length]; /* current command word being processed */
- int current_command_length; /* length of current command so far */
int commands[max_commands_in_input]; /* list of identified command tokens */
int old_commands[max_commands_in_input]; /* list of identified command tokens from */
/* last non-common, non-colon-started command*/
@@ -554,7 +552,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
parameter_found = 0; /* no numeric parameters yet */
units_found = 0;
is_query = 0;
- current_command_length = 0;
+
+ GString *current_word = g_string_new ("");
if (semicolon_found && !dont_use_this_header) {
old_command_depth=command_depth-2;
@@ -590,24 +589,30 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
/* if it is a separator, ignore it if it is duplicated */
if ( !isspace(in[in_pos-1]) && (in[in_pos-1] != ':') && (in[in_pos-1] != ';')) {
/* valid separator, so terminate current command word string */
- current_command[current_command_length] = '\0';
if (space_found) {
/* Just end things if it is a semicolon */
if (in[in_pos]!=';') {
- current_command[current_command_length] = in[in_pos];
- ++current_command_length;
+ g_string_append_c (current_word, in[in_pos]);
}
- current_command[current_command_length] = '\0';
++parameter_found;
- parameter = g_strdup (current_command);
+
+ // the parameter may have multiple words,
+ // so this branch may be called repeatedly
+ g_free (parameter);
+ parameter = g_strdup (current_word->str);
+
} else if (!space_found) {
- /* just a regular command word */
+ /* end of a regular command word - use it */
+
+ commands[command_depth]=Parser_id_word( current_word->str,
+ &channel,
+ &with_id_code);
- /* terminate the current command string */
- current_command_length = 0; /* make room for a new command string */
- commands[command_depth]=Parser_id_word(current_command,&channel,&with_id_code);
+ /* get ready for the next token */
+ g_string_free (current_word, 1);
+ current_word = g_string_new ("");
if ( commands[command_depth]<13
|| commands[command_depth]==63
@@ -633,8 +638,7 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
} /* a separator */
else if (in[in_pos]!='?') {
/* if not white space or separator, add character to current command word */
- current_command[current_command_length] = in[in_pos];
- ++current_command_length;
+ g_string_append_c (current_word, in[in_pos]);
} /* not a separator */
else {
++is_query;
@@ -712,6 +716,7 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
g_free (response);
g_free (error_response);
g_free (parameter);
+ g_string_free (current_word, 1);
if (!is_query) {
Main_update_shift_registers(); /* update values in pulse generator circuit */