Commit 01edcda07888b72a5072e4c67b8109525c0bcb10

Authored by perry.werneck@gmail.com
1 parent 7a18fcce

Removendo campos sem uso, incluindo suporte a auto-reconnect, iniciando reinclus…

…ao de movimentação da seleção por mouse
@@ -379,7 +379,7 @@ @@ -379,7 +379,7 @@
379 379
380 /* Get connection info */ 380 /* Get connection info */
381 #define get_connected_lu(h) lib3270_get_luname(h) 381 #define get_connected_lu(h) lib3270_get_luname(h)
382 - #define get_current_host(h) lib3270_get_host(h) 382 +// #define get_current_host(h) lib3270_get_host(h)
383 383
384 LOCAL_EXTERN SCRIPT_STATE status_script(SCRIPT_STATE state); 384 LOCAL_EXTERN SCRIPT_STATE status_script(SCRIPT_STATE state);
385 385
@@ -212,9 +212,11 @@ LIB3270_INTERNAL char *hostname; @@ -212,9 +212,11 @@ LIB3270_INTERNAL char *hostname;
212 212
213 #endif /*]*/ 213 #endif /*]*/
214 214
215 -#if defined(LOCAL_PROCESS) /*[*/ 215 +/*
  216 +#if defined(LOCAL_PROCESS)
216 LIB3270_INTERNAL Boolean local_process; 217 LIB3270_INTERNAL Boolean local_process;
217 -#endif /*]*/ 218 +#endif
  219 +*/
218 220
219 // LIB3270_INTERNAL int maxCOLS; 221 // LIB3270_INTERNAL int maxCOLS;
220 // LIB3270_INTERNAL int maxROWS; 222 // LIB3270_INTERNAL int maxROWS;
@@ -194,8 +194,9 @@ hostfile_lookup(const char *name, char **hostname, char **loginstring) @@ -194,8 +194,9 @@ hostfile_lookup(const char *name, char **hostname, char **loginstring)
194 } 194 }
195 */ 195 */
196 196
197 -#if defined(LOCAL_PROCESS) /*[*/  
198 -/* Recognize and translate "-e" options. */ 197 +/*
  198 +#if defined(LOCAL_PROCESS)
  199 +// Recognize and translate "-e" options.
199 static const char * 200 static const char *
200 parse_localprocess(const char *s) 201 parse_localprocess(const char *s)
201 { 202 {
@@ -216,7 +217,8 @@ parse_localprocess(const char *s) @@ -216,7 +217,8 @@ parse_localprocess(const char *s)
216 } 217 }
217 return CN; 218 return CN;
218 } 219 }
219 -#endif /*]*/ 220 +#endif
  221 +*/
220 222
221 /* 223 /*
222 * Strip qualifiers from a hostname. 224 * Strip qualifiers from a hostname.
@@ -480,16 +482,18 @@ static int do_connect(H3270 *hSession, const char *n) @@ -480,16 +482,18 @@ static int do_connect(H3270 *hSession, const char *n)
480 Boolean resolving; 482 Boolean resolving;
481 Boolean pending; 483 Boolean pending;
482 static Boolean ansi_host; 484 static Boolean ansi_host;
483 - const char *localprocess_cmd = NULL; 485 +// const char *localprocess_cmd = NULL;
484 Boolean has_colons = False; 486 Boolean has_colons = False;
485 487
486 - if (CONNECTED || hSession->auto_reconnect_inprogress)  
487 - return 0; 488 + if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress)
  489 + return EBUSY;
488 490
489 /* Skip leading blanks. */ 491 /* Skip leading blanks. */
490 while (*n == ' ') 492 while (*n == ' ')
491 n++; 493 n++;
492 - if (!*n) { 494 +
  495 + if (!*n)
  496 + {
493 popup_an_error(hSession,_( "Invalid (empty) hostname" )); 497 popup_an_error(hSession,_( "Invalid (empty) hostname" ));
494 return -1; 498 return -1;
495 } 499 }
@@ -503,19 +507,16 @@ static int do_connect(H3270 *hSession, const char *n) @@ -503,19 +507,16 @@ static int do_connect(H3270 *hSession, const char *n)
503 *s-- = '\0'; 507 *s-- = '\0';
504 508
505 /* Remember this hostname, as the last hostname we connected to. */ 509 /* Remember this hostname, as the last hostname we connected to. */
506 - Replace(hSession->reconnect_host, NewString(nb)); 510 + lib3270_set_host(hSession,nb);
507 511
508 -// #if defined(X3270_DISPLAY)  
509 -// /* Remember this hostname in the recent connection list and file. */  
510 -// save_recent(nb);  
511 -// #endif  
512 -  
513 -#if defined(LOCAL_PROCESS) /*[*/ 512 +/*
  513 +#if defined(LOCAL_PROCESS)
