summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-14 10:37:22 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-14 10:37:22 -0400
commitad41125d65400ae608d99fd95aefad93102d260e (patch)
treecd240b42c880536f6e3b9a905d818de75809e350 /parser.c
parentcc81ed5ed18464d6e632c79a1ccc9a2a8eea45b4 (diff)
remove unneeded outer loop
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c335
1 files changed, 166 insertions, 169 deletions
diff --git a/parser.c b/parser.c
index dbc5f91..cc350f6 100644
--- a/parser.c
+++ b/parser.c
@@ -556,217 +556,214 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
int channel;
int with_id_code;
- // fixme - delete enclosing loop and re-indent
- if (1) {
- strcpy(in+strlen(in)," "); /* add white space to the end of the input string */
-
- in_pos = 0; /* start at the beginning of the input string */
- semicolon_found = 0;
- compound_message = 0;
- command_depth=0;
- old_command_depth=0;
- dont_use_this_header=NO;
-
- while (isspace(in[in_pos]) || in[in_pos]==':' || in[in_pos]==';') {
- /* ignore leading spaces */
- ++in_pos;
- }
+ strcpy(in+strlen(in)," "); /* add white space to the end of the input string */
+
+ in_pos = 0; /* start at the beginning of the input string */
+ semicolon_found = 0;
+ compound_message = 0;
+ command_depth=0;
+ old_command_depth=0;
+ dont_use_this_header=NO;
+
+ while (isspace(in[in_pos]) || in[in_pos]==':' || in[in_pos]==';') {
+ /* ignore leading spaces */
+ ++in_pos;
+ }
- /* examine each letter in the string until EOS */
- while (in[in_pos] != 0) {
+ /* examine each letter in the string until EOS */
+ while (in[in_pos] != 0) {
- channel=-1;
- with_id_code=0;
- space_found = 0;
- parameter_found = 0; /* no numeric parameters yet */
- parameter[0] = 0;
- units_found = 0;
- is_query = 0;
- current_command_length = 0;
+ channel=-1;
+ with_id_code=0;
+ space_found = 0;
+ parameter_found = 0; /* no numeric parameters yet */
+ parameter[0] = 0;
+ units_found = 0;
+ is_query = 0;
+ current_command_length = 0;
- if (semicolon_found && !dont_use_this_header) {
- old_command_depth=command_depth-2;
- for (i=0; i<old_command_depth; ++i) {
- old_commands[i]=commands[i];
- }
+ if (semicolon_found && !dont_use_this_header) {
+ old_command_depth=command_depth-2;
+ for (i=0; i<old_command_depth; ++i) {
+ old_commands[i]=commands[i];
}
+ }
- command_depth=old_command_depth;
- for (i=0; i<command_depth; ++i) {
- commands[i]=old_commands[i];
- }
+ command_depth=old_command_depth;
+ for (i=0; i<command_depth; ++i) {
+ commands[i]=old_commands[i];
+ }
- semicolon_found=0;
- dont_use_this_header=NO;
+ semicolon_found=0;
+ dont_use_this_header=NO;
- /* break it up if semicolons are present */
- while (!semicolon_found && in[in_pos] != 0) {
+ /* break it up if semicolons are present */
+ while (!semicolon_found && in[in_pos] != 0) {
- in[in_pos]=tolower(in[in_pos]);
- /* everything to lowercase */
+ in[in_pos]=tolower(in[in_pos]);
+ /* everything to lowercase */
- /* words are separated by white space or colons or semicolons */
- if ( isspace(in[in_pos]) || in[in_pos] == ':' || in[in_pos] == ';')
+ /* words are separated by white space or colons or semicolons */
+ if ( isspace(in[in_pos]) || in[in_pos] == ':' || in[in_pos] == ';')
- {
+ {
- if (in[in_pos] == ';') {
- ++semicolon_found;
- }
- ++compound_message;
+ if (in[in_pos] == ';') {
+ ++semicolon_found;
+ }
+ ++compound_message;
+
+ /* 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;
+ }
- /* 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';
+ ++parameter_found;
+ strcpy(parameter,current_command);
+ } else if (!space_found) {
+ /* just a regular command word */
+
+ /* 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);
+
+ if ( commands[command_depth]<13
+ || commands[command_depth]==63
+ || commands[command_depth]==64) {
+ dont_use_this_header=YES;
+ commands[0]=commands[command_depth];
+ command_depth=0;
+ }
+
+ ++command_depth; /* indicate that a new command word is ready */
- 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;
- }
-
- current_command[current_command_length] = '\0';
- ++parameter_found;
- strcpy(parameter,current_command);
- } else if (!space_found) {
- /* just a regular command word */
-
- /* 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);
-
- if ( commands[command_depth]<13
- || commands[command_depth]==63
- || commands[command_depth]==64) {
- dont_use_this_header=YES;
- commands[0]=commands[command_depth];
- command_depth=0;
- }
-
- ++command_depth; /* indicate that a new command word is ready */
-
- /* indicate if the separator was a space - next bit parameter then */
- if (in[in_pos]==' ') {
- ++space_found;
- }
+ /* indicate if the separator was a space - next bit parameter then */
+ if (in[in_pos]==' ') {
+ ++space_found;
}
- } /* non-repeated separator */
- else if (compound_message && in[in_pos-1]==';' && in[in_pos]==':') {
- dont_use_this_header=YES;
- command_depth=0;
}
-
- } /* 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;
- } /* not a separator */
- else {
- ++is_query;
- /* question mark found */
+ } /* non-repeated separator */
+ else if (compound_message && in[in_pos-1]==';' && in[in_pos]==':') {
+ dont_use_this_header=YES;
+ command_depth=0;
}
+ } /* 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;
+ } /* not a separator */
+ else {
+ ++is_query;
+ /* question mark found */
+ }
- ++in_pos; /* move pointer to next letter */
- } /* not a semi-colon */
+ ++in_pos; /* move pointer to next letter */
- commands[command_depth]=0;
- ++command_depth;
- /* add end of tokens marker (0) */
+ } /* not a semi-colon */
- int error_num=OK;
- gchar *response = NULL;
- gchar *error_response = NULL;
+ commands[command_depth]=0;
+ ++command_depth;
+ /* add end of tokens marker (0) */
- if (parameter_found) {
- units_found = Parser_get_unit(parameter,units);
- }
+ int error_num=OK;
+ gchar *response = NULL;
+ gchar *error_response = NULL;
- if (!error_num) {
- if (!units_found) {
- units[0]='\0';
- }
- g_strstrip (parameter);
- command_type=(is_query<<2) | (parameter_found?2:0) | units_found;
+ if (parameter_found) {
+ units_found = Parser_get_unit(parameter,units);
+ }
- if (commands[0]!=0) {
- routine_num = Parser_find_commands(commands,command_depth);
+ if (!error_num) {
+ if (!units_found) {
+ units[0]='\0';
+ }
+ g_strstrip (parameter);
+ command_type=(is_query<<2) | (parameter_found?2:0) | units_found;
- /* check for valid channel number, based on position in command */
- if ( (error_num=Parser_channel(&channel,with_id_code,routine_num)) )
- /* not a valid command due to improper channel suffix */
- {
- routine_num=9999;
- }
- } else {
+ if (commands[0]!=0) {
+ routine_num = Parser_find_commands(commands,command_depth);
+
+ /* check for valid channel number, based on position in command */
+ if ( (error_num=Parser_channel(&channel,with_id_code,routine_num)) )
+ /* not a valid command due to improper channel suffix */
+ {
routine_num=9999;
- /* ignore empty commands lists, generated by a white space string */
}
+ } else {
+ routine_num=9999;
+ /* ignore empty commands lists, generated by a white space string */
+ }
- switch (routine_num) {
- case 0:
- response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d",routine_num,channel,parameter,units,command_type);
- error_num=Unrecognized;
- break;
- case 11:
- error_num=Go_syst_err_11(&response,channel,parameter,units,command_type);
- break;
- case 32:
- case 33:
- error_num=Go_freq_32_33(&response,channel,parameter,units,command_type);
- break;
- case 66:
- error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type);
- break;
-
- case 9999:
- // was only whitespace, ignore
- break;
-
- default:
- /* valid but not implemented yet */
- response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d",routine_num,channel,parameter,units,command_type);
- break;
+ switch (routine_num) {
+ case 0:
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d",routine_num,channel,parameter,units,command_type);
+ error_num=Unrecognized;
+ break;
+ case 11:
+ error_num=Go_syst_err_11(&response,channel,parameter,units,command_type);
+ break;
+ case 32:
+ case 33:
+ error_num=Go_freq_32_33(&response,channel,parameter,units,command_type);
+ break;
+ case 66:
+ error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type);
+ break;
+
+ case 9999:
+ // was only whitespace, ignore
+ break;
+
+ default:
+ /* valid but not implemented yet */
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d",routine_num,channel,parameter,units,command_type);
+ break;
- }
}
+ }
- if (error_num) {
- queue_error_from_parser(&error_response, error_num);
- if (interactive_terminal) {
- (*cbfunc)(user_data, error_response);
- }
- } else {
- (*cbfunc)(user_data, response);
+ if (error_num) {
+ queue_error_from_parser(&error_response, error_num);
+ if (interactive_terminal) {
+ (*cbfunc)(user_data, error_response);
}
+ } else {
+ (*cbfunc)(user_data, response);
+ }
- g_free (response);
- g_free (error_response);
+ g_free (response);
+ g_free (error_response);
- if (!is_query) {
- Main_update_shift_registers(); /* update values in pulse generator circuit */
- }
-
- } /* not EOS */
+ if (!is_query) {
+ Main_update_shift_registers(); /* update values in pulse generator circuit */
+ }
- /* update display if it wasn't a query, and if the control menu isn't on (this gives the user
- a chance to press "Go To Local" to override control */
+ } /* not EOS */
- int Selected_Submenu=0, Submenu1_rem_loc=0, Type_Of_Menu=0, Submenu_On=0;
+ /* update display if it wasn't a query, and if the control menu isn't on (this gives the user
+ a chance to press "Go To Local" to override control */
- if (!is_query && !(Selected_Submenu==Submenu1_rem_loc && Type_Of_Menu==Submenu_On)) {
- Menu_Update_Display();
- }
+ int Selected_Submenu=0, Submenu1_rem_loc=0, Type_Of_Menu=0, Submenu_On=0;
- /* re-run error_check to update min/max values based on actual settings, not proposed settings */
- Error_check(globals.ChannelState);
+ if (!is_query && !(Selected_Submenu==Submenu1_rem_loc && Type_Of_Menu==Submenu_On)) {
+ Menu_Update_Display();
}
+ /* re-run error_check to update min/max values based on actual settings, not proposed settings */
+ Error_check(globals.ChannelState);
+
// trigger a prompt
if (interactive_terminal) {
(*cbfunc)(user_data, "");