summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c357
1 files changed, 103 insertions, 254 deletions
diff --git a/parser.c b/parser.c
index b1fe924..cfb3bbb 100644
--- a/parser.c
+++ b/parser.c
@@ -14,7 +14,6 @@ END DESCRIPTION **********************************************************/
#include "flash.h"
#include "nicutils.h"
#include "version.h"
-#include "dummy_functions.h"
#include "i2c.h"
#include "lcd.h"
#include "menus.h"
@@ -36,7 +35,6 @@ static int process_int_param (char *parameter, int *value, int item_count, int *
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);
@@ -91,11 +89,7 @@ static int Go_zout_20(gchar** response, int channel, char *parameter,char *units
static int Go_prot_trip_21(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_gpib_addr_59(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_ser_baud_60(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_ser_par_61(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_ser_bits_62(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_ser_sbits_63(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_ser_rts_64(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_ser_echo_65(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_load_68(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_meas_ampl_69(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_rst_6(gchar** response, int channel, char *parameter,char *units,int command_type);
@@ -122,7 +116,6 @@ static int Go_avrq_ampl(gchar** response, int channel, char *parameter,char *uni
static int Go_cal_100(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_cal_interval_101(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_eprom_reset_102(gchar** response, int channel, char *parameter,char *units,int command_type);
-static int Go_broadcast_103(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
{
@@ -144,7 +137,9 @@ static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
}
- if (!strcmp(id_me,"*cls") ) {
+ if (!strcmp(id_me,"") ) {
+ id_code = 0;
+ } else if (!strcmp(id_me,"*cls") ) {
id_code = 1;
} else if (!strcmp(id_me,"*ese") ) {
id_code = 2;
@@ -356,8 +351,6 @@ static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
id_code = 107;
} else if (!strcmp(id_me,"reset") || !strcmp(id_me,"res")) {
id_code = 108;
- } else if (!strcmp(id_me,"broadcast") ) { //FIXME
- id_code = 109;
} else {
id_code = 9999;
}
@@ -441,11 +434,11 @@ static int Parser_find_commands(int commands[], int command_depth)
{23,67,45}, /* diag:test:delay - 58 */
{13,68,70,69}, /* syst:comm:gpib:addr - 59 */
{13,68,71,72|optional,73}, /* syst:comm:ser:rec:baud - 60 */
- {13,68,71,72|optional,74,75|optional}, /* syst:comm:ser:rec:parity - 61 */
- {13,68,71,72|optional,76}, /* syst:comm:ser:rec:bits - 62 */
- {13,68,71,72|optional,77}, /* syst:comm:ser:rec:sbits - 63 */
+ {13,68,71,72|optional,74,75|optional}, /* syst:comm:ser:rec:parity - 61 - not used */
+ {13,68,71,72|optional,76}, /* syst:comm:ser:rec:bits - 62 - not used */
+ {13,68,71,72|optional,77}, /* syst:comm:ser:rec:sbits - 63 - not used */
{13,68,71,80,79}, /* syst:comm:ser:control:rts - 64 */
- {13,68,71,72|optional,78}, /* syst:comm:ser:rec:echo - 65 */
+ {13,68,71,72|optional,78}, /* syst:comm:ser:rec:echo - 65 - not used */
{13,14,82}, /* syst:err:count - 66 */
{28|optional,40,65,30}, /* sour:puls:gate:level - 67 */
{24,85}, /* output:load - 68 */
@@ -483,7 +476,6 @@ static int Parser_find_commands(int commands[], int command_depth)
{88,107|optional}, /* calibration:all - 100 */
{88,37}, /* calibration:frequency - 101 */
{23,57,108}, /* diag:eprom:reset - 102 */
- {109} /* broadcast - 103 */
};
@@ -596,12 +588,10 @@ static int Parser_get_unit(char **parameter, char **units)
static gchar* regex_replace (gchar* in_string, gchar* regex_string, gchar* replace_with)
{
- GRegex *regex = g_regex_new (regex_string, 0, 0, NULL);
- gchar *out = g_regex_replace_literal (regex, in_string, -1, 0, replace_with, 0, NULL);
- g_regex_unref (regex);
- return out;
+ return conditional_regex_replace (TRUE, in_string, regex_string, replace_with);
}
+
static gchar* filter_input (gchar *raw_in)
{
g_strstrip (raw_in);
@@ -636,6 +626,9 @@ static gchar* filter_input (gchar *raw_in)
void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer, gchar *), gpointer user_data)
{
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+ g_static_mutex_lock (&mutex);
+
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 */
@@ -652,7 +645,6 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
int compound_message; /* this indicates that at least one semicolon has been found, so */
/* the message is a compound one */
-
int is_query;
int command_type; /* combination of is_query, parameter_found, and units_found */
@@ -788,6 +780,10 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
units_found = Parser_get_unit(&parameter,&units);
+ if (!globals.Sys.startup_complete) {
+ error_num=Startup_Not_Finished;
+ }
+
if (!error_num) {
command_type=(is_query<<2) | (parameter_found?2:0) | units_found;
@@ -943,21 +939,9 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
case 60:
error_num=Go_ser_baud_60(&response,channel,parameter,units,command_type);
break;
- case 61:
- error_num=Go_ser_par_61(&response,channel,parameter,units,command_type);
- break;
- case 62:
- error_num=Go_ser_bits_62(&response,channel,parameter,units,command_type);
- break;
- case 63:
- error_num=Go_ser_sbits_63(&response,channel,parameter,units,command_type);
- break;
case 64:
error_num=Go_ser_rts_64(&response,channel,parameter,units,command_type);
break;
- case 65:
- error_num=Go_ser_echo_65(&response,channel,parameter,units,command_type);
- break;
case 66:
error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type);
break;
@@ -1060,9 +1044,6 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
case 102:
error_num=Go_eprom_reset_102(&response,channel,parameter,units,command_type);
break;
- case 103:
- error_num=Go_broadcast_103(&response,channel,parameter,units,command_type);
- break;
case 9999:
// was only whitespace, ignore
@@ -1080,10 +1061,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
if (interactive_terminal) {
(*cbfunc)(user_data, error_response);
}
- } else {
- if (interactive_terminal) {
- (*cbfunc)(user_data, response);
- }
+ } else if (response != NULL) {
+ (*cbfunc)(user_data, response);
}
g_free (units);
@@ -1100,9 +1079,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
/* 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 && !(globals.MenuStatus.Selected_Submenu==Submenu1_rem_loc && globals.MenuStatus.Type_Of_Menu==Submenu_On)) {
- Menu_Update_Display();
+ Show_Main_Menu();
}
/* re-run error_check to update min/max values based on actual settings, not proposed settings */
@@ -1114,6 +1092,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
}
g_free (in);
+
+ g_static_mutex_unlock (&mutex);
}
@@ -1209,7 +1189,7 @@ static int Go_Str_eprom_47(gchar** response, int channel, char *loc_string,char
if (store_string[i]=='~') {
store_string[i]=' ';
}
- *(char *)(&globals.Flash.flash_start + eprom_loc+i)=store_string[i];
+ *(char *)(&globals.Flash.flash_start + eprom_loc+i)=g_ascii_toupper(store_string[i]);
}
*(char *)(&globals.Flash.flash_start + eprom_loc + i)=(char) 0; /* end of string */
writeUserBlock(&globals.Flash, eprom_loc, strlen(store_string)+1);
@@ -1405,8 +1385,6 @@ static int Handle_Units(float *mult,char *units, char *in_base)
base = g_strdup ("%");
prefix[len_all - 1] = 0;
} else if (strcmp(prefix+pos,base)) {
- g_free (base);
- g_free (prefix);
errornum = UnknownUnits;
} else {
prefix[pos]=0;
@@ -1621,12 +1599,6 @@ static int process_two_ints (char *parameter, int *value, int min, int 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 */
@@ -2239,6 +2211,7 @@ static int Go_trig_source46(gchar** response, int channel, char *parameter,char
} else {
return SyntaxError;
}
+ return OK;
break;
case query_simple:
@@ -2362,7 +2335,8 @@ static int Go_delay_test58(gchar** response, int channel, char *parameter,char *
return status;
}
globals.ChannelState[channel].test_delay_mode=on_off;
- return Set_Mux(channel);
+ Set_Mux(channel);
+ return OK;
break;
default:
@@ -2511,7 +2485,7 @@ static int Go_stb_8(gchar** response, int channel, char *parameter,char *units,i
{
switch (command_type) {
case query_simple:
- return query_int (response, GPIB_get_STB());
+ return query_int (response, GPIB_and_VXI_get_STB());
break;
default:
@@ -2737,16 +2711,14 @@ static int Go_gpib_addr_59(gchar** response, int channel, char *parameter,char *
static int Go_ser_baud_60(gchar** response, int channel, char *parameter,char *units,int command_type)
{
int new_baud, status;
- int valid_choices[] = {1200, 2400, 4800, 9600};
+ int valid_choices[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200};
switch (command_type) {
case command_withparam:
- // FIXME - expand this list
- // FIXME - hardcoded "4"
- if (status = process_int_param (parameter, &new_baud, 4, valid_choices, NO_ON_OFF)) {
+ if (status = process_int_param (parameter, &new_baud, 8, valid_choices, NO_ON_OFF)) {
return status;
}
- return IO_Setup_RS232(new_baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo, TRUE);
+ return IO_Setup_RS232(new_baud, globals.Flash.hardhand, TRUE);
break;
case query_simple:
@@ -2754,110 +2726,7 @@ static int Go_ser_baud_60(gchar** response, int channel, char *parameter,char *u
break;
case query_param:
- // FIXME - extract min, max from a new baud list
- return query_min_max_int (response, parameter, 1200, 9600);
- break;
-
- default:
- return SyntaxError;
- break;
- }
-
- return ThisShouldntHappen;
-}
-
-
-static int Go_ser_par_61(gchar** response, int channel, char *parameter,char *units,int command_type)
-{
-
- int new_parity;
-
- switch (command_type) {
- case command_withparam:
- if (!strcmp(parameter,"even")) {
- new_parity = rs232_parity_even;
- } else if (!strcmp(parameter,"odd")) {
- new_parity = rs232_parity_odd;
- } else if (!strcmp(parameter,"none")) {
- new_parity = rs232_parity_none;
- } else {
- return IllegalParameter;
- }
-
- return IO_Setup_RS232(globals.Flash.baud, (char) new_parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo, TRUE);
- break;
-
- case query_simple:
- if (globals.Flash.parity==rs232_parity_even) {
- return query_string(response, "EVEN");
- } else if (globals.Flash.parity==rs232_parity_odd) {
- return query_string(response, "ODD");
- } else if (globals.Flash.parity==rs232_parity_none) {
- return query_string(response, "NONE");
- }
- return OK;
- break;
-
- default:
- return SyntaxError;
- break;
- }
-
- return ThisShouldntHappen;
-}
-
-
-static int Go_ser_bits_62(gchar** response, int channel, char *parameter,char *units,int command_type)
-{
- int new_databits;
- int status;
-
- switch (command_type) {
- case command_withparam:
- if (status=process_two_ints (parameter, &new_databits, 7, 8)) {
- return status;
- }
-
- return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, (char) new_databits, globals.Flash.hardhand, globals.Flash.echo, TRUE);
- break;
-
- case query_simple:
- return query_int (response, globals.Flash.databits);
- break;
-
- case query_param:
- return query_min_max_int (response, parameter, 7, 8);
- break;
-
- default:
- return SyntaxError;
- break;
- }
-
- return ThisShouldntHappen;
-}
-
-
-static int Go_ser_sbits_63(gchar** response, int channel, char *parameter,char *units,int command_type)
-{
- int new_stopbits;
- int status;
-
- switch (command_type) {
- case command_withparam:
- if (status=process_two_ints (parameter, &new_stopbits, 1, 2)) {
- return status;
- }
-
- return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, (char) new_stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo, TRUE);
- break;
-
- case query_simple:
- return query_int (response, globals.Flash.stopbits);
- break;
-
- case query_param:
- return query_min_max_int (response, parameter, 1, 2);
+ return query_min_max_int (response, parameter, 1200, 115200);
break;
default:
@@ -2880,22 +2749,18 @@ static int Go_ser_rts_64(gchar** response, int channel, char *parameter,char *un
// these are valid hardware handshake modes
new_hardhand = 1;
} else if (!strcmp(parameter,"on")) {
- // FIXME - confusing: in absence of handware handshaking,
- // RTS is supposed to be always ON? Confirm
new_hardhand = 0;
} else {
return IllegalParameter;
}
- return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, new_hardhand, globals.Flash.echo, TRUE);
+ return IO_Setup_RS232(globals.Flash.baud, new_hardhand, TRUE);
break;
case query_simple:
if (globals.Flash.hardhand) {
return query_string(response, "IBF");
} else {
- // FIXME: confirm RTS is always high in BB ports if
- // hardware handshaking is not used
return query_string(response, "ON");
}
return OK;
@@ -2910,37 +2775,6 @@ static int Go_ser_rts_64(gchar** response, int channel, char *parameter,char *un
}
-static int Go_ser_echo_65(gchar** response, int channel, char *parameter,char *units,int command_type)
-{
- int new_echo;
- int status;
-
- switch (command_type) {
- case command_withparam:
- if (status=process_on_off (parameter, &new_echo)) {
- return status;
- }
- return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, (char) new_echo, TRUE);
- break;
-
- case query_simple:
- if (globals.Flash.echo) {
- return query_int (response, 1);
- } else {
- return query_int (response, 0);
- }
- return OK;
- break;
-
- default:
- return SyntaxError;
- break;
- }
-
- return ThisShouldntHappen;
-}
-
-
static int Go_load_68(gchar** response, int channel, char *parameter,char *units,int command_type)
{
float new_load_type;
@@ -3325,6 +3159,7 @@ static int Go_routeclose_78(gchar** response, int channel, char *parameter,char
} else {
Set_Route(channel,ROUTE_PRIMARY,temp1);
Set_Route(channel,ROUTE_SECONDARY,temp2);
+ return OK;
}
break;
@@ -3358,11 +3193,7 @@ static int Parse_chan_list(int channel,char *parameter,int *primary_selected, in
int *value_pointer;
#define PARSE_MAX_STRING 20
- char temp[PARSE_MAX_STRING+1];
- if (*response) {
- *response[0]=0;
- }
if ( !(parameter[0]=='(' && parameter[1]=='@')) {
return SyntaxError;
@@ -3376,53 +3207,72 @@ static int Parse_chan_list(int channel,char *parameter,int *primary_selected, in
return Route_Range_Error;
}
+
pointer=1;
do {
+ int error_num = OK;
+
pointer++;
has_module_name = FALSE;
/* get module name, if any */
+
+ GString *name = g_string_new ("");
+
for (i=0; isalpha(parameter[pointer]) && (i<PARSE_MAX_STRING); i++) {
- temp[i]=parameter[pointer];
+ name = g_string_append_c (name, parameter[pointer]);
pointer++;
}
- temp[i]=0;
value_pointer = primary_selected;
if (i>0) {
has_module_name = TRUE;
- if (!strcmp (temp, "anod")) {
+ if (!strcmp (name->str, "anod")) {
value_pointer = primary_selected;
- } else if (!strcmp (temp, "cath")) {
+ } else if (!strcmp (name->str, "cath")) {
if (globals.Flash.routing_required[channel]<2) {
- return IllegalParameter;
+ error_num = IllegalParameter;
}
value_pointer = secondary_selected;
} else {
- return IllegalParameter;
+ error_num = IllegalParameter;
}
- if (parameter[pointer] == '(' ) {
+ if (!error_num && (parameter[pointer] == '(' )) {
pointer++;
} else {
- return SyntaxError;
+ error_num =SyntaxError;
}
+
}
+ g_string_free (name, TRUE);
+
+ if (error_num) {
+ return error_num;
+ }
+
+ GString *digits = g_string_new ("");
+
/* get digits */
for (i=0; isdigit(parameter[pointer]) && (i<PARSE_MAX_STRING); i++) {
- temp[i]=parameter[pointer];
+ digits = g_string_append_c (digits, parameter[pointer]);
pointer++;
}
- temp[i]=0;
if (i==0) {
- return SyntaxError;
+ error_num = SyntaxError;
+ }
+
+ n = atoi(digits->str);
+ g_string_free (digits, TRUE);
+
+ if (error_num) {
+ return error_num;
}
- n = atoi(temp);
if ((n < 1) || (n > globals.Flash.routing_max_pins[channel])) {
return OutOfRange;
}
@@ -3436,11 +3286,11 @@ static int Parse_chan_list(int channel,char *parameter,int *primary_selected, in
}
/* query or command? */
- if (*response) {
+ if (response) {
if (*value_pointer == n) {
- strcat(*response,"1 ");
+ *response = g_strdup ("1 ");
} else {
- strcat(*response,"0 ");
+ *response = g_strdup ("0 ");
}
} else {
if (value_pointer) {
@@ -3770,8 +3620,41 @@ static int Go_puls_sep_89(gchar** response, int channel, char *parameter,char *u
static int Go_sys_pwd_92(gchar** response, int channel, char *parameter,int command_type)
{
- // FIXME - needs /etc/shadow
- return SyntaxError;
+ gchar *old_password = NULL;
+ gchar *new_password = NULL;
+ char *new_loc;
+ int error_num;
+
+ switch (command_type) {
+ case command_withparam:
+ /* new password follows comma */
+
+ new_loc = strchr(parameter,',');
+ if (new_loc == NULL) {
+ return password_change_error;
+ }
+
+ new_password = g_strdup_printf ("%s", new_loc + 1);
+ new_loc[0]=0;
+ old_password = g_strdup (parameter);
+
+ error_num = OK;
+ if ((strlen(new_password)< 6) || (strlen(new_password)>32)) {
+ error_num = password_change_error;
+ }
+
+ if (!error_num) {
+ error_num = change_password (old_password, new_password);
+ }
+
+ g_free (new_password);
+ g_free (old_password);
+ return error_num;
+
+ default:
+ return SyntaxError;
+ break;
+ }
}
@@ -4098,7 +3981,8 @@ static int Go_cal_100(gchar** response, int channel, char *parameter,char *units
case query_simple:
status = do_full_self_cal(&caldata);
if (!no_report) {
- query_string(response, caldata.response);
+ query_string(response, caldata.response->str);
+ g_string_free (caldata.response, TRUE);
}
return status;
break;
@@ -4145,38 +4029,3 @@ static int Go_cal_interval_101(gchar** response, int channel, char *parameter,ch
return ThisShouldntHappen;
}
-
-
-static int Go_broadcast_103(gchar** response, int channel, char *parameter,char *units,int command_type)
-{
-#ifdef DEBUG_ON
-
- gchar *broadcast_str = NULL;
-
- switch (command_type) {
- case command_withparam:
- broadcast_str = g_strdup_printf ("broadcast msg: %s\r\n> ", parameter);
- send_message(broadcast_str);
- g_free (broadcast_str);
- return OK;
- break;
-
- case command_param_units:
- broadcast_str = g_strdup_printf ("broadcast msg: %s %s\r\n> ", parameter, units);
- send_message(broadcast_str);
- g_free (broadcast_str);
- return OK;
- break;
-
- default:
- return SyntaxError;
- break;
- }
-
- return ThisShouldntHappen;
-
-#else
-
- return Unrecognized;
-#endif
-}