514 if ((localprocess_cmd = parse_localprocess(nb)) != CN) { 514 if ((localprocess_cmd = parse_localprocess(nb)) != CN) {
515 chost = localprocess_cmd; 515 chost = localprocess_cmd;
516 port = appres.port; 516 port = appres.port;
517 } else 517 } else
518 -#endif /*]*/ 518 +#endif
  519 +*/
519 { 520 {
520 Boolean needed; 521 Boolean needed;
521 522
@@ -541,12 +542,12 @@ static int do_connect(H3270 *hSession, const char *n) @@ -541,12 +542,12 @@ static int do_connect(H3270 *hSession, const char *n)
541 * full_current_host is the entire string, for use in reconnecting 542 * full_current_host is the entire string, for use in reconnecting
542 */ 543 */
543 if (n != hSession->full_current_host) 544 if (n != hSession->full_current_host)
544 - {  
545 - Replace(hSession->full_current_host, NewString(n));  
546 - } 545 + lib3270_set_host(hSession,n);
547 546
548 Replace(hSession->current_host, CN); 547 Replace(hSession->current_host, CN);
549 548
  549 +/*
  550 +
550 if (localprocess_cmd != CN) { 551 if (localprocess_cmd != CN) {
551 if (hSession->full_current_host[strlen(OptLocalProcess)] != '\0') 552 if (hSession->full_current_host[strlen(OptLocalProcess)] != '\0')
552 hSession->current_host = NewString(hSession->full_current_host + strlen(OptLocalProcess) + 1); 553 hSession->current_host = NewString(hSession->full_current_host + strlen(OptLocalProcess) + 1);
@@ -555,6 +556,7 @@ static int do_connect(H3270 *hSession, const char *n) @@ -555,6 +556,7 @@ static int do_connect(H3270 *hSession, const char *n)
555 } else { 556 } else {
556 hSession->current_host = s; 557 hSession->current_host = s;
557 } 558 }
  559 +*/
558 560
559 has_colons = (strchr(chost, ':') != NULL); 561 has_colons = (strchr(chost, ':') != NULL);
560 562
@@ -569,7 +571,7 @@ static int do_connect(H3270 *hSession, const char *n) @@ -569,7 +571,7 @@ static int do_connect(H3270 *hSession, const char *n)
569 571
570 /* Attempt contact. */ 572 /* Attempt contact. */
571 hSession->ever_3270 = False; 573 hSession->ever_3270 = False;
572 - hSession->net_sock = net_connect(hSession, chost, port, localprocess_cmd != CN, &resolving,&pending); 574 + hSession->net_sock = net_connect(hSession, chost, port, 0, &resolving,&pending);
573 575
574 if (hSession->net_sock < 0 && !resolving) 576 if (hSession->net_sock < 0 && !resolving)
575 { 577 {
@@ -612,6 +614,16 @@ static int do_connect(H3270 *hSession, const char *n) @@ -612,6 +614,16 @@ static int do_connect(H3270 *hSession, const char *n)
612 return 0; 614 return 0;
613 } 615 }
614 616
  617 +/**
  618 + * Connect to selected host.
  619 + *
  620 + * @param h Session handle.
  621 + * @param n Hostname (null to reconnect to the last one;
  622 + * @param wait Wait for connection ok before return.
  623 + *
  624 + * @return 0 if the connection was ok, non zero on error.
  625 + *
  626 + */
615 int lib3270_connect(H3270 *h, const char *n, int wait) 627 int lib3270_connect(H3270 *h, const char *n, int wait)
616 { 628 {
617 int rc; 629 int rc;
@@ -627,7 +639,11 @@ int lib3270_connect(H3270 *h, const char *n, int wait) @@ -627,7 +639,11 @@ int lib3270_connect(H3270 *h, const char *n, int wait)
627 return EBUSY; 639 return EBUSY;
628 640
629 if(!n) 641 if(!n)
630 - return ENOENT; 642 + {
  643 + n = h->full_current_host;
  644 + if(!n)
  645 + return EINVAL;
  646 + }
631 647
632 rc = do_connect(h,n); 648 rc = do_connect(h,n);
633 if(rc) 649 if(rc)
@@ -654,7 +670,7 @@ int lib3270_connect(H3270 *h, const char *n, int wait) @@ -654,7 +670,7 @@ int lib3270_connect(H3270 *h, const char *n, int wait)
654 */ 670 */
655 static void try_reconnect(H3270 *session) 671 static void try_reconnect(H3270 *session)
656 { 672 {
657 - WriteLog("3270","Starting auto-reconnect (Host: %s)",session->reconnect_host ? session->reconnect_host : "-"); 673 + WriteLog("3270","Starting auto-reconnect (Host: %s)",session->full_current_host ? session->full_current_host : "-");
658 session->auto_reconnect_inprogress = False; 674 session->auto_reconnect_inprogress = False;
659 lib3270_reconnect(session,0); 675 lib3270_reconnect(session,0);
660 } 676 }
@@ -758,6 +774,29 @@ void lib3270_st_changed(H3270 *h, int tx, int mode) @@ -758,6 +774,29 @@ void lib3270_st_changed(H3270 *h, int tx, int mode)
758 } 774 }
759 } 775 }
760 776
  777 +LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
  778 +{
  779 + CHECK_SESSION_HANDLE(h);
  780 +
  781 + Trace("%s: %p",__FUNCTION__,n);
  782 +
  783 + if(!n)
  784 + return NULL;
  785 +
  786 + if(h->full_current_host)
  787 + free(h->full_current_host);
  788 +
  789 + h->full_current_host = strdup(n);
  790 +
  791 + return h->full_current_host;
  792 +}
  793 +
  794 +LIB3270_EXPORT const char * lib3270_get_host(H3270 *h)
  795 +{
  796 + CHECK_SESSION_HANDLE(h);
  797 + return h->full_current_host;
  798 +}
  799 +
