diff --git a/src/include/v3270.h b/src/include/v3270.h index ac1302b..4e28a87 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -287,7 +287,7 @@ LIB3270_EXPORT int v3270_print_selected(GtkWidget *widget, GError **error); LIB3270_EXPORT int v3270_print_copy(GtkWidget *widget, GError **error); - LIB3270_EXPORT void v3270_exec_command(GtkWidget *widget, const gchar *cmdline); + LIB3270_EXPORT int v3270_exec_command(GtkWidget *widget, const gchar *cmdline); LIB3270_EXPORT GtkWidget * v3270_dialog_new(const gchar *title, GtkWindow *parent, const gchar *apply); diff --git a/src/trace/exec.c b/src/trace/exec.c index afcb632..13b50c9 100644 --- a/src/trace/exec.c +++ b/src/trace/exec.c @@ -34,6 +34,7 @@ #include #include + #include #include #include @@ -58,53 +59,92 @@ return rc; } - static void set_property(H3270 *hSession, gchar *ptr) + static int set_property(H3270 *hSession, const gchar *name, const gchar * value) { size_t ix; - const gchar * name = get_word(&ptr); - - debug("property_name: \"%s\"",name); + debug("%s=%s",name,value); // Check toggles for(ix = 0; ix < (size_t) LIB3270_TOGGLE_COUNT; ix++) { - debug("%s %s %d",name,lib3270_get_toggle_name((LIB3270_TOGGLE) ix),g_ascii_strcasecmp(name,lib3270_get_toggle_name((LIB3270_TOGGLE) ix))); if(g_ascii_strcasecmp(name,lib3270_get_toggle_name((LIB3270_TOGGLE) ix)) == 0) - { - lib3270_set_toggle(hSession,(LIB3270_TOGGLE) ix, 1); - return; - } + return lib3270_set_toggle(hSession,(LIB3270_TOGGLE) ix, atoi(value)); + } // Check boolean properties - const LIB3270_INT_PROPERTY * iProp = lib3270_get_boolean_properties_list(); + const LIB3270_INT_PROPERTY * bProp = lib3270_get_boolean_properties_list(); + for(ix = 0; bProp[ix].name; ix++) + { + if(g_ascii_strcasecmp(name,bProp[ix].name) == 0 && bProp[ix].set) + return bProp[ix].set(hSession,atoi(value)); + + } + + // Check integer properties + const LIB3270_INT_PROPERTY * iProp = lib3270_get_int_properties_list(); for(ix = 0; iProp[ix].name; ix++) { - debug("%s %s %d",name,iProp[ix].name,g_ascii_strcasecmp(name,iProp[ix].name)); if(g_ascii_strcasecmp(name,iProp[ix].name) == 0 && iProp[ix].set) - { - iProp[ix].set(hSession,1); - return; - } + return iProp[ix].set(hSession,atoi(value)); + } + // Check string properties + const LIB3270_STRING_PROPERTY * sProp = lib3270_get_string_properties_list(); + for(ix = 0; sProp[ix].name; ix++) + { + if(g_ascii_strcasecmp(name,sProp[ix].name) == 0 && sProp[ix].set) + return sProp[ix].set(hSession,value); + } + + return errno = ENOENT; } - void v3270_exec_command(GtkWidget *widget, const gchar *text) + int v3270_exec_command(GtkWidget *widget, const gchar *text) { + H3270 *hSession = v3270_get_session(widget); g_autofree gchar * cmdline = g_strdup(text); g_strstrip(cmdline); debug("cmdline: \"%s\"",cmdline); - if(g_str_has_prefix(cmdline,"set ")) + if(g_str_has_prefix(cmdline,"connect")) + { + return lib3270_reconnect(hSession,0); + } + + if(g_str_has_prefix(cmdline,"disconnect")) + { + return lib3270_disconnect(hSession); + } + + if(g_str_has_prefix(cmdline,"set")) + { + gchar *txtptr = cmdline+3; + const gchar * name = get_word(&txtptr); + g_strstrip(txtptr); + return set_property(hSession,name,(*txtptr ? txtptr : "1")); + } + + if(g_str_has_prefix(cmdline,"reset")) + { + gchar *txtptr = cmdline+3; + const gchar * name = get_word(&txtptr); + g_strstrip(txtptr); + return set_property(hSession,name,(*txtptr ? txtptr : "0")); + } + + gchar * sep = strchr(cmdline,'='); + if(sep) { - set_property(v3270_get_session(widget), cmdline+3); - return; + *(sep++) = 0; + set_property(hSession,g_strstrip(cmdline),g_strstrip(sep)); } + return errno = ENOENT; } diff --git a/src/trace/trace.c b/src/trace/trace.c index 4b06104..d9b4a15 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -166,7 +166,11 @@ static void destroy(GtkWidget *widget) static void activate(G_GNUC_UNUSED GtkButton *button, v3270_trace *window) { - v3270_exec_command(GTK_WIDGET(window),gtk_entry_get_text(GTK_ENTRY(window->entry))); + GtkWidget * terminal = GTK_WIDGET(lib3270_get_user_data(window->hSession)); + + int rc = v3270_exec_command(terminal,gtk_entry_get_text(GTK_ENTRY(window->entry))); + + v3270_trace_printf(GTK_WIDGET(window),"exec(\"%s\") exits with rc=%d (%s)\n",gtk_entry_get_text(GTK_ENTRY(window->entry)),rc,strerror(rc)); gtk_entry_set_text(GTK_ENTRY(window->entry),""); } diff --git a/v3270.cbp b/v3270.cbp index ee44929..7130807 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -74,123 +74,126 @@ - - - - - - - - - - - + - + - + - + - + - + - + + - + + - + - + - + - + - + - + - - - - + - + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + + - - + + - + - + - + - + - + + - + - + + + -- libgit2 0.21.2