Commit 2799360970ac8606c739c17c5082c861c19ea954

Authored by perry.werneck@gmail.com
1 parent 5c34e900
Exists in master

Movendo posição do cursor para o buffer de sessão

latest/src/include/lib3270.h
@@ -106,5 +106,19 @@ @@ -106,5 +106,19 @@
106 LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h); 106 LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h);
107 107
108 108
  109 + /**
  110 + * Set string at current cursor position.
  111 + *
  112 + * Returns are ignored; newlines mean "move to beginning of next line";
  113 + * tabs and formfeeds become spaces. Backslashes are not special
  114 + *
  115 + * @param h Session handle.
  116 + * @param s String to input.
  117 + *
  118 + * @Returns Negative if error or number of processed characters.
  119 + *
  120 + */
  121 + LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str);
  122 +
109 123
110 #endif // LIB3270_H_INCLUDED 124 #endif // LIB3270_H_INCLUDED
latest/src/include/lib3270/api.h
@@ -203,6 +203,7 @@ @@ -203,6 +203,7 @@
203 int maxCOLS; 203 int maxCOLS;
204 int rows; 204 int rows;
205 int cols; 205 int cols;
  206 + int cursor_addr;
206 207
207 // Widget info 208 // Widget info
208 void * widget; 209 void * widget;
@@ -524,8 +525,8 @@ @@ -524,8 +525,8 @@
524 LIB3270_EXPORT void Input_String(const unsigned char *str); 525 LIB3270_EXPORT void Input_String(const unsigned char *str);
525 LIB3270_EXPORT void screen_size(int *rows, int *cols); 526 LIB3270_EXPORT void screen_size(int *rows, int *cols);
526 LIB3270_EXPORT int query_secure_connection(H3270 *h); 527 LIB3270_EXPORT int query_secure_connection(H3270 *h);
527 - LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str);  
528 528
  529 + #define lib3270_paste_string(str) lib3270_set_string(NULL,str)