761 LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) 800 LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait)
762 { 801 {
763 int rc; 802 int rc;
@@ -767,13 +806,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) @@ -767,13 +806,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait)
767 if (CONNECTED || HALF_CONNECTED) 806 if (CONNECTED || HALF_CONNECTED)
768 return EBUSY; 807 return EBUSY;
769 808
770 - if (h->current_host == CN)  
771 - return ENOENT; 809 + if (h->full_current_host == CN)
  810 + return EINVAL;
772 811
773 if (h->auto_reconnect_inprogress) 812 if (h->auto_reconnect_inprogress)
774 return EBUSY; 813 return EBUSY;
775 814
776 - rc = lib3270_connect(h,h->reconnect_host,wait); 815 + rc = lib3270_connect(h,h->full_current_host,wait);
777 816
778 if(rc) 817 if(rc)
779 { 818 {
@@ -790,8 +829,3 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) @@ -790,8 +829,3 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h)
790 return h->connected_lu; 829 return h->connected_lu;
791 } 830 }
792 831
793 -LIB3270_EXPORT const char * lib3270_get_host(H3270 *h)  
794 -{  
795 - CHECK_SESSION_HANDLE(h);  
796 - return h->current_host;  
797 -}  
@@ -71,6 +71,20 @@ static void update_selected_rectangle(H3270 *session) @@ -71,6 +71,20 @@ static void update_selected_rectangle(H3270 *session)
71 p[1].row = (end/session->cols); 71 p[1].row = (end/session->cols);
72 p[1].col = (end%session->cols); 72 p[1].col = (end%session->cols);
73 73
  74 + if(p[0].row > p[1].row)
  75 + {
  76 + int swp = p[0].row;
  77 + p[0].row = p[1].row;
  78 + p[1].row = swp;
  79 + }
  80 +
  81 + if(p[0].col > p[1].col)
  82 + {
  83 + int swp = p[0].col;
  84 + p[0].col = p[1].col;
  85 + p[1].col = swp;
  86 + }
  87 +
