summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-13 20:54:45 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-13 20:54:45 -0400
commit0b3ae523971cd3bfae93dbffe202285e5a435520 (patch)
tree20d7562036e603cc4c44c7715d3867cb9275b106
parentfc17e46aefc3b5f4e2d4dda8e09f9fa6533377be (diff)
let parser handle command prompt generation
-rw-r--r--error_utils.c2
-rw-r--r--instr-client.c3
-rw-r--r--parser.c11
-rw-r--r--response.c12
4 files changed, 12 insertions, 16 deletions
diff --git a/error_utils.c b/error_utils.c
index 2c48aba..ab44893 100644
--- a/error_utils.c
+++ b/error_utils.c
@@ -211,7 +211,7 @@ void format_error_text (gchar **response, int error_type, char *in)
}
- *response = g_strdup_printf("%d, \"%s; %s\"\n", error_type, prefix, in);
+ *response = g_strdup_printf("%d, \"%s; %s\"", error_type, prefix, in);
g_free(prefix);
}
diff --git a/instr-client.c b/instr-client.c
index fc15a20..a091d4e 100644
--- a/instr-client.c
+++ b/instr-client.c
@@ -105,7 +105,6 @@ static gboolean cbServerInput(gpointer data, gpointer additional)
if(buffer[0] != ' ') {
g_print("%s", buffer);
}
- g_print("> ");
return TRUE;
}
@@ -155,4 +154,4 @@ int main(int argc, char** argv)
g_source_attach(inSource, NULL);
g_main_loop_run (g_main_loop_new (NULL, FALSE));
return 0;
-} \ No newline at end of file
+}
diff --git a/parser.c b/parser.c
index 631d948..a39fcce 100644
--- a/parser.c
+++ b/parser.c
@@ -557,8 +557,6 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
int channel;
int with_id_code;
-//printf ("decoding this input: %s\n\r",in);
-
// fixme - delete enclosing loop and re-indent
if (1) {
strcpy(in+strlen(in)," "); /* add white space to the end of the input string */
@@ -715,7 +713,7 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
switch (routine_num) {
case 0:
- response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ 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:
@@ -735,7 +733,7 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
default:
/* valid but not implemented yet */
- response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d",routine_num,channel,parameter,units,command_type);
break;
}
@@ -771,6 +769,11 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
/* 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, "");
+ }
}
static int Parser_channel (int *channel,int with_id_code,int routine_num)
diff --git a/response.c b/response.c
index d6bfcc1..db008dd 100644
--- a/response.c
+++ b/response.c
@@ -94,20 +94,14 @@ static void writeOutput(GPollableOutputStream* stream, gchar* data)
gssize written_bytes = 0;
gchar *terminated;
- if(data==NULL) {
+ if (data==NULL) {
terminated = g_strdup("\r\n");
+ } else if (!strlen(data)) {
+ terminated = g_strdup("> ");
} else {
terminated = g_strdup_printf ("%s\r\n", data);
}
-// if(!strlen(out)) {
-// strcpy(out, " ");
-// }
-//
-// if(out[strlen(out)-1] != '\n' && out[strlen(out)-1] != '\r') {
-// strcat(out, "\n");
-// }
-
written_bytes = g_pollable_output_stream_write_nonblocking(stream, terminated, strlen(terminated), NULL, NULL);
if (written_bytes == -1) {
g_print("Could not send message to client\n");