Commit 5c56d0706893bdd0609cea1e14a1fb2f9598efee

Authored by perry.werneck@gmail.com
1 parent f70e8139

Incluindo opcao de linha de comando para definir o modelo do terminal

src/include/lib3270.h
... ... @@ -976,9 +976,8 @@
976 976  
977 977 LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *hSession, int baddr, int *start, int *end);
978 978  
979   -
980   - LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model);
981   - LIB3270_EXPORT int lib3270_set_model_name(H3270 *hSession, const char *name);
  979 +// LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model);
  980 + LIB3270_EXPORT int lib3270_set_model(H3270 *hSession, const char *name);
982 981  
983 982 LIB3270_EXPORT int lib3270_get_model(H3270 *session);
984 983  
... ...
src/lib3270/api.h
... ... @@ -314,8 +314,8 @@
314 314  
315 315 #define query_3270_terminal_status(void) lib3270_get_program_message(NULL)
316 316  
317   - #define set_3270_model(h,m) lib3270_set_model(h,m)
318   - #define get_3270_model(h) lib3270_get_model(h)
  317 +// #define set_3270_model(h,m) lib3270_set_model(h,m)
  318 +// #define get_3270_model(h) lib3270_get_model(h)
319 319  
320 320 /* Get connection info */
321 321 #define get_connected_lu(h) lib3270_get_luname(h)
... ...
src/lib3270/ctlr.c
... ... @@ -150,6 +150,84 @@ void ctlr_reinit(H3270 *session, unsigned cmask)
150 150 }
151 151 }
152 152  
  153 + /**
  154 + * Parse the model number.
  155 + *
  156 + * @param session Session Handle.
  157 + * @param m Model number.
  158 + *
  159 + * @return -1 (error), 0 (default), or the specified number.
  160 + */
  161 +static int parse_model_number(H3270 *session, const char *m)
  162 +{
  163 + int sl;
  164 + int n;
  165 +
  166 + if(!m)
  167 + return 0;
  168 +
  169 + sl = strlen(m);
  170 +
  171 + /* An empty model number is no good. */
  172 + if (!sl)
  173 + return 0;
  174 +
  175 + if (sl > 1) {
  176 + /*
  177 + * If it's longer than one character, it needs to start with
  178 + * '327[89]', and it sets the m3279 resource.
  179 + */
  180 + if (!strncmp(m, "3278", 4))
  181 + {
  182 + session->m3279 = 0;
  183 + }
  184 + else if (!strncmp(m, "3279", 4))
  185 + {
  186 + session->m3279 = 1;
  187 + }
  188 + else
  189 + {
  190 + return -1;
  191 + }
  192 + m += 4;
  193 + sl -= 4;
  194 +
  195 + /* Check more syntax. -E is allowed, but ignored. */
  196 + switch (m[0]) {
  197 + case '\0':
  198 + /* Use default model number. */
  199 + return 0;
  200 + case '-':
  201 + /* Model number specified. */
  202 + m++;
  203 + sl--;
  204 + break;
  205 + default:
  206 + return -1;
  207 + }
  208 + switch (sl) {
  209 + case 1: /* n */
  210 + break;
  211 + case 3: /* n-E */
  212 + if (strcasecmp(m + 1, "-E")) {
  213 + return -1;
  214 + }
  215 + break;
  216 + default:
  217 + return -1;
  218 + }
  219 + }
  220 +
  221 + /* Check the numeric model number. */
  222 + n = atoi(m);
  223 + if (n >= 2 && n <= 5) {
  224 + return n;
  225 + } else {
  226 + return -1;
  227 + }
  228 +
  229 +}
  230 +