74 // First remove unselected areas 88 // First remove unselected areas
75 baddr = 0; 89 baddr = 0;
76 for(row=0;row < session->rows;row++) 90 for(row=0;row < session->rows;row++)
@@ -214,6 +228,35 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) @@ -214,6 +228,35 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr)
214 228
215 } 229 }
216 230
  231 +LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int baddr)
  232 +{
  233 + int row,col;
  234 + unsigned char rc = 0;
  235 +
  236 + CHECK_SESSION_HANDLE(hSession);
  237 +
  238 + if(!(lib3270_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)))
  239 + return rc;
  240 +
  241 + row = baddr / hSession->cols;
  242 + col = baddr % hSession->cols;
  243 + rc |= 0x01;
  244 +
  245 + if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) )
  246 + rc |= 0x02;
  247 +
  248 + if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) )
  249 + rc |= 0x04;
  250 +
  251 + if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) )
  252 + rc |= 0x08;
  253 +
  254 + if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) )
  255 + rc |= 0x10;
  256 +
  257 + return rc;
  258 +}
  259 +
217 LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) 260 LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr)
218 { 261 {
219 int pos, len; 262 int pos, len;
@@ -373,6 +416,8 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) @@ -373,6 +416,8 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
373 416
374 LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) 417 LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end)
375 { 418 {
  419 + CHECK_SESSION_HANDLE(hSession);
  420 +
376 if(!hSession->selected || hSession->select.begin == hSession->select.end) 421 if(!hSession->selected || hSession->select.begin == hSession->select.end)
377 return -1; 422 return -1;
378 423
@@ -390,6 +435,12 @@ LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *e @@ -390,6 +435,12 @@ LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *e
390 return 0; 435 return 0;
391 } 436 }
392 437
  438 +LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to)
  439 +{
  440 +
  441 +
  442 + return from;
  443 +}
