Commit fae7d9d28a7f4e490bc82f31fd4b2ff282326eec
1 parent
9d289f73
Exists in
master
and in
3 other branches
Separando alocação/liberação da estrutura de sessão num bloco separado, reorgani…
…zando gerenciamento de buffers, melhorando apresentação da posição do cursor que as vezes, ficava cortada
Showing
8 changed files
with
378 additions
and
310 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -89,7 +89,7 @@ $(OBJRLS)/%.o: %.c $(DEPENDS) |
| 89 | 89 | |
| 90 | 90 | #---[ Sources ]---------------------------------------------------------------- |
| 91 | 91 | |
| 92 | -SOURCES = XtGlue.c actions.c ansi.c charset.c ctlr.c \ | |
| 92 | +SOURCES = XtGlue.c init.c actions.c ansi.c charset.c ctlr.c \ | |
| 93 | 93 | ft.c ft_cut.c ft_dft.c glue.c host.c kybd.c \ |
| 94 | 94 | print.c printer.c proxy.c resources.c rpq.c screen.c see.c \ |
| 95 | 95 | sf.c tables.c telnet.c toggles.c trace_ds.c utf8.c util.c \ | ... | ... |
XtGlue.c
| ... | ... | @@ -555,8 +555,7 @@ static int DefaultProcessEvents(int block) |
| 555 | 555 | |
| 556 | 556 | /*---[ Implement external calls ]---------------------------------------------------------------------------*/ |
| 557 | 557 | |
| 558 | -void * | |
| 559 | -Malloc(size_t len) | |
| 558 | +void * Malloc(size_t len) | |
| 560 | 559 | { |
| 561 | 560 | char *r; |
| 562 | 561 | |
| ... | ... | @@ -566,11 +565,10 @@ Malloc(size_t len) |
| 566 | 565 | return r; |
| 567 | 566 | } |
| 568 | 567 | |
| 569 | -void * | |
| 570 | -Calloc(size_t nelem, size_t elsize) | |
| 568 | +void * Calloc(size_t nelem, size_t elsize) | |
| 571 | 569 | { |
| 572 | - int sz = nelem * elsize; | |
| 573 | - char *r = malloc(sz); | |
| 570 | + int sz = nelem * elsize; | |
| 571 | + char * r = malloc(sz); | |
| 574 | 572 | |
| 575 | 573 | if(!r) |
| 576 | 574 | Error(NULL,"Out of memory"); |
| ... | ... | @@ -579,8 +577,7 @@ Calloc(size_t nelem, size_t elsize) |
| 579 | 577 | return r; |
| 580 | 578 | } |
| 581 | 579 | |
| 582 | -void * | |
| 583 | -Realloc(void *p, size_t len) | |
| 580 | +void * Realloc(void *p, size_t len) | |
| 584 | 581 | { |
| 585 | 582 | p = realloc(p, len); |
| 586 | 583 | if (p == NULL) |
| ... | ... | @@ -590,10 +587,28 @@ Realloc(void *p, size_t len) |
| 590 | 587 | |
| 591 | 588 | void Free(void *p) |
| 592 | 589 | { |
| 593 | - if (p != NULL) | |
| 590 | + if(p) | |
| 594 | 591 | free(p); |
| 595 | 592 | } |
| 596 | 593 | |
| 594 | +void * lib3270_calloc(size_t elsize, size_t nelem, void *ptr) | |
| 595 | +{ | |
| 596 | + size_t sz = nelem * elsize; | |
| 597 | + | |
| 598 | + if(ptr) | |
| 599 | + ptr = realloc(ptr,sz); | |
| 600 | + else | |
| 601 | + ptr = malloc(sz); | |
| 602 | + | |
| 603 | + if(ptr) | |
| 604 | + memset(ptr,0,sz); | |
| 605 | + else | |
| 606 | + Error(NULL,"Out of memory"); | |
| 607 | + | |
| 608 | + return ptr; | |
| 609 | +} | |
| 610 | + | |
| 611 | + | |
| 597 | 612 | static struct { |
| 598 | 613 | const char *name; |
| 599 | 614 | KeySym keysym; | ... | ... |
ctlr.c
| ... | ... | @@ -91,7 +91,7 @@ Boolean dbcs = False; |
| 91 | 91 | |
| 92 | 92 | /* Statics */ |
| 93 | 93 | static struct ea *aea_buf; /* alternate 3270 extended attribute buffer */ |
| 94 | -static unsigned char *zero_buf; /* empty buffer, for area clears */ | |
| 94 | +static unsigned char *zero_buf; // empty buffer, for area clears | |
| 95 | 95 | static void set_formatted(H3270 *session); |
| 96 | 96 | static void ctlr_blanks(void); |
| 97 | 97 | static Boolean trace_primed = False; |
| ... | ... | @@ -160,22 +160,28 @@ void ctlr_init(H3270 *session, unsigned cmask unused) |
| 160 | 160 | */ |
| 161 | 161 | void ctlr_reinit(H3270 *session, unsigned cmask) |
| 162 | 162 | { |
| 163 | - static struct ea *real_ea_buf = NULL; | |
| 164 | - static struct ea *real_aea_buf = NULL; | |
| 163 | +// static struct ea *real_ea_buf = NULL; | |
| 164 | +// static struct ea *real_aea_buf = NULL; | |
| 165 | 165 | |
| 166 | - if (cmask & MODEL_CHANGE) { | |
| 166 | + if (cmask & MODEL_CHANGE) | |
| 167 | + { | |
| 167 | 168 | /* Allocate buffers */ |
| 168 | - if (real_ea_buf) | |
| 169 | - Free((char *)real_ea_buf); | |
| 170 | - real_ea_buf = (struct ea *)Calloc(sizeof(struct ea),(session->maxROWS * session->maxCOLS) + 1); | |
| 171 | - session->ea_buf = real_ea_buf + 1; | |
| 172 | - if (real_aea_buf) | |
| 173 | - Free((char *)real_aea_buf); | |
| 174 | - real_aea_buf = (struct ea *)Calloc(sizeof(struct ea),(session->maxROWS * session->maxCOLS) + 1); | |
| 175 | - aea_buf = real_aea_buf + 1; | |
| 176 | - Replace(zero_buf, (unsigned char *)Calloc(sizeof(struct ea),session->maxROWS * session->maxCOLS)); | |
| 177 | - session->cursor_addr = 0; | |
| 178 | - buffer_addr = 0; | |
| 169 | + struct ea *tmp; | |
| 170 | + size_t sz = (session->maxROWS * session->maxCOLS); | |
| 171 | + | |
| 172 | + | |
| 173 | + session->buffer[0] = tmp = lib3270_calloc(sizeof(struct ea),sz+1, session->buffer[0]); | |
| 174 | + session->ea_buf = tmp + 1; | |
| 175 | + | |
| 176 | + session->buffer[1] = tmp = lib3270_calloc(sizeof(struct ea),sz+1,session->buffer[1]); | |
| 177 | + aea_buf = tmp + 1; | |
| 178 | + | |
| 179 | + session->text = lib3270_calloc(sizeof(struct lib3270_text),sz,session->text); | |
| 180 | + | |
| 181 | + Replace(zero_buf, (unsigned char *)Calloc(sizeof(struct ea),sz)); | |
| 182 | + | |
| 183 | + session->cursor_addr = 0; | |
| 184 | + buffer_addr = 0; | |
| 179 | 185 | } |
| 180 | 186 | } |
| 181 | 187 | |
| ... | ... | @@ -2551,8 +2557,7 @@ ctlr_bcopy(int baddr_from, int baddr_to, int count, int move_ea) |
| 2551 | 2557 | * Erase a region of the 3270 buffer, optionally clearing extended attributes |
| 2552 | 2558 | * as well. |
| 2553 | 2559 | */ |
| 2554 | -void | |
| 2555 | -ctlr_aclear(int baddr, int count, int clear_ea) | |
| 2560 | +void ctlr_aclear(int baddr, int count, int clear_ea) | |
| 2556 | 2561 | { |
| 2557 | 2562 | if (memcmp((char *) &h3270.ea_buf[baddr], (char *) zero_buf, |
| 2558 | 2563 | count * sizeof(struct ea))) { | ... | ... |
glue.c
| ... | ... | @@ -99,10 +99,6 @@ |
| 99 | 99 | |
| 100 | 100 | #define LAST_ARG "--" |
| 101 | 101 | |
| 102 | -/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ | |
| 103 | - | |
| 104 | - static int parse_model_number(const char *m); | |
| 105 | - | |
| 106 | 102 | /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ |
| 107 | 103 | H3270 h3270; |
| 108 | 104 | const char * programname; |
| ... | ... | @@ -117,179 +113,6 @@ |
| 117 | 113 | char *profile_name = CN; |
| 118 | 114 | #endif /*]*/ |
| 119 | 115 | |
| 120 | -void lib3270_session_free(H3270 *h) | |
| 121 | -{ | |
| 122 | - int f; | |
| 123 | - | |
| 124 | - // Terminate session | |
| 125 | - if(lib3270_connected(h)) | |
| 126 | - lib3270_disconnect(h); | |
| 127 | - | |
| 128 | - shutdown_toggles(h,appres.toggle); | |
| 129 | - | |
| 130 | - // Release state change callbacks | |
| 131 | - for(f=0;f<N_ST;f++) | |
| 132 | - { | |
| 133 | - while(h->st_callbacks[f]) | |
| 134 | - { | |
| 135 | - struct lib3270_state_callback *next = h->st_callbacks[f]->next; | |
| 136 | - Free(h->st_callbacks[f]); | |
| 137 | - h->st_callbacks[f] = next; | |
| 138 | - } | |
| 139 | - } | |
| 140 | - | |
| 141 | - // Release memory | |
| 142 | - #define RELEASE_BUFFER(x) if(x) { free(x); x = NULL; } | |
| 143 | - | |
| 144 | - RELEASE_BUFFER(h->charset); | |
| 145 | - RELEASE_BUFFER(h->paste_buffer); | |
| 146 | - | |
| 147 | -} | |
| 148 | - | |
| 149 | -static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) | |
| 150 | -{ | |
| 151 | - | |
| 152 | -} | |
| 153 | - | |
| 154 | -static void nop_char(H3270 *session, unsigned char chr) | |
| 155 | -{ | |
| 156 | - | |
| 157 | -} | |
| 158 | - | |
| 159 | -static void nop(H3270 *session) | |
| 160 | -{ | |
| 161 | - | |
| 162 | -} | |
| 163 | - | |
| 164 | -static void lib3270_session_init(H3270 *hSession, const char *model) | |
| 165 | -{ | |
| 166 | - int ovc, ovr; | |
| 167 | - char junk; | |
| 168 | - int model_number; | |
| 169 | - | |
| 170 | - memset(hSession,0,sizeof(H3270)); | |
| 171 | - hSession->sz = sizeof(H3270); | |
| 172 | - | |
| 173 | - // A few dummy calls to avoid "ifs" | |
| 174 | - hSession->update = update_char; | |
| 175 | - hSession->set_selection = nop_char; | |
| 176 | - hSession->ctlr_done = nop; | |
| 177 | - | |
| 178 | - hSession->sock = -1; | |
| 179 | - hSession->model_num = -1; | |
| 180 | - hSession->cstate = NOT_CONNECTED; | |
| 181 | - hSession->oia_status = -1; | |
| 182 | - | |
| 183 | - strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); | |
| 184 | - hSession->model_name = &hSession->full_model_name[4]; | |
| 185 | - | |
| 186 | - /* | |
| 187 | - * Sort out model and color modes, based on the model number resource. | |
| 188 | - */ /* | |
| 189 | - if(appres.model && *appres.model) | |
| 190 | - model = appres.model; | |
| 191 | - */ | |
| 192 | - | |
| 193 | - if(!*model) | |
| 194 | - model = "2"; // No model, use the default one | |
| 195 | - | |
| 196 | -// Trace("Parsing model: %s",appres.model); | |
| 197 | - model_number = parse_model_number(model); | |
| 198 | - if (model_number < 0) | |
| 199 | - { | |
| 200 | - popup_an_error(NULL,"Invalid model number: %s", model); | |
| 201 | - model_number = 0; | |
| 202 | - } | |
| 203 | - | |
| 204 | - if (!model_number) | |
| 205 | - { | |
| 206 | -#if defined(RESTRICT_3279) | |
| 207 | - model_number = 3; | |
| 208 | -#else | |
| 209 | - model_number = 4; | |
| 210 | -#endif | |
| 211 | - } | |
| 212 | - | |
| 213 | - if(appres.mono) | |
| 214 | - appres.m3279 = False; | |
| 215 | - | |
| 216 | - if(!appres.extended) | |
| 217 | - appres.oversize = CN; | |
| 218 | - | |
| 219 | -#if defined(RESTRICT_3279) | |
| 220 | - if (appres.m3279 && model_number == 4) | |
| 221 | - model_number = 3; | |
| 222 | -#endif | |
| 223 | - | |
| 224 | - Trace("Model_number: %d",model_number); | |
| 225 | - | |
| 226 | - if (!appres.extended || appres.oversize == CN || sscanf(appres.oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) | |
| 227 | - { | |
| 228 | - ovc = 0; | |
| 229 | - ovr = 0; | |
| 230 | - } | |
| 231 | - ctlr_set_rows_cols(hSession, model_number, ovc, ovr); | |
| 232 | - | |
| 233 | - if (appres.termname != CN) | |
| 234 | - hSession->termtype = appres.termname; | |
| 235 | - else | |
| 236 | - hSession->termtype = hSession->full_model_name; | |
| 237 | - | |
| 238 | - Trace("Termtype: %s",hSession->termtype); | |
| 239 | - | |
| 240 | - if (appres.apl_mode) | |
| 241 | - appres.charset = Apl; | |
| 242 | - | |
| 243 | -} | |
| 244 | - | |
| 245 | -H3270 * lib3270_session_new(const char *model) | |
| 246 | -{ | |
| 247 | - static int configured = 0; | |
| 248 | - | |
| 249 | - H3270 *hSession = &h3270; | |
| 250 | - | |
| 251 | - Trace("%s - configured=%d",__FUNCTION__,configured); | |
| 252 | - | |
| 253 | - if(configured) | |
| 254 | - { | |
| 255 | - // TODO (perry#5#): Allocate a new structure. | |
| 256 | - errno = EBUSY; | |
| 257 | - return hSession; | |
| 258 | - } | |
| 259 | - | |
| 260 | - configured = 1; | |
| 261 | - | |
| 262 | - lib3270_session_init(hSession, model); | |
| 263 | - | |
| 264 | - if(screen_init(hSession)) | |
| 265 | - return NULL; | |
| 266 | - | |
| 267 | - Trace("Charset: %s",appres.charset); | |
| 268 | - if (charset_init(hSession,appres.charset) != CS_OKAY) | |
| 269 | - { | |
| 270 | - Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), appres.charset); | |
| 271 | - (void) charset_init(hSession,CN); | |
| 272 | - } | |
| 273 | - | |
| 274 | - kybd_init(); | |
| 275 | -// hostfile_init(); | |
| 276 | -// hostfile_init(); | |
| 277 | - ansi_init(); | |
| 278 | - | |
| 279 | -#if defined(X3270_FT) | |
| 280 | - ft_init(); | |
| 281 | -#endif | |
| 282 | - | |
| 283 | -#if defined(X3270_PRINTER) | |
| 284 | - printer_init(); | |
| 285 | -#endif | |
| 286 | - | |
| 287 | - Trace("%s finished",__FUNCTION__); | |
| 288 | - | |
| 289 | - errno = 0; | |
| 290 | - return hSession; | |
| 291 | -} | |
| 292 | - | |
| 293 | 116 | /* |
| 294 | 117 | * Set default options |
| 295 | 118 | */ |
| ... | ... | @@ -536,75 +359,6 @@ const struct lib3270_option * get_3270_option_table(int sz) |
| 536 | 359 | } |
| 537 | 360 | |
| 538 | 361 | /* |
| 539 | - * Parse the model number. | |
| 540 | - * Returns -1 (error), 0 (default), or the specified number. | |
| 541 | - */ | |
| 542 | -static int parse_model_number(const char *m) | |
| 543 | -{ | |
| 544 | - int sl; | |
| 545 | - int n; | |
| 546 | - | |
| 547 | - if(!m) | |
| 548 | - return 0; | |
| 549 | - | |
| 550 | - sl = strlen(m); | |
| 551 | - | |
| 552 | - /* An empty model number is no good. */ | |
| 553 | - if (!sl) | |
| 554 | - return 0; | |
| 555 | - | |
| 556 | - if (sl > 1) { | |
| 557 | - /* | |
| 558 | - * If it's longer than one character, it needs to start with | |
| 559 | - * '327[89]', and it sets the m3279 resource. | |
| 560 | - */ | |
| 561 | - if (!strncmp(m, "3278", 4)) { | |
| 562 | - appres.m3279 = False; | |
| 563 | - } else if (!strncmp(m, "3279", 4)) { | |
| 564 | - appres.m3279 = True; | |
| 565 | - } else { | |
| 566 | - return -1; | |
| 567 | - } | |
| 568 | - m += 4; | |
| 569 | - sl -= 4; | |
| 570 | - | |
| 571 | - /* Check more syntax. -E is allowed, but ignored. */ | |
| 572 | - switch (m[0]) { | |
| 573 | - case '\0': | |
| 574 | - /* Use default model number. */ | |
| 575 | - return 0; | |
| 576 | - case '-': | |
| 577 | - /* Model number specified. */ | |
| 578 | - m++; | |
| 579 | - sl--; | |
| 580 | - break; | |
| 581 | - default: | |
| 582 | - return -1; | |
| 583 | - } | |
| 584 | - switch (sl) { | |
| 585 | - case 1: /* n */ | |
| 586 | - break; | |
| 587 | - case 3: /* n-E */ | |
| 588 | - if (strcasecmp(m + 1, "-E")) { | |
| 589 | - return -1; | |
| 590 | - } | |
| 591 | - break; | |
| 592 | - default: | |
| 593 | - return -1; | |
| 594 | - } | |
| 595 | - } | |
| 596 | - | |
| 597 | - /* Check the numeric model number. */ | |
| 598 | - n = atoi(m); | |
| 599 | - if (n >= 2 && n <= 5) { | |
| 600 | - return n; | |
| 601 | - } else { | |
| 602 | - return -1; | |
| 603 | - } | |
| 604 | - | |
| 605 | -} | |
| 606 | - | |
| 607 | -/* | |
| 608 | 362 | * Parse '-xrm' options. |
| 609 | 363 | * Understands only: |
| 610 | 364 | * {c,s,tcl}3270.<resourcename>: value | ... | ... |
| ... | ... | @@ -0,0 +1,279 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como init.c e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * licinio@bb.com.br (Licínio Luis Branco) | |
| 28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
| 29 | + * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | |
| 30 | + * | |
| 31 | + */ | |
| 32 | + | |
| 33 | + | |
| 34 | +#include "globals.h" | |
| 35 | +#include "appres.h" | |
| 36 | +#include "charsetc.h" | |
| 37 | + | |
| 38 | +/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ | |
| 39 | + | |
| 40 | + static int parse_model_number(H3270 *session, const char *m); | |
| 41 | + | |
| 42 | +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ | |
| 43 | + | |
| 44 | +void lib3270_session_free(H3270 *h) | |
| 45 | +{ | |
| 46 | + int f; | |
| 47 | + | |
| 48 | + // Terminate session | |
| 49 | + if(lib3270_connected(h)) | |
| 50 | + lib3270_disconnect(h); | |
| 51 | + | |
| 52 | + shutdown_toggles(h,appres.toggle); | |
| 53 | + | |
| 54 | + // Release state change callbacks | |
| 55 | + for(f=0;f<N_ST;f++) | |
| 56 | + { | |
| 57 | + while(h->st_callbacks[f]) | |
| 58 | + { | |
| 59 | + struct lib3270_state_callback *next = h->st_callbacks[f]->next; | |
| 60 | + Free(h->st_callbacks[f]); | |
| 61 | + h->st_callbacks[f] = next; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + // Release memory | |
| 66 | + #define RELEASE_BUFFER(x) if(x) { free(x); x = NULL; } | |
| 67 | + | |
| 68 | + RELEASE_BUFFER(h->charset); | |
| 69 | + RELEASE_BUFFER(h->paste_buffer); | |
| 70 | + | |
| 71 | + for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++) | |
| 72 | + { | |
| 73 | + RELEASE_BUFFER(h->buffer[f]); | |
| 74 | + } | |
| 75 | + | |
| 76 | +} | |
| 77 | + | |
| 78 | +static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) | |
| 79 | +{ | |
| 80 | + | |
| 81 | +} | |
| 82 | + | |
| 83 | +static void nop_char(H3270 *session, unsigned char chr) | |
| 84 | +{ | |
| 85 | + | |
| 86 | +} | |
| 87 | + | |
| 88 | +static void nop(H3270 *session) | |
| 89 | +{ | |
| 90 | + | |
| 91 | +} | |
| 92 | + | |
| 93 | +static void lib3270_session_init(H3270 *hSession, const char *model) | |
| 94 | +{ | |
| 95 | + int ovc, ovr; | |
| 96 | + char junk; | |
| 97 | + int model_number; | |
| 98 | + | |
| 99 | + memset(hSession,0,sizeof(H3270)); | |
| 100 | + hSession->sz = sizeof(H3270); | |
| 101 | + | |
| 102 | + // A few dummy calls to avoid "ifs" | |
| 103 | + hSession->update = update_char; | |
| 104 | + hSession->set_selection = nop_char; | |
| 105 | + hSession->ctlr_done = nop; | |
| 106 | + | |
| 107 | + hSession->sock = -1; | |
| 108 | + hSession->model_num = -1; | |
| 109 | + hSession->cstate = NOT_CONNECTED; | |
| 110 | + hSession->oia_status = -1; | |
| 111 | + | |
| 112 | + strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); | |
| 113 | + hSession->model_name = &hSession->full_model_name[4]; | |
| 114 | + | |
| 115 | + if(!*model) | |
| 116 | + model = "2"; // No model, use the default one | |
| 117 | + | |
| 118 | + model_number = parse_model_number(hSession,model); | |
| 119 | + if (model_number < 0) | |
| 120 | + { | |
| 121 | + popup_an_error(NULL,"Invalid model number: %s", model); | |
| 122 | + model_number = 0; | |
| 123 | + } | |
| 124 | + | |
| 125 | + if (!model_number) | |
| 126 | + { | |
| 127 | +#if defined(RESTRICT_3279) | |
| 128 | + model_number = 3; | |
| 129 | +#else | |
| 130 | + model_number = 4; | |
| 131 | +#endif | |
| 132 | + } | |
| 133 | + | |
| 134 | + if(appres.mono) | |
| 135 | + appres.m3279 = False; | |
| 136 | + | |
| 137 | + if(!appres.extended) | |
| 138 | + appres.oversize = CN; | |
| 139 | + | |
| 140 | +#if defined(RESTRICT_3279) | |
| 141 | + if (appres.m3279 && model_number == 4) | |
| 142 | + model_number = 3; | |
| 143 | +#endif | |
| 144 | + | |
| 145 | + Trace("Model_number: %d",model_number); | |
| 146 | + | |
| 147 | + if (!appres.extended || appres.oversize == CN || sscanf(appres.oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) | |
| 148 | + { | |
| 149 | + ovc = 0; | |
| 150 | + ovr = 0; | |
| 151 | + } | |
| 152 | + ctlr_set_rows_cols(hSession, model_number, ovc, ovr); | |
| 153 | + | |
| 154 | + if (appres.termname != CN) | |
| 155 | + hSession->termtype = appres.termname; | |
| 156 | + else | |
| 157 | + hSession->termtype = hSession->full_model_name; | |
| 158 | + | |
| 159 | + Trace("Termtype: %s",hSession->termtype); | |
| 160 | + | |
| 161 | + if (appres.apl_mode) | |
| 162 | + appres.charset = "apl"; | |
| 163 | + | |
| 164 | +} | |
| 165 | + | |
| 166 | +H3270 * lib3270_session_new(const char *model) | |
| 167 | +{ | |
| 168 | + static int configured = 0; | |
| 169 | + | |
| 170 | + H3270 *hSession = &h3270; | |
| 171 | + | |
| 172 | + Trace("%s - configured=%d",__FUNCTION__,configured); | |
| 173 | + | |
| 174 | + if(configured) | |
| 175 | + { | |
| 176 | + // TODO (perry#5#): Allocate a new structure. | |
| 177 | + errno = EBUSY; | |
| 178 | + return hSession; | |
| 179 | + } | |
| 180 | + | |
| 181 | + configured = 1; | |
| 182 | + | |
| 183 | + lib3270_session_init(hSession, model); | |
| 184 | + | |
| 185 | + if(screen_init(hSession)) | |
| 186 | + return NULL; | |
| 187 | + | |
| 188 | + Trace("Charset: %s",appres.charset); | |
| 189 | + if (charset_init(hSession,appres.charset) != CS_OKAY) | |
| 190 | + { | |
| 191 | + Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), appres.charset); | |
| 192 | + (void) charset_init(hSession,CN); | |
| 193 | + } | |
| 194 | + | |
| 195 | + kybd_init(); | |
| 196 | + ansi_init(); | |
| 197 | + | |
| 198 | +#if defined(X3270_FT) | |
| 199 | + ft_init(); | |
| 200 | +#endif | |
| 201 | + | |
| 202 | +#if defined(X3270_PRINTER) | |
| 203 | + printer_init(); | |
| 204 | +#endif | |
| 205 | + | |
| 206 | + Trace("%s finished",__FUNCTION__); | |
| 207 | + | |
| 208 | + errno = 0; | |
| 209 | + return hSession; | |
| 210 | +} | |
| 211 | + | |
| 212 | + /* | |
| 213 | +- * Parse the model number. | |
| 214 | +- * Returns -1 (error), 0 (default), or the specified number. | |
| 215 | +- */ | |
| 216 | +static int parse_model_number(H3270 *session, const char *m) | |
| 217 | +{ | |
| 218 | + int sl; | |
| 219 | + int n; | |
| 220 | + | |
| 221 | + if(!m) | |
| 222 | + return 0; | |
| 223 | + | |
| 224 | + sl = strlen(m); | |
| 225 | + | |
| 226 | + /* An empty model number is no good. */ | |
| 227 | + if (!sl) | |
| 228 | + return 0; | |
| 229 | + | |
| 230 | + if (sl > 1) { | |
| 231 | + /* | |
| 232 | + * If it's longer than one character, it needs to start with | |
| 233 | + * '327[89]', and it sets the m3279 resource. | |
| 234 | + */ | |
| 235 | + if (!strncmp(m, "3278", 4)) { | |
| 236 | + appres.m3279 = False; | |
| 237 | + } else if (!strncmp(m, "3279", 4)) { | |
| 238 | + appres.m3279 = True; | |
| 239 | + } else { | |
| 240 | + return -1; | |
| 241 | + } | |
| 242 | + m += 4; | |
| 243 | + sl -= 4; | |
| 244 | + | |
| 245 | + /* Check more syntax. -E is allowed, but ignored. */ | |
| 246 | + switch (m[0]) { | |
| 247 | + case '\0': | |
| 248 | + /* Use default model number. */ | |
| 249 | + return 0; | |
| 250 | + case '-': | |
| 251 | + /* Model number specified. */ | |
| 252 | + m++; | |
| 253 | + sl--; | |
| 254 | + break; | |
| 255 | + default: | |
| 256 | + return -1; | |
| 257 | + } | |
| 258 | + switch (sl) { | |
| 259 | + case 1: /* n */ | |
| 260 | + break; | |
| 261 | + case 3: /* n-E */ | |
| 262 | + if (strcasecmp(m + 1, "-E")) { | |
| 263 | + return -1; | |
| 264 | + } | |
| 265 | + break; | |
| 266 | + default: | |
| 267 | + return -1; | |
| 268 | + } | |
| 269 | + } | |
| 270 | + | |
| 271 | + /* Check the numeric model number. */ | |
| 272 | + n = atoi(m); | |
| 273 | + if (n >= 2 && n <= 5) { | |
| 274 | + return n; | |
| 275 | + } else { | |
| 276 | + return -1; | |
| 277 | + } | |
| 278 | + | |
| 279 | +} | ... | ... |
localdefs.h
| ... | ... | @@ -55,10 +55,25 @@ typedef struct _XtActionsRec{ |
| 55 | 55 | #define NoSymbol 0L |
| 56 | 56 | |
| 57 | 57 | /* These are local functions with similar semantics to X functions. */ |
| 58 | -void *Malloc(size_t); | |
| 59 | -void Free(void *); | |
| 60 | -void *Calloc(size_t, size_t); | |
| 61 | -void *Realloc(void *, size_t); | |
| 58 | + | |
| 59 | +void * Malloc(size_t); | |
| 60 | +void Free(void *); | |
| 61 | +void * Calloc(size_t, size_t); | |
| 62 | +void * Realloc(void *, size_t); | |
| 63 | + | |
| 64 | +/** | |
| 65 | + * Alloc/Realloc memory buffer. | |
| 66 | + * | |
| 67 | + * Allocate/reallocate an array. | |
| 68 | + * | |
| 69 | + * @param elsize Element size. | |
| 70 | + * @param nelem Number of elements in the array. | |
| 71 | + * @param ptr Pointer to the actual array. | |
| 72 | + * | |
| 73 | + * @return ptr allocated with the new array size. | |
| 74 | + * | |
| 75 | + */ | |
| 76 | +void * lib3270_calloc(size_t elsize, size_t nelem, void *ptr); | |
| 62 | 77 | |
| 63 | 78 | #define NewString(x) strdup(x) |
| 64 | 79 | //extern char *NewString(const char *); | ... | ... |
screen.c
| ... | ... | @@ -88,14 +88,14 @@ static void addch(H3270 *session, int baddr, unsigned char c, unsigned short att |
| 88 | 88 | { |
| 89 | 89 | // If set to keep selection adjust corresponding flag based on the current state |
| 90 | 90 | if(lib3270_get_toggle(session,LIB3270_TOGGLE_KEEP_SELECTED)) |
| 91 | - attr |= (session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED); | |
| 91 | + attr |= (session->text[baddr].attr & LIB3270_ATTR_SELECTED); | |
| 92 | 92 | |
| 93 | - if(session->ea_buf[baddr].chr == c && session->ea_buf[baddr].attr == attr) | |
| 93 | + if(session->text[baddr].chr == c && session->text[baddr].attr == attr) | |
| 94 | 94 | return; |
| 95 | 95 | |
| 96 | 96 | /* Converted char has changed, update it */ |
| 97 | - session->ea_buf[baddr].chr = c; | |
| 98 | - session->ea_buf[baddr].attr = attr; | |
| 97 | + session->text[baddr].chr = c; | |
| 98 | + session->text[baddr].attr = attr; | |
| 99 | 99 | |
| 100 | 100 | if(session->update) |
| 101 | 101 | session->update(session,baddr,c,attr,baddr == session->cursor_addr); |
| ... | ... | @@ -262,8 +262,8 @@ LIB3270_EXPORT int lib3270_get_contents(H3270 *h, int first, int last, unsigned |
| 262 | 262 | |
| 263 | 263 | for(baddr = first; baddr <= last;baddr++) |
| 264 | 264 | { |
| 265 | - *(chr++) = h3270.ea_buf[baddr].chr ? h3270.ea_buf[baddr].chr : ' '; | |
| 266 | - *(attr++) = h3270.ea_buf[baddr].attr; | |
| 265 | + *(chr++) = h->text[baddr].chr ? h->text[baddr].chr : ' '; | |
| 266 | + *(attr++) = h->text[baddr].attr; | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | return 0; |
| ... | ... | @@ -410,7 +410,7 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr) |
| 410 | 410 | h->cursor_addr = baddr; |
| 411 | 411 | |
| 412 | 412 | if(h->update_cursor) |
| 413 | - h->update_cursor(h,(unsigned short) (baddr/h->cols),(unsigned short) (baddr%h->cols),h->ea_buf[baddr].chr,h->ea_buf[baddr].attr); | |
| 413 | + h->update_cursor(h,(unsigned short) (baddr/h->cols),(unsigned short) (baddr%h->cols),h->text[baddr].chr,h->text[baddr].attr); | |
| 414 | 414 | |
| 415 | 415 | return ret; |
| 416 | 416 | } | ... | ... |
selection.c
| ... | ... | @@ -75,10 +75,10 @@ static void update_selected_rectangle(H3270 *session) |
| 75 | 75 | { |
| 76 | 76 | for(col = 0; col < session->cols;col++) |
| 77 | 77 | { |
| 78 | - if(!(row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && (session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 78 | + if(!(row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && (session->text[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 79 | 79 | { |
| 80 | - session->ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 81 | - session->update(session,baddr,session->ea_buf[baddr].chr,session->ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 80 | + session->text[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 81 | + session->update(session,baddr,session->text[baddr].chr,session->text[baddr].attr,baddr == session->cursor_addr); | |
| 82 | 82 | } |
| 83 | 83 | baddr++; |
| 84 | 84 | } |
| ... | ... | @@ -90,10 +90,10 @@ static void update_selected_rectangle(H3270 *session) |
| 90 | 90 | { |
| 91 | 91 | for(col = 0; col < session->cols;col++) |
| 92 | 92 | { |
| 93 | - if((row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && !(session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 93 | + if((row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && !(session->text[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 94 | 94 | { |
| 95 | - session->ea_buf[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 96 | - session->update(session,baddr,session->ea_buf[baddr].chr,session->ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 95 | + session->text[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 96 | + session->update(session,baddr,session->text[baddr].chr,session->text[baddr].attr,baddr == session->cursor_addr); | |
| 97 | 97 | } |
| 98 | 98 | baddr++; |
| 99 | 99 | } |
| ... | ... | @@ -111,29 +111,29 @@ static void update_selected_region(H3270 *session) |
| 111 | 111 | // First remove unselected areas |
| 112 | 112 | for(baddr = 0; baddr < begin; baddr++) |
| 113 | 113 | { |
| 114 | - if(session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 114 | + if(session->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 115 | 115 | { |
| 116 | - session->ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 117 | - session->update(session,baddr,session->ea_buf[baddr].chr,session->ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 116 | + session->text[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 117 | + session->update(session,baddr,session->text[baddr].chr,session->text[baddr].attr,baddr == session->cursor_addr); | |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | for(baddr = end+1; baddr < len; baddr++) |
| 122 | 122 | { |
| 123 | - if(session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 123 | + if(session->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 124 | 124 | { |
| 125 | - session->ea_buf[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 126 | - session->update(session,baddr,session->ea_buf[baddr].chr,session->ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 125 | + session->text[baddr].attr &= ~LIB3270_ATTR_SELECTED; | |
| 126 | + session->update(session,baddr,session->text[baddr].chr,session->text[baddr].attr,baddr == session->cursor_addr); | |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Then draw the selected ones |
| 131 | 131 | for(baddr = begin; baddr <= end; baddr++) |
| 132 | 132 | { |
| 133 | - if(!(session->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 133 | + if(!(session->text[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 134 | 134 | { |
| 135 | - session->ea_buf[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 136 | - session->update(session,baddr,session->ea_buf[baddr].chr,session->ea_buf[baddr].attr,baddr == session->cursor_addr); | |
| 135 | + session->text[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 136 | + session->update(session,baddr,session->text[baddr].chr,session->text[baddr].attr,baddr == session->cursor_addr); | |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| ... | ... | @@ -180,11 +180,11 @@ LIB3270_ACTION(unselect) |
| 180 | 180 | |
| 181 | 181 | for(a = 0; a < hSession->rows*hSession->cols; a++) |
| 182 | 182 | { |
| 183 | - if(hSession->ea_buf[a].attr & LIB3270_ATTR_SELECTED) | |
| 183 | + if(hSession->text[a].attr & LIB3270_ATTR_SELECTED) | |
| 184 | 184 | { |
| 185 | - hSession->ea_buf[a].attr &= ~LIB3270_ATTR_SELECTED; | |
| 185 | + hSession->text[a].attr &= ~LIB3270_ATTR_SELECTED; | |
| 186 | 186 | if(hSession->update) |
| 187 | - hSession->update(hSession,a,hSession->ea_buf[a].chr,hSession->ea_buf[a].attr,a == hSession->cursor_addr); | |
| 187 | + hSession->update(hSession,a,hSession->text[a].chr,hSession->text[a].attr,a == hSession->cursor_addr); | |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| ... | ... | @@ -218,17 +218,17 @@ LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) |
| 218 | 218 | |
| 219 | 219 | CHECK_SESSION_HANDLE(session); |
| 220 | 220 | |
| 221 | - if(!lib3270_connected(session) || isspace(session->ea_buf[baddr].chr)) | |
| 221 | + if(!lib3270_connected(session) || isspace(session->text[baddr].chr)) | |
| 222 | 222 | { |
| 223 | 223 | lib3270_ring_bell(session); |
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - for(pos = baddr; pos > 0 && !isspace(session->ea_buf[pos].chr);pos--); | |
| 227 | + for(pos = baddr; pos > 0 && !isspace(session->text[pos].chr);pos--); | |
| 228 | 228 | session->select.begin = pos > 0 ? pos+1 : 0; |
| 229 | 229 | |
| 230 | 230 | len = session->rows * session->cols; |
| 231 | - for(pos = baddr; pos < len && !isspace(session->ea_buf[pos].chr);pos++); | |
| 231 | + for(pos = baddr; pos < len && !isspace(session->text[pos].chr);pos++); | |
| 232 | 232 | session->select.end = pos < len ? pos-1 : len; |
| 233 | 233 | |
| 234 | 234 | set_selected(session); |
| ... | ... | @@ -286,10 +286,10 @@ LIB3270_ACTION( selectall ) |
| 286 | 286 | // First remove unselected areas |
| 287 | 287 | for(baddr = 0; baddr < len; baddr++) |
| 288 | 288 | { |
| 289 | - if(!(hSession->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 289 | + if(!(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)) | |
| 290 | 290 | { |
| 291 | - hSession->ea_buf[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 292 | - hSession->update(hSession,baddr,hSession->ea_buf[baddr].chr,hSession->ea_buf[baddr].attr,baddr == hSession->cursor_addr); | |
| 291 | + hSession->text[baddr].attr |= LIB3270_ATTR_SELECTED; | |
| 292 | + hSession->update(hSession,baddr,hSession->text[baddr].chr,hSession->text[baddr].attr,baddr == hSession->cursor_addr); | |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
| ... | ... | @@ -329,10 +329,10 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) |
| 329 | 329 | |
| 330 | 330 | for(col = 0; col < hSession->cols;col++) |
| 331 | 331 | { |
| 332 | - if(hSession->ea_buf[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 332 | + if(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 333 | 333 | { |
| 334 | 334 | cr++; |
| 335 | - ret[sz++] = hSession->ea_buf[baddr].chr; | |
| 335 | + ret[sz++] = hSession->text[baddr].chr; | |
| 336 | 336 | } |
| 337 | 337 | baddr++; |
| 338 | 338 | } | ... | ... |