diff --git a/ctlr.c b/ctlr.c index d97ca9a..678abd8 100644 --- a/ctlr.c +++ b/ctlr.c @@ -67,7 +67,8 @@ // Boolean dbcs = False; /* Statics */ -static void set_formatted(H3270 *session); +static void update_formatted(H3270 *session); +static void set_formatted(H3270 *hSession, int state); static void ctlr_blanks(H3270 *session); static void ctlr_half_connect(H3270 *session, int ignored, void *dunno); static void ctlr_connect(H3270 *session, int ignored, void *dunno); @@ -224,37 +225,50 @@ void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr) set_viewsize(session,sz[idx].rows,sz[idx].cols); - /* - // Make sure that the current rows/cols are still 24x80. - session->cols = 80; - session->rows = 24; - session->screen_alt = 0; - */ - } - +static void set_formatted(H3270 *hSession, int state) +{ + hSession->formatted = state; /* - * Set the formatted screen flag. A formatted screen is a screen that - * has at least one field somewhere on it. + int last = (int) hSession->formatted; + hSession->formatted = state; + + if( ((int) hSession->formatted) != last) + { + trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); + hSession->update_formatted(hSession,hSession->formatted); + } +*/ + trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); +} + +/** + * Update the formatted screen flag. + * + * A formatted screen is a screen that has at least one field somewhere on it. + * + * @param hSession Session Handle */ -static void set_formatted(H3270 *hSession) +static void update_formatted(H3270 *hSession) { register int baddr; CHECK_SESSION_HANDLE(hSession); - hSession->formatted = False; baddr = 0; do { if(hSession->ea_buf[baddr].fa) { - hSession->formatted = True; - break; + set_formatted(hSession,1); + return; } INC_BA(baddr); } while (baddr != 0); + + set_formatted(hSession,0); + } /* @@ -277,6 +291,7 @@ static void ctlr_connect(H3270 *hSession, int ignored unused, void *dunno) hSession->ea_buf[-1].fa = FA_PRINTABLE | FA_MODIFY; else hSession->ea_buf[-1].fa = FA_PRINTABLE | FA_PROTECT; + if (!IN_3270 || (IN_SSCP && (hSession->kybdlock & KL_OIA_TWAIT))) { lib3270_kybdlock_clear(hSession,KL_OIA_TWAIT); @@ -292,8 +307,6 @@ static void ctlr_connect(H3270 *hSession, int ignored unused, void *dunno) hSession->crm_nattr = 0; } - - LIB3270_EXPORT int lib3270_field_addr(H3270 *hSession, int baddr) { int sbaddr; @@ -886,7 +899,8 @@ void ctlr_erase_all_unprotected(H3270 *hSession) kybd_inhibit(hSession,False); - if (hSession->formatted) { + if (hSession->formatted) + { /* find first field attribute */ baddr = 0; do { @@ -975,7 +989,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er ctlr_add_gr(hSession,hSession->buffer_addr, 0); \ ctlr_add_ic(hSession,hSession->buffer_addr, 0); \ trace_ds(hSession,"%s",see_attr(fa)); \ - hSession->formatted = True; \ + set_formatted(hSession,1); \ } kybd_inhibit(hSession,False); @@ -1721,7 +1735,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er break; } } - set_formatted(hSession); + update_formatted(hSession); END_TEXT0; trace_ds(hSession,"\n"); if (wcc_keyboard_restore) { @@ -2196,7 +2210,7 @@ ctlr_clear(H3270 *session, Boolean can_snap) cursor_move(session,0); session->buffer_addr = 0; lib3270_unselect(session); - session->formatted = False; + set_formatted(session,0); session->default_fg = 0; session->default_bg = 0; session->default_gr = 0; @@ -2225,7 +2239,7 @@ static void ctlr_blanks(H3270 *session) cursor_move(session,0); session->buffer_addr = 0; lib3270_unselect(session); - session->formatted = False; + set_formatted(session,0); ALL_CHANGED(session); } diff --git a/host.c b/host.c index 0b495ed..fbd5263 100644 --- a/host.c +++ b/host.c @@ -706,7 +706,9 @@ void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) void lib3270_set_connected(H3270 *hSession) { - hSession->cstate = CONNECTED_INITIAL; + hSession->cstate = CONNECTED_INITIAL; + hSession->starting = 1; // Enable autostart + lib3270_st_changed(hSession, LIB3270_STATE_CONNECT, True); if(hSession->update_connect) hSession->update_connect(hSession,1); @@ -716,7 +718,9 @@ void lib3270_set_disconnected(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); - hSession->cstate = NOT_CONNECTED; + hSession->cstate = NOT_CONNECTED; + hSession->starting = 0; + set_status(hSession,OIA_FLAG_UNDERA,False); lib3270_st_changed(hSession,LIB3270_STATE_CONNECT, False); status_changed(hSession,LIB3270_MESSAGE_DISCONNECTED); diff --git a/kybd.c b/kybd.c index 7a3ae40..abcb250 100644 --- a/kybd.c +++ b/kybd.c @@ -1209,7 +1209,8 @@ LIB3270_ACTION( firstfield ) return 0; } #endif /*]*/ - if (!hSession->formatted) { + if (!hSession->formatted) + { cursor_move(hSession,0); return 0; } @@ -2066,8 +2067,10 @@ LIB3270_ACTION( eraseeof ) operator_error(hSession,KL_OERR_PROTECTED); return -1; } - if (hSession->formatted) { /* erase to next field attribute */ - do { + if (hSession->formatted) + { /* erase to next field attribute */ + do + { ctlr_add(hSession,baddr, EBC_null, 0); INC_BA(baddr); } while (!hSession->ea_buf[baddr].fa); @@ -2109,7 +2112,8 @@ LIB3270_ACTION( eraseinput ) if (IN_ANSI) return 0; #endif /*]*/ - if (hSession->formatted) { + if (hSession->formatted) + { /* find first field attribute */ baddr = 0; do { @@ -2170,7 +2174,8 @@ LIB3270_ACTION( deleteword ) return 0; } #if defined(X3270_ANSI) /*[*/ - if (IN_ANSI) { + if (IN_ANSI) + { net_send_werase(hSession); return 0; } @@ -2455,7 +2460,7 @@ static Boolean remargin(H3270 *hSession, int lmargin) return True; } -LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, char *s, int len, int pasting) +LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len, int pasting) { enum { BASE, BACKSLASH, BACKX, BACKP, BACKPA, BACKPF, OCTAL, HEX, XGE } state = BASE; int literal = 0; @@ -2474,7 +2479,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, char *s, int len, int UChar *ws; #else /*][*/ char c; - char *ws; + const char *ws; #endif /*]*/ CHECK_SESSION_HANDLE(hSession); diff --git a/resolver.c b/resolver.c index f82b9b3..c2d93b4 100644 --- a/resolver.c +++ b/resolver.c @@ -183,10 +183,10 @@ static int cresolve_host_and_port(H3270 *h, struct parms *p) int resolve_host_and_port(H3270 *hSession, const char *host, char *portname, unsigned short *pport,struct sockaddr *sa, socklen_t *sa_len, char *errmsg, int em_len) { int rc; - LIB3270_STATUS saved_status = hSession->oia_status; + LIB3270_MESSAGE saved_status = hSession->oia_status; struct parms p = { sizeof(struct parms), host, portname, pport, sa, sa_len, errmsg, em_len }; - trace("Calling resolver for %s", p.host); + trace("Calling resolver for %s status=%d", p.host, (int) saved_status); status_changed(hSession,LIB3270_STATUS_RESOLVING); hSession->cursor(hSession,CURSOR_MODE_LOCKED); @@ -194,7 +194,9 @@ int resolve_host_and_port(H3270 *hSession, const char *host, char *portname, uns rc = lib3270_call_thread((int (*)(H3270 *, void *)) cresolve_host_and_port,hSession,&p); hSession->cursor(hSession,CURSOR_MODE_NORMAL); - status_changed(hSession,saved_status); + + if(saved_status != -1) + status_changed(hSession,saved_status); trace("Calling resolver for %s exits with %d", p.host, rc); diff --git a/screen.c b/screen.c index a2418b3..cdb3714 100644 --- a/screen.c +++ b/screen.c @@ -372,7 +372,21 @@ void screen_update(H3270 *session, int bstart, int bend) session->changed(session,first,len); } - trace("%s ends",__FUNCTION__); + if(session->starting && session->formatted && lib3270_in_3270(session)) + { + session->starting = 0; + session->autostart(session); +#ifdef DEBUG + { + char *text = lib3270_get_text(session,0,-1); + trace("First screen:\n%s\n",text); + lib3270_free(text); + } +#endif + } + +// trace("%s ends",__FUNCTION__); + } LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) @@ -426,20 +440,20 @@ void status_ctlr_done(H3270 *session) void status_oerr(H3270 *session, int error_type) { - LIB3270_STATUS sts = LIB3270_STATUS_USER; + LIB3270_STATUS sts = LIB3270_MESSAGE_USER; CHECK_SESSION_HANDLE(session); switch (error_type) { case KL_OERR_PROTECTED: - sts = LIB3270_STATUS_PROTECTED; + sts = LIB3270_MESSAGE_PROTECTED; break; case KL_OERR_NUMERIC: - sts = LIB3270_STATUS_NUMERIC; + sts = LIB3270_MESSAGE_NUMERIC; break; case KL_OERR_OVERFLOW: - sts = LIB3270_STATUS_OVERFLOW; + sts = LIB3270_MESSAGE_OVERFLOW; break; default: @@ -453,9 +467,9 @@ void status_oerr(H3270 *session, int error_type) void status_connecting(H3270 *session, Boolean on) { if(session->cursor) - session->cursor(session,on ? CURSOR_MODE_LOCKED : CURSOR_MODE_NORMAL); + session->cursor(session,on ? CURSOR_MODE_LOCKED : CURSOR_MODE_NORMAL); - status_changed(session, on ? LIB3270_STATUS_CONNECTING : LIB3270_STATUS_BLANK); + status_changed(session, on ? LIB3270_MESSAGE_CONNECTING : LIB3270_MESSAGE_NONE); } void status_reset(H3270 *session) @@ -464,17 +478,17 @@ void status_reset(H3270 *session) if (session->kybdlock & KL_ENTER_INHIBIT) { - status_changed(session,LIB3270_STATUS_INHIBIT); + status_changed(session,LIB3270_MESSAGE_INHIBIT); } else if (session->kybdlock & KL_DEFERRED_UNLOCK) { - status_changed(session,LIB3270_STATUS_X); + status_changed(session,LIB3270_MESSAGE_X); } else { if(session->cursor) session->cursor(session,CURSOR_MODE_NORMAL); - status_changed(session,LIB3270_STATUS_BLANK); + status_changed(session,LIB3270_MESSAGE_NONE); } session->display(session); @@ -503,8 +517,7 @@ void status_changed(H3270 *session, LIB3270_STATUS id) session->oia_status = id; - if(session->update_status) - session->update_status(session,id); + session->update_status(session,id); } void status_twait(H3270 *session) diff --git a/selection.c b/selection.c index ef717a6..d80c75e 100644 --- a/selection.c +++ b/selection.c @@ -378,7 +378,7 @@ static char * get_text(H3270 *hSession,unsigned char all) size_t buflen = (hSession->rows * (hSession->cols+1))+1; size_t sz = 0; - if(!lib3270_connected(hSession)) + if(!(lib3270_connected(hSession) && hSession->text)) return NULL; ret = lib3270_malloc(buflen); diff --git a/session.c b/session.c index 3b16911..742a0d9 100644 --- a/session.c +++ b/session.c @@ -160,7 +160,7 @@ static void screen_disp(H3270 *session) screen_update(session,0,session->rows*session->cols); } -static void set_width(H3270 *session, int width) +static void nop_int(H3270 *session, int width) { return; } @@ -194,7 +194,9 @@ static void lib3270_session_init(H3270 *hSession, const char *model) hSession->message = message; hSession->update_ssl = update_ssl; hSession->display = screen_disp; - hSession->set_width = set_width; + hSession->set_width = nop_int; + hSession->update_status = (void (*)(H3270 *, LIB3270_STATUS)) nop_int; + hSession->autostart = nop; // Set the defaults. hSession->extended = 1; @@ -425,7 +427,11 @@ void check_session_handle(H3270 **hSession) *hSession = lib3270_get_default_session_handle(); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s called with empty session\n", __FUNCTION__); +#else lib3270_write_log(*hSession,"%s called with empty session",__FUNCTION__); +#endif // ANDROID } LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) diff --git a/telnet.c b/telnet.c index d9c3741..799c76d 100644 --- a/telnet.c +++ b/telnet.c @@ -1300,9 +1300,11 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) hSession->ns_rrcvd++; if (process_eor(hSession)) return -1; - } else + } + else + { Warning(hSession, _( "EOR received when not in 3270 mode, ignored." )); - + } trace_dsn(hSession,"RCVD EOR\n"); hSession->ibptr = hSession->ibuf; hSession->telnet_state = TNS_DATA; @@ -1900,6 +1902,7 @@ static void process_bind(H3270 *hSession, unsigned char *buf, int buflen) static int process_eor(H3270 *hSession) { + trace("%s: syncing=%s",__FUNCTION__,hSession->syncing ? "Yes" : "No"); if (hSession->syncing || !(hSession->ibptr - hSession->ibuf)) return(0); -- libgit2 0.21.2