393 444
394 LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) 445 LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir)
395 { 446 {
@@ -111,6 +111,7 @@ int ns_rsent; @@ -111,6 +111,7 @@ int ns_rsent;
111 unsigned char *obuf; /* 3270 output buffer */ 111 unsigned char *obuf; /* 3270 output buffer */
112 unsigned char *obptr = (unsigned char *) NULL; 112 unsigned char *obptr = (unsigned char *) NULL;
113 int linemode = 1; 113 int linemode = 1;
  114 +
114 /* 115 /*
115 #if defined(LOCAL_PROCESS) 116 #if defined(LOCAL_PROCESS)
116 Boolean local_process = False; 117 Boolean local_process = False;
@@ -1010,10 +1011,11 @@ void net_input(H3270 *session) @@ -1010,10 +1011,11 @@ void net_input(H3270 *session)
1010 1011
1011 ns_brcvd += nr; 1012 ns_brcvd += nr;
1012 for (cp = netrbuf; cp < (netrbuf + nr); cp++) { 1013 for (cp = netrbuf; cp < (netrbuf + nr); cp++) {
1013 -#if defined(LOCAL_PROCESS) /*[*/ 1014 +/*
  1015 +#if defined(LOCAL_PROCESS)
1014 if (local_process) { 1016 if (local_process) {
1015 - /* More to do here, probably. */  
1016 - if (IN_NEITHER) { /* now can assume ANSI mode */ 1017 + // More to do here, probably.
  1018 + if (IN_NEITHER) { // now can assume ANSI mode
1017 host_in3270(CONNECTED_ANSI); 1019 host_in3270(CONNECTED_ANSI);
1018 hisopts[TELOPT_ECHO] = 1; 1020 hisopts[TELOPT_ECHO] = 1;
1019 check_linemode(False); 1021 check_linemode(False);
@@ -1023,7 +1025,8 @@ void net_input(H3270 *session) @@ -1023,7 +1025,8 @@ void net_input(H3270 *session)
1023 } 1025 }
1024 ansi_process((unsigned int) *cp); 1026 ansi_process((unsigned int) *cp);
1025 } else { 1027 } else {
1026 -#endif /*]*/ 1028 +#endif
  1029 +*/
1027 if (telnet_fsm(*cp)) { 1030 if (telnet_fsm(*cp)) {
1028 (void) ctlr_dbcs_postprocess(); 1031 (void) ctlr_dbcs_postprocess();
1029 host_disconnect(&h3270,True); 1032 host_disconnect(&h3270,True);
@@ -1891,11 +1894,13 @@ process_eor(void) @@ -1891,11 +1894,13 @@ process_eor(void)
1891 */ 1894 */
1892 void net_exception(H3270 *session) 1895 void net_exception(H3270 *session)
1893 { 1896 {
1894 -#if defined(LOCAL_PROCESS) /*[*/ 1897 +/*
  1898 +#if defined(LOCAL_PROCESS)
1895 if (local_process) { 1899 if (local_process) {
1896 trace_dsn("RCVD exception\n"); 1900 trace_dsn("RCVD exception\n");
1897 } else 1901 } else
1898 -#endif /*[*/ 1902 +#endif
  1903 +*/
1899 { 1904 {
1900 trace_dsn("RCVD urgent data indication\n"); 1905 trace_dsn("RCVD urgent data indication\n");
1901 if (!syncing) { 1906 if (!syncing) {
@@ -1953,11 +1958,14 @@ net_rawout(unsigned const char *buf, int len) @@ -1953,11 +1958,14 @@ net_rawout(unsigned const char *buf, int len)
1953 nw = SSL_write(ssl_con, (const char *) buf, n2w); 1958 nw = SSL_write(ssl_con, (const char *) buf, n2w);
1954 else 1959 else
1955 #endif /*]*/ 1960 #endif /*]*/
1956 -#if defined(LOCAL_PROCESS) /*[*/ 1961 +
  1962 +/*
  1963 +#if defined(LOCAL_PROCESS)
1957 if (local_process) 1964 if (local_process)
1958 nw = write(sock, (const char *) buf, n2w); 1965 nw = write(sock, (const char *) buf, n2w);
1959 else 1966 else
1960 -#endif /*]*/ 1967 +#endif
  1968 +*/
1961 nw = send(h3270.sock, (const char *) buf, n2w, 0); 1969 nw = send(h3270.sock, (const char *) buf, n2w, 0);
1962 if (nw < 0) { 1970 if (nw < 0) {
1963 #if defined(HAVE_LIBSSL) /*[*/ 1971 #if defined(HAVE_LIBSSL) /*[*/
@@ -2791,9 +2799,11 @@ void @@ -2791,9 +2799,11 @@ void
2791 net_sendc(char c) 2799 net_sendc(char c)
2792 { 2800 {
2793 if (c == '\r' && !linemode 2801 if (c == '\r' && !linemode
2794 -#if defined(LOCAL_PROCESS) /*[*/ 2802 +/*
  2803 +#if defined(LOCAL_PROCESS)
2795 && !local_process 2804 && !local_process
2796 -#endif /*]*/ 2805 +#endif
  2806 +*/
2797 ) { 2807 ) {
2798 /* CR must be quoted */ 2808 /* CR must be quoted */
2799 net_cookout("\r\0", 2); 2809 net_cookout("\r\0", 2);