diff --git a/api.h b/api.h index cc0b8d4..e026cc5 100644 --- a/api.h +++ b/api.h @@ -379,7 +379,7 @@ /* Get connection info */ #define get_connected_lu(h) lib3270_get_luname(h) - #define get_current_host(h) lib3270_get_host(h) +// #define get_current_host(h) lib3270_get_host(h) LOCAL_EXTERN SCRIPT_STATE status_script(SCRIPT_STATE state); diff --git a/globals.h b/globals.h index 2c22294..bddca25 100644 --- a/globals.h +++ b/globals.h @@ -212,9 +212,11 @@ LIB3270_INTERNAL char *hostname; #endif /*]*/ -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) LIB3270_INTERNAL Boolean local_process; -#endif /*]*/ +#endif +*/ // LIB3270_INTERNAL int maxCOLS; // LIB3270_INTERNAL int maxROWS; diff --git a/host.c b/host.c index 9bd48a7..ebc9450 100644 --- a/host.c +++ b/host.c @@ -194,8 +194,9 @@ hostfile_lookup(const char *name, char **hostname, char **loginstring) } */ -#if defined(LOCAL_PROCESS) /*[*/ -/* Recognize and translate "-e" options. */ +/* +#if defined(LOCAL_PROCESS) +// Recognize and translate "-e" options. static const char * parse_localprocess(const char *s) { @@ -216,7 +217,8 @@ parse_localprocess(const char *s) } return CN; } -#endif /*]*/ +#endif +*/ /* * Strip qualifiers from a hostname. @@ -480,16 +482,18 @@ static int do_connect(H3270 *hSession, const char *n) Boolean resolving; Boolean pending; static Boolean ansi_host; - const char *localprocess_cmd = NULL; +// const char *localprocess_cmd = NULL; Boolean has_colons = False; - if (CONNECTED || hSession->auto_reconnect_inprogress) - return 0; + if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress) + return EBUSY; /* Skip leading blanks. */ while (*n == ' ') n++; - if (!*n) { + + if (!*n) + { popup_an_error(hSession,_( "Invalid (empty) hostname" )); return -1; } @@ -503,19 +507,16 @@ static int do_connect(H3270 *hSession, const char *n) *s-- = '\0'; /* Remember this hostname, as the last hostname we connected to. */ - Replace(hSession->reconnect_host, NewString(nb)); + lib3270_set_host(hSession,nb); -// #if defined(X3270_DISPLAY) -// /* Remember this hostname in the recent connection list and file. */ -// save_recent(nb); -// #endif - -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if ((localprocess_cmd = parse_localprocess(nb)) != CN) { chost = localprocess_cmd; port = appres.port; } else -#endif /*]*/ +#endif +*/ { Boolean needed; @@ -541,12 +542,12 @@ static int do_connect(H3270 *hSession, const char *n) * full_current_host is the entire string, for use in reconnecting */ if (n != hSession->full_current_host) - { - Replace(hSession->full_current_host, NewString(n)); - } + lib3270_set_host(hSession,n); Replace(hSession->current_host, CN); +/* + if (localprocess_cmd != CN) { if (hSession->full_current_host[strlen(OptLocalProcess)] != '\0') hSession->current_host = NewString(hSession->full_current_host + strlen(OptLocalProcess) + 1); @@ -555,6 +556,7 @@ static int do_connect(H3270 *hSession, const char *n) } else { hSession->current_host = s; } +*/ has_colons = (strchr(chost, ':') != NULL); @@ -569,7 +571,7 @@ static int do_connect(H3270 *hSession, const char *n) /* Attempt contact. */ hSession->ever_3270 = False; - hSession->net_sock = net_connect(hSession, chost, port, localprocess_cmd != CN, &resolving,&pending); + hSession->net_sock = net_connect(hSession, chost, port, 0, &resolving,&pending); if (hSession->net_sock < 0 && !resolving) { @@ -612,6 +614,16 @@ static int do_connect(H3270 *hSession, const char *n) return 0; } +/** + * Connect to selected host. + * + * @param h Session handle. + * @param n Hostname (null to reconnect to the last one; + * @param wait Wait for connection ok before return. + * + * @return 0 if the connection was ok, non zero on error. + * + */ int lib3270_connect(H3270 *h, const char *n, int wait) { int rc; @@ -627,7 +639,11 @@ int lib3270_connect(H3270 *h, const char *n, int wait) return EBUSY; if(!n) - return ENOENT; + { + n = h->full_current_host; + if(!n) + return EINVAL; + } rc = do_connect(h,n); if(rc) @@ -654,7 +670,7 @@ int lib3270_connect(H3270 *h, const char *n, int wait) */ static void try_reconnect(H3270 *session) { - WriteLog("3270","Starting auto-reconnect (Host: %s)",session->reconnect_host ? session->reconnect_host : "-"); + WriteLog("3270","Starting auto-reconnect (Host: %s)",session->full_current_host ? session->full_current_host : "-"); session->auto_reconnect_inprogress = False; lib3270_reconnect(session,0); } @@ -758,6 +774,29 @@ void lib3270_st_changed(H3270 *h, int tx, int mode) } } +LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) +{ + CHECK_SESSION_HANDLE(h); + + Trace("%s: %p",__FUNCTION__,n); + + if(!n) + return NULL; + + if(h->full_current_host) + free(h->full_current_host); + + h->full_current_host = strdup(n); + + return h->full_current_host; +} + +LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->full_current_host; +} + LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) { int rc; @@ -767,13 +806,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) if (CONNECTED || HALF_CONNECTED) return EBUSY; - if (h->current_host == CN) - return ENOENT; + if (h->full_current_host == CN) + return EINVAL; if (h->auto_reconnect_inprogress) return EBUSY; - rc = lib3270_connect(h,h->reconnect_host,wait); + rc = lib3270_connect(h,h->full_current_host,wait); if(rc) { @@ -790,8 +829,3 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) return h->connected_lu; } -LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return h->current_host; -} diff --git a/selection.c b/selection.c index f383202..434ef69 100644 --- a/selection.c +++ b/selection.c @@ -71,6 +71,20 @@ static void update_selected_rectangle(H3270 *session) p[1].row = (end/session->cols); p[1].col = (end%session->cols); + if(p[0].row > p[1].row) + { + int swp = p[0].row; + p[0].row = p[1].row; + p[1].row = swp; + } + + if(p[0].col > p[1].col) + { + int swp = p[0].col; + p[0].col = p[1].col; + p[1].col = swp; + } + // First remove unselected areas baddr = 0; for(row=0;row < session->rows;row++) @@ -214,6 +228,35 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) } +LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int baddr) +{ + int row,col; + unsigned char rc = 0; + + CHECK_SESSION_HANDLE(hSession); + + if(!(lib3270_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED))) + return rc; + + row = baddr / hSession->cols; + col = baddr % hSession->cols; + rc |= 0x01; + + if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x02; + + if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x04; + + if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x08; + + if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x10; + + return rc; +} + LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) { int pos, len; @@ -373,6 +416,8 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) { + CHECK_SESSION_HANDLE(hSession); + if(!hSession->selected || hSession->select.begin == hSession->select.end) return -1; @@ -390,6 +435,12 @@ LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *e return 0; } +LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) +{ + + + return from; +} LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { diff --git a/telnet.c b/telnet.c index 602492b..b06a741 100644 --- a/telnet.c +++ b/telnet.c @@ -111,6 +111,7 @@ int ns_rsent; unsigned char *obuf; /* 3270 output buffer */ unsigned char *obptr = (unsigned char *) NULL; int linemode = 1; + /* #if defined(LOCAL_PROCESS) Boolean local_process = False; @@ -1010,10 +1011,11 @@ void net_input(H3270 *session) ns_brcvd += nr; for (cp = netrbuf; cp < (netrbuf + nr); cp++) { -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if (local_process) { - /* More to do here, probably. */ - if (IN_NEITHER) { /* now can assume ANSI mode */ + // More to do here, probably. + if (IN_NEITHER) { // now can assume ANSI mode host_in3270(CONNECTED_ANSI); hisopts[TELOPT_ECHO] = 1; check_linemode(False); @@ -1023,7 +1025,8 @@ void net_input(H3270 *session) } ansi_process((unsigned int) *cp); } else { -#endif /*]*/ +#endif +*/ if (telnet_fsm(*cp)) { (void) ctlr_dbcs_postprocess(); host_disconnect(&h3270,True); @@ -1891,11 +1894,13 @@ process_eor(void) */ void net_exception(H3270 *session) { -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if (local_process) { trace_dsn("RCVD exception\n"); } else -#endif /*[*/ +#endif +*/ { trace_dsn("RCVD urgent data indication\n"); if (!syncing) { @@ -1953,11 +1958,14 @@ net_rawout(unsigned const char *buf, int len) nw = SSL_write(ssl_con, (const char *) buf, n2w); else #endif /*]*/ -#if defined(LOCAL_PROCESS) /*[*/ + +/* +#if defined(LOCAL_PROCESS) if (local_process) nw = write(sock, (const char *) buf, n2w); else -#endif /*]*/ +#endif +*/ nw = send(h3270.sock, (const char *) buf, n2w, 0); if (nw < 0) { #if defined(HAVE_LIBSSL) /*[*/ @@ -2791,9 +2799,11 @@ void net_sendc(char c) { if (c == '\r' && !linemode -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) && !local_process -#endif /*]*/ +#endif +*/ ) { /* CR must be quoted */ net_cookout("\r\0", 2); -- libgit2 0.21.2