diff --git a/latest/src/include/lib3270.h b/latest/src/include/lib3270.h index fed1b96..37dae11 100644 --- a/latest/src/include/lib3270.h +++ b/latest/src/include/lib3270.h @@ -106,5 +106,19 @@ LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h); + /** + * Set string at current cursor position. + * + * Returns are ignored; newlines mean "move to beginning of next line"; + * tabs and formfeeds become spaces. Backslashes are not special + * + * @param h Session handle. + * @param s String to input. + * + * @Returns Negative if error or number of processed characters. + * + */ + LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); + #endif // LIB3270_H_INCLUDED diff --git a/latest/src/include/lib3270/api.h b/latest/src/include/lib3270/api.h index f8fc1a3..84fe50d 100644 --- a/latest/src/include/lib3270/api.h +++ b/latest/src/include/lib3270/api.h @@ -203,6 +203,7 @@ int maxCOLS; int rows; int cols; + int cursor_addr; // Widget info void * widget; @@ -524,8 +525,8 @@ LIB3270_EXPORT void Input_String(const unsigned char *str); LIB3270_EXPORT void screen_size(int *rows, int *cols); LIB3270_EXPORT int query_secure_connection(H3270 *h); - LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str); + #define lib3270_paste_string(str) lib3270_set_string(NULL,str) #define get_3270_terminal_size(h,r,c) lib3270_get_screen_size(h,r,c) /* Keyboard */ diff --git a/latest/src/lib/ansi.c b/latest/src/lib/ansi.c index 44b3229..e85e2f2 100644 --- a/latest/src/lib/ansi.c +++ b/latest/src/lib/ansi.c @@ -499,7 +499,7 @@ dec_save_cursor(int ig1 unused, int ig2 unused) { int i; - saved_cursor = cursor_addr; + saved_cursor = h3270.cursor_addr; saved_cset = cset; for (i = 0; i < 4; i++) saved_csd[i] = csd[i]; @@ -530,8 +530,8 @@ ansi_newline(int ig1 unused, int ig2 unused) { int nc; - cursor_move(cursor_addr - (cursor_addr % h3270.cols)); - nc = cursor_addr + h3270.cols; + cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); + nc = h3270.cursor_addr + h3270.cols; if (nc < scroll_bottom * h3270.cols) cursor_move(nc); else @@ -547,11 +547,11 @@ ansi_cursor_up(int nn, int ig2 unused) if (nn < 1) nn = 1; - rr = cursor_addr / h3270.cols; + rr = h3270.cursor_addr / h3270.cols; if (rr - nn < 0) - cursor_move(cursor_addr % h3270.cols); + cursor_move(h3270.cursor_addr % h3270.cols); else - cursor_move(cursor_addr - (nn * h3270.cols)); + cursor_move(h3270.cursor_addr - (nn * h3270.cols)); held_wrap = False; return DATA; } @@ -619,7 +619,7 @@ ansi_reset(int ig1 unused, int ig2 unused) static enum state ansi_insert_chars(int nn, int ig2 unused) { - int cc = cursor_addr % h3270.cols; /* current col */ + int cc = h3270.cursor_addr % h3270.cols; /* current col */ int mc = h3270.cols - cc; /* max chars that can be inserted */ int ns; /* chars that are shifting */ @@ -631,10 +631,10 @@ ansi_insert_chars(int nn, int ig2 unused) /* Move the surviving chars right */ ns = mc - nn; if (ns) - ctlr_bcopy(cursor_addr, cursor_addr + nn, ns, 1); + ctlr_bcopy(h3270.cursor_addr, h3270.cursor_addr + nn, ns, 1); /* Clear the middle of the line */ - ctlr_aclear(cursor_addr, nn, 1); + ctlr_aclear(h3270.cursor_addr, nn, 1); return DATA; } @@ -645,11 +645,11 @@ ansi_cursor_down(int nn, int ig2 unused) if (nn < 1) nn = 1; - rr = cursor_addr / h3270.cols; + rr = h3270.cursor_addr / h3270.cols; if (rr + nn >= h3270.cols) - cursor_move((h3270.cols-1)*h3270.cols + (cursor_addr%h3270.cols)); + cursor_move((h3270.cols-1)*h3270.cols + (h3270.cursor_addr%h3270.cols)); else - cursor_move(cursor_addr + (nn * h3270.cols)); + cursor_move(h3270.cursor_addr + (nn * h3270.cols)); held_wrap = False; return DATA; } @@ -661,12 +661,12 @@ ansi_cursor_right(int nn, int ig2 unused) if (nn < 1) nn = 1; - cc = cursor_addr % h3270.cols; + cc = h3270.cursor_addr % h3270.cols; if (cc == h3270.cols-1) return DATA; if (cc + nn >= h3270.cols) nn = h3270.cols - 1 - cc; - cursor_move(cursor_addr + nn); + cursor_move(h3270.cursor_addr + nn); held_wrap = False; return DATA; } @@ -682,12 +682,12 @@ ansi_cursor_left(int nn, int ig2 unused) } if (nn < 1) nn = 1; - cc = cursor_addr % h3270.cols; + cc = h3270.cursor_addr % h3270.cols; if (!cc) return DATA; if (nn > cc) nn = cc; - cursor_move(cursor_addr - nn); + cursor_move(h3270.cursor_addr - nn); return DATA; } @@ -708,10 +708,10 @@ ansi_erase_in_display(int nn, int ig2 unused) { switch (nn) { case 0: /* below */ - ctlr_aclear(cursor_addr, (h3270.rows * h3270.cols) - cursor_addr, 1); + ctlr_aclear(h3270.cursor_addr, (h3270.rows * h3270.cols) - h3270.cursor_addr, 1); break; case 1: /* above */ - ctlr_aclear(0, cursor_addr + 1, 1); + ctlr_aclear(0, h3270.cursor_addr + 1, 1); break; case 2: /* all (without moving cursor) */ if (cursor_addr == 0 && !is_altbuffer) @@ -725,17 +725,17 @@ ansi_erase_in_display(int nn, int ig2 unused) static enum state ansi_erase_in_line(int nn, int ig2 unused) { - int nc = cursor_addr % h3270.cols; + int nc = h3270.cursor_addr % h3270.cols; switch (nn) { case 0: /* to right */ - ctlr_aclear(cursor_addr, h3270.cols - nc, 1); + ctlr_aclear(h3270.cursor_addr, h3270.cols - nc, 1); break; case 1: /* to left */ - ctlr_aclear(cursor_addr - nc, nc+1, 1); + ctlr_aclear(h3270.cursor_addr - nc, nc+1, 1); break; case 2: /* all */ - ctlr_aclear(cursor_addr - nc, h3270.cols, 1); + ctlr_aclear(h3270.cursor_addr - nc, h3270.cols, 1); break; } return DATA; @@ -744,7 +744,7 @@ ansi_erase_in_line(int nn, int ig2 unused) static enum state ansi_insert_lines(int nn, int ig2 unused) { - int rr = cursor_addr / h3270.cols; /* current row */ + int rr = h3270.cursor_addr / h3270.cols; /* current row */ int mr = scroll_bottom - rr; /* rows left at and below this one */ int ns; /* rows that are shifting */ @@ -770,7 +770,7 @@ ansi_insert_lines(int nn, int ig2 unused) static enum state ansi_delete_lines(int nn, int ig2 unused) { - int rr = cursor_addr / h3270.cols; /* current row */ + int rr = h3270.cursor_addr / h3270.cols; /* current row */ int mr = scroll_bottom - rr; /* max rows that can be deleted */ int ns; /* rows that are shifting */ @@ -796,7 +796,7 @@ ansi_delete_lines(int nn, int ig2 unused) static enum state ansi_delete_chars(int nn, int ig2 unused) { - int cc = cursor_addr % h3270.cols; /* current col */ + int cc = h3270.cursor_addr % h3270.cols; /* current col */ int mc = h3270.cols - cc; /* max chars that can be deleted */ int ns; /* chars that are shifting */ @@ -808,10 +808,10 @@ ansi_delete_chars(int nn, int ig2 unused) /* Move the surviving chars left */ ns = mc - nn; if (ns) - ctlr_bcopy(cursor_addr + nn, cursor_addr, ns, 1); + ctlr_bcopy(h3270.cursor_addr + nn, h3270.cursor_addr, ns, 1); /* Clear the end of the line */ - ctlr_aclear(cursor_addr + ns, nn, 1); + ctlr_aclear(h3270.cursor_addr + ns, nn, 1); return DATA; } @@ -936,11 +936,11 @@ ansi_backspace(int ig1 unused, int ig2 unused) return DATA; } if (rev_wraparound_mode) { - if (cursor_addr > (scroll_top - 1) * h3270.cols) - cursor_move(cursor_addr - 1); + if (h3270.cursor_addr > (scroll_top - 1) * h3270.cols) + cursor_move(h3270.cursor_addr - 1); } else { - if (cursor_addr % h3270.cols) - cursor_move(cursor_addr - 1); + if (h3270.cursor_addr % h3270.cols) + cursor_move(h3270.cursor_addr - 1); } return DATA; } @@ -948,8 +948,8 @@ ansi_backspace(int ig1 unused, int ig2 unused) static enum state ansi_cr(int ig1 unused, int ig2 unused) { - if (cursor_addr % h3270.cols) - cursor_move(cursor_addr - (cursor_addr % h3270.cols)); + if (h3270.cursor_addr % h3270.cols) + cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); if (auto_newline_mode) (void) ansi_lf(0, 0); held_wrap = False; @@ -959,12 +959,12 @@ ansi_cr(int ig1 unused, int ig2 unused) static enum state ansi_lf(int ig1 unused, int ig2 unused) { - int nc = cursor_addr + h3270.cols; + int nc = h3270.cursor_addr + h3270.cols; held_wrap = False; /* If we're below the scrolling region, don't scroll. */ - if ((cursor_addr / h3270.cols) >= scroll_bottom) { + if ((h3270.cursor_addr / h3270.cols) >= scroll_bottom) { if (nc < h3270.rows * h3270.cols) cursor_move(nc); return DATA; @@ -980,7 +980,7 @@ ansi_lf(int ig1 unused, int ig2 unused) static enum state ansi_htab(int ig1 unused, int ig2 unused) { - int col = cursor_addr % h3270.cols; + int col = h3270.cursor_addr % h3270.cols; int i; held_wrap = False; @@ -989,7 +989,7 @@ ansi_htab(int ig1 unused, int ig2 unused) for (i = col+1; i < h3270.cols-1; i++) if (tabs[i/8] & 1<<(i%8)) break; - cursor_move(cursor_addr - col + i); + cursor_move(h3270.cursor_addr - col + i); return DATA; } @@ -1006,12 +1006,12 @@ ansi_nop(int ig1 unused, int ig2 unused) } #define PWRAP { \ - nc = cursor_addr + 1; \ + nc = h3270.cursor_addr + 1; \ if (nc < scroll_bottom * h3270.cols) \ cursor_move(nc); \ else { \ - if (cursor_addr / h3270.cols >= scroll_bottom) \ - cursor_move(cursor_addr / h3270.cols * h3270.cols); \ + if (h3270.cursor_addr / h3270.cols >= scroll_bottom) \ + cursor_move(h3270.cursor_addr / h3270.cols * h3270.cols); \ else { \ ansi_scroll(); \ cursor_move(nc - h3270.cols); \ @@ -1070,16 +1070,16 @@ ansi_printing(int ig1 unused, int ig2 unused) switch (csd[(once_cset != -1) ? once_cset : cset]) { case CSD_LD: /* line drawing "0" */ if (ansi_ch >= 0x5f && ansi_ch <= 0x7e) - ctlr_add(cursor_addr, (unsigned char)(ansi_ch - 0x5f), + ctlr_add(h3270.cursor_addr, (unsigned char)(ansi_ch - 0x5f), CS_LINEDRAW); else - ctlr_add(cursor_addr, asc2ebc[ansi_ch], CS_BASE); + ctlr_add(h3270.cursor_addr, asc2ebc[ansi_ch], CS_BASE); break; case CSD_UK: /* UK "A" */ if (ansi_ch == '#') - ctlr_add(cursor_addr, 0x1e, CS_LINEDRAW); + ctlr_add(h3270.cursor_addr, 0x1e, CS_LINEDRAW); else - ctlr_add(cursor_addr, asc2ebc[ansi_ch], CS_BASE); + ctlr_add(h3270.cursor_addr, asc2ebc[ansi_ch], CS_BASE); break; case CSD_US: /* US "B" */ ebc_ch = asc2ebc[ansi_ch]; @@ -1157,7 +1157,7 @@ ansi_printing(int ig1 unused, int ig2 unused) ea_buf[cursor_addr].db = DBCS_NONE; } #endif /*]*/ - ctlr_add(cursor_addr, ebc_ch, default_cs); + ctlr_add(h3270.cursor_addr, ebc_ch, default_cs); #if defined(X3270_DBCS) /*[*/ if (default_cs == CS_DBCS) (void) ctlr_dbcs_postprocess(); @@ -1165,9 +1165,9 @@ ansi_printing(int ig1 unused, int ig2 unused) break; } once_cset = -1; - ctlr_add_gr(cursor_addr, gr); - ctlr_add_fg(cursor_addr, fg); - ctlr_add_bg(cursor_addr, bg); + ctlr_add_gr(h3270.cursor_addr, gr); + ctlr_add_fg(h3270.cursor_addr, fg); + ctlr_add_bg(h3270.cursor_addr, bg); if (wraparound_mode) { /* * There is a fascinating behavior of xterm which we will @@ -1182,14 +1182,14 @@ ansi_printing(int ig1 unused, int ig2 unused) * In my opinion, very strange, but among other things, 'vi' * depends on it! */ - if (!((cursor_addr + 1) % h3270.cols)) { + if (!((h3270.cursor_addr + 1) % h3270.cols)) { held_wrap = True; } else { PWRAP; } } else { - if ((cursor_addr % h3270.cols) != (h3270.cols - 1)) - cursor_move(cursor_addr + 1); + if ((h3270.cursor_addr % h3270.cols) != (h3270.cols - 1)) + cursor_move(h3270.cursor_addr + 1); } return DATA; } @@ -1259,7 +1259,7 @@ ansi_digit(int ig1 unused, int ig2 unused) static enum state ansi_reverse_index(int ig1 unused, int ig2 unused) { - int rr = cursor_addr / h3270.cols; /* current row */ + int rr = h3270.cursor_addr / h3270.cols; /* current row */ int np = (scroll_top - 1) - rr; /* number of rows in the scrolling region, above this line */ int ns; /* number of rows to scroll */ @@ -1345,7 +1345,7 @@ ansi_status_report(int nn, int ig2 unused) break; case 6: (void) sprintf(cpr, "\033[%d;%dR", - (cursor_addr/h3270.cols) + 1, (cursor_addr%h3270.cols) + 1); + (h3270.cursor_addr/h3270.cols) + 1, (h3270.cursor_addr%h3270.cols) + 1); net_sends(cpr); break; } @@ -1630,7 +1630,7 @@ xterm_text_do(int ig1 unused, int ig2 unused) static enum state ansi_htab_set(int ig1 unused, int ig2 unused) { - register int col = cursor_addr % h3270.cols; + register int col = h3270.cursor_addr % h3270.cols; tabs[col/8] |= 1<<(col%8); return DATA; @@ -1643,7 +1643,7 @@ ansi_htab_clear(int nn, int ig2 unused) switch (nn) { case 0: - col = cursor_addr % h3270.cols; + col = h3270.cursor_addr % h3270.cols; tabs[col/8] &= ~(1<<(col%8)); break; case 3: diff --git a/latest/src/lib/ctlr.c b/latest/src/lib/ctlr.c index 73635fe..1aee5f5 100644 --- a/latest/src/lib/ctlr.c +++ b/latest/src/lib/ctlr.c @@ -74,8 +74,9 @@ extern unsigned char aid; // int ROWS, COLS; //int maxROWS = 0; //int maxCOLS = 0; +// int cursor_addr; -int cursor_addr, buffer_addr; +int buffer_addr; Boolean screen_alt = False; /* alternate screen? */ Boolean is_altbuffer = False; @@ -174,7 +175,7 @@ void ctlr_reinit(H3270 *session, unsigned cmask) real_aea_buf = (struct ea *)Calloc(sizeof(struct ea),(session->maxROWS * session->maxCOLS) + 1); aea_buf = real_aea_buf + 1; Replace(zero_buf, (unsigned char *)Calloc(sizeof(struct ea),session->maxROWS * session->maxCOLS)); - cursor_addr = 0; + session->cursor_addr = 0; buffer_addr = 0; } } @@ -676,8 +677,8 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) trace_ds("%s",see_aid(aid_byte)); if (short_read) goto rm_done; - ENCODE_BADDR(obptr, cursor_addr); - trace_ds("%s",rcba(cursor_addr)); + ENCODE_BADDR(obptr, h3270.cursor_addr); + trace_ds("%s",rcba(h3270.cursor_addr)); } else { space3270out(1); /* just in case */ } @@ -820,8 +821,8 @@ ctlr_read_buffer(unsigned char aid_byte) space3270out(3); *obptr++ = aid_byte; - ENCODE_BADDR(obptr, cursor_addr); - trace_ds("%s%s", see_aid(aid_byte), rcba(cursor_addr)); + ENCODE_BADDR(obptr, h3270.cursor_addr); + trace_ds("%s%s", see_aid(aid_byte), rcba(h3270.cursor_addr)); baddr = 0; do { @@ -1018,7 +1019,7 @@ ctlr_snap_buffer(void) space3270out(4); *obptr++ = ORDER_SBA; - ENCODE_BADDR(obptr, cursor_addr); + ENCODE_BADDR(obptr, h3270.cursor_addr); *obptr++ = ORDER_IC; } @@ -1165,7 +1166,7 @@ ctlr_write(unsigned char buf[], int buflen, Boolean erase) default_cs = 0; default_ic = 0; trace_primed = True; - buffer_addr = cursor_addr; + buffer_addr = h3270.cursor_addr; if (WCC_RESET(buf[1])) { if (erase) reply_mode = SF_SRM_FIELD; @@ -2745,12 +2746,14 @@ static void keep_ticking(H3270 *session) struct timeval t1; long msec; - do { + do + { (void) gettimeofday(&t1, (struct timezone *) 0); t_want.tv_sec++; msec = delta_msec(&t_want, &t1); } while (msec <= 0); - tick_id = AddTimeOut(msec, &h3270, keep_ticking); + + tick_id = AddTimeOut(msec, session, keep_ticking); status_timing(&t_start, &t1); } diff --git a/latest/src/lib/globals.h b/latest/src/lib/globals.h index aff9c28..01f8f90 100644 --- a/latest/src/lib/globals.h +++ b/latest/src/lib/globals.h @@ -130,6 +130,8 @@ /* Stop conflicting with curses' COLS, even if we don't link with it. */ // #define COLS cCOLS +#define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270; + /* types of internal actions */ enum iaction { diff --git a/latest/src/lib/kybd.c b/latest/src/lib/kybd.c index ddea330..76a5eb8 100644 --- a/latest/src/lib/kybd.c +++ b/latest/src/lib/kybd.c @@ -511,7 +511,7 @@ key_AID(unsigned char aid_code) plugin_aid(aid_code); #endif /*]*/ - Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,cursor_addr); + Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr); if (IN_SSCP) { if (kybdlock & KL_OIA_MINUS) @@ -524,7 +524,7 @@ key_AID(unsigned char aid_code) } if (IN_SSCP && aid_code == AID_ENTER) { /* Act as if the host had written our input. */ - buffer_addr = cursor_addr; + buffer_addr = h3270.cursor_addr; } if (!IN_SSCP || aid_code != AID_CLEAR) { status_twait(); @@ -765,7 +765,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) enq_ta(key_Character_wrapper, codename, CN); return False; } - baddr = cursor_addr; + baddr = h3270.cursor_addr; faddr = find_field_attribute(baddr); fa = get_field_attribute(baddr); if (ea_buf[baddr].fa || FA_IS_PROTECTED(fa)) { @@ -953,7 +953,7 @@ key_Character(int code, Boolean with_ge, Boolean pasting, Boolean *skipped) } } - mdt_set(cursor_addr); + mdt_set(h3270.cursor_addr); /* * Implement auto-skip, and don't land on attribute bytes. @@ -1437,7 +1437,7 @@ LIB3270_KEY_ACTION( tab ) return 0; } #endif /*]*/ - cursor_move(next_unprotected(cursor_addr)); + cursor_move(next_unprotected(h3270.cursor_addr)); return 0; } @@ -1463,7 +1463,7 @@ LIB3270_KEY_ACTION( backtab ) } if (!IN_3270) return 0; - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); if (ea_buf[baddr].fa) /* at bof */ DEC_BA(baddr); @@ -1621,7 +1621,7 @@ do_left(void) register int baddr; enum dbcs_state d; - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); d = ctlr_dbcs_state(baddr); if (IS_LEFT(d)) @@ -1666,7 +1666,7 @@ LIB3270_CURSOR_ACTION( left ) { register int baddr; - baddr = cursor_addr; + baddr = h3270.cursor_addr; INC_BA(baddr); /* XXX: DBCS? */ cursor_move(baddr); @@ -1688,7 +1688,7 @@ do_delete(void) int ndel; register int i; - baddr = cursor_addr; + baddr = h3270.cursor_addr; /* Can't delete a field attribute. */ fa = get_field_attribute(baddr); @@ -1748,7 +1748,7 @@ do_delete(void) ctlr_add(end_baddr - i, EBC_null, 0); /* Set the MDT for this field. */ - mdt_set(cursor_addr); + mdt_set(h3270.cursor_addr); /* Patch up the DBCS state for display. */ (void) ctlr_dbcs_postprocess(); @@ -1806,7 +1806,7 @@ LIB3270_ACTION( backspace ) else { register int baddr; - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); cursor_move(baddr); } @@ -1824,7 +1824,7 @@ do_erase(void) int baddr, faddr; enum dbcs_state d; - baddr = cursor_addr; + baddr = h3270.cursor_addr; faddr = find_field_attribute(baddr); if (faddr == baddr || FA_IS_PROTECTED(ea_buf[baddr].fa)) { operator_error(KL_OERR_PROTECTED); @@ -1837,8 +1837,8 @@ do_erase(void) /* * If we are now on an SI, move left again. */ - if (ea_buf[cursor_addr].cc == EBC_si) { - baddr = cursor_addr; + if (ea_buf[h3270.cursor_addr].cc == EBC_si) { + baddr = h3270.cursor_addr; DEC_BA(baddr); cursor_move(baddr); } @@ -1866,9 +1866,9 @@ do_erase(void) * If we've just erased the last character of a DBCS subfield, erase * the SO/SI pair as well. */ - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); - if (ea_buf[baddr].cc == EBC_so && ea_buf[cursor_addr].cc == EBC_si) { + if (ea_buf[baddr].cc == EBC_so && ea_buf[h3270.cursor_addr].cc == EBC_si) { cursor_move(baddr); (void) do_delete(); } @@ -1921,7 +1921,7 @@ LIB3270_CURSOR_ACTION( right ) #endif /*]*/ if (!flipped) { - baddr = cursor_addr; + baddr = h3270.cursor_addr; INC_BA(baddr); d = ctlr_dbcs_state(baddr); if (IS_RIGHT(d)) @@ -1996,7 +1996,7 @@ LIB3270_ACTION( previousword ) if (!formatted) return 0; - baddr = cursor_addr; + baddr = h3270.cursor_addr; prot = FA_IS_PROTECTED(get_field_attribute(baddr)); /* Skip to before this word, if in one now. */ @@ -2004,7 +2004,7 @@ LIB3270_ACTION( previousword ) c = ea_buf[baddr].cc; while (!ea_buf[baddr].fa && c != EBC_space && c != EBC_null) { DEC_BA(baddr); - if (baddr == cursor_addr) + if (baddr == h3270.cursor_addr) return 0; c = ea_buf[baddr].cc; } @@ -2148,25 +2148,25 @@ LIB3270_ACTION( nextword ) return 0; /* If not in an unprotected field, go to the next unprotected word. */ - if (ea_buf[cursor_addr].fa || - FA_IS_PROTECTED(get_field_attribute(cursor_addr))) { - baddr = nu_word(cursor_addr); + if (ea_buf[h3270.cursor_addr].fa || + FA_IS_PROTECTED(get_field_attribute(h3270.cursor_addr))) { + baddr = nu_word(h3270.cursor_addr); if (baddr != -1) cursor_move(baddr); return 0; } /* If there's another word in this field, go to it. */ - baddr = nt_word(cursor_addr); + baddr = nt_word(h3270.cursor_addr); if (baddr != -1) { cursor_move(baddr); return 0; } /* If in a word, go to just after its end. */ - c = ea_buf[cursor_addr].cc; + c = ea_buf[h3270.cursor_addr].cc; if (c != EBC_space && c != EBC_null) { - baddr = cursor_addr; + baddr = h3270.cursor_addr; do { c = ea_buf[baddr].cc; if (c == EBC_space || c == EBC_null) { @@ -2179,11 +2179,11 @@ LIB3270_ACTION( nextword ) return 0; } INC_BA(baddr); - } while (baddr != cursor_addr); + } while (baddr != h3270.cursor_addr); } /* Otherwise, go to the next unprotected word. */ else { - baddr = nu_word(cursor_addr); + baddr = nu_word(h3270.cursor_addr); if (baddr != -1) cursor_move(baddr); } @@ -2231,9 +2231,9 @@ LIB3270_CURSOR_ACTION( up ) return 0; } #endif /*]*/ - baddr = cursor_addr - h3270.cols; + baddr = h3270.cursor_addr - h3270.cols; if (baddr < 0) - baddr = (cursor_addr + (h3270.rows * h3270.cols)) - h3270.cols; + baddr = (h3270.cursor_addr + (h3270.rows * h3270.cols)) - h3270.cols; cursor_move(baddr); return 0; } @@ -2280,7 +2280,7 @@ LIB3270_CURSOR_ACTION( down ) return 0; } #endif /*]*/ - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); + baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); cursor_move(baddr); return 0; } @@ -2308,7 +2308,7 @@ LIB3270_CURSOR_ACTION( newline ) return 0; } #endif /*]*/ - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */ + baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */ baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */ faddr = find_field_attribute(baddr); fa = ea_buf[faddr].fa; @@ -2337,7 +2337,7 @@ Dup_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) return; #endif /*]*/ if (key_Character(EBC_dup, False, False, NULL)) - cursor_move(next_unprotected(cursor_addr)); + cursor_move(next_unprotected(h3270.cursor_addr)); } @@ -2542,29 +2542,6 @@ CursorSelect_action(Widget w unused, XEvent *event, String *params, } */ -#if defined(X3270_DISPLAY) -/* - * Cursor Select mouse action (light pen simulator). - */ -/* -void -MouseSelect_action(Widget w, XEvent *event, String *params, - Cardinal *num_params) -{ - if (w != *screen) - return; -// reset_idle_timer(); - if (kybdlock) - return; -#if defined(X3270_ANSI) - if (IN_ANSI) - return; -#endif - lightpen_select(mouse_baddr(w, event)); -} -*/ -#endif - /** * Erase End Of Line Key. * @@ -2587,7 +2564,7 @@ LIB3270_ACTION( eraseeol ) return 0; #endif /*]*/ - baddr = cursor_addr; + baddr = h3270.cursor_addr; fa = get_field_attribute(baddr); if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) { @@ -2604,7 +2581,7 @@ LIB3270_ACTION( eraseeol ) INC_BA(baddr); } while (!ea_buf[baddr].fa && BA_TO_COL(baddr) > 0); - mdt_set(cursor_addr); + mdt_set(h3270.cursor_addr); } else { @@ -2652,7 +2629,7 @@ LIB3270_ACTION( eraseeof ) if (IN_ANSI) return 0; #endif /*]*/ - baddr = cursor_addr; + baddr = h3270.cursor_addr; fa = get_field_attribute(baddr); if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) { operator_error(KL_OERR_PROTECTED); @@ -2663,7 +2640,7 @@ LIB3270_ACTION( eraseeof ) ctlr_add(baddr, EBC_null, 0); INC_BA(baddr); } while (!ea_buf[baddr].fa); - mdt_set(cursor_addr); + mdt_set(h3270.cursor_addr); } else { /* erase to end of screen */ do { ctlr_add(baddr, EBC_null, 0); @@ -2770,7 +2747,7 @@ LIB3270_ACTION( deleteword ) if (!formatted) return 0; - baddr = cursor_addr; + baddr = h3270.cursor_addr; fa = get_field_attribute(baddr); /* Make sure we're on a modifiable field. */ @@ -2781,7 +2758,7 @@ LIB3270_ACTION( deleteword ) /* Backspace over any spaces to the left of the cursor. */ for (;;) { - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); if (ea_buf[baddr].fa) return 0; @@ -2794,7 +2771,7 @@ LIB3270_ACTION( deleteword ) /* Backspace until the character to the left of the cursor is blank. */ for (;;) { - baddr = cursor_addr; + baddr = h3270.cursor_addr; DEC_BA(baddr); if (ea_buf[baddr].fa) return 0; @@ -2837,7 +2814,7 @@ LIB3270_ACTION( deletefield ) if (!formatted) return 0; - baddr = cursor_addr; + baddr = h3270.cursor_addr; fa = get_field_attribute(baddr); if (FA_IS_PROTECTED(fa) || ea_buf[baddr].fa) { operator_error(KL_OERR_PROTECTED); @@ -2846,7 +2823,7 @@ LIB3270_ACTION( deletefield ) while (!ea_buf[baddr].fa) DEC_BA(baddr); INC_BA(baddr); - mdt_set(cursor_addr); + mdt_set(h3270.cursor_addr); cursor_move(baddr); while (!ea_buf[baddr].fa) { ctlr_add(baddr, EBC_null, 0); @@ -2940,7 +2917,7 @@ LIB3270_ACTION( fieldend ) #endif /*]*/ if (!formatted) return 0; - baddr = cursor_addr; + baddr = h3270.cursor_addr; faddr = find_field_attribute(baddr); fa = ea_buf[faddr].fa; if (faddr == baddr || FA_IS_PROTECTED(fa)) @@ -3314,7 +3291,7 @@ remargin(int lmargin) int faddr; unsigned char fa; - baddr = cursor_addr; + baddr = h3270.cursor_addr; while (BA_TO_COL(baddr) < lmargin) { baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin); if (!ever) { @@ -3361,8 +3338,8 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) int literal = 0; int nc = 0; enum iaction ia = pasting ? IA_PASTE : IA_STRING; - int orig_addr = cursor_addr; - int orig_col = BA_TO_COL(cursor_addr); + int orig_addr = h3270.cursor_addr; + int orig_col = BA_TO_COL(h3270.cursor_addr); Boolean skipped = False; #if defined(X3270_DBCS) /*[*/ unsigned char ebc[2]; @@ -3414,12 +3391,12 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) if (pasting && IN_3270) { /* Check for cursor wrap to top of screen. */ - if (cursor_addr < orig_addr) + if (h3270.cursor_addr < orig_addr) return len-1; /* wrapped */ /* Jump cursor over left margin. */ if (toggled(MARGINED_PASTE) && - BA_TO_COL(cursor_addr) < orig_col) { + BA_TO_COL(h3270.cursor_addr) < orig_col) { if (!remargin(orig_col)) return len-1; skipped = True; @@ -3718,7 +3695,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) switch (state) { case BASE: if (toggled(MARGINED_PASTE) && - BA_TO_COL(cursor_addr) < orig_col) { + BA_TO_COL(h3270.cursor_addr) < orig_col) { (void) remargin(orig_col); } break; @@ -3727,7 +3704,7 @@ LIB3270_EXPORT int emulate_input(char *s, int len, int pasting) key_ACharacter((unsigned char) literal, KT_STD, ia, &skipped); state = BASE; if (toggled(MARGINED_PASTE) && - BA_TO_COL(cursor_addr) < orig_col) { + BA_TO_COL(h3270.cursor_addr) < orig_col) { (void) remargin(orig_col); } break; @@ -3880,13 +3857,13 @@ kybd_prime(void) if (!formatted || kybdlock || !IN_3270) return 0; - fa = get_field_attribute(cursor_addr); - if (ea_buf[cursor_addr].fa || FA_IS_PROTECTED(fa)) { + fa = get_field_attribute(h3270.cursor_addr); + if (ea_buf[h3270.cursor_addr].fa || FA_IS_PROTECTED(fa)) { /* * The cursor is not in an unprotected field. Find the * next one. */ - baddr = next_unprotected(cursor_addr); + baddr = next_unprotected(h3270.cursor_addr); /* If there isn't any, give up. */ if (!baddr) @@ -3895,7 +3872,7 @@ kybd_prime(void) /* Move the cursor there. */ } else { /* Already in an unprotected field. Find its start. */ - baddr = cursor_addr; + baddr = h3270.cursor_addr; while (!ea_buf[baddr].fa) { DEC_BA(baddr); } diff --git a/latest/src/lib/paste.c b/latest/src/lib/paste.c index ef4843e..ea6e756 100644 --- a/latest/src/lib/paste.c +++ b/latest/src/lib/paste.c @@ -101,7 +101,7 @@ if(toggled(MARGINED_PASTE)) { - baddr = cursor_addr; + baddr = h3270.cursor_addr; while(BA_TO_COL(baddr) < lmargin) { baddr = ROWCOL_TO_BA(BA_TO_ROW(baddr), lmargin); @@ -132,9 +132,9 @@ if(toggled(SMART_PASTE)) { - int faddr = find_field_attribute(cursor_addr); + int faddr = find_field_attribute(h3270.cursor_addr); if(FA_IS_PROTECTED(ea_buf[faddr].fa)) - cursor_addr++; + h3270.cursor_addr++; else key_ACharacter(c, KT_STD, IA_PASTE, NULL); } @@ -145,43 +145,39 @@ data->qtd++; - if(BA_TO_ROW(cursor_addr) != data->row) + if(BA_TO_ROW(h3270.cursor_addr) != data->row) { - Trace("Row changed from %d to %d",data->row,BA_TO_ROW(cursor_addr)); + Trace("Row changed from %d to %d",data->row,BA_TO_ROW(h3270.cursor_addr)); if(!remargin(data->orig_col)) return 0; - data->row = BA_TO_ROW(cursor_addr); + data->row = BA_TO_ROW(h3270.cursor_addr); return '\n'; } return c; } -/** - * Paste string - * - * Returns are ignored; newlines mean "move to beginning of next line"; - * tabs and formfeeds become spaces. Backslashes are not special - * - * @param s String to input. - * - * @Returns 0 if ok, negative if error or number of processed characters. - * - */ -LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) +LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) { - PASTE_DATA data = { 0, BA_TO_ROW(cursor_addr), cursor_addr, BA_TO_COL(cursor_addr) }; + PASTE_DATA data; unsigned char last = 1; int baddr; int faddr; unsigned char fa; + CHECK_SESSION_HANDLE(h); + + memset(&data,0,sizeof(data)); + data.row = BA_TO_ROW(h->cursor_addr); + data.orig_addr = h->cursor_addr; + data.orig_col = BA_TO_COL(h->cursor_addr); + if(kybdlock) return -EINVAL; screen_suspend(); - while(*str && last && !kybdlock && cursor_addr >= data.orig_addr) + while(*str && last && !kybdlock && h->cursor_addr >= data.orig_addr) { switch(*str) { @@ -192,15 +188,15 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) case '\n': if(last != '\n') { - baddr = (cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */ - baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */ + baddr = (h->cursor_addr + h->cols) % (h->cols * h->rows); /* down */ + baddr = (baddr / h->cols) * h->cols; /* 1st col */ faddr = find_field_attribute(baddr); fa = ea_buf[faddr].fa; if (faddr != baddr && !FA_IS_PROTECTED(fa)) cursor_move(baddr); else cursor_move(next_unprotected(baddr)); - data.row = BA_TO_ROW(cursor_addr); + data.row = BA_TO_ROW(h->cursor_addr); } last = ' '; data.qtd++; @@ -212,7 +208,7 @@ LIB3270_EXPORT int lib3270_paste_string(const unsigned char *str) } str++; - if(IN_3270 && toggled(MARGINED_PASTE) && BA_TO_COL(cursor_addr) < data.orig_col) + if(IN_3270 && toggled(MARGINED_PASTE) && BA_TO_COL(h->cursor_addr) < data.orig_col) { if(!remargin(data.orig_col)) last = 0; diff --git a/latest/src/lib/screen.c b/latest/src/lib/screen.c index f24414d..02cac69 100644 --- a/latest/src/lib/screen.c +++ b/latest/src/lib/screen.c @@ -535,16 +535,16 @@ void screen_resume(void) int cursor_get_addr(void) { - return cursor_addr; + return h3270.cursor_addr; } int cursor_set_addr(int baddr) { - int ret = cursor_addr; + int ret = h3270.cursor_addr; - if(cursor_addr != baddr) + if(h3270.cursor_addr != baddr) { - cursor_addr = baddr; + h3270.cursor_addr = baddr; if(callbacks && callbacks->move_cursor) callbacks->move_cursor(baddr/h3270.cols, baddr%h3270.cols); -- libgit2 0.21.2