153 231 /**
154 232 * Get current 3270 model.
155 233 *
... ... @@ -166,7 +244,7 @@ int lib3270_get_model(H3270 *hSession)
166 244 *
167 245 * @param hSession Session handle.
168 246 * @param model New model (updates model name)
169   - */
  247 + */ /*
170 248 int lib3270_set_model(H3270 *hSession, int model)
171 249 {
172 250 if(CONNECTED)
... ... @@ -176,6 +254,72 @@ int lib3270_set_model(H3270 *hSession, int model)
176 254 ctlr_reinit(hSession,MODEL_CHANGE);
177 255 screen_update(hSession,0,hSession->rows*hSession->cols);
178 256 return 0;
  257 +} */
  258 +
  259 +int lib3270_set_model(H3270 *hSession, const char *model)
  260 +{
  261 + int ovc, ovr;
  262 + char junk;
  263 + int model_number;
  264 +
  265 + if(hSession->cstate != LIB3270_NOT_CONNECTED)
  266 + return EBUSY;
  267 +
  268 + strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);
  269 + hSession->model_name = &hSession->full_model_name[4];
  270 +
  271 + if(!*model)
  272 + model = "2"; // No model, use the default one
  273 +
  274 + model_number = parse_model_number(hSession,model);
  275 + if (model_number < 0)
  276 + {
  277 + popup_an_error(hSession,"Invalid model number: %s", model);
  278 + model_number = 0;
  279 + }
  280 +
  281 + if (!model_number)
  282 + {
  283 +#if defined(RESTRICT_3279)
  284 + model_number = 3;
  285 +#else
  286 + model_number = 4;
  287 +#endif
  288 + }
  289 +
  290 + if(hSession->mono)
  291 + hSession->m3279 = 0;
  292 + else
  293 + hSession->m3279 = 1;
  294 +
  295 + if(!hSession->extended)
  296 + hSession->oversize = CN;
  297 +
  298 +#if defined(RESTRICT_3279)
  299 + if (hSession->m3279 && model_number == 4)
  300 + model_number = 3;
  301 +#endif
  302 +
  303 + trace("Model_number: %d",model_number);
  304 +
  305 + if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2)
  306 + {
  307 + ovc = 0;
  308 + ovr = 0;
  309 + }
  310 + ctlr_set_rows_cols(hSession, model_number, ovc, ovr);
  311 +
  312 + if (hSession->termname != CN)
  313 + hSession->termtype = hSession->termname;
  314 + else
  315 + hSession->termtype = hSession->full_model_name;
  316 +
  317 + trace("Termtype: %s",hSession->termtype);
  318 +
  319 + ctlr_reinit(hSession,MODEL_CHANGE);
  320 + screen_update(hSession,0,hSession->rows*hSession->cols);
  321 +
  322 + return 0;
179 323 }
180 324  
181 325 void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr)
... ...
src/lib3270/session.c
... ... @@ -54,8 +54,6 @@
54 54  
55 55 /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/
56 56  
57   - static int parse_model_number(H3270 *session, const char *m);
58   -
59 57 /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
60 58  
61 59 void lib3270_session_free(H3270 *h)
... ... @@ -184,69 +182,6 @@ static void nop_int(H3270 *session, int width)
184 182 return;
185 183 }
186 184  
187   -int lib3270_set_model_name(H3270 *hSession, const char *model)
188   -{
189   - int ovc, ovr;
190   - char junk;
191   - int model_number;
192   -
193   - if(hSession->cstate != LIB3270_NOT_CONNECTED)
194   - return EBUSY;
195   -
196   - strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);
197   - hSession->model_name = &hSession->full_model_name[4];
198   -
199   - if(!*model)
200   - model = "2"; // No model, use the default one
201   -
202   - model_number = parse_model_number(hSession,model);
203   - if (model_number < 0)
204   - {
205   - popup_an_error(hSession,"Invalid model number: %s", model);
206   - model_number = 0;
207   - }
208   -
209   - if (!model_number)
210   - {
211   -#if defined(RESTRICT_3279)
212   - model_number = 3;
213   -#else
214   - model_number = 4;
215   -#endif
216   - }
217   -
218   - if(hSession->mono)
219   - hSession->m3279 = 0;
220   - else
221   - hSession->m3279 = 1;
222   -
223   - if(!hSession->extended)
224   - hSession->oversize = CN;
225   -
226   -#if defined(RESTRICT_3279)
227   - if (hSession->m3279 && model_number == 4)
228   - model_number = 3;
229   -#endif
230   -
231   - trace("Model_number: %d",model_number);
232   -
233   - if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2)
234   - {
235   - ovc = 0;
236   - ovr = 0;
237   - }
238   - ctlr_set_rows_cols(hSession, model_number, ovc, ovr);
239   -
240   - if (hSession->termname != CN)
241   - hSession->termtype = hSession->termname;
242   - else
243   - hSession->termtype = hSession->full_model_name;
244   -
245   - trace("Termtype: %s",hSession->termtype);
246   -
247   - return 0;
248   -}
249   -
250 185 static void lib3270_session_init(H3270 *hSession, const char *model, const char *charset)
251 186 {
252 187 int f;
... ... @@ -313,7 +248,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char
313 248 // Initialize toggles
314 249 initialize_toggles(hSession);
315 250  
316   - lib3270_set_model_name(hSession,model);
  251 + lib3270_set_model(hSession,model);
317 252  
318 253 }
319 254  
... ... @@ -357,84 +292,6 @@ H3270 * lib3270_session_new(const char *model)
357 292 return hSession;
358 293 }
359 294  
360   - /**
361   - * Parse the model number.
362   - *
363   - * @param session Session Handle.
364   - * @param m Model number.
365   - *
366   - * @return -1 (error), 0 (default), or the specified number.
367   - */
368   -static int parse_model_number(H3270 *session, const char *m)
369   -{
370   - int sl;
371   - int n;
372   -
373   - if(!m)
374   - return 0;
375   -
376   - sl = strlen(m);
377   -
378   - /* An empty model number is no good. */
379   - if (!sl)
380   - return 0;
381   -
382   - if (sl > 1) {
383   - /*
384   - * If it's longer than one character, it needs to start with
385   - * '327[89]', and it sets the m3279 resource.
386   - */
387   - if (!strncmp(m, "3278", 4))
388   - {
389   - session->m3279 = 0;
390   - }
391   - else if (!strncmp(m, "3279", 4))
392   - {
393   - session->m3279 = 1;
394   - }
395   - else
396   - {
397   - return -1;
398   - }
399   - m += 4;
400   - sl -= 4;
401   -
402   - /* Check more syntax. -E is allowed, but ignored. */
403   - switch (m[0]) {
404   - case '\0':
405   - /* Use default model number. */
406   - return 0;
407   - case '-':
408   - /* Model number specified. */
409   - m++;
410   - sl--;
411   - break;
412   - default:
413   - return -1;
414   - }
415   - switch (sl) {
416   - case 1: /* n */
417   - break;
418   - case 3: /* n-E */
419   - if (strcasecmp(m + 1, "-E")) {
420   - return -1;
421   - }
422   - break;
423   - default:
424   - return -1;
425   - }
426   - }
427   -
428   - /* Check the numeric model number. */
429   - n = atoi(m);
430   - if (n >= 2 && n <= 5) {
431   - return n;
432   - } else {
433   - return -1;
434   - }
435   -
436   -}
437   -
438 295 #if defined(DEBUG)
439 296 void check_session_handle(H3270 **hSession, const char *fname)
440 297 #else
... ...
src/pw3270/main.c
... ... @@ -61,6 +61,7 @@
61 61 static const gchar * logfile = NULL;
62 62 static const gchar * tracefile = NULL;
63 63 static const gchar * charset = NULL;
  64 + static const gchar * model = NULL;
