From 5c56d0706893bdd0609cea1e14a1fb2f9598efee Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 14 Jan 2014 22:59:55 +0000 Subject: [PATCH] Incluindo opcao de linha de comando para definir o modelo do terminal --- src/include/lib3270.h | 5 ++--- src/lib3270/api.h | 4 ++-- src/lib3270/ctlr.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/lib3270/session.c | 145 +------------------------------------------------------------------------------------------------------------------------------------------------ src/pw3270/main.c | 29 +++++++++++++++++------------ src/pw3270/window.c | 15 +++++++++++++-- 6 files changed, 180 insertions(+), 164 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index eb82370..0597e6a 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -976,9 +976,8 @@ LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *hSession, int baddr, int *start, int *end); - - LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); - LIB3270_EXPORT int lib3270_set_model_name(H3270 *hSession, const char *name); +// LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); + LIB3270_EXPORT int lib3270_set_model(H3270 *hSession, const char *name); LIB3270_EXPORT int lib3270_get_model(H3270 *session); diff --git a/src/lib3270/api.h b/src/lib3270/api.h index 612e879..0f9d5a0 100644 --- a/src/lib3270/api.h +++ b/src/lib3270/api.h @@ -314,8 +314,8 @@ #define query_3270_terminal_status(void) lib3270_get_program_message(NULL) - #define set_3270_model(h,m) lib3270_set_model(h,m) - #define get_3270_model(h) lib3270_get_model(h) +// #define set_3270_model(h,m) lib3270_set_model(h,m) +// #define get_3270_model(h) lib3270_get_model(h) /* Get connection info */ #define get_connected_lu(h) lib3270_get_luname(h) diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 99a11cb..824bb81 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -150,6 +150,84 @@ void ctlr_reinit(H3270 *session, unsigned cmask) } } + /** + * Parse the model number. + * + * @param session Session Handle. + * @param m Model number. + * + * @return -1 (error), 0 (default), or the specified number. + */ +static int parse_model_number(H3270 *session, const char *m) +{ + int sl; + int n; + + if(!m) + return 0; + + sl = strlen(m); + + /* An empty model number is no good. */ + if (!sl) + return 0; + + if (sl > 1) { + /* + * If it's longer than one character, it needs to start with + * '327[89]', and it sets the m3279 resource. + */ + if (!strncmp(m, "3278", 4)) + { + session->m3279 = 0; + } + else if (!strncmp(m, "3279", 4)) + { + session->m3279 = 1; + } + else + { + return -1; + } + m += 4; + sl -= 4; + + /* Check more syntax. -E is allowed, but ignored. */ + switch (m[0]) { + case '\0': + /* Use default model number. */ + return 0; + case '-': + /* Model number specified. */ + m++; + sl--; + break; + default: + return -1; + } + switch (sl) { + case 1: /* n */ + break; + case 3: /* n-E */ + if (strcasecmp(m + 1, "-E")) { + return -1; + } + break; + default: + return -1; + } + } + + /* Check the numeric model number. */ + n = atoi(m); + if (n >= 2 && n <= 5) { + return n; + } else { + return -1; + } + +} + /** * Get current 3270 model. * @@ -166,7 +244,7 @@ int lib3270_get_model(H3270 *hSession) * * @param hSession Session handle. * @param model New model (updates model name) - */ + */ /* int lib3270_set_model(H3270 *hSession, int model) { if(CONNECTED) @@ -176,6 +254,72 @@ int lib3270_set_model(H3270 *hSession, int model) ctlr_reinit(hSession,MODEL_CHANGE); screen_update(hSession,0,hSession->rows*hSession->cols); return 0; +} */ + +int lib3270_set_model(H3270 *hSession, const char *model) +{ + int ovc, ovr; + char junk; + int model_number; + + if(hSession->cstate != LIB3270_NOT_CONNECTED) + return EBUSY; + + strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); + hSession->model_name = &hSession->full_model_name[4]; + + if(!*model) + model = "2"; // No model, use the default one + + model_number = parse_model_number(hSession,model); + if (model_number < 0) + { + popup_an_error(hSession,"Invalid model number: %s", model); + model_number = 0; + } + + if (!model_number) + { +#if defined(RESTRICT_3279) + model_number = 3; +#else + model_number = 4; +#endif + } + + if(hSession->mono) + hSession->m3279 = 0; + else + hSession->m3279 = 1; + + if(!hSession->extended) + hSession->oversize = CN; + +#if defined(RESTRICT_3279) + if (hSession->m3279 && model_number == 4) + model_number = 3; +#endif + + trace("Model_number: %d",model_number); + + if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) + { + ovc = 0; + ovr = 0; + } + ctlr_set_rows_cols(hSession, model_number, ovc, ovr); + + if (hSession->termname != CN) + hSession->termtype = hSession->termname; + else + hSession->termtype = hSession->full_model_name; + + trace("Termtype: %s",hSession->termtype); + + ctlr_reinit(hSession,MODEL_CHANGE); + screen_update(hSession,0,hSession->rows*hSession->cols); + + return 0; } void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr) diff --git a/src/lib3270/session.c b/src/lib3270/session.c index bc77e2f..4601460 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -54,8 +54,6 @@ /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ - static int parse_model_number(H3270 *session, const char *m); - /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ void lib3270_session_free(H3270 *h) @@ -184,69 +182,6 @@ static void nop_int(H3270 *session, int width) return; } -int lib3270_set_model_name(H3270 *hSession, const char *model) -{ - int ovc, ovr; - char junk; - int model_number; - - if(hSession->cstate != LIB3270_NOT_CONNECTED) - return EBUSY; - - strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); - hSession->model_name = &hSession->full_model_name[4]; - - if(!*model) - model = "2"; // No model, use the default one - - model_number = parse_model_number(hSession,model); - if (model_number < 0) - { - popup_an_error(hSession,"Invalid model number: %s", model); - model_number = 0; - } - - if (!model_number) - { -#if defined(RESTRICT_3279) - model_number = 3; -#else - model_number = 4; -#endif - } - - if(hSession->mono) - hSession->m3279 = 0; - else - hSession->m3279 = 1; - - if(!hSession->extended) - hSession->oversize = CN; - -#if defined(RESTRICT_3279) - if (hSession->m3279 && model_number == 4) - model_number = 3; -#endif - - trace("Model_number: %d",model_number); - - if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) - { - ovc = 0; - ovr = 0; - } - ctlr_set_rows_cols(hSession, model_number, ovc, ovr); - - if (hSession->termname != CN) - hSession->termtype = hSession->termname; - else - hSession->termtype = hSession->full_model_name; - - trace("Termtype: %s",hSession->termtype); - - return 0; -} - static void lib3270_session_init(H3270 *hSession, const char *model, const char *charset) { int f; @@ -313,7 +248,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char // Initialize toggles initialize_toggles(hSession); - lib3270_set_model_name(hSession,model); + lib3270_set_model(hSession,model); } @@ -357,84 +292,6 @@ H3270 * lib3270_session_new(const char *model) return hSession; } - /** - * Parse the model number. - * - * @param session Session Handle. - * @param m Model number. - * - * @return -1 (error), 0 (default), or the specified number. - */ -static int parse_model_number(H3270 *session, const char *m) -{ - int sl; - int n; - - if(!m) - return 0; - - sl = strlen(m); - - /* An empty model number is no good. */ - if (!sl) - return 0; - - if (sl > 1) { - /* - * If it's longer than one character, it needs to start with - * '327[89]', and it sets the m3279 resource. - */ - if (!strncmp(m, "3278", 4)) - { - session->m3279 = 0; - } - else if (!strncmp(m, "3279", 4)) - { - session->m3279 = 1; - } - else - { - return -1; - } - m += 4; - sl -= 4; - - /* Check more syntax. -E is allowed, but ignored. */ - switch (m[0]) { - case '\0': - /* Use default model number. */ - return 0; - case '-': - /* Model number specified. */ - m++; - sl--; - break; - default: - return -1; - } - switch (sl) { - case 1: /* n */ - break; - case 3: /* n-E */ - if (strcasecmp(m + 1, "-E")) { - return -1; - } - break; - default: - return -1; - } - } - - /* Check the numeric model number. */ - n = atoi(m); - if (n >= 2 && n <= 5) { - return n; - } else { - return -1; - } - -} - #if defined(DEBUG) void check_session_handle(H3270 **hSession, const char *fname) #else diff --git a/src/pw3270/main.c b/src/pw3270/main.c index a03843c..f107dd1 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -61,6 +61,7 @@ static const gchar * logfile = NULL; static const gchar * tracefile = NULL; static const gchar * charset = NULL; + static const gchar * model = NULL; #ifdef HAVE_GTKMAC GtkOSXApplication * osxapp = NULL; @@ -394,24 +395,25 @@ int main(int argc, char *argv[]) static const GOptionEntry app_options[] = { #if ! defined( WIN32 ) - { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, #else - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL }, #endif // WIN32 - { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, - { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, - { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, - { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" }, - { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL }, - { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL }, - { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), NULL }, + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, + { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, + { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" }, + { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL }, + { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL }, + { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), NULL }, + { "model", 'M', 0, G_OPTION_ARG_STRING, &model, N_( "The model of 3270 display to be emulated." ), NULL }, #if defined( HAVE_SYSLOG ) - { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, + { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, #endif - { "tracefile", 'T', 0, G_OPTION_ARG_FILENAME, &tracefile, N_( "Set trace filename" ), NULL }, - { "log", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, N_( "Log to file" ), NULL }, + { "tracefile", 'T', 0, G_OPTION_ARG_FILENAME, &tracefile, N_( "Set trace filename" ), NULL }, + { "log", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, N_( "Log to file" ), NULL }, { NULL } }; @@ -557,6 +559,9 @@ int main(int argc, char *argv[]) else pw3270_restore_window(toplevel,"toplevel"); + if(model) + lib3270_set_model(pw3270_get_session(toplevel),model); + pw3270_start_plugins(toplevel); gtk_window_present(GTK_WINDOW(toplevel)); diff --git a/src/pw3270/window.c b/src/pw3270/window.c index f118235..5e77dcd 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -344,8 +344,13 @@ { if(gtk_check_menu_item_get_active(item)) { + char name[2]; + trace("screen model on widget %p changes to %d",widget,GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270"))); - lib3270_set_model(v3270_get_session(widget),GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270"))); + + name[0] = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270"))+'0'; + name[1] = 0; + lib3270_set_model(v3270_get_session(widget),name); } } @@ -450,6 +455,7 @@ { trace("Widget %p changed to %s (id=%d)",widget,name,id); set_integer_to_config("terminal","model",id); + set_string_to_config("terminal","model_name","%s",name); } static void selecting(GtkWidget *widget, gboolean on, GtkActionGroup **group) @@ -572,7 +578,12 @@ if(str) g_free(str); } - lib3270_set_model(v3270_get_session(widget->terminal),get_integer_from_config("terminal","model",2)); + { + char str[2]; + str[0] = get_integer_from_config("terminal","model",2)+'0'; + str[1] = 0; + lib3270_set_model(v3270_get_session(widget->terminal),str); + } for(f=0;f