529 #define get_3270_terminal_size(h,r,c) lib3270_get_screen_size(h,r,c) 530 #define get_3270_terminal_size(h,r,c) lib3270_get_screen_size(h,r,c)
530 531
531 /* Keyboard */ 532 /* Keyboard */
latest/src/lib/ansi.c
@@ -499,7 +499,7 @@ dec_save_cursor(int ig1 unused, int ig2 unused) @@ -499,7 +499,7 @@ dec_save_cursor(int ig1 unused, int ig2 unused)
499 { 499 {
500 int i; 500 int i;
501 501
502 - saved_cursor = cursor_addr; 502 + saved_cursor = h3270.cursor_addr;
503 saved_cset = cset; 503 saved_cset = cset;
504 for (i = 0; i < 4; i++) 504 for (i = 0; i < 4; i++)
505 saved_csd[i] = csd[i]; 505 saved_csd[i] = csd[i];
@@ -530,8 +530,8 @@ ansi_newline(int ig1 unused, int ig2 unused) @@ -530,8 +530,8 @@ ansi_newline(int ig1 unused, int ig2 unused)
530 { 530 {
531 int nc; 531 int nc;
532 532
533 - cursor_move(cursor_addr - (cursor_addr % h3270.cols));  
534 - nc = cursor_addr + h3270.cols; 533 + cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols));
  534 + nc = h3270.cursor_addr + h3270.cols;
535 if (nc < scroll_bottom * h3270.cols) 535 if (nc < scroll_bottom * h3270.cols)
536 cursor_move(nc); 536 cursor_move(nc);
537 else 537 else
@@ -547,11 +547,11 @@ ansi_cursor_up(int nn, int ig2 unused) @@ -547,11 +547,11 @@ ansi_cursor_up(int nn, int ig2 unused)
547 547
548 if (nn < 1) 548 if (nn < 1)
549 nn = 1; 549 nn = 1;
550 - rr = cursor_addr / h3270.cols; 550 + rr = h3270.cursor_addr / h3270.cols;
551 if (rr - nn < 0) 551 if (rr - nn < 0)
552 - cursor_move(cursor_addr % h3270.cols); 552 + cursor_move(h3270.cursor_addr % h3270.cols);
553 else 553 else
554 - cursor_move(cursor_addr - (nn * h3270.cols)); 554 + cursor_move(h3270.cursor_addr - (nn * h3270.cols));
555 held_wrap = False; 555 held_wrap = False;
556 return DATA; 556 return DATA;
557 } 557 }
@@ -619,7 +619,7 @@ ansi_reset(int ig1 unused, int ig2 unused) @@ -619,7 +619,7 @@ ansi_reset(int ig1 unused, int ig2 unused)
619 static enum state 619 static enum state
620 ansi_insert_chars(int nn, int ig2 unused) 620 ansi_insert_chars(int nn, int ig2 unused)
621 { 621 {
622 - int cc = cursor_addr % h3270.cols; /* current col */ 622 + int cc = h3270.cursor_addr % h3270.cols; /* current col */
623 int mc = h3270.cols - cc; /* max chars that can be inserted */ 623 int mc = h3270.cols - cc; /* max chars that can be inserted */
624 int ns; /* chars that are shifting */ 624 int ns; /* chars that are shifting */
625 625
@@ -631,10 +631,10 @@ ansi_insert_chars(int nn, int ig2 unused) @@ -631,10 +631,10 @@ ansi_insert_chars(int nn, int ig2 unused)
631 /* Move the surviving chars right */ 631 /* Move the surviving chars right */
632 ns = mc - nn; 632 ns = mc - nn;
633 if (ns) 633 if (ns)
634 - ctlr_bcopy(cursor_addr, cursor_addr + nn, ns, 1); 634 + ctlr_bcopy(h3270.cursor_addr, h3270.cursor_addr + nn, ns, 1);
635 635
636 /* Clear the middle of the line */ 636 /* Clear the middle of the line */
637 - ctlr_aclear(cursor_addr, nn, 1); 637 + ctlr_aclear(h3270.cursor_addr, nn, 1);
638 return DATA; 638 return DATA;
639 } 639 }
640 640
@@ -645,11 +645,11 @@ ansi_cursor_down(int nn, int ig2 unused) @@ -645,11 +645,11 @@ ansi_cursor_down(int nn, int ig2 unused)
645 645
646 if (nn < 1) 646 if (nn < 1)
647 nn = 1; 647 nn = 1;
648 - rr = cursor_addr / h3270.cols; 648 + rr = h3270.cursor_addr / h3270.cols;
649 if (rr + nn >= h3270.cols) 649 if (rr + nn >= h3270.cols)
650 - cursor_move((h3270.cols-1)*h3270.cols + (cursor_addr%h3270.cols)); 650 + cursor_move((h3270.cols-1)*h3270.cols + (h3270.cursor_addr%h3270.cols));
651 else 651 else
652 - cursor_move(cursor_addr + (nn * h3270.cols)); 652 + cursor_move(h3270.cursor_addr + (nn * h3270.cols));
653 held_wrap = False; 653 held_wrap = False;
654 return DATA; 654 return DATA;
655 } 655 }
@@ -661,12 +661,12 @@ ansi_cursor_right(int nn, int ig2 unused) @@ -661,12 +661,12 @@ ansi_cursor_right(int nn, int ig2 unused)
661 661
662 if (nn < 1) 662 if (nn < 1)
663 nn = 1; 663 nn = 1;
664 - cc = cursor_addr % h3270.cols; 664 + cc = h3270.cursor_addr % h3270.cols;
665 if (cc == h3270.cols-1) 665 if (cc == h3270.cols-1)
666 return DATA; 666 return DATA;
667 if (cc + nn >= h3270.cols) 667 if (cc + nn >= h3270.cols)
668 nn = h3270.cols - 1 - cc; 668 nn = h3270.cols - 1 - cc;
669 - cursor_move(cursor_addr + nn); 669 + cursor_move(h3270.cursor_addr + nn);
670 held_wrap = False; 670 held_wrap = False;
671 return DATA; 671 return DATA;
672 } 672 }
@@ -682,12 +682,12 @@ ansi_cursor_left(int nn, int ig2 unused) @@ -682,12 +682,12 @@ ansi_cursor_left(int nn, int ig2 unused)
682 } 682 }
683 if (nn < 1) 683 if (nn < 1)
684 nn = 1; 684 nn = 1;
685 - cc = cursor_addr % h3270.cols; 685 + cc = h3270.cursor_addr % h3270.cols;
686 if (!cc) 686 if (!cc)
687 return DATA; 687 return DATA;
688 if (nn > cc) 688 if (nn > cc)
689 nn = cc; 689 nn = cc;
690 - cursor_move(cursor_addr - nn); 690 + cursor_move(h3270.cursor_addr - nn);
691 return DATA; 691 return DATA;
692 } 692 }
693 693
@@ -708,10 +708,10 @@ ansi_erase_in_display(int nn, int ig2 unused) @@ -708,10 +708,10 @@ ansi_erase_in_display(int nn, int ig2 unused)
708 { 708 {
709 switch (nn) { 709 switch (nn) {
710 case 0: /* below */ 710 case 0: /* below */
711 - ctlr_aclear(cursor_addr, (h3270.rows * h3270.cols) - cursor_addr, 1); 711 + ctlr_aclear(h3270.cursor_addr, (h3270.rows * h3270.cols) - h3270.cursor_addr, 1);
712 break; 712 break;
713 case 1: /* above */ 713 case 1: /* above */
714 - ctlr_aclear(0, cursor_addr + 1, 1); 714 + ctlr_aclear(0, h3270.cursor_addr + 1, 1);
715 break; 715 break;
716 case 2: /* all (without moving cursor) */ 716 case 2: /* all (without moving cursor) */
717 if (cursor_addr == 0 && !is_altbuffer) 717 if (cursor_addr == 0 && !is_altbuffer)
@@ -725,17 +725,17 @@ ansi_erase_in_display(int nn, int ig2 unused) @@ -725,17 +725,17 @@ ansi_erase_in_display(int nn, int ig2 unused)
725 static enum state 725 static enum state
726 ansi_erase_in_line(int nn, int ig2 unused) 726 ansi_erase_in_line(int nn, int ig2 unused)
727 { 727 {
728 - int nc = cursor_addr % h3270.cols; 728 + int nc = h3270.cursor_addr % h3270.cols;
729 729
730 switch (nn) { 730 switch (nn) {
731 case 0: /* to right */ 731 case 0: /* to right */
732 - ctlr_aclear(cursor_addr, h3270.cols - nc, 1); 732 + ctlr_aclear(h3270.cursor_addr, h3270.cols - nc, 1);
733 break; 733 break;
734 case 1: /* to left */ 734 case 1: /* to left */
735 - ctlr_aclear(cursor_addr - nc, nc+1, 1); 735 + ctlr_aclear(h3270.cursor_addr - nc, nc+1, 1);
736 break; 736 break;
737 case 2: /* all */ 737 case 2: /* all */
738 - ctlr_aclear(cursor_addr - nc, h3270.cols, 1); 738 + ctlr_aclear(h3270.cursor_addr - nc, h3270.cols, 1);
739 break; 739 break;
740 } 740 }
741 return DATA; 741 return DATA;
@@ -744,7 +744,7 @@ ansi_erase_in_line(int nn, int ig2 unused) @@ -744,7 +744,7 @@ ansi_erase_in_line(int nn, int ig2 unused)
744 static enum state 744 static enum state
745 ansi_insert_lines(int nn, int ig2 unused) 745 ansi_insert_lines(int nn, int ig2 unused)
746 { 746 {
747 - int rr = cursor_addr / h3270.cols; /* current row */ 747 + int rr = h3270.cursor_addr / h3270.cols; /* current row */
748 int mr = scroll_bottom - rr; /* rows left at and below this one */ 748 int mr = scroll_bottom - rr; /* rows left at and below this one */
749 int ns; /* rows that are shifting */ 749 int ns; /* rows that are shifting */
750 750
@@ -770,7 +770,7 @@ ansi_insert_lines(int nn, int ig2 unused) @@ -770,7 +770,7 @@ ansi_insert_lines(int nn, int ig2 unused)
770 static enum state 770 static enum state
771 ansi_delete_lines(int nn, int ig2 unused) 771 ansi_delete_lines(int nn, int ig2 unused)
772 { 772 {
773 - int rr = cursor_addr / h3270.cols; /* current row */ 773 + int rr = h3270.cursor_addr / h3270.cols; /* current row */
774 int mr = scroll_bottom - rr; /* max rows that can be deleted */ 774 int mr = scroll_bottom - rr; /* max rows that can be deleted */
775 int ns; /* rows that are shifting */ 775 int ns; /* rows that are shifting */
776 776
@@ -796,7 +796,7 @@ ansi_delete_lines(int nn, int ig2 unused) @@ -796,7 +796,7 @@ ansi_delete_lines(int nn, int ig2 unused)
796 static enum state 796 static enum state
797 ansi_delete_chars(int nn, int ig2 unused) 797 ansi_delete_chars(int nn, int ig2 unused)
798 { 798 {
799 - int cc = cursor_addr % h3270.cols; /* current col */ 799 + int cc = h3270.cursor_addr % h3270.cols; /* current col */
800 int mc = h3270.cols - cc; /* max chars that can be deleted */ 800 int mc = h3270.cols - cc; /* max chars that can be deleted */
801 int ns; /* chars that are shifting */ 801 int ns; /* chars that are shifting */
802 802
@@ -808,10 +808,10 @@ ansi_delete_chars(int nn, int ig2 unused) @@ -808,10 +808,10 @@ ansi_delete_chars(int nn, int ig2 unused)
808 /* Move the surviving chars left */ 808 /* Move the surviving chars left */
809 ns = mc - nn; 809 ns = mc - nn;
810 if (ns) 810 if (ns)
811 - ctlr_bcopy(cursor_addr + nn, cursor_addr, ns, 1); 811 + ctlr_bcopy(h3270.cursor_addr + nn, h3270.cursor_addr, ns, 1);
812 812
813 /* Clear the end of the line */ 813 /* Clear the end of the line */
814 - ctlr_aclear(cursor_addr + ns, nn, 1); 814 + ctlr_aclear(h3270.cursor_addr + ns, nn, 1);
815 return DATA; 815 return DATA;
816 } 816 }
817 817
@@ -936,11 +936,11 @@ ansi_backspace(int ig1 unused, int ig2 unused) @@ -936,11 +936,11 @@ ansi_backspace(int ig1 unused, int ig2 unused)
936 return DATA; 936 return DATA;
937 } 937 }
938 if (rev_wraparound_mode) { 938 if (rev_wraparound_mode) {
939 - if (cursor_addr > (scroll_top - 1) * h3270.cols)  
940 - cursor_move(cursor_addr - 1); 939 + if (h3270.cursor_addr > (scroll_top - 1) * h3270.cols)
  940 + cursor_move(h3270.cursor_addr - 1);
941 } else { 941 } else {
942 - if (cursor_addr % h3270.cols)  
943 - cursor_move(cursor_addr - 1); 942 + if (h3270.cursor_addr % h3270.cols)
  943 + cursor_move(h3270.cursor_addr - 1);
944 } 944 }
945 return DATA; 945 return DATA;
946 } 946 }
@@ -948,8 +948,8 @@ ansi_backspace(int ig1 unused, int ig2 unused) @@ -948,8 +948,8 @@ ansi_backspace(int ig1 unused, int ig2 unused)
948 static enum state 948 static enum state
949 ansi_cr(int ig1 unused, int ig2 unused) 949 ansi_cr(int ig1 unused, int ig2 unused)
950 { 950 {
951 - if (cursor_addr % h3270.cols)  
952 - cursor_move(cursor_addr - (cursor_addr % h3270.cols)); 951 + if (h3270.cursor_addr % h3270.cols)
  952 + cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols));
953 if (auto_newline_mode) 953 if (auto_newline_mode)
954 (void) ansi_lf(0, 0); 954 (void) ansi_lf(0, 0);
955 held_wrap = False; 955 held_wrap = False;
@@ -959,12 +959,12 @@ ansi_cr(int ig1 unused, int ig2 unused) @@ -959,12 +959,12 @@ ansi_cr(int ig1 unused, int ig2 unused)
959 static enum state 959 static enum state
960 ansi_lf(int ig1 unused, int ig2 unused) 960 ansi_lf(int ig1 unused, int ig2 unused)
961 { 961 {
962 - int nc = cursor_addr + h3270.cols; 962 + int nc = h3270.cursor_addr + h3270.cols;
963 963
964 held_wrap = False; 964 held_wrap = False;
965 965
966 /* If we're below the scrolling region, don't scroll. */ 966 /* If we're below the scrolling region, don't scroll. */
967 - if ((cursor_addr / h3270.cols) >= scroll_bottom) { 967 + if ((h3270.cursor_addr / h3270.cols) >= scroll_bottom) {
968 if (nc < h3270.rows * h3270.cols) 968 if (nc < h3270.rows * h3270.cols)
969 cursor_move(nc); 969 cursor_move(nc);
970 return DATA; 970 return DATA;
@@ -980,7 +980,7 @@ ansi_lf(int ig1 unused, int ig2 unused) @@ -980,7 +980,7 @@ ansi_lf(int ig1 unused, int ig2 unused)
980 static enum state 980 static enum state
981 ansi_htab(int ig1 unused, int ig2 unused) 981 ansi_htab(int ig1 unused, int ig2 unused)
982 { 982 {
983 - int col = cursor_addr % h3270.cols; 983 + int col = h3270.cursor_addr % h3270.cols;
984 int i; 984 int i;
985 985
986 held_wrap = False; 986 held_wrap = False;
@@ -989,7 +989,7 @@ ansi_htab(int ig1 unused, int ig2 unused) @@ -989,7 +989,7 @@ ansi_htab(int ig1 unused, int ig2 unused)
989 for (i = col+1; i < h3270.cols-1; i++) 989 for (i = col+1; i < h3270.cols-1; i++)
990 if (tabs[i/8] & 1<<(i%8)) 990 if (tabs[i/8] & 1<<(i%8))
991 break; 991 break;
992 - cursor_move(cursor_addr - col + i); 992 + cursor_move(h3270.cursor_addr - col + i);
993 return DATA; 993 return DATA;
994 } 994 }
995 995
@@ -1006,12 +1006,12 @@ ansi_nop(int ig1 unused, int ig2 unused) @@ -1006,12 +1006,12 @@ ansi_nop(int ig1 unused, int ig2 unused)
1006 } 1006 }
1007 1007
1008 #define PWRAP { \ 1008 #define PWRAP { \
1009 - nc = cursor_addr + 1; \ 1009 + nc = h3270.cursor_addr + 1; \
1010 if (nc < scroll_bottom * h3270.cols) \ 1010 if (nc < scroll_bottom * h3270.cols) \
1011 cursor_move(nc); \ 1011 cursor_move(nc); \
1012 else { \ 1012 else { \
1013 - if (cursor_addr / h3270.cols >= scroll_bottom) \  
1014 - cursor_move(cursor_addr / h3270.cols * h3270.cols); \ 1013 + if (h3270.cursor_addr / h3270.cols >= scroll_bottom) \
  1014 + cursor_move(h3270.cursor_addr / h3270.cols * h3270.cols); \
1015 else { \ 1015 else { \
1016 ansi_scroll(); \ 1016 ansi_scroll(); \
1017 cursor_move(nc - h3270.cols); \ 1017 cursor_move(nc - h3270.cols); \
@@ -1070,16 +1070,16 @@ ansi_printing(int ig1 unused, int ig2 unused) @@ -1070,16 +1070,16 @@ ansi_printing(int ig1 unused, int ig2 unused)
1070 switch (csd[(once_cset != -1) ? once_cset : cset]) { 1070 switch (csd[(once_cset != -1) ? once_cset : cset]) {
1071 case CSD_LD: /* line drawing "0" */ 1071 case CSD_LD: /* line drawing "0" */
1072 if (ansi_ch >= 0x5f && ansi_ch <= 0x7e) 1072 if (ansi_ch >= 0x5f && ansi_ch <= 0x7e)
1073 - ctlr_add(cursor_addr, (unsigned char)(ansi_ch - 0x5f), 1073 + ctlr_add(h3270.cursor_addr, (unsigned char)(ansi_ch - 0x5f),
1074 CS_LINEDRAW); 1074 CS_LINEDRAW);
1075 else 1075 else
1076 - ctlr_add(cursor_addr, asc2ebc[ansi_ch], CS_BASE); 1076 + ctlr_add(h3270.cursor_addr, asc2ebc[ansi_ch], CS_BASE);
1077 break; 1077 break;
1078 case CSD_UK: /* UK "A" */ 1078 case CSD_UK: /* UK "A" */
1079 if (ansi_ch == '#') 1079 if (ansi_ch == '#')
1080 - ctlr_add(cursor_addr, 0x1e, CS_LINEDRAW); 1080 + ctlr_add(h3270.cursor_addr, 0x1e, CS_LINEDRAW);
1081 else 1081 else
1082 - ctlr_add(cursor_addr, asc2ebc[ansi_ch], CS_BASE); 1082 + ctlr_add(h3270.cursor_addr, asc2ebc[ansi_ch], CS_BASE);
1083 break; 1083 break;
1084 case CSD_US: /* US "B" */ 1084 case CSD_US: /* US "B" */
1085 ebc_ch = asc2ebc[ansi_ch]; 1085 ebc_ch = asc2ebc[ansi_ch];
@@ -1157,7 +1157,7 @@ ansi_printing(int ig1 unused, int ig2 unused) @@ -1157,7 +1157,7 @@ ansi_printing(int ig1 unused, int ig2 unused)
1157 ea_buf[cursor_addr].db = DBCS_NONE; 1157 ea_buf[cursor_addr].db = DBCS_NONE;
1158 } 1158 }
1159 #endif /*]*/ 1159 #endif /*]*/
1160 - ctlr_add(cursor_addr, ebc_ch, default_cs); 1160 + ctlr_add(h3270.cursor_addr, ebc_ch, default_cs);
1161 #if defined(X3270_DBCS) /*[*/ 1161 #if defined(X3270_DBCS) /*[*/
1162 if (default_cs == CS_DBCS) 1162 if (default_cs == CS_DBCS)
1163 (void) ctlr_dbcs_postprocess(); 1163 (void) ctlr_dbcs_postprocess();
@@ -1165,9 +1165,9 @@ ansi_printing(int ig1 unused, int ig2 unused) @@ -1165,9 +1165,9 @@ ansi_printing(int ig1 unused, int ig2 unused)
1165 break; 1165 break;
1166 } 1166 }
1167 once_cset = -1; 1167 once_cset = -1;
1168 - ctlr_add_gr(cursor_addr, gr);  
1169 - ctlr_add_fg(cursor_addr, fg);  
1170 - ctlr_add_bg(cursor_addr, bg); 1168 + ctlr_add_gr(h3270.cursor_addr, gr);
  1169 + ctlr_add_fg(h3270.cursor_addr, fg);
  1170 + ctlr_add_bg(h3270.cursor_addr, bg);
1171 if (wraparound_mode) { 1171 if (wraparound_mode) {
1172 /* 1172 /*
1173 * There is a fascinating behavior of xterm which we will 1173 * There is a fascinating behavior of xterm which we will
@@ -1182,14 +1182,14 @@ ansi_printing(int ig1 unused, int ig2 unused) @@ -1182,14 +1182,14 @@ ansi_printing(int ig1 unused, int ig2 unused)
1182 * In my opinion, very strange, but among other things, 'vi' 1182 * In my opinion, very strange, but among other things, 'vi'
1183 * depends on it! 1183 * depends on it!
1184 */ 1184 */
1185 - if (!((cursor_addr + 1) % h3270.cols)) { 1185 + if (!((h3270.cursor_addr + 1) % h3270.cols)) {
1186 held_wrap = True; 1186 held_wrap = True;
1187 } else { 1187 } else {
1188 PWRAP; 1188 PWRAP;
1189 } 1189 }
1190 } else { 1190 } else {
1191 - if ((cursor_addr % h3270.cols) != (h3270.cols - 1))  
1192 - cursor_move(cursor_addr + 1); 1191 + if ((h3270.cursor_addr % h3270.cols) != (h3270.cols - 1))
  1192 + cursor_move(h3270.cursor_addr + 1);
1193 } 1193 }
1194 return DATA; 1194 return DATA;
1195 } 1195 }
@@ -1259,7 +1259,7 @@ ansi_digit(int ig1 unused, int ig2 unused) @@ -1259,7 +1259,7 @@ ansi_digit(int ig1 unused, int ig2 unused)
1259 static enum state 1259 static enum state
1260 ansi_reverse_index(int ig1 unused, int ig2 unused) 1260 ansi_reverse_index(int ig1 unused, int ig2 unused)
1261 { 1261 {
1262 - int rr = cursor_addr / h3270.cols; /* current row */ 1262 + int rr = h3270.cursor_addr / h3270.cols; /* current row */
1263 int np = (scroll_top - 1) - rr; /* number of rows in the scrolling 1263 int np = (scroll_top - 1) - rr; /* number of rows in the scrolling
1264 region, above this line */ 1264 region, above this line */
1265 int ns; /* number of rows to scroll */ 1265 int ns; /* number of rows to scroll */
@@ -1345,7 +1345,7 @@ ansi_status_report(int nn, int ig2 unused) @@ -1345,7 +1345,7 @@ ansi_status_report(int nn, int ig2 unused)
1345 break; 1345 break;
1346 case 6: 1346 case 6:
1347 (void) sprintf(cpr, "\033[%d;%dR", 1347 (void) sprintf(cpr, "\033[%d;%dR",
1348 - (cursor_addr/h3270.cols) + 1, (cursor_addr%h3270.cols) + 1); 1348 + (h3270.cursor_addr/h3270.cols) + 1, (h3270.cursor_addr%h3270.cols) + 1);
1349 net_sends(cpr); 1349 net_sends(cpr);
1350 break; 1350 break;
1351 } 1351 }
@@ -1630,7 +1630,7 @@ xterm_text_do(int ig1 unused, int ig2 unused) @@ -1630,7 +1630,7 @@ xterm_text_do(int ig1 unused, int ig2 unused)
1630 static enum state 1630 static enum state
1631 ansi_htab_set(int ig1 unused, int ig2 unused) 1631 ansi_htab_set(int ig1 unused, int ig2 unused)
1632 { 1632 {
1633 - register int col = cursor_addr % h3270.cols; 1633 + register int col = h3270.cursor_addr % h3270.cols;
1634 1634
1635 tabs[col/8] |= 1<<(col%8); 1635 tabs[col/8] |= 1<<(col%8);
1636 return DATA; 1636 return DATA;
@@ -1643,7 +1643,7 @@ ansi_htab_clear(int nn, int ig2 unused) @@ -1643,7 +1643,7 @@ ansi_htab_clear(int nn, int ig2 unused)
1643 1643
1644 switch (nn) { 1644 switch (nn) {
1645 case 0: 1645 case 0:
1646 - col = cursor_addr % h3270.cols; 1646 + col = h3270.cursor_addr % h3270.cols;
1647 tabs[col/8] &= ~(1<<(col%8)); 1647 tabs[col/8] &= ~(1<<(col%8));
1648 break; 1648 break;
1649 case 3: 1649 case 3:
latest/src/lib/ctlr.c
@@ -74,8 +74,9 @@ extern unsigned char aid; @@ -74,8 +74,9 @@ extern unsigned char aid;
74 // int ROWS, COLS; 74 // int ROWS, COLS;
75 //int maxROWS = 0; 75 //int maxROWS = 0;
76 //int maxCOLS = 0; 76 //int maxCOLS = 0;
  77 +// int cursor_addr;
77 78
78 -int cursor_addr, buffer_addr; 79 +int buffer_addr;
79 Boolean screen_alt = False; /* alternate screen? */ 80 Boolean screen_alt = False; /* alternate screen? */
80 Boolean is_altbuffer = False; 81 Boolean is_altbuffer = False;
81 82
@@ -174,7 +175,7 @@ void ctlr_reinit(H3270 *session, unsigned cmask) @@ -174,7 +175,7 @@ void ctlr_reinit(H3270 *session, unsigned cmask)
174 real_aea_buf = (struct ea *)Calloc(sizeof(struct ea),(session->maxROWS * session->maxCOLS) + 1); 175 real_aea_buf = (struct ea *)Calloc(sizeof(struct ea),(session->maxROWS * session->maxCOLS) + 1);
175 aea_buf = real_aea_buf + 1; 176 aea_buf = real_aea_buf + 1;
176 Replace(zero_buf, (unsigned char *)Calloc(sizeof(struct ea),session->maxROWS * session->maxCOLS)); 177 Replace(zero_buf, (unsigned char *)Calloc(sizeof(struct ea),session->maxROWS * session->maxCOLS));
177 - cursor_addr = 0; 178 + session->cursor_addr = 0;
178 buffer_addr = 0; 179 buffer_addr = 0;
179 } 180 }
180 } 181 }
@@ -676,8 +677,8 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) @@ -676,8 +677,8 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all)
676 trace_ds("%s",see_aid(aid_byte)); 677 trace_ds("%s",see_aid(aid_byte));
677 if (short_read) 678 if (short_read)
678 goto rm_done; 679 goto rm_done;
679 - ENCODE_BADDR(obptr, cursor_addr);  
680 - trace_ds("%s",rcba(cursor_addr)); 680 + ENCODE_BADDR(obptr, h3270.cursor_addr);
  681 + trace_ds("%s",rcba(h3270.cursor_addr));
681 } else { 682 } else {
682 space3270out(1); /* just in case */ 683 space3270out(1); /* just in case */
683 } 684 }
@@ -820,8 +821,8 @@ ctlr_read_buffer(unsigned char aid_byte) @@ -820,8 +821,8 @@ ctlr_read_buffer(unsigned char aid_byte)
820 821
821 space3270out(3); 822 space3270out(3);
822 *obptr++ = aid_byte; 823 *obptr++ = aid_byte;
823 - ENCODE_BADDR(obptr, cursor_addr);  
824 - trace_ds("%s%s", see_aid(aid_byte), rcba(cursor_addr)); 824 + ENCODE_BADDR(obptr, h3270.cursor_addr);
  825 + trace_ds("%s%s", see_aid(aid_byte), rcba(h3270.cursor_addr));
825 826
826 baddr = 0; 827 baddr = 0;
827 do { 828 do {
@@ -1018,7 +1019,7 @@ ctlr_snap_buffer(void) @@ -1018,7 +1019,7 @@ ctlr_snap_buffer(void)
1018 1019
1019 space3270out(4); 1020 space3270out(4);
1020 *obptr++ = ORDER_SBA; 1021 *obptr++ = ORDER_SBA;
1021 - ENCODE_BADDR(obptr, cursor_addr); 1022 + ENCODE_BADDR(obptr, h3270.cursor_addr);
1022 *obptr++ = ORDER_IC; 1023 *obptr++ = ORDER_IC;
1023 } 1024 }
1024 1025
@@ -1165,7 +1166,7 @@ ctlr_write(unsigned char buf[], int buflen, Boolean erase) @@ -1165,7 +1166,7 @@ ctlr_write(unsigned char buf[], int buflen, Boolean erase)
1165 default_cs = 0; 1166 default_cs = 0;
1166 default_ic = 0; 1167 default_ic = 0;
1167 trace_primed = True; 1168 trace_primed = True;
1168 - buffer_addr = cursor_addr; 1169 + buffer_addr = h3270.cursor_addr;
1169 if (WCC_RESET(buf[1])) { 1170 if (WCC_RESET(buf[1])) {
1170 if (erase) 1171 if (erase)
1171 reply_mode = SF_SRM_FIELD; 1172 reply_mode = SF_SRM_FIELD;
@@ -2745,12 +2746,14 @@ static void keep_ticking(H3270 *session) @@ -2745,12 +2746,14 @@ static void keep_ticking(H3270 *session)
2745 struct timeval t1; 2746 struct timeval t1;
2746 long msec; 2747 long msec;
2747 2748
2748 - do { 2749 + do
  2750 + {
2749 (void) gettimeofday(&t1, (struct timezone *) 0); 2751 (void) gettimeofday(&t1, (struct timezone *) 0);
2750 t_want.tv_sec++; 2752 t_want.tv_sec++;
2751 msec = delta_msec(&t_want, &t1); 2753 msec = delta_msec(&t_want, &t1);
2752 } while (msec <= 0); 2754 } while (msec <= 0);
2753 - tick_id = AddTimeOut(msec, &h3270, keep_ticking); 2755 +
  2756 + tick_id = AddTimeOut(msec, session, keep_ticking);
2754 status_timing(&t_start, &t1); 2757 status_timing(&t_start, &t1);
2755 } 2758 }
2756 2759
latest/src/lib/globals.h
@@ -130,6 +130,8 @@ @@ -130,6 +130,8 @@
130 /* Stop conflicting with curses' COLS, even if we don't link with it. */ 130 /* Stop conflicting with curses' COLS, even if we don't link with it. */
131 // #define COLS cCOLS 131 // #define COLS cCOLS
132 132
  133 +#define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270;
  134 +
133 135
134 /* types of internal actions */ 136 /* types of internal actions */
135 enum iaction { 137 enum iaction {
latest/src/lib/kybd.c
@@ -511,7 +511,7 @@ key_AID(unsigned char aid_code) @@ -511,7 +511,7 @@ key_AID(unsigned char aid_code)
511 plugin_aid(aid_code); 511 plugin_aid(aid_code);
512 #endif /*]*/ 512 #endif /*]*/
513 513
514 - Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,cursor_addr); 514 + Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr);
515 515
516 if (IN_SSCP) { 516 if (IN_SSCP) {
517 if (kybdlock & KL_OIA_MINUS) 517 if (kybdlock & KL_OIA_MINUS)
@@ -524,7 +524,7 @@ key_AID(unsigned char aid_code) @@ -524,7 +524,7 @@ key_AID(unsigned char aid_code)
524 } 524 }
525 if (IN_SSCP && aid_code == AID_ENTER) { 525 if (IN_SSCP && aid_code == AID_ENTER) {
526 /* Act as if the host had written our input. */ 526 /* Act as if the host had written our input. */
527 - buffer_addr = cursor_addr; 527 + buffer_addr = h3270.cursor_addr;
528 } 528 }
529 if (!IN_SSCP || aid_code != AID_CLEAR) { 529 if (!IN_SSCP || aid_code != AID_CLEAR) {
530 status_twait(); 530 status_twait();
@@ -765,7 +765,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) @@ -765,7 +765,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped)
765 enq_ta(key_Character_wrapper, codename, CN); 765 enq_ta(key_Character_wrapper, codename, CN);
766 return False; 766 return False;
767 } 767 }
768 - baddr = cursor_addr; 768 + baddr = h3270.cursor_addr;
769 faddr = find_field_attribute(baddr); 769 faddr = find_field_attribute(baddr);
770 fa = get_field_attribute(baddr); 770 fa = get_field_attribute(baddr);
771 if (ea_buf[baddr].fa || FA_IS_PROTECTED(fa)) { 771 if (ea_buf[baddr].fa || FA_IS_PROTECTED(fa)) {
@@ -953,7 +953,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) @@ -953,7 +953,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped)
953 } 953 }
954 } 954 }
955 955
956 - mdt_set(cursor_addr); 956 + mdt_set(h3270.cursor_addr);
957 957
958 /* 958 /*
959 * Implement auto-skip, and don't land on attribute bytes. 959 * Implement auto-skip, and don't land on attribute bytes.
@@ -1437,7 +1437,7 @@ LIB3270_KEY_ACTION( tab ) @@ -1437,7 +1437,7 @@ LIB3270_KEY_ACTION( tab )
1437 return 0; 1437 return 0;
1438 } 1438 }
1439 #endif /*]*/ 1439 #endif /*]*/
1440 - cursor_move(next_unprotected(cursor_addr)); 1440 + cursor_move(next_unprotected(h3270.cursor_addr));
1441 return 0; 1441 return 0;
1442 } 1442 }
1443 1443
@@ -1463,7 +1463,7 @@ LIB3270_KEY_ACTION( backtab ) @@ -1463,7 +1463,7 @@ LIB3270_KEY_ACTION( backtab )
1463 } 1463 }
1464 if (!IN_3270) 1464 if (!IN_3270)
1465 return 0; 1465 return 0;
1466 - baddr = cursor_addr; 1466 + baddr = h3270.cursor_addr;
1467 DEC_BA(baddr); 1467 DEC_BA(baddr);
1468 if (ea_buf[baddr].fa) /* at bof */ 1468 if (ea_buf[baddr].fa) /* at bof */
1469 DEC_BA(baddr); 1469 DEC_BA(baddr);
@@ -1621,7 +1621,7 @@ do_left(void) @@ -1621,7 +1621,7 @@ do_left(void)
1621 register int baddr; 1621 register int baddr;
1622 enum dbcs_state d; 1622 enum dbcs_state d;
1623 1623
1624 - baddr = cursor_addr; 1624 + baddr = h3270.cursor_addr;
1625 DEC_BA(baddr); 1625 DEC_BA(baddr);
1626 d = ctlr_dbcs_state(baddr); 1626 d = ctlr_dbcs_state(baddr);
1627 if (IS_LEFT(d)) 1627 if (IS_LEFT(d))
@@ -1666,7 +1666,7 @@ LIB3270_CURSOR_ACTION( left ) @@ -1666,7 +1666,7 @@ LIB3270_CURSOR_ACTION( left )
1666 { 1666 {
1667 register int baddr; 1667 register int baddr;
1668 1668
1669 - baddr = cursor_addr; 1669 + baddr = h3270.cursor_addr;
1670 INC_BA(baddr); 1670 INC_BA(baddr);
1671 /* XXX: DBCS? */ 1671 /* XXX: DBCS? */
1672 cursor_move(baddr); 1672 cursor_move(baddr);
@@ -1688,7 +1688,7 @@ do_delete(void) @@ -1688,7 +1688,7 @@ do_delete(void)
1688 int ndel; 1688 int ndel;
1689 register int i; 1689 register int i;
1690 1690
1691 - baddr = cursor_addr; 1691 + baddr = h3270.cursor_addr;
1692 1692
1693 /* Can't delete a field attribute. */ 1693 /* Can't delete a field attribute. */
1694 fa = get_field_attribute(baddr); 1694 fa = get_field_attribute(baddr);
@@ -1748,7 +1748,7 @@ do_delete(void) @@ -1748,7 +1748,7 @@ do_delete(void)
1748 ctlr_add(end_baddr - i, EBC_null, 0); 1748 ctlr_add(end_baddr - i, EBC_null, 0);
1749 1749
1750 /* Set the MDT for this field. */ 1750 /* Set the MDT for this field. */
1751 - mdt_set(cursor_addr); 1751 + mdt_set(h3270.cursor_addr);
1752 1752
1753 /* Patch up the DBCS state for display. */ 1753 /* Patch up the DBCS state for display. */
1754 (void) ctlr_dbcs_postprocess(); 1754 (void) ctlr_dbcs_postprocess();
@@ -1806,7 +1806,7 @@ LIB3270_ACTION( backspace ) @@ -1806,7 +1806,7 @@ LIB3270_ACTION( backspace )
1806 else { 1806 else {
1807 register int baddr; 1807 register int baddr;
1808 1808
1809 - baddr = cursor_addr; 1809 + baddr = h3270.cursor_addr;
1810 DEC_BA(baddr); 1810 DEC_BA(baddr);
1811 cursor_move(baddr); 1811 cursor_move(baddr);
1812 } 1812 }
@@ -1824,7 +1824,7 @@ do_erase(void) @@ -1824,7 +1824,7 @@ do_erase(void)
1824 int baddr, faddr; 1824 int baddr, faddr;
1825 enum dbcs_state d; 1825 enum dbcs_state d;
1826 1826
1827 - baddr = cursor_addr; 1827 + baddr = h3270.cursor_addr;
1828 faddr = find_field_attribute(baddr); 1828 faddr = find_field_attribute(baddr);
1829 if (faddr == baddr || FA_IS_PROTECTED(ea_buf[baddr].fa)) { 1829 if (faddr == baddr || FA_IS_PROTECTED(ea_buf[baddr].fa)) {
1830 operator_error(KL_OERR_PROTECTED); 1830 operator_error(KL_OERR_PROTECTED);
@@ -1837,8 +1837,8 @@ do_erase(void) @@ -1837,8 +1837,8 @@ do_erase(void)
1837 /* 1837 /*
1838 * If we are now on an SI, move left again. 1838 * If we are now on an SI, move left again.
1839 */ 1839 */
1840 - if (ea_buf[cursor_addr].cc == EBC_si) {  
1841 - baddr = cursor_addr; 1840 + if (ea_buf[h3270.cursor_addr].cc == EBC_si) {
  1841 + baddr = h3270.cursor_addr;
1842 DEC_BA(baddr); 1842 DEC_BA(baddr);
1843 cursor_move(baddr); 1843 cursor_move(baddr);
1844 } 1844 }
@@ -1866,9 +1866,9 @@ do_erase(void) @@ -1866,9 +1866,9 @@ do_erase(void)
1866 * If we've just erased the last character of a DBCS subfield, erase 1866 * If we've just erased the last character of a DBCS subfield, erase
1867 * the SO/SI pair as well. 1867 * the SO/SI pair as well.
1868 */ 1868 */
1869 - baddr = cursor_addr; 1869 + baddr = h3270.cursor_addr;
1870 DEC_BA(baddr); 1870 DEC_BA(baddr);
1871 - if (ea_buf[baddr].cc == EBC_so && ea_buf[cursor_addr].cc == EBC_si) { 1871 + if (ea_buf[baddr].cc == EBC_so && ea_buf[h3270.cursor_addr].cc == EBC_si) {
1872 cursor_move(baddr); 1872 cursor_move(baddr);
1873 (void) do_delete(); 1873 (void) do_delete();
1874 } 1874 }
@@ -1921,7 +1921,7 @@ LIB3270_CURSOR_ACTION( right ) @@ -1921,7 +1921,7 @@ LIB3270_CURSOR_ACTION( right )
1921 #endif /*]*/ 1921 #endif /*]*/
1922 if (!flipped) 1922 if (!flipped)
1923 { 1923 {
1924 - baddr = cursor_addr; 1924 + baddr = h3270.cursor_addr;
1925 INC_BA(baddr); 1925 INC_BA(baddr);
1926 d = ctlr_dbcs_state(baddr); 1926 d = ctlr_dbcs_state(baddr);
1927 if (IS_RIGHT(d)) 1927 if (IS_RIGHT(d))
@@ -1996,7 +1996,7 @@ LIB3270_ACTION( previousword ) @@ -1996,7 +1996,7 @@ LIB3270_ACTION( previousword )
1996 if (!formatted) 1996 if (!formatted)
1997 return 0; 1997 return 0;
1998 1998
1999 - baddr = cursor_addr; 1999 + baddr = h3270.cursor_addr;
2000 prot = FA_IS_PROTECTED(get_field_attribute(baddr)); 2000 prot = FA_IS_PROTECTED(get_field_attribute(baddr));
2001 2001
2002 /* Skip to before this word, if in one now. */ 2002 /* Skip to before this word, if in one now. */
@@ -2004,7 +2004,7 @@ LIB3270_ACTION( previousword ) @@ -2004,7 +2004,7 @@ LIB3270_ACTION( previousword )
2004 c = ea_buf[baddr].cc; 2004 c = ea_buf[baddr].cc;
2005 while (!ea_buf[baddr].fa && c != EBC_space && c != EBC_null) { 2005 while (!ea_buf[baddr].fa && c != EBC_space && c != EBC_null) {
2006 DEC_BA(baddr); 2006 DEC_BA(baddr);
2007 - if (baddr == cursor_addr) 2007 + if (baddr == h3270.cursor_addr)
2008 return 0; 2008 return 0;
2009 c = ea_buf[baddr].cc; 2009 c = ea_buf[baddr].cc;
2010 } 2010 }
@@ -2148,25 +2148,25 @@ LIB3270_ACTION( nextword ) @@ -2148,25 +2148,25 @@ LIB3270_ACTION( nextword )
2148 return 0; 2148 return 0;
2149 2149
2150 /* If not in an unprotected field, go to the next unprotected word. */ 2150 /* If not in an unprotected field, go to the next unprotected word. */
2151 - if (ea_buf[cursor_addr].fa ||  
2152 - FA_IS_PROTECTED(get_field_attribute(cursor_addr))) {  
2153 - baddr = nu_word(cursor_addr); 2151 + if (ea_buf[h3270.cursor_addr].fa ||
  2152 + FA_IS_PROTECTED(get_field_attribute(h3270.cursor_addr))) {
  2153 + baddr = nu_word(h3270.cursor_addr);
2154 if (baddr != -1) 2154 if (baddr != -1)
2155 cursor_move(baddr); 2155 cursor_move(baddr);
2156 return 0; 2156 return 0;
2157 } 2157 }
2158 2158
2159 /* If there's another word in this field, go to it. */ 2159 /* If there's another word in this field, go to it. */
2160 - baddr = nt_word(cursor_addr); 2160 + baddr = nt_word(h3270.cursor_addr);
2161 if (baddr != -1) { 2161 if (baddr != -1) {
2162 cursor_move(baddr); 2162 cursor_move(baddr);
2163 return 0; 2163 return 0;
2164 } 2164 }
2165 2165
2166 /* If in a word, go to just after its end. */ 2166 /* If in a word, go to just after its end. */
2167 - c = ea_buf[cursor_addr].cc; 2167 + c = ea_buf[h3270.cursor_addr].cc;
2168 if (c != EBC_space && c != EBC_null) { 2168 if (c != EBC_space && c != EBC_null) {
2169 - baddr = cursor_addr; 2169 + baddr = h3270.cursor_addr;
2170 do { 2170 do {
2171 c = ea_buf[baddr].cc; 2171 c = ea_buf[baddr].cc;
2172 if (c == EBC_space || c == EBC_null) { 2172 if (c == EBC_space || c == EBC_null) {
@@ -2179,11 +2179,11 @@ LIB3270_ACTION( nextword ) @@ -2179,11 +2179,11 @@ LIB3270_ACTION( nextword )
2179 return 0; 2179 return 0;
2180 } 2180 }
2181 INC_BA(baddr); 2181 INC_BA(baddr);
2182 - } while (baddr != cursor_addr); 2182 + } while (baddr != h3270.cursor_addr);
2183 } 2183 }
2184 /* Otherwise, go to the next unprotected word. */ 2184 /* Otherwise, go to the next unprotected word. */
2185 else { 2185 else {
2186 - baddr = nu_word(cursor_addr); 2186 + baddr = nu_word(h3270.cursor_addr);
2187 if (baddr != -1) 2187 if (baddr != -1)
2188 cursor_move(baddr); 2188 cursor_move(baddr);
2189 } 2189 }
@@ -2231,9 +2231,9 @@ LIB3270_CURSOR_ACTION( up ) @@ -2231,9 +2231,9 @@ LIB3270_CURSOR_ACTION( up )
2231 return 0; 2231 return 0;
2232 } 2232 }
2233 #endif /*]*/ 2233 #endif /*]*/
2234 - baddr = cursor_addr - h3270.cols; 2234 + baddr = h3270.cursor_addr - h3270.cols;
2235 if (baddr < 0) 2235 if (baddr < 0)
2236 - baddr = (cursor_addr + (h3270.rows * h3270.cols)) - h3270.cols; 2236 + baddr = (h3270.cursor_addr + (h3270.rows * h3270.cols)) - h3270.cols;
2237 cursor_move(baddr); 2237 cursor_move(baddr);
2238 return 0; 2238 return 0;
2239 } 2239 }
@@ -2280,7 +2280,7 @@ LIB3270_CURSOR_ACTION( down ) @@ -2280,7 +2280,7 @@ LIB3270_CURSOR_ACTION( down )
2280 return 0; 2280 return 0;
2281 } 2281 }
2282 #endif /*]*/ 2282 #endif /*]*/
2283 - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); 2283 + baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows);
2284 cursor_move(baddr); 2284 cursor_move(baddr);
2285 return 0; 2285 return 0;
2286 } 2286 }
@@ -2308,7 +2308,7 @@ LIB3270_CURSOR_ACTION( newline ) @@ -2308,7 +2308,7 @@ LIB3270_CURSOR_ACTION( newline )
2308 return 0; 2308 return 0;
2309 } 2309 }
2310 #endif /*]*/ 2310 #endif /*]*/
2311 - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */ 2311 + baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */
2312 baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */ 2312 baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */
2313 faddr = find_field_attribute(baddr); 2313 faddr = find_field_attribute(baddr);
2314 fa = ea_buf[faddr].fa; 2314 fa = ea_buf[faddr].fa;
@@ -2337,7 +2337,7 @@ Dup_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) @@ -2337,7 +2337,7 @@ Dup_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params)
2337 return; 2337 return;
2338 #endif /*]*/ 2338 #endif /*]*/
2339 if (key_Character(EBC_dup, False, False, NULL)) 2339 if (key_Character(EBC_dup, False, False, NULL))
2340 - cursor_move(next_unprotected(cursor_addr)); 2340 + cursor_move(next_unprotected(h3270.cursor_addr));
2341 } 2341 }
2342 2342
2343 2343
@@ -2542,29 +2542,6 @@ CursorSelect_action(Widget w unused, XEvent *event, String *params, @@ -2542,29 +2542,6 @@ CursorSelect_action(Widget w unused, XEvent *event, String *params,
2542 } 2542 }
2543 */ 2543 */
2544 2544
2545 -#if defined(X3270_DISPLAY)  
2546 -/*  
2547 - * Cursor Select mouse action (light pen simulator).  
2548 - */  
2549 -/*  
2550 -void  
2551 -MouseSelect_action(Widget w, XEvent *event, String *params,  
2552 - Cardinal *num_params)  
2553 -{  
2554 - if (w != *screen)  
2555 - return;  
2556 -// reset_idle_timer();  
2557 - if (kybdlock)  
2558 - return;  
2559 -#if defined(X3270_ANSI)  
2560 - if (IN_ANSI)  
2561 - return;  
2562 -#endif  
2563 - lightpen_select(mouse_baddr(w, event));  
2564 -}  
2565 -*/  
2566 -#endif  
2567 -  
2568 /** 2545 /**
2569 * Erase End Of Line Key. 2546 * Erase End Of Line Key.
2570 * 2547 *
@@ -2587,7 +2564,7 @@ LIB3270_ACTION( eraseeol ) @@ -2587,7 +2564,7 @@ LIB3270_ACTION( eraseeol )
2587 return 0; 2564 return 0;
2588 #endif /*]*/ 2565 #endif /*]*/
2589 2566
2590 - baddr = cursor_addr; 2567 + baddr = h3270.cursor_addr;
2591 fa = get_field_attribute(baddr); 2568 fa = get_field_attribute(baddr);
2592 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) 2569 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa)
2593 { 2570 {
@@ -2604,7 +2581,7 @@ LIB3270_ACTION( eraseeol ) @@ -2604,7 +2581,7 @@ LIB3270_ACTION( eraseeol )
2604 INC_BA(baddr); 2581 INC_BA(baddr);
2605 } while (!ea_buf[baddr].fa && BA_TO_COL(baddr) > 0); 2582 } while (!ea_buf[baddr].fa && BA_TO_COL(baddr) > 0);
2606 2583
2607 - mdt_set(cursor_addr); 2584 + mdt_set(h3270.cursor_addr);
2608 } 2585 }
2609 else 2586 else
2610 { 2587 {
@@ -2652,7 +2629,7 @@ LIB3270_ACTION( eraseeof ) @@ -2652,7 +2629,7 @@ LIB3270_ACTION( eraseeof )
2652 if (IN_ANSI) 2629 if (IN_ANSI)
2653 return 0; 2630 return 0;
2654 #endif /*]*/ 2631 #endif /*]*/
2655 - baddr = cursor_addr; 2632 + baddr = h3270.cursor_addr;
2656 fa = get_field_attribute(baddr); 2633 fa = get_field_attribute(baddr);
2657 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) { 2634 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) {
2658 operator_error(KL_OERR_PROTECTED); 2635 operator_error(KL_OERR_PROTECTED);
@@ -2663,7 +2640,7 @@ LIB3270_ACTION( eraseeof ) @@ -2663,7 +2640,7 @@ LIB3270_ACTION( eraseeof )
2663 ctlr_add(baddr, EBC_null, 0); 2640 ctlr_add(baddr, EBC_null, 0);
2664 INC_BA(baddr); 2641 INC_BA(baddr);
2665 } while (!ea_buf[baddr].fa); 2642 } while (!ea_buf[baddr].fa);
2666 - mdt_set(cursor_addr); 2643 + mdt_set(h3270.cursor_addr);
2667 } else { /* erase to end of screen */ 2644 } else { /* erase to end of screen */
2668 do { 2645 do {
2669 ctlr_add(baddr, EBC_null, 0); 2646 ctlr_add(baddr, EBC_null, 0);
@@ -2770,7 +2747,7 @@ LIB3270_ACTION( deleteword ) @@ -2770,7 +2747,7 @@ LIB3270_ACTION( deleteword )
2770 if (!formatted) 2747 if (!formatted)
2771 return 0; 2748 return 0;
2772 2749
2773 - baddr = cursor_addr; 2750 + baddr = h3270.cursor_addr;
2774 fa = get_field_attribute(baddr); 2751 fa = get_field_attribute(baddr);
2775 2752
2776 /* Make sure we're on a modifiable field. */ 2753 /* Make sure we're on a modifiable field. */
@@ -2781,7 +2758,7 @@ LIB3270_ACTION( deleteword ) @@ -2781,7 +2758,7 @@ LIB3270_ACTION( deleteword )
2781 2758
2782 /* Backspace over any spaces to the left of the cursor. */ 2759 /* Backspace over any spaces to the left of the cursor. */
2783 for (;;) { 2760 for (;;) {
2784 - baddr = cursor_addr; 2761 + baddr = h3270.cursor_addr;
2785 DEC_BA(baddr); 2762 DEC_BA(baddr);
2786 if (ea_buf[baddr].fa) 2763 if (ea_buf[baddr].fa)
2787 return 0; 2764 return 0;
@@ -2794,7 +2771,7 @@ LIB3270_ACTION( deleteword ) @@ -2794,7 +2771,7 @@ LIB3270_ACTION( deleteword )
2794 2771
2795 /* Backspace until the character to the left of the cursor is blank. */ 2772 /* Backspace until the character to the left of the cursor is blank. */
2796 for (;;) { 2773 for (;;) {
2797 - baddr = cursor_addr; 2774 + baddr = h3270.cursor_addr;
2798 DEC_BA(baddr); 2775 DEC_BA(baddr);
2799 if (ea_buf[baddr].fa) 2776 if (ea_buf[baddr].fa)
2800 return 0; 2777 return 0;
@@ -2837,7 +2814,7 @@ LIB3270_ACTION( deletefield ) @@ -2837,7 +2814,7 @@ LIB3270_ACTION( deletefield )
2837 if (!formatted) 2814 if (!formatted)
2838 return 0; 2815 return 0;
2839 2816
2840 - baddr = cursor_addr; 2817 + baddr = h3270.cursor_addr;
2841 fa = get_field_attribute(baddr); 2818 fa = get_field_attribute(baddr);
2842 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) { 2819 if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) {
2843 operator_error(KL_OERR_PROTECTED); 2820 operator_error(KL_OERR_PROTECTED);
@@ -2846,7 +2823,7 @@ LIB3270_ACTION( deletefield ) @@ -2846,7 +2823,7 @@ LIB3270_ACTION( deletefield )
2846 while (!ea_buf[baddr].fa) 2823 while (!ea_buf[baddr].fa)
2847 DEC_BA(baddr); 2824 DEC_BA(baddr);
2848 INC_BA(baddr); 2825 INC_BA(baddr);
2849 - mdt_set(cursor_addr); 2826 + mdt_set(h3270.cursor_addr);
2850 cursor_move(baddr); 2827 cursor_move(baddr);
2851 while (!ea_buf[baddr].fa) { 2828 while (!ea_buf[baddr].fa) {
2852 ctlr_add(baddr, EBC_null, 0); 2829 ctlr_add(baddr, EBC_null, 0);
@@ -2940,7 +2917,7 @@ LIB3270_ACTION( fieldend ) @@ -2940,7 +2917,7 @@ LIB3270_ACTION( fieldend )
2940 #endif /*]*/ 2917 #endif /*]*/
2941 if (!formatted) 2918 if (!formatted)
2942 return 0; 2919 return 0;
2943 - baddr = cursor_addr; 2920 + baddr = h3270.cursor_addr;
2944 faddr = find_field_attribute(baddr); 2921 faddr = find_field_attribute(baddr);
2945 fa = ea_buf[faddr].fa; 2922 fa = ea_buf[faddr].fa;
2946 if (faddr == baddr || FA_IS_PROTECTED(fa)) 2923 if (faddr == baddr || FA_IS_PROTECTED(fa))
@@ -3314,7 +3291,7 @@ remargin(int lmargin) @@ -3314,7 +3291,7 @@ remargin(int lmargin)
3314 int faddr; 3291 int faddr;
3315 unsigned char fa; 3292 unsigned char fa;
3316 3293
3317 - baddr = cursor_addr; 3294 + baddr = h3270.cursor_addr;
3318 while (BA_TO_COL(baddr) < lmargin) { 3295 while (BA_TO_COL(baddr) < lmargin) {
3319 baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin); 3296 baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin);
3320 if (!ever) { 3297 if (!ever) {
@@ -3361,8 +3338,8 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) @@ -3361,8 +3338,8 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting)
3361 int literal = 0; 3338 int literal = 0;
3362 int nc = 0; 3339 int nc = 0;
3363 enum iaction ia = pasting ? IA_PASTE : IA_STRING; 3340 enum iaction ia = pasting ? IA_PASTE : IA_STRING;
3364 - int orig_addr = cursor_addr;  
3365 - int orig_col = BA_TO_COL(cursor_addr); 3341 + int orig_addr = h3270.cursor_addr;
  3342 + int orig_col = BA_TO_COL(h3270.cursor_addr);
3366 Boolean skipped = False; 3343 Boolean skipped = False;
3367 #if defined(X3270_DBCS) /*[*/ 3344 #if defined(X3270_DBCS) /*[*/
3368 unsigned char ebc[2]; 3345 unsigned char ebc[2];
@@ -3414,12 +3391,12 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) @@ -3414,12 +3391,12 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting)
3414 if (pasting && IN_3270) { 3391 if (pasting && IN_3270) {
3415 3392
3416 /* Check for cursor wrap to top of screen. */ 3393 /* Check for cursor wrap to top of screen. */
3417 - if (cursor_addr < orig_addr) 3394 + if (h3270.cursor_addr < orig_addr)
3418 return len-1; /* wrapped */ 3395 return len-1; /* wrapped */
3419 3396
3420 /* Jump cursor over left margin. */ 3397 /* Jump cursor over left margin. */
3421 if (toggled(MARGINED_PASTE) && 3398 if (toggled(MARGINED_PASTE) &&
3422 - BA_TO_COL(cursor_addr) < orig_col) { 3399 + BA_TO_COL(h3270.cursor_addr) < orig_col) {
3423 if (!remargin(orig_col)) 3400 if (!remargin(orig_col))
3424 return len-1; 3401 return len-1;
3425 skipped = True; 3402 skipped = True;
@@ -3718,7 +3695,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) @@ -3718,7 +3695,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting)
3718 switch (state) { 3695 switch (state) {
3719 case BASE: 3696 case BASE:
3720 if (toggled(MARGINED_PASTE) && 3697 if (toggled(MARGINED_PASTE) &&
3721 - BA_TO_COL(cursor_addr) < orig_col) { 3698 + BA_TO_COL(h3270.cursor_addr) < orig_col) {
3722 (void) remargin(orig_col); 3699 (void) remargin(orig_col);
3723 } 3700 }
3724 break; 3701 break;
@@ -3727,7 +3704,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) @@ -3727,7 +3704,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting)
3727 key_ACharacter((unsigned char) literal, KT_STD, ia, &skipped); 3704 key_ACharacter((unsigned char) literal, KT_STD, ia, &skipped);
3728 state = BASE; 3705 state = BASE;
3729 if (toggled(MARGINED_PASTE) && 3706 if (toggled(MARGINED_PASTE) &&
3730 - BA_TO_COL(cursor_addr) < orig_col) { 3707 + BA_TO_COL(h3270.cursor_addr) < orig_col) {
3731 (void) remargin(orig_col); 3708 (void) remargin(orig_col);
3732 } 3709 }
3733 break; 3710 break;
@@ -3880,13 +3857,13 @@ kybd_prime(void) @@ -3880,13 +3857,13 @@ kybd_prime(void)
3880 if (!formatted || kybdlock || !IN_3270) 3857 if (!formatted || kybdlock || !IN_3270)
3881 return 0; 3858 return 0;
3882 3859
3883 - fa = get_field_attribute(cursor_addr);  
3884 - if (ea_buf[cursor_addr].fa || FA_IS_PROTECTED(fa)) { 3860 + fa = get_field_attribute(h3270.cursor_addr);
  3861 + if (ea_buf[h3270.cursor_addr].fa || FA_IS_PROTECTED(fa)) {
3885 /* 3862 /*
3886 * The cursor is not in an unprotected field. Find the 3863 * The cursor is not in an unprotected field. Find the
3887 * next one. 3864 * next one.
3888 */ 3865 */
3889 - baddr = next_unprotected(cursor_addr); 3866 + baddr = next_unprotected(h3270.cursor_addr);
3890 3867
3891 /* If there isn't any, give up. */ 3868 /* If there isn't any, give up. */
3892 if (!baddr) 3869 if (!baddr)
@@ -3895,7 +3872,7 @@ kybd_prime(void) @@ -3895,7 +3872,7 @@ kybd_prime(void)
3895 /* Move the cursor there. */ 3872 /* Move the cursor there. */
3896 } else { 3873 } else {
3897 /* Already in an unprotected field. Find its start. */ 3874 /* Already in an unprotected field. Find its start. */
3898 - baddr = cursor_addr; 3875 + baddr = h3270.cursor_addr;
3899 while (!ea_buf[baddr].fa) { 3876 while (!ea_buf[baddr].fa) {
3900 DEC_BA(baddr); 3877 DEC_BA(baddr);
3901 } 3878 }
latest/src/lib/paste.c
@@ -101,7 +101,7 @@ @@ -101,7 +101,7 @@
101 101
102 if(toggled(MARGINED_PASTE)) 102 if(toggled(MARGINED_PASTE))
103 { 103 {
104 - baddr = cursor_addr; 104 + baddr = h3270.cursor_addr;
105 while(BA_TO_COL(baddr) < lmargin) 105 while(BA_TO_COL(baddr) < lmargin)
106 { 106 {
107 baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin); 107 baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin);
@@ -132,9 +132,9 @@ @@ -132,9 +132,9 @@
132 132
133 if(toggled(SMART_PASTE)) 133 if(toggled(SMART_PASTE))
134 { 134 {
135 - int faddr = find_field_attribute(cursor_addr); 135 + int faddr = find_field_attribute(h3270.cursor_addr);
136 if(FA_IS_PROTECTED(ea_buf[faddr].fa)) 136 if(FA_IS_PROTECTED(ea_buf[faddr].fa))
137 - cursor_addr++; 137 + h3270.cursor_addr++;
138 else 138 else
139 key_ACharacter(c, KT_STD, IA_PASTE, NULL); 139 key_ACharacter(c, KT_STD, IA_PASTE, NULL);
140 } 140 }
@@ -145,43 +145,39 @@ @@ -145,43 +145,39 @@
145 145
146 data->qtd++; 146 data->qtd++;
147 147
148 - if(BA_TO_ROW(cursor_addr) != data->row) 148 + if(BA_TO_ROW(h3270.cursor_addr) != data->row)
149 { 149 {
150 - Trace("Row changed from %d to %d",data->row,BA_TO_ROW(cursor_addr)); 150 + Trace("Row changed from %d to %d",data->row,BA_TO_ROW(h3270.cursor_addr));
151 if(!remargin(data->orig_col)) 151 if(!remargin(data->orig_col))
152 return 0; 152 return 0;
153 - data->row = BA_TO_ROW(cursor_addr); 153 + data->row = BA_TO_ROW(h3270.cursor_addr);
154 return '\n'; 154 return '\n';
155 } 155 }
156 156
157 return c; 157 return c;
158 } 158 }
159 159
160 -/**  
161 - * Paste string  
162 - *  
163 - * Returns are ignored; newlines mean "move to beginning of next line";  
164 - * tabs and formfeeds become spaces. Backslashes are not special  
165 - *  
166 - * @param s String to input.  
167 - *  
168 - * @Returns 0 if ok, negative if error or number of processed characters.  
169 - *  
170 - */  
171 -LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) 160 +LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str)
172 { 161 {
173 - PASTE_DATA data = { 0, BA_TO_ROW(cursor_addr), cursor_addr, BA_TO_COL(cursor_addr) }; 162 + PASTE_DATA data;
174 unsigned char last = 1; 163 unsigned char last = 1;
175 int baddr; 164 int baddr;
176 int faddr; 165 int faddr;
177 unsigned char fa; 166 unsigned char fa;
178 167
  168 + CHECK_SESSION_HANDLE(h);
  169 +
  170 + memset(&data,0,sizeof(data));
  171 + data.row = BA_TO_ROW(h->cursor_addr);
  172 + data.orig_addr = h->cursor_addr;
  173 + data.orig_col = BA_TO_COL(h->cursor_addr);
  174 +
179 if(kybdlock) 175 if(kybdlock)
180 return -EINVAL; 176 return -EINVAL;
181 177
182 screen_suspend(); 178 screen_suspend();
183 179
184 - while(*str && last && !kybdlock && cursor_addr >= data.orig_addr) 180 + while(*str && last && !kybdlock && h->cursor_addr >= data.orig_addr)
185 { 181 {
186 switch(*str) 182 switch(*str)
187 { 183 {
@@ -192,15 +188,15 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) @@ -192,15 +188,15 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str)
192 case '\n': 188 case '\n':
193 if(last != '\n') 189 if(last != '\n')
194 { 190 {
195 - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */  
196 - baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */ 191 + baddr = (h->cursor_addr + h->cols) % (h->cols * h->rows); /* down */
  192 + baddr = (baddr / h->cols) * h->cols; /* 1st col */
197 faddr = find_field_attribute(baddr); 193 faddr = find_field_attribute(baddr);
198 fa = ea_buf[faddr].fa; 194 fa = ea_buf[faddr].fa;
199 if (faddr != baddr && !FA_IS_PROTECTED(fa)) 195 if (faddr != baddr && !FA_IS_PROTECTED(fa))
200 cursor_move(baddr); 196 cursor_move(baddr);
201 else 197 else
202 cursor_move(next_unprotected(baddr)); 198 cursor_move(next_unprotected(baddr));
203 - data.row = BA_TO_ROW(cursor_addr); 199 + data.row = BA_TO_ROW(h->cursor_addr);
204 } 200 }
205 last = ' '; 201 last = ' ';
206 data.qtd++; 202 data.qtd++;
@@ -212,7 +208,7 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) @@ -212,7 +208,7 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str)
212 } 208 }
213 str++; 209 str++;
214 210
215 - if(IN_3270 && toggled(MARGINED_PASTE) && BA_TO_COL(cursor_addr) < data.orig_col) 211 + if(IN_3270 && toggled(MARGINED_PASTE) && BA_TO_COL(h->cursor_addr) < data.orig_col)
216 { 212 {
217 if(!remargin(data.orig_col)) 213 if(!remargin(data.orig_col))
218 last = 0; 214 last = 0;
latest/src/lib/screen.c
@@ -535,16 +535,16 @@ void screen_resume(void) @@ -535,16 +535,16 @@ void screen_resume(void)
535 535
536 int cursor_get_addr(void) 536 int cursor_get_addr(void)
537 { 537 {
538 - return cursor_addr; 538 + return h3270.cursor_addr;
539 } 539 }
540 540
541 int cursor_set_addr(int baddr) 541 int cursor_set_addr(int baddr)
542 { 542 {
543 - int ret = cursor_addr; 543 + int ret = h3270.cursor_addr;
544 544
545 - if(cursor_addr != baddr) 545 + if(h3270.cursor_addr != baddr)
546 { 546 {
547 - cursor_addr = baddr; 547 + h3270.cursor_addr = baddr;
548 548
549 if(callbacks && callbacks->move_cursor) 549 if(callbacks && callbacks->move_cursor)
550 callbacks->move_cursor(baddr/h3270.cols, baddr%h3270.cols); 550 callbacks->move_cursor(baddr/h3270.cols, baddr%h3270.cols);