64 65  
65 66 #ifdef HAVE_GTKMAC
66 67 GtkOSXApplication * osxapp = NULL;
... ... @@ -394,24 +395,25 @@ int main(int argc, char *argv[])
394 395 static const GOptionEntry app_options[] =
395 396 {
396 397 #if ! defined( WIN32 )
397   - { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME },
  398 + { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME },
398 399 #else
399   - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME },
  400 + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME },
400 401 { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL },
401 402 #endif // WIN32
402   - { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME },
403   - { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL },
404   - { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" },
405   - { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" },
406   - { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL },
407   - { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL },
408   - { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), NULL },
  403 + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME },
  404 + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL },
  405 + { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" },
  406 + { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" },
  407 + { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL },
  408 + { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL },
  409 + { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), NULL },
  410 + { "model", 'M', 0, G_OPTION_ARG_STRING, &model, N_( "The model of 3270 display to be emulated." ), NULL },
409 411  
410 412 #if defined( HAVE_SYSLOG )
411   - { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL },
  413 + { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL },
412 414 #endif
413   - { "tracefile", 'T', 0, G_OPTION_ARG_FILENAME, &tracefile, N_( "Set trace filename" ), NULL },
414   - { "log", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, N_( "Log to file" ), NULL },
  415 + { "tracefile", 'T', 0, G_OPTION_ARG_FILENAME, &tracefile, N_( "Set trace filename" ), NULL },
  416 + { "log", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, N_( "Log to file" ), NULL },
415 417  
416 418 { NULL }
417 419 };
... ... @@ -557,6 +559,9 @@ int main(int argc, char *argv[])
557 559 else
558 560 pw3270_restore_window(toplevel,"toplevel");
559 561  
  562 + if(model)
  563 + lib3270_set_model(pw3270_get_session(toplevel),model);
  564 +
560 565 pw3270_start_plugins(toplevel);
561 566 gtk_window_present(GTK_WINDOW(toplevel));
562 567  
... ...
src/pw3270/window.c
... ... @@ -344,8 +344,13 @@
344 344 {
345 345 if(gtk_check_menu_item_get_active(item))
346 346 {
  347 + char name[2];
  348 +
347 349 trace("screen model on widget %p changes to %d",widget,GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270")));
348   - lib3270_set_model(v3270_get_session(widget),GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270")));
  350 +
  351 + name[0] = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),"mode_3270"))+'0';
  352 + name[1] = 0;
  353 + lib3270_set_model(v3270_get_session(widget),name);
349 354 }
350 355 }
351 356  
... ... @@ -450,6 +455,7 @@
450 455 {
451 456 trace("Widget %p changed to %s (id=%d)",widget,name,id);
452 457 set_integer_to_config("terminal","model",id);
  458 + set_string_to_config("terminal","model_name","%s",name);
453 459 }
454 460  
455 461 static void selecting(GtkWidget *widget, gboolean on, GtkActionGroup **group)
... ... @@ -572,7 +578,12 @@
572 578 if(str)
573 579 g_free(str);
574 580 }
575   - lib3270_set_model(v3270_get_session(widget->terminal),get_integer_from_config("terminal","model",2));
  581 + {
  582 + char str[2];
  583 + str[0] = get_integer_from_config("terminal","model",2)+'0';
  584 + str[1] = 0;
  585 + lib3270_set_model(v3270_get_session(widget->terminal),str);
  586 + }
576 587  
577 588 for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
578 589 {
... ...